OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: getRegistrations()</title> | 2 <title>Service Worker: getRegistrations()</title> |
3 <script src="/resources/testharness.js"></script> | 3 <script src="/resources/testharness.js"></script> |
4 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.sub.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
6 <script src="/common/get-host-info.sub.js"></script> | 6 <script src="/common/get-host-info.sub.js"></script> |
7 <script src="../fetch/resources/fetch-test-helpers.sub.js"></script> | |
8 <script> | 7 <script> |
9 // Purge the existing registrations for the origin. | 8 // Purge the existing registrations for the origin. |
10 // getRegistrations() is used in order to avoid adding additional complexity | 9 // getRegistrations() is used in order to avoid adding additional complexity |
11 // e.g. adding an internal function. | 10 // e.g. adding an internal function. |
12 promise_test(function(t) { | 11 setup({ explicit_done: true }); |
12 | |
13 promise_test(function() { | |
14 function waitForUnregistered() { | |
15 return navigator.serviceWorker.getRegistrations() | |
16 .then(function(value) { | |
17 if (value.length > 0) { | |
18 return waitForUnregistered(); | |
19 } | |
20 }); | |
21 } | |
22 | |
13 return navigator.serviceWorker.getRegistrations() | 23 return navigator.serviceWorker.getRegistrations() |
14 .then(function(registrations) { | 24 .then(function(registrations) { |
15 return registrations.reduce(function(sequence, registration) { | 25 return registrations.reduce(function(sequence, registration) { |
16 return sequence.then(function() { | 26 return sequence.then(function() { |
17 return registration.unregister(); | 27 return registration.unregister(); |
18 }); | 28 }); |
19 }, Promise.resolve()); | 29 }, Promise.resolve()); |
20 }); | 30 }) |
21 }, 'Purge the existing registrations.'); | 31 .then(waitForUnregistered) |
Marijn Kruisselbrink
2017/05/03 16:31:41
I don't think this waitForUnregistered change (rat
mike3
2017/05/03 17:26:19
Ah, right. I'll remove `waitForUnregistered`.
| |
32 // This test's sub-tests should only be defined (and subsequently | |
33 // executed) after all registrations are known to be cleared. | |
Marijn Kruisselbrink
2017/05/03 16:31:41
promise_tests are ran sequentially anyway (i.e. th
mike3
2017/05/03 17:26:19
I made both changes according to the mistaken beli
| |
34 .then(defineTests) | |
35 // Invoking the global `done` function instructs the test harness to | |
36 // interpret the completion of all currently-defined sub-tests as a | |
37 // signal of test completion. | |
38 .then(done); | |
39 }, 'test set up: purge all registrations'); | |
22 | 40 |
23 promise_test(function(t) { | 41 function defineTests() { |
24 return navigator.serviceWorker.getRegistrations() | |
25 .then(function(value) { | |
26 assert_array_equals( | |
27 value, | |
28 [], | |
29 'getRegistrations should resolve with an empty array.'); | |
30 }); | |
31 }, 'getRegistrations'); | |
32 | |
33 promise_test(function(t) { | 42 promise_test(function(t) { |
34 var scope = 'resources/scope/getregistrations/normal'; | 43 var scope = 'resources/scope/getregistrations/normal'; |
35 var script = 'resources/empty-worker.js'; | 44 var script = 'resources/empty-worker.js'; |
36 var registrations = []; | 45 var registrations = []; |
37 return service_worker_unregister_and_register(t, script, scope) | 46 return service_worker_unregister_and_register(t, script, scope) |
38 .then(function(r) { | 47 .then(function(r) { |
39 registrations.push(r); | 48 registrations.push(r); |
40 return navigator.serviceWorker.getRegistrations(); | 49 return navigator.serviceWorker.getRegistrations(); |
41 }) | 50 }) |
42 .then(function(value) { | 51 .then(function(value) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 resolve(); | 188 resolve(); |
180 }; | 189 }; |
181 frame.contentWindow.postMessage('unregister', '*', [channel.port2]); | 190 frame.contentWindow.postMessage('unregister', '*', [channel.port2]); |
182 return p; | 191 return p; |
183 }) | 192 }) |
184 .then(function() { | 193 .then(function() { |
185 frame.remove(); | 194 frame.remove(); |
186 return service_worker_unregister(t, scope); | 195 return service_worker_unregister(t, scope); |
187 }); | 196 }); |
188 }, 'getRegistrations promise resolves only with same origin registrations.'); | 197 }, 'getRegistrations promise resolves only with same origin registrations.'); |
189 | 198 } |
190 done(); | |
191 </script> | 199 </script> |
OLD | NEW |