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