mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1262702 Avoid racing with initial shutdown in test_service_worker_lifetime.html. r=kitcambridge
This commit is contained in:
parent
f97bc8ed0f
commit
77f99cddcd
@ -45,13 +45,19 @@ function resolvePromise() {
|
||||
}
|
||||
|
||||
onmessage = function(event) {
|
||||
// FIXME(catalinb): we cannot treat these events as extendable
|
||||
// yet. Bug 1143717
|
||||
event.source.postMessage({type: "message", state: state});
|
||||
var lastState = state;
|
||||
state = event.data;
|
||||
if (event.data === "release") {
|
||||
if (state === 'wait') {
|
||||
event.waitUntil(new Promise(function(res, rej) {
|
||||
if (resolvePromiseCallback) {
|
||||
dump("ERROR: service worker was already waiting on a promise.\n");
|
||||
}
|
||||
resolvePromiseCallback = res;
|
||||
}));
|
||||
} else if (state === 'release') {
|
||||
resolvePromise();
|
||||
}
|
||||
event.source.postMessage({type: "message", state: lastState});
|
||||
}
|
||||
|
||||
onpush = function(event) {
|
||||
|
@ -253,11 +253,17 @@
|
||||
.then(cancelShutdownObserver)
|
||||
|
||||
// Test with push events and message events
|
||||
.then(setShutdownObserver(true))
|
||||
.then(createIframe)
|
||||
// Make sure we are shutdown before entering our "no shutdown" sequence
|
||||
// to avoid races.
|
||||
.then(waitOnShutdownObserver)
|
||||
.then(setShutdownObserver(false))
|
||||
.then(checkStateAndUpdate(pushEvent, "from_scope", "wait"))
|
||||
.then(checkStateAndUpdate(messageEventIframe, "wait", "update"))
|
||||
.then(checkStateAndUpdate(messageEventIframe, "update", "update"))
|
||||
.then(setShutdownObserver(true))
|
||||
.then(checkStateAndUpdate(messageEventIframe, "wait", "release"))
|
||||
.then(checkStateAndUpdate(messageEventIframe, "update", "release"))
|
||||
.then(waitOnShutdownObserver)
|
||||
.then(closeIframe)
|
||||
}
|
||||
@ -272,8 +278,12 @@
|
||||
// Older versions used to terminate workers when the last controlled
|
||||
// window was closed. This should no longer happen, though. Verify
|
||||
// the new behavior.
|
||||
setShutdownObserver(true)(ctx);
|
||||
return createIframe(ctx)
|
||||
.then(setShutdownObserver(true))
|
||||
// Make sure we are shutdown before entering our "no shutdown" sequence
|
||||
// to avoid races.
|
||||
.then(waitOnShutdownObserver)
|
||||
.then(setShutdownObserver(false))
|
||||
.then(checkStateAndUpdate(fetchEvent, "from_scope", "wait"))
|
||||
.then(closeIframe)
|
||||
.then(setShutdownObserver(true))
|
||||
@ -282,7 +292,11 @@
|
||||
|
||||
// Push workers were exempt from the old rule and should continue to
|
||||
// survive past the closing of the last controlled window.
|
||||
.then(setShutdownObserver(true))
|
||||
.then(createIframe)
|
||||
// Make sure we are shutdown before entering our "no shutdown" sequence
|
||||
// to avoid races.
|
||||
.then(waitOnShutdownObserver)
|
||||
.then(setShutdownObserver(false))
|
||||
.then(checkStateAndUpdate(pushEvent, "from_scope", "wait"))
|
||||
.then(closeIframe)
|
||||
|
Loading…
Reference in New Issue
Block a user