Bug 1927677 - part 3 - Show the navbar divider in the same layout as the navbar r...
[gecko.git] / dom / serviceworkers / test / test_service_worker_allowed.html
bloba74379f38368ea71ee67d7f1676b735534bd044f
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <!DOCTYPE HTML>
6 <html>
7 <head>
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" />
11 </head>
12 <body>
13 <div id="content"></div>
14 <script class="testbody" type="text/javascript">
15 var gTests = [
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/"})
24 .then(swr => {
25 ok(true, "Registration should finish successfully");
26 return swr.unregister();
27 }, err => {
28 ok(false, "Unexpected error when registering the service worker: " + err);
29 });
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/"})
36 .then(swr => {
37 ok(true, "Registration should finish successfully");
38 return swr.unregister();
39 }, err => {
40 ok(false, "Unexpected error when registering the service worker: " + err);
41 });
44 function runTest() {
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);
50 });
51 })).then(values => {
52 values.forEach(error => {
53 is(error.name, "SecurityError", "Registration should fail");
54 });
55 Promise.all([
56 testPermissiveHeader(),
57 testPreciseHeader(),
58 ]).then(SimpleTest.finish, SimpleTest.finish);
59 }, (x) => {
60 ok(false, "Registration should not succeed, but it did");
61 SimpleTest.finish();
62 });
65 SimpleTest.waitForExplicitFinish();
66 SpecialPowers.pushPrefEnv({"set": [
67 ["dom.serviceWorkers.enabled", true],
68 ["dom.serviceWorkers.testing.enabled", true],
69 ["dom.serviceWorkers.exemptFromPerDomainMax", true],
70 ]}, runTest);
71 </script>
72 </pre>
73 </body>
74 </html>