OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <title>register() and scope</title> | |
3 <script src="../resources/testharness.js"></script> | |
4 <script src="../resources/testharnessreport.js"></script> | |
5 <script src="resources/test-helpers.js"></script> | |
6 <script> | |
7 | |
8 promise_test(function(t) { | |
9 var script = 'resources/empty-worker.js'; | |
10 var script_url = new URL(script, location.href); | |
11 var expected_scope = new URL('./', script_url).href; | |
12 return service_worker_unregister(t, expected_scope) | |
13 .then(function() { | |
14 return navigator.serviceWorker.register('resources/empty-worker.js'); | |
15 }).then(function(registration) { | |
16 assert_equals(registration.scope, expected_scope, | |
17 'The default scope should be URL("./", script_url)'); | |
18 return registration.unregister(); | |
19 }).then(function() { | |
20 t.done(); | |
21 }); | |
22 }, 'default scope'); | |
23 | |
24 promise_test(function(t) { | |
25 // This script must be different than the 'default scope' test, or else | |
26 // the scopes will collide. | |
27 var script = 'resources/empty.js'; | |
28 var script_url = new URL(script, location.href); | |
29 var expected_scope = new URL('./', script_url).href; | |
30 return service_worker_unregister(t, expected_scope) | |
31 .then(function() { | |
32 return navigator.serviceWorker.register('resources/empty.js', | |
33 { scope: undefined }); | |
34 }).then(function(registration) { | |
35 assert_equals(registration.scope, expected_scope, | |
36 'The default scope should be URL("./", script_url)'); | |
37 return registration.unregister(); | |
38 }).then(function() { | |
39 t.done(); | |
40 }); | |
41 }, 'undefined scope'); | |
42 | |
43 promise_test(function(t) { | |
44 var script = 'resources/simple-fetch-worker.js'; | |
45 var script_url = new URL(script, location.href); | |
46 var expected_scope = new URL('./', script_url).href; | |
47 return service_worker_unregister(t, expected_scope) | |
48 .then(function() { | |
49 return navigator.serviceWorker.register('resources/empty.js', | |
50 { scope: null }); | |
51 }) | |
52 .then( | |
53 function(registration) { | |
54 assert_unreached('register should fail'); | |
55 service_worker_unregister_and_done(t, registration.scope); | |
56 }, | |
57 function(error) { | |
58 assert_equals(error.name, 'SecurityError', | |
59 'passing a null scope should be interpreted as ' + | |
60 'scope="null" which violates the path restriction'); | |
61 t.done(); | |
62 }); | |
63 }, 'null scope'); | |
64 | |
65 </script> | |
OLD | NEW |