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 multi-global tests for service worker URL parsing #3449

Merged
merged 3 commits into from
Feb 10, 2017

Conversation

domenic
Copy link
Member

@domenic domenic commented Aug 10, 2016

See w3c/ServiceWorker#922.

This should not be merged until we have consensus on that spec fix.

@wpt-pr-bot
Copy link
Collaborator

Reviewers for this pull request are: @ehsan.

if (event.request.url.includes('test.txt')) {
event.respondWith(new Response('current'));
} else {
event.respondWith(fetch(event.request));
Copy link
Member

Choose a reason for hiding this comment

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

You could remove these for simplicity: not calling respondWith will fallback to network.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed!

domenic added a commit to domenic/ServiceWorker that referenced this pull request Aug 26, 2016
Fixes w3c#922. Web platform tests at web-platform-tests/wpt#3449. Part of the overall effort in whatwg/html#1431.

In the process, fixes some ambiguity about how to parse URLs in the Link header, as previous it parsed relative to the entry settings object, which did not exist during this algorithm.
@ayg ayg closed this Aug 28, 2016
@ayg ayg deleted the service-worker-multi-globals branch August 28, 2016 13:58
@domenic
Copy link
Member Author

domenic commented Aug 28, 2016

Why close and delete my PR?

@domenic domenic restored the service-worker-multi-globals branch August 28, 2016 18:35
@domenic domenic reopened this Aug 28, 2016
@domenic domenic force-pushed the service-worker-multi-globals branch from 64f2812 to 4b90437 Compare August 29, 2016 19:05
domenic added a commit to domenic/ServiceWorker that referenced this pull request Sep 6, 2016
Fixes w3c#922. Web platform tests at web-platform-tests/wpt#3449. Part of the overall effort in whatwg/html#1431.

In the process, fixes some ambiguity about how to parse URLs in the Link header, as previous it parsed relative to the entry settings object, which did not exist during this algorithm.
@ayg ayg closed this Oct 26, 2016
@ayg ayg deleted the service-worker-multi-globals branch October 26, 2016 17:37
@ayg
Copy link
Contributor

ayg commented Oct 27, 2016

I can't figure out how to restore the branch at this point, so please re-push it if you still have it locally in case I don't wind up finding a solution. (I deleted it by mistake.)

@ayg ayg restored the service-worker-multi-globals branch October 27, 2016 12:35
@ayg ayg reopened this Oct 27, 2016
@wpt-stability-bot
Copy link

Firefox

Testing revision b1c22eb
Starting 10 test iterations
All results were stable

All results

/service-workers/service-worker/multi-globals/url-parsing.https.html

Subtest Results
OK
register should use the relevant global of the object it was called on to resolve the scope URL FAIL
getRegistration should use the relevant global of the object it was called on to resolve the script URL FAIL
register should use the relevant global of the object it was called on to resolve the script URL FAIL

@wpt-stability-bot
Copy link

Chrome

Testing revision b1c22eb
Starting 10 test iterations
All results were stable

All results

/service-workers/service-worker/multi-globals/url-parsing.https.html

Subtest Results
ERROR
register should use the relevant global of the object it was called on to resolve the scope URL FAIL
getRegistration should use the relevant global of the object it was called on to resolve the script URL FAIL
register should use the relevant global of the object it was called on to resolve the script URL FAIL

Copy link
Contributor

@jungkees jungkees left a comment

Choose a reason for hiding this comment

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

Tests look good, but left comments about making sure the document gets the controller before fetching the resource.

return frames[0].testRegister();
}).then(r => {
registration = r;
return fetch('test.txt');
Copy link
Contributor

@jungkees jungkees Feb 9, 2017

Choose a reason for hiding this comment

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

This fetch is not intercepted as the document hasn't gotten its controller yet. We should make sure the registration has advanced to "activated" state before this fetch. For that, add a promise returning utility function wait_for_state before this line. It would look like:

const newestWorker = r.installing || r.waiting || r.active;
return wait_for_state(test, newestWorker, 'activated').then(_ => {
  // Fetch here
});

Also, the following code is needed in the service worker script to promote the worker to active worker and to make all of its clients controlled right away (without reloading them:)

this.addEventListener('install', event => {
    this.skipWaiting();
});

this.addEventListener('activate', event => {
    clients.claim();
});

And I think the fetch should fetch('relevant/test.txt') instead of test.txt as we expect the relevant scoped worker intercept this request.

@@ -0,0 +1,5 @@
this.addEventListener('fetch', event => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The second snippet in 4b90437#r100237660 needs to be added in this script and to other service worker scripts I guess.

@domenic
Copy link
Member Author

domenic commented Feb 9, 2017

Thanks @jungkees! Fixed; PTAL.

@w3c-bots
Copy link

w3c-bots commented Feb 9, 2017

Chrome (unstable channel)

Testing web-platform-tests at revision 30c4331f8d618ddf5ebff47e0b7b3ce6603757ee
Using browser at version 58.0.3004.3 dev
Starting 10 test iterations
All results were stable

All results

/service-workers/service-worker/multi-globals/url-parsing.https.html
Subtest Results
OK
register should use the relevant global of the object it was called on to resolve the scope URL FAIL
getRegistration should use the relevant global of the object it was called on to resolve the script URL FAIL
register should use the relevant global of the object it was called on to resolve the script URL FAIL

@w3c-bots
Copy link

w3c-bots commented Feb 9, 2017

Firefox (nightly channel)

Testing web-platform-tests at revision 30c4331f8d618ddf5ebff47e0b7b3ce6603757ee
Using browser at version BuildID 20170123125947; SourceStamp 36486fdc3813ef7943ae5b07b4128866d1938a6c
Starting 10 test iterations
All results were stable

All results

/service-workers/service-worker/multi-globals/url-parsing.https.html
Subtest Results
OK
register should use the relevant global of the object it was called on to resolve the scope URL FAIL
getRegistration should use the relevant global of the object it was called on to resolve the script URL PASS
register should use the relevant global of the object it was called on to resolve the script URL FAIL

})
.then(gottenRegistration => {
assert_not_equals(registration, null, 'the registration should not be null');
assert_equals(gottenRegistration, registration, 'the retrieved registration should be equal to the original');
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to fail as it compares objects gotten from different realm I guess. Comparing gottenRegistration.scope === registration.scope would do here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catch, thank you.

@jungkees
Copy link
Contributor

@domenic, it LGTM with the above comment. JS objects from different realms won't pass equality check, right?

@domenic domenic merged commit 688f5f8 into master Feb 10, 2017
@domenic domenic deleted the service-worker-multi-globals branch February 10, 2017 18:14
foolip added a commit to foolip/ServiceWorker that referenced this pull request Apr 24, 2017
The wording is adapted from the WHATWG contributor guidelines:
https://github.com/whatwg/meta/blob/master/CONTRIBUTING.md

This is sometimes already happening:
web-platform-tests/wpt#3449
web-platform-tests/wpt#5628

Drive-by: whitespace
foolip added a commit to foolip/ServiceWorker that referenced this pull request Apr 26, 2017
The wording is adapted from the WHATWG contributor guidelines:
https://github.com/whatwg/meta/blob/master/CONTRIBUTING.md

This is sometimes already happening:
web-platform-tests/wpt#3449
web-platform-tests/wpt#5628

Drive-by: whitespace
jungkees pushed a commit to w3c/ServiceWorker that referenced this pull request Apr 26, 2017
The wording is adapted from the WHATWG contributor guidelines:
https://github.com/whatwg/meta/blob/master/CONTRIBUTING.md

This is sometimes already happening:
web-platform-tests/wpt#3449
web-platform-tests/wpt#5628

Drive-by: whitespace
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