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