2 <title>register() and scope
</title>
3 <script src=
"../resources/testharness.js"></script>
4 <script src=
"../resources/testharness-helpers.js"></script>
5 <script src=
"../resources/testharnessreport.js"></script>
6 <script src=
"resources/test-helpers.js"></script>
9 promise_test(function(t
) {
10 var script
= 'resources/empty-worker.js';
11 var script_url
= new URL(script
, location
.href
);
12 var expected_scope
= new URL('./', script_url
).href
;
13 return service_worker_unregister(t
, expected_scope
)
15 return navigator
.serviceWorker
.register('resources/empty-worker.js');
16 }).then(function(registration
) {
17 assert_equals(registration
.scope
, expected_scope
,
18 'The default scope should be URL("./", script_url)');
19 return registration
.unregister();
25 promise_test(function(t
) {
26 // This script must be different than the 'default scope' test, or else
27 // the scopes will collide.
28 var script
= 'resources/empty.js';
29 var script_url
= new URL(script
, location
.href
);
30 var expected_scope
= new URL('./', script_url
).href
;
31 return service_worker_unregister(t
, expected_scope
)
33 return navigator
.serviceWorker
.register('resources/empty.js',
34 { scope
: undefined });
35 }).then(function(registration
) {
36 assert_equals(registration
.scope
, expected_scope
,
37 'The default scope should be URL("./", script_url)');
38 return registration
.unregister();
42 }, 'undefined scope');
44 promise_test(function(t
) {
45 var script
= 'resources/simple-fetch-worker.js';
46 var script_url
= new URL(script
, location
.href
);
47 var expected_scope
= new URL('./', script_url
).href
;
48 return service_worker_unregister(t
, expected_scope
)
50 return navigator
.serviceWorker
.register('resources/empty.js',
54 function(registration
) {
55 assert_unreached('register should fail');
56 service_worker_unregister_and_done(t
, registration
.scope
);
59 assert_equals(error
.name
, 'SecurityError',
60 'passing a null scope should be interpreted as ' +
61 'scope="null" which violates the path restriction');