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

[WPT] BFCache: service worker clients #31082

Merged
merged 1 commit into from
May 27, 2022

Conversation

chromium-wpt-export-bot
Copy link
Collaborator

@chromium-wpt-export-bot chromium-wpt-export-bot commented Oct 4, 2021

This CL adds service worker tests for BFCache:

  • navigator.serviceWorker.controller
  • Fetch interception
  • Clients.claim()
  • Clients.matchAll() and
  • unregister().

Expected behavior:

  • Controlled pages should remain controlled after
    restored from BFCache, i.e.
    navigator.serviceWorker.controller should remain non-null
    and fetch should be intercepted.
  • Clients.claim() should evict pages
    that would be affected from BFCache.
  • Clients.matchAll() shouldn't list pages in BFCache.
  • unregister() should evict controlled pages from BFCache.

Failing tests:

  • service-worker-clients-claim.https.html:
    On Safari/Firefox, Clients.claim() doesn't evict pages from BFCache.
  • service-worker-controlled-after-restore.https.html:
    On Firefox, fetches are not intercepted after restored from
    BFCache while navigator.serviceWorker.controller is non-null.
  • service-worker-unregister.https.html:
    Controlled pages aren't evicted by unregister() (all browsers).

Bug: 1107415, 1204228, w3c/ServiceWorker#1594
Change-Id: I73233cf917e31dd91b974823d5490d0190f0eade
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3201011
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Ben Kelly <wanderview@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1008327}

Copy link
Collaborator

@wpt-pr-bot wpt-pr-bot left a comment

Choose a reason for hiding this comment

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

The review process for this patch is being conducted in the Chromium project.

await pageA.execute_script(waitForPageShow);
await assert_bfcached(pageA);

// `pageA` should be still controlled after restored from BFCache.
Copy link
Contributor

@smaug---- smaug---- Feb 15, 2022

Choose a reason for hiding this comment

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

Hmm, is this the behavior we want?

Given https://w3c.github.io/ServiceWorker/#navigator-service-worker-unregister
the registration would be there until bfcache entry is evicted or page brought back to foreground?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rakina, any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @rubberyuzu @wanderview @fergald as they have a better idea about SW interaction with bfcache

Copy link
Contributor

Choose a reason for hiding this comment

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

Friendly ping. Any thoughts?

Copy link
Contributor

@hiroshige-g hiroshige-g May 2, 2022

Choose a reason for hiding this comment

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

In my understanding, according to the current https://w3c.github.io/ServiceWorker/#navigator-service-worker-unregister the registration is removed so that subsequent navigation are no longer controlled by the service worker, while the page in BFCache still remains controlled (as "currently controlled service worker client's active service worker's containing service worker registration is effective"), but not sure.
This also aligns with Firefox/Chrome/Safari's behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it matters here what browsers do here, since bfcache + SW is largely undefined. But it would be, IMO, rather odd to keep the page registered while you can't still communicate with it. So I would expect unregister to evict any bfcached pages (well, that is what UAs can do anyhow, since eviction may happen at any point).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, interesting. I think service worker unregistration actually already triggers eviction of the controllees in Chrome's implementation: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/service_worker/service_worker_container_host.cc;l=643;drc=b24429781c133fd2482edbb4d0c8c8305031b082

Not sure if this test is testing a different case, or is somehow not testing what it should be. But I guess eviction makes sense in the case linked above?

Copy link
Contributor

Choose a reason for hiding this comment

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

@hiroshige-g, let's update the test to expect eviction after service worker unregistration. @smaug---- , do you have other concerns for the tests? Maybe we can add a Client.postMessage() test too, but I don't think that's blocking the rest of the tests here from landing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think service worker unregistration actually already triggers eviction of the controllees in Chrome's implementation:

Probably Comments 7 and 8 of https://bugs.chromium.org/p/chromium/issues/detail?id=1204228 is the explanation for this. Because there are still active controlled pages at the time of unregister(), the full eviction code doesn't run.

Anyway I updated the test to expect eviction from BFCache on unregister().

@smaug----
Copy link
Contributor

How should Client.postMessage behave if the other side is in bfcache? I guess evict the other side from bfcache.

@rakina
Copy link
Contributor

rakina commented May 6, 2022

How should Client.postMessage behave if the other side is in bfcache? I guess evict the other side from bfcache.

Yep we are already evicting in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/service_worker/service_worker_version.cc;l=1448;drc=b24429781c133fd2482edbb4d0c8c8305031b082

@chromium-wpt-export-bot chromium-wpt-export-bot force-pushed the chromium-export-cl-3201011 branch 2 times, most recently from 2986287 to 432f728 Compare May 27, 2022 02:41
This CL adds service worker tests for BFCache:

- navigator.serviceWorker.controller
- Fetch interception
- Clients.claim()
- Clients.matchAll() and
- unregister().

Expected behavior:

- Controlled pages should remain controlled after
  restored from BFCache, i.e.
  navigator.serviceWorker.controller should remain non-null
  and fetch should be intercepted.
- Clients.claim() should evict pages
  that would be affected from BFCache.
- Clients.matchAll() shouldn't list pages in BFCache.
- unregister() should evict controlled pages from BFCache.

Failing tests:

- service-worker-clients-claim.https.html:
  On Safari/Firefox, Clients.claim() doesn't evict pages from BFCache.
- service-worker-controlled-after-restore.https.html:
  On Firefox, fetches are not intercepted after restored from
  BFCache while `navigator.serviceWorker.controller` is non-null.
- service-worker-unregister.https.html:
  Controlled pages aren't evicted by unregister() (all browsers).

Bug: 1107415, 1204228, w3c/ServiceWorker#1594
Change-Id: I73233cf917e31dd91b974823d5490d0190f0eade
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3201011
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Ben Kelly <wanderview@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1008327}
@chromium-wpt-export-bot chromium-wpt-export-bot force-pushed the chromium-export-cl-3201011 branch from 432f728 to 39f5f59 Compare May 27, 2022 18:12
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
// When a service worker is unregistered when a controlled page is in BFCache,
// the page can be still restored from BFCache and remain controlled by the
Copy link
Contributor

@smaug---- smaug---- Jun 6, 2022

Choose a reason for hiding this comment

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

This comment looks now wrong. The assertion is "navigator.serviceWorker.controller === null" and assertion comment 'pageA should not be controlled'

@smaug----
Copy link
Contributor

Yep we are already evicting in Chrome

But there is no test for Client.postMessage?

@smaug----
Copy link
Contributor

I'm adding basic tests for Client.postMessage. Firefox and Chrome behave in those similarly (once I land some tweaks to Gecko)

@smaug----
Copy link
Contributor

Looks like the tests were reverted on chromium's side 40ac061 just when I had fixed something on Mozilla's side
https://bugzilla.mozilla.org/show_bug.cgi?id=1774475#c6

@fergald
Copy link
Contributor

fergald commented Jun 21, 2022

@hiroshige-g We should reland them but with flaky expectations and we can look at debugging them in the future.

@smaug----
Copy link
Contributor

smaug---- commented Jun 21, 2022

That is happening here #34505, but looks like Chrome has still some issues with the tests.

@jgraham
Copy link
Contributor

jgraham commented Jun 21, 2022

If we were to force merge #34505 (once it's on mozilla-central) would you set the flaky metadata in Chrome as part of the sync?

@fergald
Copy link
Contributor

fergald commented Jun 21, 2022

Yes, that'd be fine. Thanks.

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.

8 participants