|
7 | 7 | <body>
|
8 | 8 | <script>
|
9 | 9 |
|
10 |
| -promise_test(function(t) { |
| 10 | +promise_test((t) => { |
11 | 11 | return runTest(t, 'resources/claim-worker-fetch-iframe.html');
|
12 | 12 | }, 'fetch() in Worker should be intercepted after the client is claimed.');
|
13 | 13 |
|
14 |
| -promise_test(function(t) { |
| 14 | +promise_test((t) => { |
15 | 15 | return runTest(t, 'resources/claim-nested-worker-fetch-iframe.html');
|
16 | 16 | }, 'fetch() in nested Worker should be intercepted after the client is claimed.');
|
17 | 17 |
|
18 |
| -promise_test(function(t) { |
| 18 | +promise_test((t) => { |
19 | 19 | return runTest(t, 'resources/claim-blob-url-worker-fetch-iframe.html');
|
20 | 20 | }, 'fetch() in blob URL Worker should be intercepted after the client is claimed.');
|
21 | 21 |
|
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'; |
24 | 26 |
|
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()); |
30 | 30 |
|
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 | + } |
38 | 39 |
|
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'); |
54 | 44 |
|
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; |
68 | 55 |
|
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 | + { |
75 | 63 | // 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 | + } |
81 | 68 | }
|
82 | 69 |
|
83 | 70 | </script>
|
|
0 commit comments