blob: bd170662dfb2c6d13ab53deb45be91f17dc5b785 [file] [log] [blame]
<!DOCTYPE html>
<meta charset="utf-8">
<title>Tests for module import: ServiceWorker</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="/workers/modules/resources/import-test-cases.js"></script>
<body>
<script>
function import_test(testCase) {
promise_test(async t => {
const msgPromise1 = new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
await service_worker_unregister(t, testCase.scriptURL);
t.add_cleanup(() => service_worker_unregister(t, testCase.scriptURL));
const registration = await navigator.serviceWorker.register(
testCase.scriptURL,
{ scope: testCase.scriptURL, type: 'module' });
registration.installing.postMessage(
'Send message for tests from main script.');
const msgEvent1 = await msgPromise1;
assert_array_equals(msgEvent1.data, testCase.expectation);
// Tests importing module scripts for updated service workers.
const msgPromise2 = new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
await registration.update();
const worker = registration.installing ? registration.installing : registration.active;
worker.postMessage('Send message for tests from main script.');
const msgEvent2 = await msgPromise2;
assert_array_equals(msgEvent2.data, testCase.expectation);
}, testCase.description);
}
testCases.forEach(import_test);
</script>
</body>