-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
service-workers/service-worker/multi-globals/current/current.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!DOCTYPE html> | ||
<title>Current page used as a test helper</title> |
15 changes: 15 additions & 0 deletions
15
service-workers/service-worker/multi-globals/current/test-sw.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
this.addEventListener('install', event => { | ||
this.skipWaiting(); | ||
}); | ||
|
||
this.addEventListener('activate', event => { | ||
clients.claim(); | ||
}); | ||
|
||
this.addEventListener('fetch', event => { | ||
if (event.request.url.includes('test.txt')) { | ||
event.respondWith(new Response('current')); | ||
} | ||
}); |
20 changes: 20 additions & 0 deletions
20
service-workers/service-worker/multi-globals/incumbent/incumbent.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<title>Incumbent page used as a test helper</title> | ||
|
||
<iframe src="../current/current.https.html" id="c"></iframe> | ||
<iframe src="../relevant/relevant.https.html" id="r"></iframe> | ||
|
||
<script> | ||
'use strict'; | ||
|
||
const current = document.querySelector('#c').contentWindow; | ||
const relevant = document.querySelector('#r').contentWindow; | ||
|
||
window.testRegister = options => { | ||
return current.navigator.serviceWorker.register.call(relevant.navigator.serviceWorker, 'test-sw.js', options); | ||
}; | ||
|
||
window.testGetRegistration = () => { | ||
return current.navigator.serviceWorker.getRegistration.call(relevant.navigator.serviceWorker, 'test-sw.js'); | ||
}; | ||
</script> |
15 changes: 15 additions & 0 deletions
15
service-workers/service-worker/multi-globals/incumbent/test-sw.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
this.addEventListener('install', event => { | ||
this.skipWaiting(); | ||
}); | ||
|
||
this.addEventListener('activate', event => { | ||
clients.claim(); | ||
}); | ||
|
||
this.addEventListener('fetch', event => { | ||
if (event.request.url.includes('test.txt')) { | ||
event.respondWith(new Response('incumbent')); | ||
} | ||
}); |
2 changes: 2 additions & 0 deletions
2
service-workers/service-worker/multi-globals/relevant/relevant.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!DOCTYPE html> | ||
<title>Relevant page used as a test helper</title> |
15 changes: 15 additions & 0 deletions
15
service-workers/service-worker/multi-globals/relevant/test-sw.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
this.addEventListener('install', event => { | ||
this.skipWaiting(); | ||
}); | ||
|
||
this.addEventListener('activate', event => { | ||
clients.claim(); | ||
}); | ||
|
||
this.addEventListener('fetch', event => { | ||
if (event.request.url.includes('test.txt')) { | ||
event.respondWith(new Response('relevant')); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
this.addEventListener('install', event => { | ||
this.skipWaiting(); | ||
}); | ||
|
||
this.addEventListener('activate', event => { | ||
clients.claim(); | ||
}); | ||
|
||
this.addEventListener('fetch', event => { | ||
if (event.request.url.includes('test.txt')) { | ||
event.respondWith(new Response('entry')); | ||
} | ||
}); |
72 changes: 72 additions & 0 deletions
72
service-workers/service-worker/multi-globals/url-parsing.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<title>register()/getRegistration() URL parsing, with multiple globals in play</title> | ||
<link rel="help" href="https://w3c.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-container-register-method"> | ||
<link rel="help" href="https://w3c.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-container-getregistration-method"> | ||
<link rel="author" title="Domenic Denicola" href="mailto:[email protected]"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="../resources/testharness-helpers.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="../resources/test-helpers.sub.js"></script> | ||
|
||
<!-- This is the entry global --> | ||
|
||
<iframe src="incumbent/incumbent.https.html"></iframe> | ||
|
||
<script> | ||
'use strict'; | ||
|
||
const loadPromise = new Promise(resolve => { | ||
window.addEventListener('load', () => resolve()); | ||
}); | ||
|
||
promise_test(t => { | ||
let registration; | ||
|
||
return loadPromise.then(() => { | ||
return frames[0].testRegister(); | ||
}).then(r => { | ||
registration = r; | ||
const newestWorker = r.installing || r.waiting || r.active; | ||
return wait_for_state(t, newestWorker, 'activated'); | ||
}).then(() => { | ||
return fetch('relevant/test.txt'); | ||
}) | ||
.then(response => response.text()) | ||
.then(text => { | ||
assert_equals(text, 'relevant', | ||
'the service worker found at relevant/test-sw.js must have been the one to intercept the fetch'); | ||
|
||
return registration.unregister(); | ||
}); | ||
}, 'register should use the relevant global of the object it was called on to resolve the script URL'); | ||
|
||
promise_test(t => { | ||
return loadPromise.then(() => { | ||
return frames[0].testRegister({ scope: 'scope' }); | ||
}).then(registration => { | ||
assert_equals(registration.scope, normalizeURL('relevant/scope'), 'the scope URL should be relevant/scope'); | ||
|
||
return registration.unregister(); | ||
}); | ||
}, 'register should use the relevant global of the object it was called on to resolve the scope URL'); | ||
|
||
promise_test(t => { | ||
let registration; | ||
|
||
return loadPromise.then(() => { | ||
return navigator.serviceWorker.register(normalizeURL('relevant/test-sw.js')); | ||
}).then(r => { | ||
registration = r; | ||
return frames[0].testGetRegistration(); | ||
}) | ||
.then(gottenRegistration => { | ||
assert_not_equals(registration, null, 'the registration should not be null'); | ||
assert_not_equals(gottenRegistration, null, 'the registration from the other frame should not be null'); | ||
assert_equals(gottenRegistration.scope, registration.scope, | ||
'the retrieved registration\'s scope should be equal to the original\'s scope'); | ||
|
||
return registration.unregister(); | ||
}); | ||
}, 'getRegistration should use the relevant global of the object it was called on to resolve the script URL'); | ||
|
||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The second snippet in 4b90437#r100237660 needs to be added in this script and to other service worker scripts I guess.