-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service workers: Resurrection is no longer a thing #17139
Changes from 6 commits
7d7dbca
01146e3
d3addae
d2602e0
bd0a9e9
8d21b98
55911ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,180 +5,131 @@ | |
<script> | ||
var worker_url = 'resources/empty-worker.js'; | ||
|
||
async_test(function(t) { | ||
var scope = 'resources/scope/unregister-then-register-new-script-that-exists'; | ||
var new_worker_url = worker_url + '?new'; | ||
var iframe; | ||
var registration; | ||
var new_registration; | ||
|
||
service_worker_unregister_and_register(t, worker_url, scope) | ||
.then(function(r) { | ||
registration = r; | ||
return wait_for_state(t, r.installing, 'activated'); | ||
}) | ||
.then(function() { | ||
return with_iframe(scope); | ||
}) | ||
.then(function(frame) { | ||
iframe = frame; | ||
return registration.unregister(); | ||
}) | ||
.then(function() { | ||
return navigator.serviceWorker.register(new_worker_url, | ||
{ scope: scope }); | ||
}) | ||
.then(function(r) { | ||
new_registration = r; | ||
assert_equals(registration.installing.scriptURL, | ||
normalizeURL(new_worker_url), | ||
'before activated registration.installing'); | ||
assert_equals(registration.waiting, null, | ||
'before activated registration.waiting'); | ||
assert_equals(registration.active.scriptURL, normalizeURL(worker_url), | ||
'before activated registration.active'); | ||
assert_equals(new_registration.installing.scriptURL, | ||
normalizeURL(new_worker_url), | ||
'before activated new_registration.installing'); | ||
assert_equals(new_registration.waiting, null, | ||
'before activated new_registration.waiting'); | ||
assert_equals(new_registration.active.scriptURL, | ||
normalizeURL(worker_url), | ||
'before activated new_registration.active'); | ||
iframe.remove(); | ||
return wait_for_state(t, registration.installing, 'activated'); | ||
}) | ||
.then(function() { | ||
assert_equals(new_registration.installing, null, | ||
'after activated new_registration.installing'); | ||
assert_equals(new_registration.waiting, null, | ||
'after activated new_registration.waiting'); | ||
assert_equals(new_registration.active.scriptURL, | ||
normalizeURL(new_worker_url), | ||
'after activated new_registration.active'); | ||
return with_iframe(scope); | ||
}) | ||
.then(function(frame) { | ||
assert_equals( | ||
frame.contentWindow.navigator.serviceWorker.controller.scriptURL, | ||
normalizeURL(new_worker_url), | ||
'the new worker should control a new document'); | ||
frame.remove(); | ||
return registration.unregister(); | ||
}) | ||
.then(function() { | ||
t.done(); | ||
}) | ||
.catch(unreached_rejection(t)); | ||
promise_test(async function(t) { | ||
const scope = 'resources/scope/unregister-then-register-new-script-that-exists'; | ||
const registration = await service_worker_unregister_and_register(t, worker_url, scope); | ||
t.add_cleanup(() => registration.unregister()); | ||
|
||
const newWorkerURL = worker_url + '?new'; | ||
await wait_for_state(t, registration.installing, 'activated'); | ||
|
||
const iframe = await with_iframe(scope); | ||
t.add_cleanup(() => iframe.remove()); | ||
|
||
await registration.unregister(); | ||
|
||
const newRegistration = await navigator.serviceWorker.register(newWorkerURL, { scope }); | ||
t.add_cleanup(() => newRegistration.unregister()); | ||
|
||
assert_equals( | ||
registration.installing.scriptURL, | ||
normalizeURL(newWorkerURL), | ||
'before activated registration.installing' | ||
); | ||
assert_equals( | ||
registration.waiting, | ||
null, | ||
'before activated registration.waiting' | ||
); | ||
assert_equals( | ||
registration.active.scriptURL, | ||
normalizeURL(worker_url), | ||
'before activated registration.active' | ||
); | ||
assert_equals( | ||
newRegistration.installing.scriptURL, | ||
normalizeURL(newWorkerURL), | ||
'before activated newRegistration.installing' | ||
); | ||
assert_equals( | ||
newRegistration.waiting, | ||
null, | ||
'before activated newRegistration.waiting' | ||
); | ||
assert_equals( | ||
newRegistration.active.scriptURL, | ||
normalizeURL(worker_url), | ||
'before activated newRegistration.active' | ||
); | ||
iframe.remove(); | ||
|
||
await wait_for_state(t, registration.installing, 'activated'); | ||
|
||
assert_equals( | ||
newRegistration.installing, | ||
null, | ||
'after activated newRegistration.installing' | ||
); | ||
assert_equals( | ||
newRegistration.waiting, | ||
null, | ||
'after activated newRegistration.waiting' | ||
); | ||
assert_equals( | ||
newRegistration.active.scriptURL, | ||
normalizeURL(newWorkerURL), | ||
'after activated newRegistration.active' | ||
); | ||
|
||
const newIframe = await with_iframe(scope); | ||
t.add_cleanup(() => newIframe.remove()); | ||
|
||
assert_equals( | ||
newIframe.contentWindow.navigator.serviceWorker.controller.scriptURL, | ||
normalizeURL(newWorkerURL), | ||
'the new worker should control a new document' | ||
); | ||
}, 'Registering a new script URL while an unregistered registration is in use'); | ||
jakearchibald marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async_test(function(t) { | ||
var scope = 'resources/scope/unregister-then-register-new-script-that-404s'; | ||
var iframe; | ||
var registration; | ||
|
||
service_worker_unregister_and_register(t, worker_url, scope) | ||
.then(function(r) { | ||
registration = r; | ||
return wait_for_state(t, r.installing, 'activated'); | ||
}) | ||
.then(function() { | ||
return with_iframe(scope); | ||
}) | ||
.then(function(frame) { | ||
iframe = frame; | ||
return registration.unregister(); | ||
}) | ||
.then(function() { | ||
// Step 5.1 of Register clears the uninstall flag before fetching | ||
// the script: | ||
// | ||
// https://w3c.github.io/ServiceWorker/#register-algorithm | ||
var promise = navigator.serviceWorker.register('this-will-404', | ||
{ scope: scope }); | ||
return promise; | ||
}) | ||
.then( | ||
function() { | ||
assert_unreached('register should reject the promise'); | ||
}, | ||
function() { | ||
assert_equals(registration.installing, null, | ||
'registration.installing'); | ||
assert_equals(registration.waiting, null, | ||
'registration.waiting'); | ||
assert_equals(registration.active.scriptURL, normalizeURL(worker_url), | ||
'registration.active'); | ||
iframe.remove(); | ||
return with_iframe(scope); | ||
}) | ||
.then(function(frame) { | ||
assert_equals( | ||
frame.contentWindow.navigator.serviceWorker.controller.scriptURL, | ||
normalizeURL(worker_url), | ||
'the original worker should control a new document'); | ||
frame.remove(); | ||
return registration.unregister(); | ||
}) | ||
.then(function() { | ||
t.done(); | ||
}) | ||
.catch(unreached_rejection(t)); | ||
}, 'Registering a new script URL that 404s does resurrect an ' + | ||
'unregistered registration'); | ||
|
||
async_test(function(t) { | ||
var scope = 'resources/scope/unregister-then-register-reject-install-worker'; | ||
var iframe; | ||
var registration; | ||
|
||
service_worker_unregister_and_register(t, worker_url, scope) | ||
.then(function(r) { | ||
registration = r; | ||
return wait_for_state(t, r.installing, 'activated'); | ||
}) | ||
.then(function() { | ||
return with_iframe(scope); | ||
}) | ||
.then(function(frame) { | ||
iframe = frame; | ||
return registration.unregister(); | ||
}) | ||
.then(function() { | ||
// Step 5.1 of Register clears the uninstall flag before firing | ||
// the install event: | ||
// | ||
// https://w3c.github.io/ServiceWorker/#register-algorithm | ||
var promise = navigator.serviceWorker.register( | ||
'resources/reject-install-worker.js', { scope: scope }); | ||
return promise; | ||
}) | ||
.then(function(r) { | ||
registration = r; | ||
return wait_for_state(t, r.installing, 'redundant'); | ||
}) | ||
.then(function() { | ||
assert_equals(registration.installing, null, | ||
'registration.installing'); | ||
assert_equals(registration.waiting, null, | ||
'registration.waiting'); | ||
assert_equals(registration.active.scriptURL, normalizeURL(worker_url), | ||
'registration.active'); | ||
iframe.remove(); | ||
return with_iframe(scope); | ||
}) | ||
.then(function(frame) { | ||
assert_equals( | ||
frame.contentWindow.navigator.serviceWorker.controller.scriptURL, | ||
normalizeURL(worker_url), | ||
'the original worker should control a new document'); | ||
frame.remove(); | ||
return registration.unregister(); | ||
}) | ||
.then(function() { | ||
t.done(); | ||
}) | ||
.catch(unreached_rejection(t)); | ||
}, 'Registering a new script URL that fails to install does resurrect ' + | ||
'an unregistered registration'); | ||
promise_test(async function(t) { | ||
const scope = 'resources/scope/unregister-then-register-new-script-that-404s'; | ||
const registration = await service_worker_unregister_and_register(t, worker_url, scope); | ||
t.add_cleanup(() => registration.unregister()); | ||
|
||
await wait_for_state(t, registration.installing, 'activated'); | ||
|
||
const iframe = await with_iframe(scope); | ||
t.add_cleanup(() => iframe.remove()); | ||
|
||
await registration.unregister(); | ||
jakearchibald marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
await promise_rejects( | ||
t, new TypeError(), | ||
navigator.serviceWorker.register('this-will-404', { scope }) | ||
); | ||
|
||
assert_equals(registration.installing, null, 'registration.installing'); | ||
assert_equals(registration.waiting, null, 'registration.waiting'); | ||
assert_equals(registration.active.scriptURL, normalizeURL(worker_url), 'registration.active'); | ||
|
||
const newIframe = await with_iframe(scope); | ||
t.add_cleanup(() => newIframe.remove()); | ||
|
||
assert_equals(newIframe.contentWindow.navigator.serviceWorker.controller, null, 'Document should not be controlled'); | ||
}, 'Registering a new script URL that 404s does not resurrect unregistered registration'); | ||
|
||
promise_test(async function(t) { | ||
const scope = 'resources/scope/unregister-then-register-new-script-that-404s'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that-404s -> that-rejects-in-install (but we don't really need these unique scopes anymore, they were just there because we used async_tests which run in parallel and caused collisions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh, silly copy-paste error. Thanks for spotting. |
||
const registration = await service_worker_unregister_and_register(t, worker_url, scope); | ||
t.add_cleanup(() => registration.unregister()); | ||
|
||
await wait_for_state(t, registration.installing, 'activated'); | ||
|
||
const iframe = await with_iframe(scope); | ||
t.add_cleanup(() => iframe.remove()); | ||
|
||
await registration.unregister(); | ||
|
||
const newRegistration = await navigator.serviceWorker.register( | ||
'resources/reject-install-worker.js', { scope } | ||
); | ||
t.add_cleanup(() => newRegistration.unregister()); | ||
|
||
await wait_for_state(t, newRegistration.installing, 'redundant'); | ||
|
||
assert_equals(registration.installing, null, 'registration.installing'); | ||
assert_equals(registration.waiting, null, 'registration.waiting'); | ||
assert_equals(registration.active, null, 'registration.active'); | ||
assert_not_equals(registration, newRegistration, 'New registration is different'); | ||
}, 'Registering a new script URL that fails to install does not resurrect unregistered registration'); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually collapse all the cleanups into one, so you can remove the frames first then do the unregister for the cleanest cleanup.
Although I suppose with this spec change that becomes less important (OTOH browsers won't implement this yet).