Commit f59ee305 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

[WPT] Add tests for module service worker static import + path restriction

Path restriction check
https://w3c.github.io/ServiceWorker/#path-restriction
shouldn't be done for non-top-level module scripts.

Bug: 1136775
Change-Id: Id75fd427aaceca189324335fae1efb37f5df7c6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462947
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819723}
parent 1fd909b2
This is a testharness.js-based test.
PASS imported-module-script.js works when used as top-level
FAIL static imports to outside path restriction should be allowed promise_test: Unhandled rejection with value: object "AbortError: Failed to register a ServiceWorker for scope ('https://web-platform.test:8444/service-workers/service-worker/resources/scope1/') with script ('https://web-platform.test:8444/service-workers/service-worker/resources/scope1/module-worker-importing-scope2.js'): ServiceWorker cannot be started"
FAIL static imports redirecting to outside path restriction should be allowed promise_test: Unhandled rejection with value: object "AbortError: Failed to register a ServiceWorker for scope ('https://web-platform.test:8444/service-workers/service-worker/resources/scope1/') with script ('https://web-platform.test:8444/service-workers/service-worker/resources/scope1/module-worker-importing-redirect-to-scope2.js'): ServiceWorker cannot be started"
Harness: the test ran to completion.
<!DOCTYPE html>
<title>Service Worker: Static imports from module top-level scripts shouldn't be affected by the service worker script path restriction</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
// https://w3c.github.io/ServiceWorker/#path-restriction
// is applied to top-level scripts in
// https://w3c.github.io/ServiceWorker/#update-algorithm
// but not to submodules imported from top-level scripts.
async function runTest(t, script, scope) {
const script_url = new URL(script, location.href);
await service_worker_unregister(t, scope);
const registration = await
navigator.serviceWorker.register(script, {type: 'module'});
t.add_cleanup(_ => registration.unregister());
const msg = await new Promise(resolve => {
registration.installing.postMessage('ping');
navigator.serviceWorker.onmessage = resolve;
});
assert_equals(msg.data, 'pong');
}
promise_test(async t => {
await runTest(t,
'resources/scope2/imported-module-script.js',
'resources/scope2/');
}, 'imported-module-script.js works when used as top-level');
promise_test(async t => {
await runTest(t,
'resources/scope1/module-worker-importing-scope2.js',
'resources/scope1/');
}, 'static imports to outside path restriction should be allowed');
promise_test(async t => {
await runTest(t,
'resources/scope1/module-worker-importing-redirect-to-scope2.js',
'resources/scope1/');
}, 'static imports redirecting to outside path restriction should be allowed');
</script>
import * as module from './redirect.py?Redirect=/service-workers/service-worker/resources/scope2/imported-module-script.js';
export const imported = 'A module script.';
onmessage = msg => {
msg.source.postMessage('pong');
};
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