2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
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" />
14 <div id=
"content" style=
"display: none"></div>
16 <script class=
"testbody" type=
"text/javascript">
20 return navigator.serviceWorker.register(
"claim_oninstall_worker.js",
22 .then((swr) =
> registration = swr);
26 function unregister() {
27 return registration.unregister().then(function(result) {
28 ok(result,
"Unregister should return true.");
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
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;
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]