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

Add tests for service worker inheritance #4610

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jungkees
Copy link
Contributor

@jungkees jungkees commented Jan 24, 2017

Loading an iframe without involving a navigate fetch inherits its
parent's active service worker, if it has one. By this rule:

  • Initial about:blank Document on iframe inherits its parent's SW
  • iframe srcdoc Document inherits its parent's SW

However, the navigate fetch through http fetch still wins. So, if a
client obtains a matched SW during the navigation, the matched SW
replaces the inherited SW.

An exception:

  • Navigating an iframe to a non-initial about:blank Document inherits
    the parent's SW

Related work: whatwg/html#2080.

@wpt-pr-bot
Copy link
Collaborator

Notifying @ehsan and @mkruisselbrink. (Learn how reviewing works.)

@jungkees
Copy link
Contributor Author

The spec work for this is in progress here: whatwg/html#2080. It'd be appreciated if anyone could review it.

/cc @ehsan, @mkruisselbrink, @jakearchibald, @annevk

return service_worker_unregister(t, scope1);
})
.then(function() {
service_worker_unregister_and_done(t, scope2);
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need the and_done() variant in a promise_test. When the overall promise resolves the test will be marked as done anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

.then(function() {
service_worker_unregister_and_done(t, scope2);
})
.catch(unreached_rejection(t));
Copy link
Contributor

Choose a reason for hiding this comment

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

You also don't need this .catch(unreached_rejection(t)) in a promise_test. If the promise passed to promise_test rejects the test will be considered a failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

'about:blank Document should inherit parent\'s SW.');
})
.then(function() {
return with_srcdoc_iframe('<p>Some HTML</p>');
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if the various tests (about:blank, srcdoc, etc) would be actually separate promise_tests, rather than just assertions all in the same test. That way the test results would much clearer show which features work/don't work, rather than only reporting the first failing result. Not sure how tricky that is going to be with the various service worker registrations, but it shouldn't be too bad I think.

One way might be to do something like (but then with proper syntax etc):

let registered_workers = service_worker_unregister_and_register(...).then(...).then(...);

promise_test(t => {
  registered_workers.then(() => with_iframe(''))
    .then(f => {
       assert(...)
     });
  }, 'about:blank document');

promise_test(t => {....}, 'srcdoc iframe');

// etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good point indeed. I addressed them as suggested basically but put the registration and activation chain in the first promise_test as it needs |t|.

var script1 = script + '?for_scope1';
var script2 = script + '?for_scope2';
var registration1, registration2;
var parent_controller, child_controller;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you declare child_controller at this scope? I think just declaring it in all the closures where you actually use it would be cleaner (I don't think you ever use it across closure boundaries?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed by declaring them in their closures.

var scope2 = 'resources/blank.html';
var script1 = script + '?for_scope1';
var script2 = script + '?for_scope2';
var registration1, registration2;
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these variables used for? You assign to them, but I don't see them being read anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. They're unused. Deleted.

'matched SW should set the controller to null.');
})
.then(function() {
return service_worker_unregister(t, scope1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than calling service_worker_unregister at the end of your test here, it is probably cleaner to call add_completion_callback(() => {r.unregister();}); as soon as you have registered a service worker, to make sure they get cleaned up even if the test fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Addressed them for registration.unregister() and frame.remove().

@mkruisselbrink
Copy link
Contributor

I think the travis check failure is because an unrelated test (that just includes the test-helpers.sub.js file you modified) has non-unique test names (see #4404)

@jungkees
Copy link
Contributor Author

@mkruisselbrink, thanks for reviewing! I uploaded a patch addressing those comments.

@jungkees
Copy link
Contributor Author

I think the travis check failure is because an unrelated test (that just includes the test-helpers.sub.js file you modified) has non-unique test names

What would be the expected resolution for this for now? It seems

ERROR:check_stability:| /service-workers/service-worker/fetch-event.https.html

has non-unique test names at least.

@mkruisselbrink
Copy link
Contributor

What would be the expected resolution for this for now? It seems

ERROR:check_stability:| /service-workers/service-worker/fetch-event.https.html

has non-unique test names at least.

That should be fixed now #4626 landed (hopefully that was the only one). Not sure how to trigger checks again on this CL though...

// This client's active service worker is set to scope1's registration's
// active worker by clients.claim() during the activation.
parent_controller = navigator.serviceWorker.controller;
return with_iframe('')
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe adding an "options" parameter to with_iframe with an auto_remove option (like in the chromium version of with_iframe) would make sense? Having a boolean that defaults to true like in the chromium version seems wrong, but having an option to pass to with_iframe to get auto remove behavior does seem reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense. I think there are quite a few tests already that manually remove the iframes. So I made it opt-in to auto remove the iframe by passing options.auto_remove set to true.

@@ -58,6 +58,25 @@ function with_iframe(url) {
});
}

function with_sandboxed_iframe(url, sandbox) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you add an "options" dictionary to with_iframe to support auto_remove, you could also add a sandbox option to that same dictionary rather than having a separate function for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I added sandbox property and srcdoc property to the options as suggested. Looks cleaner.

@jungkees
Copy link
Contributor Author

Does anyone have any idea what causes this travis-ci error?: https://travis-ci.org/w3c/web-platform-tests/jobs/195441119.

/cc @Ms2ger @jgraham @zcorpan @annevk

@annevk
Copy link
Member

annevk commented Jan 31, 2017

It seems the test takes too long to run from "The job exceeded the maximum time limit for jobs, and has been terminated."

@Ms2ger
Copy link
Contributor

Ms2ger commented Jan 31, 2017

WebDriverException: Message: no such session, it says... Not sure what's up with that.

@w3c-bots
Copy link

w3c-bots commented Feb 14, 2017

View the complete job log.

Chrome (unstable channel)

Testing web-platform-tests at revision f403d50
Using browser at version 59.0.3063.4 dev

@w3c-bots
Copy link

w3c-bots commented Feb 14, 2017

View the complete job log.

Firefox (nightly channel)

Testing web-platform-tests at revision f403d50
Using browser at version BuildID 20170406100208; SourceStamp 3c68d659c2b715f811708f043a1e7169d77be2ba

@jungkees
Copy link
Contributor Author

The test added in this PR seems okay now. Need to look at /service-workers/service-worker/request-end-to-end.https.html that's flaky on Chrome.

@w3c-bots
Copy link

w3c-bots commented Mar 10, 2017

These tests are now available on w3c-test.org

@jungkees
Copy link
Contributor Author

Try the Travis CI again after checking /service-workers/service-worker/request-end-to-end.https.html is constantly working as expected (failure) in Chrome: https://test-results.appspot.com/dashboards/flakiness_dashboard.html#testType=webkit_tests%20(with%20patch)&tests=external%2Fwpt%2Fservice-workers%2Fservice-worker%2Frequest-end-to-end.https.html

@jungkees
Copy link
Contributor Author

Recently added /service-workers/service-worker/clients-matchall-order.https.html is failing in Chrome. When the test is rolled to Chromium, we'll need to update the TestExpectations to proceed with this PR.

@w3c-bots
Copy link

View the complete job log.

Firefox (nightly channel)

Testing web-platform-tests at revision 578f5ea
Git command exited with status 128
fatal: Invalid revision range cf62b85..

@w3c-bots
Copy link

View the complete job log.

Chrome (unstable channel)

Testing web-platform-tests at revision 578f5ea
Git command exited with status 128
fatal: Invalid revision range cf62b85..

Loading an iframe without involving a navigate fetch inherits its
parent's active service worker, if it has one. By this rule:
 - Initial about:blank Document on iframe inherits its parent's SW
 - iframe srcdoc Document inherits its parent's SW

However, the navigate fetch through http fetch still wins. So, if a
client obtains a matched SW during the navigation, the matched SW
replaces the inherited SW.

An exception:
 - Navigating an iframe to a non-initial about:blank Document inherits
   the parent's SW

Related work: whatwg/html#2080.
Add options param to with_iframe to set the iframe's sandbox attribute
and srcdoc attribute as well as add a callback to remove the iframe when
the test is done.
@foolip
Copy link
Member

foolip commented Oct 1, 2018

@jungkees, can you rebase this to resolve the conflicts and retrigger Travis? Whatever the trouble with Travis was over a year ago, it's probably gone now.

@mfalken
Copy link
Member

mfalken commented Oct 23, 2018

Some of this may have changed in the intervening time see eg whatwg/html#3725 and existing tests mentioned at whatwg/html#3725 (comment)

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.

None yet

8 participants