2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
8 <title>Test the Service-Worker-Allowed header
</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
13 <div id=
"content"></div>
14 <script class=
"testbody" type=
"text/javascript">
16 "worker_scope_different.js",
17 "worker_scope_different2.js",
18 "worker_scope_too_deep.js",
21 function testPermissiveHeader() {
22 // Make sure that this registration succeeds, as the prefix check should pass.
23 return navigator.serviceWorker.register(
"swa/worker_scope_too_narrow.js", {scope:
"swa/"})
25 ok(true,
"Registration should finish successfully");
26 return swr.unregister();
28 ok(false,
"Unexpected error when registering the service worker: " + err);
32 function testPreciseHeader() {
33 // Make sure that this registration succeeds, as the prefix check should pass
34 // given that we parse the use the full pathname from this URL..
35 return navigator.serviceWorker.register(
"swa/worker_scope_precise.js", {scope:
"swa/"})
37 ok(true,
"Registration should finish successfully");
38 return swr.unregister();
40 ok(false,
"Unexpected error when registering the service worker: " + err);
45 Promise.all(gTests.map(testName =
> {
46 return new Promise((resolve, reject) =
> {
47 // Make sure that registration fails.
48 navigator.serviceWorker.register(
"swa/" + testName, {scope:
"swa/"})
49 .then(reject, resolve);
52 values.forEach(error =
> {
53 is(error.name,
"SecurityError",
"Registration should fail");
56 testPermissiveHeader(),
58 ]).then(SimpleTest.finish, SimpleTest.finish);
60 ok(false,
"Registration should not succeed, but it did");
65 SimpleTest.waitForExplicitFinish();
66 SpecialPowers.pushPrefEnv({
"set": [
67 [
"dom.serviceWorkers.enabled", true],
68 [
"dom.serviceWorkers.testing.enabled", true],
69 [
"dom.serviceWorkers.exemptFromPerDomainMax", true],