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 = '/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 = 'http://example.com/'; | 22 var scope = 'http://example.com/'; |
23 return assert_promise_rejects( | 23 return assert_promise_rejects( |
24 navigator.serviceWorker.register(script, {scope: scope}), | 24 navigator.serviceWorker.register(script, {scope: scope}), |
25 'SecurityError', | 25 'SecurityError', |
26 'Registration scope outside domain should fail with SecurityError.'); | 26 'Registration scope outside domain should fail with SecurityError.'); |
27 }, 'Registering scope outside domain'); | 27 }, 'Registering scope outside domain'); |
28 | 28 |
29 promise_test(function(t) { | 29 promise_test(function(t) { |
30 var script = 'http://example.com/worker.js'; | 30 var script = 'http://example.com/worker.js'; |
| 31 var scope = 'http://example.com/scope/'; |
31 return assert_promise_rejects( | 32 return assert_promise_rejects( |
32 navigator.serviceWorker.register(script), | 33 navigator.serviceWorker.register(script, {scope: scope}), |
33 'SecurityError', | 34 'SecurityError', |
34 'Registration script outside domain should fail with SecurityError.'); | 35 'Registration script outside domain should fail with SecurityError.'); |
35 }, 'Registering script outside domain'); | 36 }, 'Registering script outside domain'); |
36 | 37 |
37 promise_test(function(t) { | 38 promise_test(function(t) { |
38 var script = 'no-such-worker.js'; | 39 var script = 'resources/no-such-worker.js'; |
| 40 var scope = 'resources/scope/no-such-worker'; |
39 return assert_promise_rejects( | 41 return assert_promise_rejects( |
40 navigator.serviceWorker.register(script), | 42 navigator.serviceWorker.register(script, {scope: scope}), |
41 'NetworkError', | 43 'NetworkError', |
42 'Registration of non-existent script should fail.'); | 44 'Registration of non-existent script should fail.'); |
43 }, 'Registering non-existent script'); | 45 }, 'Registering non-existent script'); |
44 | 46 |
45 promise_test(function(t) { | 47 promise_test(function(t) { |
46 var script = 'resources/invalid-chunked-encoding.php'; | 48 var script = 'resources/invalid-chunked-encoding.php'; |
| 49 var scope = 'resources/scope/invalid-chunked-encoding/'; |
47 return assert_promise_rejects( | 50 return assert_promise_rejects( |
48 navigator.serviceWorker.register(script), | 51 navigator.serviceWorker.register(script, {scope: scope}), |
49 'NetworkError', | 52 'NetworkError', |
50 'Registration of invalid chunked encoding script should fail.'); | 53 'Registration of invalid chunked encoding script should fail.'); |
51 }, 'Registering invalid chunked encoding script'); | 54 }, 'Registering invalid chunked encoding script'); |
52 | 55 |
53 promise_test(function(t) { | 56 promise_test(function(t) { |
54 var script = 'resources/invalid-chunked-encoding-with-flush.php'; | 57 var script = 'resources/invalid-chunked-encoding-with-flush.php'; |
| 58 var scope = 'resources/scope/invalid-chunked-encoding-with-flush/'; |
55 return assert_promise_rejects( | 59 return assert_promise_rejects( |
56 navigator.serviceWorker.register(script), | 60 navigator.serviceWorker.register(script, {scope: scope}), |
57 'NetworkError', | 61 'NetworkError', |
58 'Registration of invalid chunked encoding script should fail.'); | 62 'Registration of invalid chunked encoding script should fail.'); |
59 }, 'Registering invalid chunked encoding script with flush'); | 63 }, 'Registering invalid chunked encoding script with flush'); |
60 | 64 |
61 promise_test(function(t) { | 65 promise_test(function(t) { |
62 var script = 'resources/plain-text-worker.php'; | 66 var script = 'resources/plain-text-worker.php'; |
| 67 var scope = 'resources/scope/plain-text-worker/'; |
63 return assert_promise_rejects( | 68 return assert_promise_rejects( |
64 navigator.serviceWorker.register(script), | 69 navigator.serviceWorker.register(script, {scope: scope}), |
65 'SecurityError', | 70 'SecurityError', |
66 'Registration of plain text script should fail.'); | 71 'Registration of plain text script should fail.'); |
67 }, 'Registering script without correct MIME type'); | 72 }, 'Registering script without correct MIME type'); |
68 | 73 |
69 promise_test(function(t) { | 74 promise_test(function(t) { |
70 var script = 'resources/redirect.php?Redirect=' + | 75 var script = 'resources/redirect.php?Redirect=' + |
71 encodeURIComponent('/resources/registration-worker.js'); | 76 encodeURIComponent('/resources/registration-worker.js'); |
| 77 var scope = 'resources/sope/redirect/'; |
72 return assert_promise_rejects( | 78 return assert_promise_rejects( |
73 navigator.serviceWorker.register(script), | 79 navigator.serviceWorker.register(script, {scope: scope}), |
74 'SecurityError', | 80 'SecurityError', |
75 'Registration of redirected script should fail.'); | 81 'Registration of redirected script should fail.'); |
76 }, 'Registering redirected script'); | 82 }, 'Registering redirected script'); |
77 | 83 |
78 </script> | 84 </script> |
OLD | NEW |