mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1290116 P7 Fixed activation races in push service worker tests. r=kitcambridge
This commit is contained in:
parent
b555cf7d21
commit
11f187d4ff
@ -47,6 +47,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
var url = "worker.js" + "?" + (Math.random());
|
||||
registration = yield navigator.serviceWorker.register(url, {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
});
|
||||
|
||||
var controlledFrame;
|
||||
|
@ -45,6 +45,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
var url = "error_worker.js" + "?" + (Math.random());
|
||||
registration = yield navigator.serviceWorker.register(url, {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
});
|
||||
|
||||
var controlledFrame;
|
||||
|
@ -10,6 +10,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
<head>
|
||||
<title>Test for Bug 1038811</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/dom/push/test/test_utils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
</head>
|
||||
@ -29,7 +30,10 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
function start() {
|
||||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."})
|
||||
.then((swr) => registration = swr);
|
||||
.then((swr) => {
|
||||
registration = swr;
|
||||
return waitForActive(registration);
|
||||
});
|
||||
}
|
||||
|
||||
function unregister() {
|
||||
|
@ -30,7 +30,10 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
function start() {
|
||||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."})
|
||||
.then((swr) => registration = swr);
|
||||
.then((swr) => {
|
||||
registration = swr
|
||||
return waitForActive(registration);
|
||||
});
|
||||
}
|
||||
|
||||
function unregister() {
|
||||
|
@ -32,7 +32,8 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
}
|
||||
|
||||
function registerServiceWorker(scope) {
|
||||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: scope});
|
||||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: scope})
|
||||
.then(swr => waitForActive(swr));
|
||||
}
|
||||
|
||||
function unregister(swr) {
|
||||
|
@ -36,6 +36,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
var url = "worker.js" + "?" + Math.random();
|
||||
registration = yield navigator.serviceWorker.register(url, {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
});
|
||||
|
||||
add_task(function* denySubscribe() {
|
||||
|
@ -51,6 +51,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
var url = "worker.js" + "?" + (Math.random());
|
||||
registration = yield navigator.serviceWorker.register(url, {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
});
|
||||
|
||||
var controlledFrame;
|
||||
|
@ -70,6 +70,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
var url = "worker.js" + "?" + (Math.random());
|
||||
registration = yield navigator.serviceWorker.register(url, {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
});
|
||||
|
||||
var controlledFrame;
|
||||
|
@ -43,7 +43,7 @@
|
||||
}
|
||||
|
||||
function waitForActiveServiceWorker(ctx) {
|
||||
return navigator.serviceWorker.ready.then(function(result) {
|
||||
return waitForActive(ctx.registration).then(function(result) {
|
||||
ok(ctx.registration.active, "Service Worker is active");
|
||||
return ctx;
|
||||
});
|
||||
|
@ -32,6 +32,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
var url = "worker.js" + "?" + (Math.random());
|
||||
registration = yield navigator.serviceWorker.register(url, {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
});
|
||||
|
||||
var controlledFrame;
|
||||
|
@ -29,7 +29,8 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
}
|
||||
|
||||
function registerServiceWorker() {
|
||||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."});
|
||||
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."})
|
||||
.then(swr => waitForActive(swr));
|
||||
}
|
||||
|
||||
function unregister(swr) {
|
||||
|
@ -36,6 +36,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
registration = yield navigator.serviceWorker.register(
|
||||
generateURL(), {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
});
|
||||
|
||||
var pushSubscription;
|
||||
@ -63,6 +64,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
registration = yield navigator.serviceWorker.register(
|
||||
generateURL(), {scope: "."});
|
||||
yield waitForActive(registration);
|
||||
var pushSubscription = yield registration.pushManager.getSubscription();
|
||||
ok(!pushSubscription,
|
||||
"Unregistering a service worker should drop its subscription");
|
||||
|
@ -227,3 +227,19 @@ function sendRequestToWorker(request) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForActive(swr) {
|
||||
let sw = swr.installing || swr.waiting || swr.active;
|
||||
return new Promise(resolve => {
|
||||
if (sw.state === 'activated') {
|
||||
resolve(swr);
|
||||
return;
|
||||
}
|
||||
sw.addEventListener('statechange', function onStateChange(evt) {
|
||||
if (sw.state === 'activated') {
|
||||
sw.removeEventListener('statechange', onStateChange);
|
||||
resolve(swr);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user