Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 9c30402

Browse files
d0iasmmoz-wptsync-bot
authored andcommitted
Bug 1678507 [wpt PR 26584] - Use async/await in claim-worker-fetch, a=testonly
Automatic update from web-platform-tests Use async/await in claim-worker-fetch This CL just updates a WPT (clim-worker-fetch.https.html) to use async/await instead of Promise/then(). This doesn't add a test nor change the test result. Change-Id: I042d0947b4593825fc58fb00dc9537cc0e102c3a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550101 Commit-Queue: Asami Doi <[email protected]> Reviewed-by: Makoto Shimazu <[email protected]> Cr-Commit-Position: refs/heads/master@{#829600} -- wpt-commits: 16d2dd4febb588e7174d0637f1211b040cd0bbab wpt-pr: 26584
1 parent 5b61219 commit 9c30402

File tree

1 file changed

+43
-56
lines changed

1 file changed

+43
-56
lines changed

testing/web-platform/tests/service-workers/service-worker/claim-worker-fetch.https.html

Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,64 @@
77
<body>
88
<script>
99

10-
promise_test(function(t) {
10+
promise_test((t) => {
1111
return runTest(t, 'resources/claim-worker-fetch-iframe.html');
1212
}, 'fetch() in Worker should be intercepted after the client is claimed.');
1313

14-
promise_test(function(t) {
14+
promise_test((t) => {
1515
return runTest(t, 'resources/claim-nested-worker-fetch-iframe.html');
1616
}, 'fetch() in nested Worker should be intercepted after the client is claimed.');
1717

18-
promise_test(function(t) {
18+
promise_test((t) => {
1919
return runTest(t, 'resources/claim-blob-url-worker-fetch-iframe.html');
2020
}, 'fetch() in blob URL Worker should be intercepted after the client is claimed.');
2121

22-
function runTest(t, iframe_url) {
23-
var resource = 'simple.txt';
22+
async function runTest(t, iframe_url) {
23+
const resource = 'simple.txt';
24+
const scope = 'resources/';
25+
const script = 'resources/claim-worker.js';
2426

25-
var frame;
26-
var registration;
27-
var worker;
28-
var scope = 'resources/';
29-
var script = 'resources/claim-worker.js';
27+
// Create the test iframe with a dedicated worker.
28+
const frame = await with_iframe(iframe_url);
29+
t.add_cleanup(_ => frame.remove());
3030

31-
return Promise.resolve()
32-
// Create the test iframe with a dedicated worker.
33-
.then(() => with_iframe(iframe_url))
34-
.then(f => {
35-
t.add_cleanup(() => f.remove());
36-
frame = f;
37-
})
31+
// Check the controller and test with fetch in the worker.
32+
assert_equals(frame.contentWindow.navigator.controller,
33+
undefined, 'Should have no controller.');
34+
{
35+
const response_text = await frame.contentWindow.fetch_in_worker(resource);
36+
assert_equals(response_text, 'a simple text file\n',
37+
'fetch() should not be intercepted.');
38+
}
3839

39-
// Check the controller and test with fetch in the worker.
40-
.then(() => assert_equals(frame.contentWindow.navigator.controller,
41-
undefined,
42-
'Should have no controller.'))
43-
.then(() => frame.contentWindow.fetch_in_worker(resource))
44-
.then(response_text => assert_equals(response_text,
45-
'a simple text file\n',
46-
'fetch() should not be intercepted.'))
47-
// Register a service worker.
48-
.then(() => service_worker_unregister_and_register(t, script, scope))
49-
.then(r => {
50-
t.add_cleanup(() => r.unregister());
51-
worker = r.installing;
52-
})
53-
.then(() => wait_for_state(t, worker, 'activated'))
40+
// Register a service worker.
41+
const reg = await service_worker_unregister_and_register(t, script, scope);
42+
t.add_cleanup(_ => reg.unregister());
43+
await wait_for_state(t, reg.installing, 'activated');
5444

55-
// Let the service worker claim the iframe and the worker.
56-
.then(() => {
57-
var channel = new MessageChannel();
58-
var saw_message = new Promise(function(resolve) {
59-
channel.port1.onmessage = t.step_func(function(e) {
60-
assert_equals(e.data, 'PASS',
61-
'Worker call to claim() should fulfill.');
62-
resolve();
63-
});
64-
});
65-
worker.postMessage({port: channel.port2}, [channel.port2]);
66-
return saw_message;
67-
})
45+
// Let the service worker claim the iframe and the worker.
46+
const channel = new MessageChannel();
47+
const saw_message = new Promise(function(resolve) {
48+
channel.port1.onmessage = t.step_func(function(e) {
49+
assert_equals(e.data, 'PASS', 'Worker call to claim() should fulfill.');
50+
resolve();
51+
});
52+
});
53+
reg.active.postMessage({port: channel.port2}, [channel.port2]);
54+
await saw_message;
6855

69-
// Check the controller and test with fetch in the worker.
70-
.then(() => frame.contentWindow.navigator.serviceWorker.getRegistration(scope))
71-
.then(r => registration = r)
72-
.then(() => assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
73-
registration.active,
74-
'Test iframe should be claimed.'))
56+
// Check the controller and test with fetch in the worker.
57+
const reg2 =
58+
await frame.contentWindow.navigator.serviceWorker.getRegistration(scope);
59+
assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
60+
reg2.active, 'Test iframe should be claimed.');
61+
62+
{
7563
// TODO(horo): Check the worker's navigator.seviceWorker.controller.
76-
.then(() => frame.contentWindow.fetch_in_worker(resource))
77-
.then(response_text =>
78-
assert_equals(response_text,
79-
'Intercepted!',
80-
'fetch() in the worker should be intercepted.'));
64+
const response_text = await frame.contentWindow.fetch_in_worker(resource);
65+
assert_equals(response_text, 'Intercepted!',
66+
'fetch() in the worker should be intercepted.');
67+
}
8168
}
8269

8370
</script>

0 commit comments

Comments
 (0)