Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: LayoutTests/http/tests/serviceworker/unregister-then-register.html

Issue 466723002: ServiceWorker: Enable ServiceWorkerRegistration and update layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@updatefound
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 assert_equals(registration.installing, null,
79 assert_equals(sw_container.installing, null,
80 'installing version is null'); 89 'installing version is null');
81 assert_equals(sw_container.waiting, null, 'waiting version is null'); 90 assert_equals(registration.waiting, null, 'waiting version is null');
82 assert_equals(sw_container.controller, worker, 91 assert_equals(
83 'the worker from the first registration is the ' + 92 iframe.contentWindow.navigator.serviceWorker.controller, worker,
84 'controller'); 93 'the worker from the first registration is the controller');
85 service_worker_unregister_and_done(t, scope); 94 service_worker_unregister_and_done(t, scope);
86 }) 95 })
87 .catch(unreached_rejection(t)); 96 .catch(unreached_rejection(t));
88 }, 'Unregister then register does not affect existing controllee'); 97 }, 'Unregister then register does not affect existing controllee');
89 98
90 async_test(function(t) { 99 async_test(function(t) {
91 var scope = 'scope/resurrection'; 100 var scope = 'scope/resurrection';
92 var iframe; 101 var iframe;
93 var worker; 102 var worker;
94 103
95 service_worker_unregister_and_register(t, worker_url, scope) 104 service_worker_unregister_and_register(t, worker_url, scope)
105 .then(function(registration) {
106 return wait_for_update(t, registration);
107 })
96 .then(function(registered_worker) { 108 .then(function(registered_worker) {
97 return wait_for_state(t, registered_worker, 'activated'); 109 return wait_for_state(t, registered_worker, 'activated');
98 }) 110 })
99 .then(function() { 111 .then(function() {
100 return with_iframe(scope); 112 return with_iframe(scope);
101 }) 113 })
102 .then(function(frame) { 114 .then(function(frame) {
103 iframe = frame; 115 iframe = frame;
104 worker = iframe.contentWindow.navigator.serviceWorker.controller; 116 worker = iframe.contentWindow.navigator.serviceWorker.controller;
105 return navigator.serviceWorker.unregister(scope); 117 return navigator.serviceWorker.unregister(scope);
(...skipping 17 matching lines...) Expand all
123 }) 135 })
124 .catch(unreached_rejection(t)); 136 .catch(unreached_rejection(t));
125 }, 'Unregister then register resurrects the registration'); 137 }, 'Unregister then register resurrects the registration');
126 138
127 async_test(function(t) { 139 async_test(function(t) {
128 var scope = 'scope/new-worker'; 140 var scope = 'scope/new-worker';
129 var new_worker_url = worker_url + '?new'; 141 var new_worker_url = worker_url + '?new';
130 var iframe; 142 var iframe;
131 143
132 service_worker_unregister_and_register(t, worker_url, scope) 144 service_worker_unregister_and_register(t, worker_url, scope)
145 .then(function(registration) {
146 return wait_for_update(t, registration);
147 })
133 .then(function(worker) { 148 .then(function(worker) {
134 return wait_for_state(t, worker, 'activated'); 149 return wait_for_state(t, worker, 'activated');
135 }) 150 })
136 .then(function() { 151 .then(function() {
137 return with_iframe(scope); 152 return with_iframe(scope);
138 }) 153 })
139 .then(function(frame) { 154 .then(function(frame) {
140 iframe = frame; 155 iframe = frame;
141 return navigator.serviceWorker.unregister(scope); 156 return navigator.serviceWorker.unregister(scope);
142 }) 157 })
143 .then(function() { 158 .then(function() {
144 // FIXME: Register should not resolve until controllees are unloaded. 159 // FIXME: Register should not resolve until controllees are unloaded.
145 return navigator.serviceWorker.register(new_worker_url, 160 return navigator.serviceWorker.register(new_worker_url,
146 { scope: scope }); 161 { scope: scope });
147 }) 162 })
163 .then(function(registration) {
164 return wait_for_update(t, registration);
165 })
148 .then(function(worker) { 166 .then(function(worker) {
149 return wait_for_state(t, worker, 'activated'); 167 return wait_for_state(t, worker, 'activated');
150 }) 168 })
151 .then(function() { 169 .then(function() {
152 return with_iframe(scope); 170 return with_iframe(scope);
153 }) 171 })
154 .then(function(frame) { 172 .then(function(frame) {
155 assert_equals(frame.contentWindow.navigator.serviceWorker.controller.s criptURL, 173 assert_equals(frame.contentWindow.navigator.serviceWorker.controller.s criptURL,
156 normalizeURL(new_worker_url), 174 normalizeURL(new_worker_url),
157 'document controller is the new worker'); 175 'document controller is the new worker');
158 service_worker_unregister_and_done(t, scope); 176 service_worker_unregister_and_done(t, scope);
159 }) 177 })
160 .catch(unreached_rejection(t)); 178 .catch(unreached_rejection(t));
161 }, 'Unregister then register a new script URL'); 179 }, 'Unregister then register a new script URL');
162 180
163 async_test(function(t) { 181 async_test(function(t) {
164 var scope = 'scope/non-existent-worker'; 182 var scope = 'scope/non-existent-worker';
165 var iframe; 183 var iframe;
166 184
167 service_worker_unregister_and_register(t, worker_url, scope) 185 service_worker_unregister_and_register(t, worker_url, scope)
186 .then(function(registration) {
187 return wait_for_update(t, registration);
188 })
168 .then(function(worker) { 189 .then(function(worker) {
169 return wait_for_state(t, worker, 'activated'); 190 return wait_for_state(t, worker, 'activated');
170 }) 191 })
171 .then(function() { 192 .then(function() {
172 return with_iframe(scope); 193 return with_iframe(scope);
173 }) 194 })
174 .then(function(frame) { 195 .then(function(frame) {
175 iframe = frame; 196 iframe = frame;
176 return navigator.serviceWorker.unregister(scope); 197 return navigator.serviceWorker.unregister(scope);
177 }) 198 })
(...skipping 20 matching lines...) Expand all
198 }) 219 })
199 .catch(unreached_rejection(t)); 220 .catch(unreached_rejection(t));
200 }, 'Registering a new script URL that 404s does not resurrect an ' + 221 }, 'Registering a new script URL that 404s does not resurrect an ' +
201 'unregistered registration'); 222 'unregistered registration');
202 223
203 async_test(function(t) { 224 async_test(function(t) {
204 var scope = 'scope/reject-install-worker'; 225 var scope = 'scope/reject-install-worker';
205 var iframe; 226 var iframe;
206 227
207 service_worker_unregister_and_register(t, worker_url, scope) 228 service_worker_unregister_and_register(t, worker_url, scope)
229 .then(function(registration) {
230 return wait_for_update(t, registration);
231 })
208 .then(function(worker) { 232 .then(function(worker) {
209 return wait_for_state(t, worker, 'activated'); 233 return wait_for_state(t, worker, 'activated');
210 }) 234 })
211 .then(function() { 235 .then(function() {
212 return with_iframe(scope); 236 return with_iframe(scope);
213 }) 237 })
214 .then(function(frame) { 238 .then(function(frame) {
215 iframe = frame; 239 iframe = frame;
216 return navigator.serviceWorker.unregister(); 240 return navigator.serviceWorker.unregister();
217 }) 241 })
218 .then(function() { 242 .then(function() {
219 // FIXME: Register should not resolve until controllees are unloaded. 243 // FIXME: Register should not resolve until controllees are unloaded.
220 return navigator.serviceWorker.register( 244 return navigator.serviceWorker.register(
221 'resources/reject-install-worker.js', { scope: scope }); 245 'resources/reject-install-worker.js', { scope: scope });
222 }) 246 })
247 .then(function(registration) {
248 return wait_for_update(t, registration);
249 })
223 .then(function(worker) { 250 .then(function(worker) {
224 return wait_for_state(t, worker, 'redundant'); 251 return wait_for_state(t, worker, 'redundant');
225 }) 252 })
226 .then(function(worker) { 253 .then(function(worker) {
227 return unload_iframe(iframe); 254 return unload_iframe(iframe);
228 }) 255 })
229 .then(function() { 256 .then(function() {
230 return with_iframe(scope); 257 return with_iframe(scope);
231 }) 258 })
232 .then(function(frame) { 259 .then(function(frame) {
233 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, 260 assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
234 null, 261 null,
235 'document should not load with a controller'); 262 'document should not load with a controller');
236 service_worker_unregister_and_done(t, scope); 263 service_worker_unregister_and_done(t, scope);
237 }) 264 })
238 .catch(unreached_rejection(t)); 265 .catch(unreached_rejection(t));
239 }, 'Registering a new script URL that fails to install does not resurrect ' + 266 }, 'Registering a new script URL that fails to install does not resurrect ' +
240 'an unregistered registration'); 267 'an unregistered registration');
241 </script> 268 </script>
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/unregister-controller.html ('k') | LayoutTests/http/tests/serviceworker/waiting.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698