| 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/testharness-helpers.js"></script> | 5 <script src="../resources/testharness-helpers.js"></script> |
| 6 <script src="resources/test-helpers.js"></script> | 6 <script src="resources/test-helpers.js"></script> |
| 7 <script src="../resources/get-host-info.js"></script> | 7 <script src="../resources/get-host-info.js"></script> |
| 8 <script> | 8 <script> |
| 9 // Purge the existing registrations for the origin. | 9 // Purge the existing registrations for the origin. |
| 10 // getRegistrations() is used in order to avoid adding additional complexity | 10 // getRegistrations() is used in order to avoid adding additional complexity |
| 11 // e.g. adding an internal function. | 11 // e.g. adding an internal function. |
| 12 sequential_promise_test(function(t) { | 12 promise_test(function(t) { |
| 13 var resolve; | 13 var resolve; |
| 14 var timer; | 14 var timer; |
| 15 var p = new Promise(function(r) { resolve = r; }); | 15 var p = new Promise(function(r) { resolve = r; }); |
| 16 navigator.serviceWorker.getRegistrations() | 16 navigator.serviceWorker.getRegistrations() |
| 17 .then(function(regs) { | 17 .then(function(regs) { |
| 18 return Promise.all(regs.map(function(r) { r.unregister(); })); | 18 return Promise.all(regs.map(function(r) { r.unregister(); })); |
| 19 }) | 19 }) |
| 20 .then(function() { | 20 .then(function() { |
| 21 // As registration.unregister() promises resolve before the | 21 // As registration.unregister() promises resolve before the |
| 22 // corresponding registrations are deleted from the storage, we must | 22 // corresponding registrations are deleted from the storage, we must |
| 23 // wait until the registrations are actually removed from the storage. | 23 // wait until the registrations are actually removed from the storage. |
| 24 // Spec reference: https://slightlyoff.github.io/ServiceWorker/spec/se
rvice_worker/#unregister-algorithm | 24 // Spec reference: https://slightlyoff.github.io/ServiceWorker/spec/se
rvice_worker/#unregister-algorithm |
| 25 timer = setInterval(function() { | 25 timer = setInterval(function() { |
| 26 navigator.serviceWorker.getRegistrations() | 26 navigator.serviceWorker.getRegistrations() |
| 27 .then(function(regs) { | 27 .then(function(regs) { |
| 28 if (regs.length == 0) { | 28 if (regs.length == 0) { |
| 29 clearInterval(timer); | 29 clearInterval(timer); |
| 30 resolve(); | 30 resolve(); |
| 31 } | 31 } |
| 32 }); | 32 }); |
| 33 }, 100); | 33 }, 100); |
| 34 }); | 34 }); |
| 35 return p; | 35 return p; |
| 36 }, 'Purge the existing registrations.'); | 36 }, 'Purge the existing registrations.'); |
| 37 | 37 |
| 38 sequential_promise_test(function(t) { | 38 promise_test(function(t) { |
| 39 var scope = 'resources/scope/getregistrations/normal'; | 39 var scope = 'resources/scope/getregistrations/normal'; |
| 40 var script = 'resources/empty-worker.js'; | 40 var script = 'resources/empty-worker.js'; |
| 41 var registrations = []; | 41 var registrations = []; |
| 42 return service_worker_unregister_and_register(t, script, scope) | 42 return service_worker_unregister_and_register(t, script, scope) |
| 43 .then(function(r) { | 43 .then(function(r) { |
| 44 registrations.push(r); | 44 registrations.push(r); |
| 45 return navigator.serviceWorker.getRegistrations(); | 45 return navigator.serviceWorker.getRegistrations(); |
| 46 }) | 46 }) |
| 47 .then(function(value) { | 47 .then(function(value) { |
| 48 assert_array_equals( | 48 assert_array_equals( |
| 49 value, | 49 value, |
| 50 registrations, | 50 registrations, |
| 51 'getRegistrations should resolve with array of registrations.'); | 51 'getRegistrations should resolve with array of registrations.'); |
| 52 return service_worker_unregister(t, scope); | 52 return service_worker_unregister(t, scope); |
| 53 }); | 53 }); |
| 54 }, 'Register then getRegistrations'); | 54 }, 'Register then getRegistrations'); |
| 55 | 55 |
| 56 sequential_promise_test(function(t) { | 56 promise_test(function(t) { |
| 57 var scope1 = 'resources/scope/getregistrations/scope1'; | 57 var scope1 = 'resources/scope/getregistrations/scope1'; |
| 58 var scope2 = 'resources/scope/getregistrations/scope2'; | 58 var scope2 = 'resources/scope/getregistrations/scope2'; |
| 59 var script = 'resources/empty-worker.js'; | 59 var script = 'resources/empty-worker.js'; |
| 60 var registrations = []; | 60 var registrations = []; |
| 61 return service_worker_unregister_and_register(t, script, scope1) | 61 return service_worker_unregister_and_register(t, script, scope1) |
| 62 .then(function(r) { | 62 .then(function(r) { |
| 63 registrations.push(r); | 63 registrations.push(r); |
| 64 return service_worker_unregister_and_register(t, script, scope2); | 64 return service_worker_unregister_and_register(t, script, scope2); |
| 65 }) | 65 }) |
| 66 .then(function(r) { | 66 .then(function(r) { |
| 67 registrations.push(r); | 67 registrations.push(r); |
| 68 return navigator.serviceWorker.getRegistrations(); | 68 return navigator.serviceWorker.getRegistrations(); |
| 69 }) | 69 }) |
| 70 .then(function(value) { | 70 .then(function(value) { |
| 71 assert_array_equals( | 71 assert_array_equals( |
| 72 value, | 72 value, |
| 73 registrations, | 73 registrations, |
| 74 'getRegistrations should resolve with array of registrations.'); | 74 'getRegistrations should resolve with array of registrations.'); |
| 75 return service_worker_unregister(t, scope1); | 75 return service_worker_unregister(t, scope1); |
| 76 }) | 76 }) |
| 77 .then(function() { | 77 .then(function() { |
| 78 return service_worker_unregister(t, scope2); | 78 return service_worker_unregister(t, scope2); |
| 79 }); | 79 }); |
| 80 }, 'Register multiple times then getRegistrations'); | 80 }, 'Register multiple times then getRegistrations'); |
| 81 | 81 |
| 82 sequential_promise_test(function(t) { | 82 promise_test(function(t) { |
| 83 var scope = 'resources/scope/getregistrations/register-unregister'; | 83 var scope = 'resources/scope/getregistrations/register-unregister'; |
| 84 var script = 'resources/empty-worker.js'; | 84 var script = 'resources/empty-worker.js'; |
| 85 return service_worker_unregister_and_register(t, script, scope) | 85 return service_worker_unregister_and_register(t, script, scope) |
| 86 .then(function(registration) { | 86 .then(function(registration) { |
| 87 return registration.unregister(); | 87 return registration.unregister(); |
| 88 }) | 88 }) |
| 89 .then(function() { | 89 .then(function() { |
| 90 return navigator.serviceWorker.getRegistrations(); | 90 return navigator.serviceWorker.getRegistrations(); |
| 91 }) | 91 }) |
| 92 .then(function(value) { | 92 .then(function(value) { |
| 93 assert_array_equals( | 93 assert_array_equals( |
| 94 value, | 94 value, |
| 95 [], | 95 [], |
| 96 'getRegistrations should resolve with an empty array.'); | 96 'getRegistrations should resolve with an empty array.'); |
| 97 }); | 97 }); |
| 98 }, 'Register then Unregister then getRegistrations'); | 98 }, 'Register then Unregister then getRegistrations'); |
| 99 | 99 |
| 100 sequential_promise_test(function(t) { | 100 promise_test(function(t) { |
| 101 // Top-level window's origin: http://127.0.0.1:8000. | 101 // Top-level window's origin: http://127.0.0.1:8000. |
| 102 // Frame's origin: http://localhost:8000. | 102 // Frame's origin: http://localhost:8000. |
| 103 var host_info = get_host_info(); | 103 var host_info = get_host_info(); |
| 104 var frame_url = host_info['HTTP_REMOTE_ORIGIN'] + | 104 var frame_url = host_info['HTTP_REMOTE_ORIGIN'] + |
| 105 '/serviceworker/resources/frame-for-getregistrations.html'; | 105 '/serviceworker/resources/frame-for-getregistrations.html'; |
| 106 var scope = 'resources/scope-for-getregistrations'; | 106 var scope = 'resources/scope-for-getregistrations'; |
| 107 var script = 'resources/empty-worker.js'; | 107 var script = 'resources/empty-worker.js'; |
| 108 var frame; | 108 var frame; |
| 109 var registrations = []; | 109 var registrations = []; |
| 110 | 110 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 141 return p; | 141 return p; |
| 142 }) | 142 }) |
| 143 .then(function() { | 143 .then(function() { |
| 144 frame.remove(); | 144 frame.remove(); |
| 145 return service_worker_unregister(t, scope); | 145 return service_worker_unregister(t, scope); |
| 146 }); | 146 }); |
| 147 }, 'getRegistrations promise resolves only with same origin registrations.'); | 147 }, 'getRegistrations promise resolves only with same origin registrations.'); |
| 148 | 148 |
| 149 done(); | 149 done(); |
| 150 </script> | 150 </script> |
| OLD | NEW |