OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Registration</title> | 2 <title>Service Worker: Registration</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharness-helpers.js"></script> | 4 <script src="../resources/testharness-helpers.js"></script> |
5 <script src="../resources/testharnessreport.js"></script> | 5 <script src="../resources/testharnessreport.js"></script> |
6 <script src="resources/test-helpers.js"></script> | 6 <script src="resources/test-helpers.js"></script> |
7 <script> | 7 <script> |
8 | 8 |
9 promise_test(function(t) { | 9 promise_test(function(t) { |
10 var script = 'resources/registration-worker.js'; | 10 var script = 'resources/registration-worker.js'; |
11 var scope = 'resources/registration/'; | 11 var scope = 'resources/registration/'; |
12 return navigator.serviceWorker.register(script, {scope: scope}) | 12 return navigator.serviceWorker.register(script, {scope: scope}) |
13 .then(function(registration) { | 13 .then(function(registration) { |
14 assert_true(registration instanceof ServiceWorkerRegistration, | 14 assert_true(registration instanceof ServiceWorkerRegistration, |
15 'Successfully registered.'); | 15 'Successfully registered.'); |
16 service_worker_unregister_and_done(t, scope); | 16 service_worker_unregister_and_done(t, scope); |
17 }) | 17 }) |
18 }, 'Registering normal pattern'); | 18 }, 'Registering normal pattern'); |
19 | 19 |
20 promise_test(function(t) { | 20 promise_test(function(t) { |
21 var script = 'resources/registration-worker.js'; | 21 var script = 'resources/registration-worker.js'; |
| 22 var scope = 'resources/'; |
| 23 return navigator.serviceWorker.register(script, {scope: scope}) |
| 24 .then(function(registration) { |
| 25 assert_true(registration instanceof ServiceWorkerRegistration, |
| 26 'Successfully registered.'); |
| 27 service_worker_unregister_and_done(t, scope); |
| 28 }) |
| 29 }, 'Registering same scope as the script directory'); |
| 30 |
| 31 promise_test(function(t) { |
| 32 var script = 'resources/registration-worker.js'; |
| 33 var scope = 'resources'; |
| 34 return assert_promise_rejects( |
| 35 navigator.serviceWorker.register(script, {scope: scope}), |
| 36 'SecurityError', |
| 37 'Registering same scope as the script directory without the last ' + |
| 38 'slash should fail with SecurityError.'); |
| 39 }, 'Registering same scope as the script directory without the last slash'); |
| 40 |
| 41 promise_test(function(t) { |
| 42 var script = 'resources/registration-worker.js'; |
| 43 var scope = 'different-directory/'; |
| 44 return assert_promise_rejects( |
| 45 navigator.serviceWorker.register(script, {scope: scope}), |
| 46 'SecurityError', |
| 47 'Registration scope outside the script directory should fail ' + |
| 48 'with SecurityError.'); |
| 49 }, 'Registration scope outside the script directory'); |
| 50 |
| 51 promise_test(function(t) { |
| 52 var script = 'resources/registration-worker.js'; |
22 var scope = 'http://example.com/'; | 53 var scope = 'http://example.com/'; |
23 return assert_promise_rejects( | 54 return assert_promise_rejects( |
24 navigator.serviceWorker.register(script, {scope: scope}), | 55 navigator.serviceWorker.register(script, {scope: scope}), |
25 'SecurityError', | 56 'SecurityError', |
26 'Registration scope outside domain should fail with SecurityError.'); | 57 'Registration scope outside domain should fail with SecurityError.'); |
27 }, 'Registering scope outside domain'); | 58 }, 'Registering scope outside domain'); |
28 | 59 |
29 promise_test(function(t) { | 60 promise_test(function(t) { |
30 var script = 'http://example.com/worker.js'; | 61 var script = 'http://example.com/worker.js'; |
31 var scope = 'http://example.com/scope/'; | 62 var scope = 'http://example.com/scope/'; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 var script = 'resources/redirect.php?Redirect=' + | 106 var script = 'resources/redirect.php?Redirect=' + |
76 encodeURIComponent('/resources/registration-worker.js'); | 107 encodeURIComponent('/resources/registration-worker.js'); |
77 var scope = 'resources/sope/redirect/'; | 108 var scope = 'resources/sope/redirect/'; |
78 return assert_promise_rejects( | 109 return assert_promise_rejects( |
79 navigator.serviceWorker.register(script, {scope: scope}), | 110 navigator.serviceWorker.register(script, {scope: scope}), |
80 'SecurityError', | 111 'SecurityError', |
81 'Registration of redirected script should fail.'); | 112 'Registration of redirected script should fail.'); |
82 }, 'Registering redirected script'); | 113 }, 'Registering redirected script'); |
83 | 114 |
84 </script> | 115 </script> |
OLD | NEW |