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