Skip to content
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

Conversation

jakearchibald
Copy link
Contributor

Copy link
Member

@mfalken mfalken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with nits.

try {
await navigator.serviceWorker.register('this-will-404', { scope });
assert_unreached('register should reject');
} catch (err) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have promise_rejects() but I'm not sure which is actually easier to read. I guess promise_rejects lets you test the exception type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

promise_rejects is better, as it also ensures it's a promise that rejects, and not a function that throws.

promise_test(async function(t) {
const scope = 'resources/scope/re-register-while-old-registration-in-use';
const registration = await service_worker_unregister_and_register(t, worker_url, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to also remove the iframe in the cleanup before unregistering, as it helps unregister really unregister.

assert_equals(newRegistration, iframeRegistration, 'iFrame uses new registration');
}, 'Unregister then register does not resurrect the registration');
// Service worker used to 'ressurect' registrations, so registration and new_registration would be equal.
// This has since been changed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests for getRegistration() after unregister() in a controlled frame? I guess it can be added to getregistration.https.html. Looks like we already have coverage for getRegistrations() in getregistrations.https.html.

@jakearchibald
Copy link
Contributor Author

@mattto changes we pretty significant, want to take another look?

Copy link
Member

@mfalken mfalken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, still lgtm.

await wait_for_state(t, registration.installing, 'activated');

const iframe = await with_iframe(scope);
t.add_cleanup(() => iframe.remove());
Copy link
Member

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).

}, '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';
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, silly copy-paste error. Thanks for spotting.

assert_true(!!newIframe.contentWindow.navigator.serviceWorker.controller, 'iFrame has controller');

assert_not_equals(registration, newRegistration, 'Registrations are different');
assert_equals(newRegistration, iframeRegistration, 'iFrame uses new registration');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this holds because newRegistration and iframeRegistration are from different windows so have different prototypes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol indeed. Will fix.

@jakearchibald jakearchibald merged commit c683985 into web-platform-tests:master Jun 6, 2019
@jakearchibald jakearchibald deleted the no-service-worker-resurrection branch June 6, 2019 07:37
marcoscaceres pushed a commit that referenced this pull request Jul 23, 2019
* Updating tests now we've removed resurrection

* Async test to promise test

* Proper cleanup after tests

* More feedback fixes

* Removing comments

* Adding test for controlled iframe

* Fixing tests following feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants