OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="resources/test-helpers.js"></script> | 4 <script src="resources/test-helpers.js"></script> |
5 <script> | 5 <script> |
6 var worker_url = 'resources/empty-worker.js'; | 6 var worker_url = 'resources/empty-worker.js'; |
7 | 7 |
8 async_test(function(t) { | 8 async_test(function(t) { |
9 var scope = 'scope/re-register-resolves-to-new-value'; | 9 var scope = 'scope/re-register-resolves-to-new-value'; |
10 var iframe; | 10 var iframe; |
11 var previous_registration; | |
11 | 12 |
12 service_worker_unregister_and_register(t, worker_url, scope) | 13 service_worker_unregister_and_register(t, worker_url, scope) |
13 .then(function(registered_worker) { | 14 .then(function(registration) { |
14 worker = registered_worker; | 15 previous_registration = registration; |
16 return wait_for_update(t, registration); | |
17 }) | |
18 .then(function(worker) { | |
15 return wait_for_state(t, worker, 'activated'); | 19 return wait_for_state(t, worker, 'activated'); |
16 }) | 20 }) |
17 .then(function() { | 21 .then(function() { |
18 return navigator.serviceWorker.unregister(scope); | 22 return navigator.serviceWorker.unregister(scope); |
19 }) | 23 }) |
20 .then(function() { | 24 .then(function() { |
21 return navigator.serviceWorker.register(worker_url, { scope: scope }); | 25 return navigator.serviceWorker.register(worker_url, { scope: scope }); |
22 }) | 26 }) |
23 .then(function(registered_worker) { | 27 .then(function(registration) { |
24 assert_not_equals(registered_worker, worker, | 28 assert_not_equals(previous_registration, registration, |
25 'register should resolve to a new value'); | 29 'register should resolve to a new value'); |
26 service_worker_unregister_and_done(t, scope); | 30 service_worker_unregister_and_done(t, scope); |
27 }) | 31 }) |
28 .catch(unreached_rejection(t)); | 32 .catch(unreached_rejection(t)); |
29 }, 'Unregister then register resolves to a new value'); | 33 }, 'Unregister then register resolves to a new value'); |
30 | 34 |
31 async_test(function(t) { | 35 async_test(function(t) { |
32 var scope = 'scope/re-register-while-old-registration-in-use'; | 36 var scope = 'scope/re-register-while-old-registration-in-use'; |
33 var worker; | 37 var previous_registration; |
34 | 38 |
35 service_worker_unregister_and_register(t, worker_url, scope) | 39 service_worker_unregister_and_register(t, worker_url, scope) |
36 .then(function(registered_worker) { | 40 .then(function(registration) { |
37 worker = registered_worker; | 41 previous_registration = registration; |
42 return wait_for_update(t, registration); | |
43 }) | |
44 .then(function(worker) { | |
38 return wait_for_state(t, worker, 'activated'); | 45 return wait_for_state(t, worker, 'activated'); |
39 }) | 46 }) |
40 .then(function() { | 47 .then(function() { |
41 return with_iframe(scope); | 48 return with_iframe(scope); |
42 }) | 49 }) |
43 .then(function(frame) { | 50 .then(function(frame) { |
44 return navigator.serviceWorker.unregister(scope); | 51 return navigator.serviceWorker.unregister(scope); |
45 }) | 52 }) |
46 .then(function() { | 53 .then(function() { |
47 return navigator.serviceWorker.register(worker_url, { scope: scope }); | 54 return navigator.serviceWorker.register(worker_url, { scope: scope }); |
48 }) | 55 }) |
49 .then(function(registered_worker) { | 56 .then(function(registration) { |
50 assert_equals(registered_worker, worker, | 57 assert_equals(previous_registration, registration, |
51 'register should resolve to the same value'); | 58 'register should resolve to the same value'); |
52 service_worker_unregister_and_done(t, scope); | 59 service_worker_unregister_and_done(t, scope); |
53 }) | 60 }) |
54 .catch(unreached_rejection(t)); | 61 .catch(unreached_rejection(t)); |
55 }, 'Unregister then register resolves to the original value if the ' + | 62 }, 'Unregister then register resolves to the original value if the ' + |
56 'registration is in use.'); | 63 'registration is in use.'); |
57 | 64 |
58 async_test(function(t) { | 65 async_test(function(t) { |
59 var scope = 'scope/re-register-does-not-affect-existing-controllee'; | 66 var scope = 'scope/re-register-does-not-affect-existing-controllee'; |
60 var iframe; | 67 var iframe; |
61 | 68 |
62 service_worker_unregister_and_register(t, worker_url, scope) | 69 service_worker_unregister_and_register(t, worker_url, scope) |
70 .then(function(registration) { | |
71 return wait_for_update(t, registration); | |
72 }) | |
63 .then(function(registered_worker) { | 73 .then(function(registered_worker) { |
64 return wait_for_state(t, registered_worker, 'activated'); | 74 return wait_for_state(t, registered_worker, 'activated'); |
65 }) | 75 }) |
66 .then(function() { | 76 .then(function() { |
67 return with_iframe(scope); | 77 return with_iframe(scope); |
68 }) | 78 }) |
69 .then(function(frame) { | 79 .then(function(frame) { |
70 iframe = frame; | 80 iframe = frame; |
71 worker = iframe.contentWindow.navigator.serviceWorker.controller; | 81 worker = iframe.contentWindow.navigator.serviceWorker.controller; |
72 return navigator.serviceWorker.unregister(scope); | 82 return navigator.serviceWorker.unregister(scope); |
73 }) | 83 }) |
74 .then(function() { | 84 .then(function() { |
75 return navigator.serviceWorker.register(worker_url, { scope: scope }); | 85 return navigator.serviceWorker.register(worker_url, { scope: scope }); |
76 }) | 86 }) |
77 .then(function() { | 87 .then(function(registration) { |
78 var sw_container = iframe.contentWindow.navigator.serviceWorker; | 88 var sw_container = iframe.contentWindow.navigator.serviceWorker; |
falken
2014/08/14 14:23:15
now this var isn't so useful
either move this var
nhiroki
2014/08/14 16:37:54
Done.
| |
79 assert_equals(sw_container.installing, null, | 89 assert_equals(registration.installing, null, |
80 'installing version is null'); | 90 'installing version is null'); |
81 assert_equals(sw_container.waiting, null, 'waiting version is null'); | 91 assert_equals(registration.waiting, null, 'waiting version is null'); |
82 assert_equals(sw_container.controller, worker, | 92 assert_equals(sw_container.controller, worker, |
83 'the worker from the first registration is the ' + | 93 'the worker from the first registration is the ' + |
84 'controller'); | 94 'controller'); |
85 service_worker_unregister_and_done(t, scope); | 95 service_worker_unregister_and_done(t, scope); |
86 }) | 96 }) |
87 .catch(unreached_rejection(t)); | 97 .catch(unreached_rejection(t)); |
88 }, 'Unregister then register does not affect existing controllee'); | 98 }, 'Unregister then register does not affect existing controllee'); |
89 | 99 |
90 async_test(function(t) { | 100 async_test(function(t) { |
91 var scope = 'scope/resurrection'; | 101 var scope = 'scope/resurrection'; |
92 var iframe; | 102 var iframe; |
93 var worker; | 103 var worker; |
94 | 104 |
95 service_worker_unregister_and_register(t, worker_url, scope) | 105 service_worker_unregister_and_register(t, worker_url, scope) |
106 .then(function(registration) { | |
107 return wait_for_update(t, registration); | |
108 }) | |
96 .then(function(registered_worker) { | 109 .then(function(registered_worker) { |
97 return wait_for_state(t, registered_worker, 'activated'); | 110 return wait_for_state(t, registered_worker, 'activated'); |
98 }) | 111 }) |
99 .then(function() { | 112 .then(function() { |
100 return with_iframe(scope); | 113 return with_iframe(scope); |
101 }) | 114 }) |
102 .then(function(frame) { | 115 .then(function(frame) { |
103 iframe = frame; | 116 iframe = frame; |
104 worker = iframe.contentWindow.navigator.serviceWorker.controller; | 117 worker = iframe.contentWindow.navigator.serviceWorker.controller; |
105 return navigator.serviceWorker.unregister(scope); | 118 return navigator.serviceWorker.unregister(scope); |
(...skipping 17 matching lines...) Expand all Loading... | |
123 }) | 136 }) |
124 .catch(unreached_rejection(t)); | 137 .catch(unreached_rejection(t)); |
125 }, 'Unregister then register resurrects the registration'); | 138 }, 'Unregister then register resurrects the registration'); |
126 | 139 |
127 async_test(function(t) { | 140 async_test(function(t) { |
128 var scope = 'scope/new-worker'; | 141 var scope = 'scope/new-worker'; |
129 var new_worker_url = worker_url + '?new'; | 142 var new_worker_url = worker_url + '?new'; |
130 var iframe; | 143 var iframe; |
131 | 144 |
132 service_worker_unregister_and_register(t, worker_url, scope) | 145 service_worker_unregister_and_register(t, worker_url, scope) |
146 .then(function(registration) { | |
147 return wait_for_update(t, registration); | |
148 }) | |
133 .then(function(worker) { | 149 .then(function(worker) { |
134 return wait_for_state(t, worker, 'activated'); | 150 return wait_for_state(t, worker, 'activated'); |
135 }) | 151 }) |
136 .then(function() { | 152 .then(function() { |
137 return with_iframe(scope); | 153 return with_iframe(scope); |
138 }) | 154 }) |
139 .then(function(frame) { | 155 .then(function(frame) { |
140 iframe = frame; | 156 iframe = frame; |
141 return navigator.serviceWorker.unregister(scope); | 157 return navigator.serviceWorker.unregister(scope); |
142 }) | 158 }) |
143 .then(function() { | 159 .then(function() { |
144 // FIXME: Register should not resolve until controllees are unloaded. | 160 // FIXME: Register should not resolve until controllees are unloaded. |
145 return navigator.serviceWorker.register(new_worker_url, | 161 return navigator.serviceWorker.register(new_worker_url, |
146 { scope: scope }); | 162 { scope: scope }); |
147 }) | 163 }) |
164 .then(function(registration) { | |
165 return wait_for_update(t, registration); | |
166 }) | |
148 .then(function(worker) { | 167 .then(function(worker) { |
149 return wait_for_state(t, worker, 'activated'); | 168 return wait_for_state(t, worker, 'activated'); |
150 }) | 169 }) |
151 .then(function() { | 170 .then(function() { |
152 return with_iframe(scope); | 171 return with_iframe(scope); |
153 }) | 172 }) |
154 .then(function(frame) { | 173 .then(function(frame) { |
155 assert_equals(frame.contentWindow.navigator.serviceWorker.controller.s criptURL, | 174 assert_equals(frame.contentWindow.navigator.serviceWorker.controller.s criptURL, |
156 normalizeURL(new_worker_url), | 175 normalizeURL(new_worker_url), |
157 'document controller is the new worker'); | 176 'document controller is the new worker'); |
158 service_worker_unregister_and_done(t, scope); | 177 service_worker_unregister_and_done(t, scope); |
159 }) | 178 }) |
160 .catch(unreached_rejection(t)); | 179 .catch(unreached_rejection(t)); |
161 }, 'Unregister then register a new script URL'); | 180 }, 'Unregister then register a new script URL'); |
162 | 181 |
163 async_test(function(t) { | 182 async_test(function(t) { |
164 var scope = 'scope/non-existent-worker'; | 183 var scope = 'scope/non-existent-worker'; |
165 var iframe; | 184 var iframe; |
166 | 185 |
167 service_worker_unregister_and_register(t, worker_url, scope) | 186 service_worker_unregister_and_register(t, worker_url, scope) |
187 .then(function(registration) { | |
188 return wait_for_update(t, registration); | |
189 }) | |
168 .then(function(worker) { | 190 .then(function(worker) { |
169 return wait_for_state(t, worker, 'activated'); | 191 return wait_for_state(t, worker, 'activated'); |
170 }) | 192 }) |
171 .then(function() { | 193 .then(function() { |
172 return with_iframe(scope); | 194 return with_iframe(scope); |
173 }) | 195 }) |
174 .then(function(frame) { | 196 .then(function(frame) { |
175 iframe = frame; | 197 iframe = frame; |
176 return navigator.serviceWorker.unregister(scope); | 198 return navigator.serviceWorker.unregister(scope); |
177 }) | 199 }) |
(...skipping 20 matching lines...) Expand all Loading... | |
198 }) | 220 }) |
199 .catch(unreached_rejection(t)); | 221 .catch(unreached_rejection(t)); |
200 }, 'Registering a new script URL that 404s does not resurrect an ' + | 222 }, 'Registering a new script URL that 404s does not resurrect an ' + |
201 'unregistered registration'); | 223 'unregistered registration'); |
202 | 224 |
203 async_test(function(t) { | 225 async_test(function(t) { |
204 var scope = 'scope/reject-install-worker'; | 226 var scope = 'scope/reject-install-worker'; |
205 var iframe; | 227 var iframe; |
206 | 228 |
207 service_worker_unregister_and_register(t, worker_url, scope) | 229 service_worker_unregister_and_register(t, worker_url, scope) |
230 .then(function(registration) { | |
231 return wait_for_update(t, registration); | |
232 }) | |
208 .then(function(worker) { | 233 .then(function(worker) { |
209 return wait_for_state(t, worker, 'activated'); | 234 return wait_for_state(t, worker, 'activated'); |
210 }) | 235 }) |
211 .then(function() { | 236 .then(function() { |
212 return with_iframe(scope); | 237 return with_iframe(scope); |
213 }) | 238 }) |
214 .then(function(frame) { | 239 .then(function(frame) { |
215 iframe = frame; | 240 iframe = frame; |
216 return navigator.serviceWorker.unregister(); | 241 return navigator.serviceWorker.unregister(); |
217 }) | 242 }) |
218 .then(function() { | 243 .then(function() { |
219 // FIXME: Register should not resolve until controllees are unloaded. | 244 // FIXME: Register should not resolve until controllees are unloaded. |
220 return navigator.serviceWorker.register( | 245 return navigator.serviceWorker.register( |
221 'resources/reject-install-worker.js', { scope: scope }); | 246 'resources/reject-install-worker.js', { scope: scope }); |
222 }) | 247 }) |
248 .then(function(registration) { | |
249 return wait_for_update(t, registration); | |
250 }) | |
223 .then(function(worker) { | 251 .then(function(worker) { |
224 return wait_for_state(t, worker, 'redundant'); | 252 return wait_for_state(t, worker, 'redundant'); |
225 }) | 253 }) |
226 .then(function(worker) { | 254 .then(function(worker) { |
227 return unload_iframe(iframe); | 255 return unload_iframe(iframe); |
228 }) | 256 }) |
229 .then(function() { | 257 .then(function() { |
230 return with_iframe(scope); | 258 return with_iframe(scope); |
231 }) | 259 }) |
232 .then(function(frame) { | 260 .then(function(frame) { |
233 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | 261 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
234 null, | 262 null, |
235 'document should not load with a controller'); | 263 'document should not load with a controller'); |
236 service_worker_unregister_and_done(t, scope); | 264 service_worker_unregister_and_done(t, scope); |
237 }) | 265 }) |
238 .catch(unreached_rejection(t)); | 266 .catch(unreached_rejection(t)); |
239 }, 'Registering a new script URL that fails to install does not resurrect ' + | 267 }, 'Registering a new script URL that fails to install does not resurrect ' + |
240 'an unregistered registration'); | 268 'an unregistered registration'); |
241 </script> | 269 </script> |
OLD | NEW |