Bug 1884032 [wpt PR 44942] - [css-color] add missing colorscheme-aware tests, a=testonly
[gecko.git] / dom / serviceworkers / test / test_claim_oninstall.html
blob54933405ce4f7ac4282cc8153d52ab10601461ef
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>Bug 1130684 - Test service worker clients.claim oninstall</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 <p id="display"></p>
14 <div id="content" style="display: none"></div>
15 <pre id="test"></pre>
16 <script class="testbody" type="text/javascript">
17 var registration;
19 function register() {
20 return navigator.serviceWorker.register("claim_oninstall_worker.js",
21 { scope: "./" })
22 .then((swr) => registration = swr);
26 function unregister() {
27 return registration.unregister().then(function(result) {
28 ok(result, "Unregister should return true.");
29 });
32 function testClaim() {
33 ok(registration.installing, "Worker should be in installing state");
35 navigator.serviceWorker.oncontrollerchange = function() {
36 ok(false, "Claim should not succeed when the worker is not active.");
39 var p = new Promise(function(res, rej) {
40 var worker = registration.installing;
41 worker.onstatechange = function(e) {
42 if (worker.state === 'installed') {
43 is(worker, registration.waiting, "Worker should be in waiting state");
44 } else if (worker.state === 'activated') {
45 // The worker will become active only if claim will reject inside the
46 // install handler.
47 is(worker, registration.active,
48 "Claim should reject if the worker is not active");
49 ok(navigator.serviceWorker.controller === null, "Client is not controlled.");
50 e.target.onstatechange = null;
51 res();
54 });
56 return p;
59 function runTest() {
60 register()
61 .then(testClaim)
62 .then(unregister)
63 .catch(function(e) {
64 ok(false, "Some test failed with error " + e);
65 }).then(SimpleTest.finish);
68 SimpleTest.waitForExplicitFinish();
69 SpecialPowers.pushPrefEnv({"set": [
70 ["dom.serviceWorkers.exemptFromPerDomainMax", true],
71 ["dom.serviceWorkers.enabled", true],
72 ["dom.serviceWorkers.testing.enabled", true]
73 ]}, runTest);
74 </script>
75 </pre>
76 </body>
77 </html>