Bug 1411746 Make tests that wait for controller change also wait for SW activation before claim(). r=tt

This commit is contained in:
Ben Kelly 2017-10-27 10:48:26 -04:00
parent 6b14fc7125
commit 602ab7b457
4 changed files with 17 additions and 20 deletions

View File

@ -10,6 +10,7 @@
</head>
<body>
<div id="content" style="display: none"></div>
<script src="utils.js"></script>
<script type="text/javascript">
"use strict";
@ -94,15 +95,12 @@ add_task(async function test_bypassServiceWorker() {
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();

View File

@ -10,6 +10,7 @@
</head>
<body>
<div id="content" style="display: none"></div>
<script src="utils.js"></script>
<script type="text/javascript">
"use strict";
@ -49,16 +50,12 @@ add_task(async function test_integrity_serviceWorker() {
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.

View File

@ -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.)
@ -39,14 +40,13 @@ add_task(async function grace_timeout_termination_with_interrupted_intercept() {
["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

View File

@ -14,6 +14,8 @@ onfetch = function(event) {
event.respondWith((keepPromiseAlive = new Promise(function(res, rej) {})));
}
onactivate = function(event) {
event.waitUntil(clients.claim());
onmessage = function(event) {
if (event.data === 'claim') {
event.waitUntil(clients.claim());
}
}