Commit ae453bb4 authored by Asami Doi's avatar Asami Doi Committed by Commit Bot

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 <asamidoi@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829600}
parent 82f2835e
...@@ -7,77 +7,64 @@ ...@@ -7,77 +7,64 @@
<body> <body>
<script> <script>
promise_test(function(t) { promise_test((t) => {
return runTest(t, 'resources/claim-worker-fetch-iframe.html'); return runTest(t, 'resources/claim-worker-fetch-iframe.html');
}, 'fetch() in Worker should be intercepted after the client is claimed.'); }, 'fetch() in Worker should be intercepted after the client is claimed.');
promise_test(function(t) { promise_test((t) => {
return runTest(t, 'resources/claim-nested-worker-fetch-iframe.html'); return runTest(t, 'resources/claim-nested-worker-fetch-iframe.html');
}, 'fetch() in nested Worker should be intercepted after the client is claimed.'); }, 'fetch() in nested Worker should be intercepted after the client is claimed.');
promise_test(function(t) { promise_test((t) => {
return runTest(t, 'resources/claim-blob-url-worker-fetch-iframe.html'); return runTest(t, 'resources/claim-blob-url-worker-fetch-iframe.html');
}, 'fetch() in blob URL Worker should be intercepted after the client is claimed.'); }, 'fetch() in blob URL Worker should be intercepted after the client is claimed.');
function runTest(t, iframe_url) { async function runTest(t, iframe_url) {
var resource = 'simple.txt'; const resource = 'simple.txt';
const scope = 'resources/';
const script = 'resources/claim-worker.js';
var frame; // Create the test iframe with a dedicated worker.
var registration; const frame = await with_iframe(iframe_url);
var worker; t.add_cleanup(_ => frame.remove());
var scope = 'resources/';
var script = 'resources/claim-worker.js';
return Promise.resolve() // Check the controller and test with fetch in the worker.
// Create the test iframe with a dedicated worker. assert_equals(frame.contentWindow.navigator.controller,
.then(() => with_iframe(iframe_url)) undefined, 'Should have no controller.');
.then(f => { {
t.add_cleanup(() => f.remove()); const response_text = await frame.contentWindow.fetch_in_worker(resource);
frame = f; assert_equals(response_text, 'a simple text file\n',
}) 'fetch() should not be intercepted.');
}
// Check the controller and test with fetch in the worker. // Register a service worker.
.then(() => assert_equals(frame.contentWindow.navigator.controller, const reg = await service_worker_unregister_and_register(t, script, scope);
undefined, t.add_cleanup(_ => reg.unregister());
'Should have no controller.')) await wait_for_state(t, reg.installing, 'activated');
.then(() => frame.contentWindow.fetch_in_worker(resource))
.then(response_text => assert_equals(response_text,
'a simple text file\n',
'fetch() should not be intercepted.'))
// Register a service worker.
.then(() => service_worker_unregister_and_register(t, script, scope))
.then(r => {
t.add_cleanup(() => r.unregister());
worker = r.installing;
})
.then(() => wait_for_state(t, worker, 'activated'))
// Let the service worker claim the iframe and the worker. // Let the service worker claim the iframe and the worker.
.then(() => { const channel = new MessageChannel();
var channel = new MessageChannel(); const saw_message = new Promise(function(resolve) {
var saw_message = new Promise(function(resolve) { channel.port1.onmessage = t.step_func(function(e) {
channel.port1.onmessage = t.step_func(function(e) { assert_equals(e.data, 'PASS', 'Worker call to claim() should fulfill.');
assert_equals(e.data, 'PASS', resolve();
'Worker call to claim() should fulfill.'); });
resolve(); });
}); reg.active.postMessage({port: channel.port2}, [channel.port2]);
}); await saw_message;
worker.postMessage({port: channel.port2}, [channel.port2]);
return saw_message;
})
// Check the controller and test with fetch in the worker. // Check the controller and test with fetch in the worker.
.then(() => frame.contentWindow.navigator.serviceWorker.getRegistration(scope)) const reg2 =
.then(r => registration = r) await frame.contentWindow.navigator.serviceWorker.getRegistration(scope);
.then(() => assert_equals(frame.contentWindow.navigator.serviceWorker.controller, assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
registration.active, reg2.active, 'Test iframe should be claimed.');
'Test iframe should be claimed.'))
{
// TODO(horo): Check the worker's navigator.seviceWorker.controller. // TODO(horo): Check the worker's navigator.seviceWorker.controller.
.then(() => frame.contentWindow.fetch_in_worker(resource)) const response_text = await frame.contentWindow.fetch_in_worker(resource);
.then(response_text => assert_equals(response_text, 'Intercepted!',
assert_equals(response_text, 'fetch() in the worker should be intercepted.');
'Intercepted!', }
'fetch() in the worker should be intercepted.'));
} }
</script> </script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment