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/testharnessreport.js"></script> | 5 <script src="../resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.js"></script> | 6 <script src="resources/test-helpers.js"></script> |
6 <script> | 7 <script> |
7 (function() { | 8 |
8 var t = async_test('Registering normal pattern'); | 9 promise_test(function(t) { |
9 t.step(function() { | 10 var script = 'resources/registration-worker.js'; |
10 var scope = '/registration/'; | 11 var scope = '/registration/'; |
11 navigator.serviceWorker.register( | 12 return navigator.serviceWorker.register(script, {scope: scope}) |
12 'resources/registration-worker.js', | 13 .then(function(registration) { |
13 {scope: scope} | 14 assert_true(registration instanceof ServiceWorkerRegistration, |
14 ).then( | 15 'Successfully registered.'); |
15 t.step_func(function(registration) { | 16 service_worker_unregister_and_done(t, scope); |
16 assert_true(registration instanceof ServiceWorkerRegistration, | 17 }) |
17 'Successfully registered.'); | 18 }, 'Registering normal pattern'); |
18 service_worker_unregister_and_done(t, scope); | |
19 }), | |
20 t.step_func(function(reason) { | |
21 assert_unreached('Registration should succeed, but failed: ' + r
eason.name); | |
22 }) | |
23 ); | |
24 }); | |
25 }()); | |
26 | 19 |
27 (function() { | 20 promise_test(function(t) { |
28 var t = async_test('Registering scope outside domain'); | 21 var script = 'resources/registration-worker.js'; |
29 t.step(function() { | 22 var scope = 'http://example.com/'; |
30 navigator.serviceWorker.register( | 23 return assert_promise_rejects( |
31 'resources/registration-worker.js', | 24 navigator.serviceWorker.register(script, {scope: scope}), |
32 {scope: 'http://example.com/'} | 25 'SecurityError', |
33 ).then( | 26 'Registration scope outside domain should fail with SecurityError.'); |
34 t.step_func(function(registration) { | 27 }, 'Registering scope outside domain'); |
35 assert_unreached('Registration scope outside domain should fail.
'); | |
36 }), | |
37 t.step_func(function(reason) { | |
38 assert_equals(reason.name, 'SecurityError', | |
39 'Registration scope outside domain should fail wit
h SecurityError.'); | |
40 t.done(); | |
41 }) | |
42 ); | |
43 }); | |
44 }()); | |
45 | 28 |
46 (function() { | 29 promise_test(function(t) { |
47 var t = async_test('Registering script outside domain'); | 30 var script = 'http://example.com/worker.js'; |
48 t.step(function() { | 31 return assert_promise_rejects( |
49 navigator.serviceWorker.register( | 32 navigator.serviceWorker.register(script), |
50 'http://example.com/worker.js' | 33 'SecurityError', |
51 ).then( | 34 'Registration script outside domain should fail with SecurityError.'); |
52 t.step_func(function(registration) { | 35 }, 'Registering script outside domain'); |
53 assert_unreached('Registration script outside domain should fail
.'); | |
54 }), | |
55 t.step_func(function(reason) { | |
56 assert_equals(reason.name, 'SecurityError', | |
57 'Registration script outside domain should fail wit
h SecurityError.'); | |
58 t.done(); | |
59 }) | |
60 ); | |
61 }); | |
62 }()); | |
63 | 36 |
64 (function() { | 37 promise_test(function(t) { |
65 var t = async_test('Registering non-existent script'); | 38 var script = 'no-such-worker.js'; |
66 t.step(function() { | 39 return assert_promise_rejects( |
67 navigator.serviceWorker.register( | 40 navigator.serviceWorker.register(script), |
68 'resources/no-such-worker.js' | 41 'NetworkError', |
69 ).then( | 42 'Registration of non-existent script should fail.'); |
70 t.step_func(function(registration) { | 43 }, 'Registering non-existent script'); |
71 assert_unreached('Registration of non-existent script should fai
l.'); | |
72 }), | |
73 t.step_func(function(reason) { | |
74 assert_equals(reason.name, 'NetworkError', | |
75 'Registration of non-existent script should fail.')
; | |
76 t.done(); | |
77 }) | |
78 ); | |
79 }); | |
80 }()); | |
81 | 44 |
82 (function() { | 45 promise_test(function(t) { |
83 var t = async_test('Registering script without correct MIME type'); | 46 var script = 'resources/invalid-chunked-encoding.php'; |
84 t.step(function() { | 47 return assert_promise_rejects( |
85 navigator.serviceWorker.register( | 48 navigator.serviceWorker.register(script), |
86 'resources/plain-text-worker.php' | 49 'NetworkError', |
87 ).then( | 50 'Registration of invalid chunked encoding script should fail.'); |
88 t.step_func(function(registration) { | 51 }, 'Registering invalid chunked encoding script'); |
89 assert_unreached('Registration of plain text script should fail.
'); | |
90 }), | |
91 t.step_func(function(reason) { | |
92 assert_equals(reason.name, 'SecurityError', | |
93 'Registration of plain text script should fail.'); | |
94 t.done(); | |
95 }) | |
96 ); | |
97 }); | |
98 }()); | |
99 | 52 |
100 (function() { | 53 promise_test(function(t) { |
101 var t = async_test('Registering redirected script'); | 54 var script = 'resources/invalid-chunked-encoding-with-flush.php'; |
102 t.step(function() { | 55 return assert_promise_rejects( |
103 navigator.serviceWorker.register( | 56 navigator.serviceWorker.register(script), |
104 'resources/redirect.php?Redirect=' + | 57 'NetworkError', |
105 encodeURIComponent('/resources/registration-worker.js') | 58 'Registration of invalid chunked encoding script should fail.'); |
106 ).then( | 59 }, 'Registering invalid chunked encoding script with flush'); |
107 t.step_func(function(registration) { | 60 |
108 assert_unreached('Registration of redirected script should fail.
'); | 61 promise_test(function(t) { |
109 }), | 62 var script = 'resources/plain-text-worker.php'; |
110 t.step_func(function(reason) { | 63 return assert_promise_rejects( |
111 assert_equals(reason.name, 'SecurityError', | 64 navigator.serviceWorker.register(script), |
112 'Registration of redirected script should fail.'); | 65 'SecurityError', |
113 t.done(); | 66 'Registration of plain text script should fail.'); |
114 }) | 67 }, 'Registering script without correct MIME type'); |
115 ); | 68 |
116 }); | 69 promise_test(function(t) { |
117 }()); | 70 var script = 'resources/redirect.php?Redirect=' + |
| 71 encodeURIComponent('/resources/registration-worker.js'); |
| 72 return assert_promise_rejects( |
| 73 navigator.serviceWorker.register(script), |
| 74 'SecurityError', |
| 75 'Registration of redirected script should fail.'); |
| 76 }, 'Registering redirected script'); |
118 | 77 |
119 </script> | 78 </script> |
OLD | NEW |