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 @@
<body>
<script>
promise_test(function(t) {
promise_test((t) => {
return runTest(t, 'resources/claim-worker-fetch-iframe.html');
}, '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');
}, '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');
}, 'fetch() in blob URL Worker should be intercepted after the client is claimed.');
function runTest(t, iframe_url) {
var resource = 'simple.txt';
async function runTest(t, iframe_url) {
const resource = 'simple.txt';
const scope = 'resources/';
const script = 'resources/claim-worker.js';
var frame;
var registration;
var worker;
var scope = 'resources/';
var script = 'resources/claim-worker.js';
return Promise.resolve()
// Create the test iframe with a dedicated worker.
.then(() => with_iframe(iframe_url))
.then(f => {
t.add_cleanup(() => f.remove());
frame = f;
})
const frame = await with_iframe(iframe_url);
t.add_cleanup(_ => frame.remove());
// Check the controller and test with fetch in the worker.
.then(() => assert_equals(frame.contentWindow.navigator.controller,
undefined,
'Should have no controller.'))
.then(() => frame.contentWindow.fetch_in_worker(resource))
.then(response_text => assert_equals(response_text,
'a simple text file\n',
'fetch() should not be intercepted.'))
assert_equals(frame.contentWindow.navigator.controller,
undefined, 'Should have no controller.');
{
const response_text = await frame.contentWindow.fetch_in_worker(resource);
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'))
const reg = await service_worker_unregister_and_register(t, script, scope);
t.add_cleanup(_ => reg.unregister());
await wait_for_state(t, reg.installing, 'activated');
// Let the service worker claim the iframe and the worker.
.then(() => {
var channel = new MessageChannel();
var saw_message = new Promise(function(resolve) {
const channel = new MessageChannel();
const saw_message = new Promise(function(resolve) {
channel.port1.onmessage = t.step_func(function(e) {
assert_equals(e.data, 'PASS',
'Worker call to claim() should fulfill.');
assert_equals(e.data, 'PASS', 'Worker call to claim() should fulfill.');
resolve();
});
});
worker.postMessage({port: channel.port2}, [channel.port2]);
return saw_message;
})
reg.active.postMessage({port: channel.port2}, [channel.port2]);
await saw_message;
// Check the controller and test with fetch in the worker.
.then(() => frame.contentWindow.navigator.serviceWorker.getRegistration(scope))
.then(r => registration = r)
.then(() => assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
registration.active,
'Test iframe should be claimed.'))
const reg2 =
await frame.contentWindow.navigator.serviceWorker.getRegistration(scope);
assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
reg2.active, 'Test iframe should be claimed.');
{
// TODO(horo): Check the worker's navigator.seviceWorker.controller.
.then(() => frame.contentWindow.fetch_in_worker(resource))
.then(response_text =>
assert_equals(response_text,
'Intercepted!',
'fetch() in the worker should be intercepted.'));
const response_text = await frame.contentWindow.fetch_in_worker(resource);
assert_equals(response_text, 'Intercepted!',
'fetch() in the worker should be intercepted.');
}
}
</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