Skip to content

Commit

Permalink
ServiceWorker: Change base URL for parsing script URL and scope URL
Browse files Browse the repository at this point in the history
According to the spec change, this changes to use the relevant settings object
instead of the entry settings object to parse the script URL and the scope URL
given to ServiceWorkerContainer.register() and
ServiceWorkerContainer.getRegistration().

Before this CL, register() and getRegistration() used entered execution context
to parse the URLs. After this CL, the methods use the execution context
retrieved from ScriptState::getExecutionContext().

WPT: external/wpt/service-workers/service-worker/multi-globals/url-parsing.https.html

Spec issue: w3c/ServiceWorker#922
Spec change: w3c/ServiceWorker@ec1aac2

BUG=691008

Review-Url: https://codereview.chromium.org/2691903005
Cr-Commit-Position: refs/heads/master@{#453033}
  • Loading branch information
jungkees authored and jeffcarp committed Feb 25, 2017
1 parent 2df2dc1 commit c3e1d2d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<body>
<script>
promise_test(function(t) {
var scope = 'resources/blank.html';
const iframe_scope = 'blank.html';
const scope = 'resources/' + iframe_scope;
var frame;
var registration;
var controller;
Expand All @@ -17,7 +18,7 @@
.then(function(f) {
frame = f;
return frame.contentWindow.navigator.serviceWorker.register(
'resources/empty-worker.js', {scope: scope});
'empty-worker.js', {scope: iframe_scope});
})
.then(function(swr) {
registration = swr;
Expand All @@ -42,7 +43,7 @@
// objects from separate windows should not be equal
assert_not_equals(controller, registration.active);

return w.navigator.serviceWorker.getRegistration();
return w.navigator.serviceWorker.getRegistration(iframe_scope);
})
.then(function(frameRegistration) {
assert_equals(frameRegistration.active, controller);
Expand Down
3 changes: 2 additions & 1 deletion service-workers/service-worker/multiple-register.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
.then(function(f) {
frame = f;
return frame.contentWindow.navigator.serviceWorker.register(
worker_url, { scope: scope });
'empty-worker.js',
{ scope: 'scope/subsequent-register-from-different-iframe' });
})
.then(function(new_registration) {
assert_not_equals(
Expand Down
63 changes: 32 additions & 31 deletions service-workers/service-worker/registration-iframe.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
// Set script url and scope url relative to the calling frame's document's url.
// Assert the implementation parses the urls against the calling frame's
// document's url.

// Set script url and scope url relative to the iframe's document's url. Assert
// the implementation parses the urls against the iframe's document's url.
async_test(function(t) {
var url = 'resources/blank.html';
var scope = 'resources/registration-for-iframe-from-calling-frame';
var parsed_scope = normalizeURL(scope);
var script = 'resources/empty-worker.js';
var parsed_script = normalizeURL(script);
var scope = 'registration-for-iframe-from-parent-frame';
var expected_scope = normalizeURL('resources/' + scope);
var script = 'empty-worker.js';
var expected_script = normalizeURL('resources/' + script);
var frame;
var registration;

Expand All @@ -30,28 +30,25 @@
return wait_for_state(t, r.installing, 'activated');
})
.then(function() {
assert_equals(
registration.scope, parsed_scope,
'registration\'s scope must be the scope parsed against calling ' +
'document\'s url');
assert_equals(
registration.active.scriptURL, parsed_script,
'worker\'s script must be the url parsed against calling ' +
'document\'s url');
assert_equals(registration.scope, expected_scope,
'registration\'s scope must be parsed against the ' +
'"relevant global object"');
assert_equals(registration.active.scriptURL, expected_script,
'worker\'s scriptURL must be parsed against the ' +
'"relevant global object"');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'Subframe\'s container\'s register method should use calling frame\'s ' +
'document\'s url as a base url for parsing its script url and scope url ' +
'- normal case');
}, 'register method should use the "relevant global object" to parse its ' +
'scriptURL and scope - normal case');

// Set script url and scope url relative to the iframe's document's url.
// Assert the implementation throws a NetworkError exception.
// Set script url and scope url relative to the parent frame's document's url.
// Assert the implementation throws a TypeError exception.
async_test(function(t) {
var url = 'resources/blank.html';
var scope = 'registration-for-iframe-from-calling-frame';
var script = 'empty-worker.js';
var scope = 'resources/registration-for-iframe-from-parent-frame';
var script = 'resources/empty-worker.js';
var frame;
var registration;

Expand All @@ -68,21 +65,22 @@
assert_unreached('register() should reject');
},
function(e) {
assert_equals(e.name, 'TypeError');
assert_equals(e.name, 'TypeError',
'register method with scriptURL and scope parsed to ' +
'nonexistent location should reject with TypeError');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'Subframe\'s container\'s register method should use calling frame\'s ' +
'document\'s url as a base url for parsing its script url and scope url ' +
'- error case');
}, 'register method should use the "relevant global object" to parse its ' +
'scriptURL and scope - error case');

// Set the scope url to a non-subdirectory of the script url.
// Assert the implementation throws a SecurityError exception.
// Set the scope url to a non-subdirectory of the script url. Assert the
// implementation throws a SecurityError exception.
async_test(function(t) {
var url = 'resources/blank.html';
var scope = 'registration-for-iframe-from-calling-frame';
var script = 'resources/empty-worker.js';
var scope = '../registration-for-iframe-from-parent-frame';
var script = 'empty-worker.js';
var frame;
var registration;

Expand All @@ -99,10 +97,13 @@
assert_unreached('register() should reject');
},
function(e) {
assert_equals(e.name, 'SecurityError');
assert_equals(e.name, 'SecurityError',
'The scope set to a non-subdirectory of the scriptURL ' +
'should reject with SecurityError');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'A scope url should start with the given script url');

</script>

0 comments on commit c3e1d2d

Please sign in to comment.