Skip to content

Commit

Permalink
Bug 1411746 Make tests that wait for controller change also wait for …
Browse files Browse the repository at this point in the history
…SW activation before claim(). r=tt
  • Loading branch information
wanderview committed Oct 27, 2017
1 parent 337e94b commit 6ac7d7c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</head>
<body>
<div id="content" style="display: none"></div>
<script src="utils.js"></script>
<script type="text/javascript">
"use strict";

Expand Down Expand Up @@ -94,15 +95,12 @@
const swURL = "fetch.js";
let registration = await navigator.serviceWorker.register(swURL);

// Wait for the service worker to control the document
let waitForControlled = new Promise(resolve => {
navigator.serviceWorker.oncontrollerchange = resolve;
});

let sw =
registration.active || registration.waiting || registration.installing;

await waitForState(sw, 'activated');
sw.postMessage("claim");
await waitForControlled;
await waitForControlled(window);

try {
await testBypassSW();
Expand Down
9 changes: 3 additions & 6 deletions dom/workers/test/serviceworkers/test_fetch_integrity.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</head>
<body>
<div id="content" style="display: none"></div>
<script src="utils.js"></script>
<script type="text/javascript">
"use strict";

Expand Down Expand Up @@ -49,16 +50,12 @@
var filename = make_absolute_url("fetch.js");
var filename2 = make_absolute_url("fake.html");

// The SW will claim us once it activates; this is async, start listening now.
let waitForControlled = new Promise((resolve) => {
navigator.serviceWorker.oncontrollerchange = resolve;
});

let registration = await navigator.serviceWorker.register("fetch.js",
{ scope: "./" });
let worker = registration.installing || registration.active;
await waitForState(worker, 'activated');
worker.postMessage('claim');
await waitForControlled;
await waitForControlled(window);

info("Test for mNavigationInterceptions.")
// The client_win will reload to another URL after opening filename2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<pre id="test">
</pre>

<script src="utils.js"></script>
<script class="testbody" type="text/javascript">
// (This doesn't really need to be its own task, but it allows the actual test
// case to be self-contained.)
Expand All @@ -39,14 +40,13 @@
["dom.serviceWorkers.idle_timeout", 0],
["dom.serviceWorkers.idle_extended_timeout", 299999]]});

// The SW will claim us once it activates; this is async, start listening now.
let waitForControlled = new Promise((resolve) => {
navigator.serviceWorker.oncontrollerchange = resolve;
});

let registration = await navigator.serviceWorker.register(
"unresolved_fetch_worker.js", { scope: "./"} );
await waitForControlled;

let worker = registration.installing || registration.active;
await waitForState(worker, 'activated');
worker.postMessage('claim');
await waitForControlled(window);
ok(navigator.serviceWorker.controller, "Controlled"); // double check!

// We want to make sure the SW is active and processing the fetch before we
Expand Down
3 changes: 2 additions & 1 deletion dom/workers/test/serviceworkers/unresolved_fetch_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ onfetch = function(event) {
event.respondWith((keepPromiseAlive = new Promise(function(res, rej) {})));
}

onactivate = function(event) {
onmessage = function(event) {
event.waitUntil(clients.claim());
self.onmessage = null;
}

0 comments on commit 6ac7d7c

Please sign in to comment.