| 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/new-worker'; | 9 var scope = 'scope/register-waits-for-unregistered-registration-to-clear'; |
| 10 var new_worker_url = worker_url + '?new'; | 10 var new_worker_url = worker_url + '?new'; |
| 11 var iframe; | 11 var iframe; |
| 12 var registration; | 12 var registration; |
| 13 var unloaded = false; |
| 13 | 14 |
| 14 service_worker_unregister_and_register(t, worker_url, scope) | 15 service_worker_unregister_and_register(t, worker_url, scope) |
| 15 .then(function(r) { | 16 .then(function(r) { |
| 16 registration = r; | 17 registration = r; |
| 17 return wait_for_update(t, registration); | 18 return wait_for_update(t, registration); |
| 18 }) | 19 }) |
| 19 .then(function(worker) { | 20 .then(function(worker) { |
| 20 return wait_for_state(t, worker, 'activated'); | 21 return wait_for_state(t, worker, 'activated'); |
| 21 }) | 22 }) |
| 22 .then(function() { | 23 .then(function() { |
| 23 return with_iframe(scope); | 24 return with_iframe(scope); |
| 24 }) | 25 }) |
| 25 .then(function(frame) { | 26 .then(function(frame) { |
| 26 iframe = frame; | 27 iframe = frame; |
| 27 return registration.unregister(); | 28 return registration.unregister(); |
| 28 }) | 29 }) |
| 29 .then(function() { | 30 .then(function() { |
| 30 // FIXME: Register should not resolve until controllees are unloaded. | 31 setTimeout(function() { |
| 32 unloaded = true; |
| 33 unload_iframe(iframe); |
| 34 }, 10); |
| 31 return navigator.serviceWorker.register(new_worker_url, | 35 return navigator.serviceWorker.register(new_worker_url, |
| 32 { scope: scope }); | 36 { scope: scope }); |
| 33 }) | 37 }) |
| 34 .then(function(new_registration) { | 38 .then(function(new_registration) { |
| 35 return wait_for_update(t, new_registration); | 39 assert_true(unloaded, |
| 40 'register should not resolve until iframe unloaded'); |
| 41 assert_equals(registration.installing, null, |
| 42 'registration.installing'); |
| 43 assert_equals(registration.waiting, null, 'registration.waiting'); |
| 44 assert_equals(registration.active, null, 'registration.active'); |
| 45 return new_registration.unregister(); |
| 46 }) |
| 47 .then(function() { |
| 48 t.done(); |
| 49 }) |
| 50 .catch(unreached_rejection(t)); |
| 51 }, 'Registering a new script URL does not resolve until unregistered ' + |
| 52 'registration is cleared'); |
| 53 |
| 54 async_test(function(t) { |
| 55 var scope = 'scope/unregister-then-register-new-script'; |
| 56 var new_worker_url = worker_url + '?new'; |
| 57 var iframe; |
| 58 var registration; |
| 59 |
| 60 service_worker_unregister_and_register(t, worker_url, scope) |
| 61 .then(function(r) { |
| 62 registration = r; |
| 63 return wait_for_update(t, registration); |
| 36 }) | 64 }) |
| 37 .then(function(worker) { | 65 .then(function(worker) { |
| 38 return wait_for_state(t, worker, 'activated'); | 66 return wait_for_state(t, worker, 'activated'); |
| 39 }) | 67 }) |
| 40 .then(function() { | 68 .then(function() { |
| 69 return with_iframe(scope); |
| 70 }) |
| 71 .then(function(frame) { |
| 72 iframe = frame; |
| 73 return registration.unregister(); |
| 74 }) |
| 75 .then(function() { |
| 76 var promise = navigator.serviceWorker.register(new_worker_url, |
| 77 { scope: scope }); |
| 78 unload_iframe(iframe); |
| 79 return promise; |
| 80 }) |
| 81 .then(function(new_registration) { |
| 82 assert_not_equals(registration, new_registration, |
| 83 'register() should resolve to a new registration'); |
| 84 assert_equals(registration.installing, null, |
| 85 'old registration.installing'); |
| 86 assert_equals(registration.waiting, null, |
| 87 'old registration.waiting'); |
| 88 assert_equals(registration.active, null, |
| 89 'old registration.active'); |
| 90 registration = new_registration; |
| 91 return wait_for_update(t, registration); |
| 92 }) |
| 93 .then(function(worker) { |
| 94 assert_equals(registration.installing.scriptURL, |
| 95 normalizeURL(new_worker_url), |
| 96 'new registration.installing'); |
| 97 assert_equals(registration.waiting, null, |
| 98 'new registration.waiting'); |
| 99 assert_equals(registration.active, null, |
| 100 'new registration.active'); |
| 101 return wait_for_state(t, worker, 'activated'); |
| 102 }) |
| 103 .then(function() { |
| 41 return with_iframe(scope); | 104 return with_iframe(scope); |
| 42 }) | 105 }) |
| 43 .then(function(frame) { | 106 .then(function(frame) { |
| 44 assert_equals( | 107 assert_equals( |
| 45 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, | 108 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| 46 normalizeURL(new_worker_url), | 109 normalizeURL(new_worker_url), |
| 47 'document controller is the new worker'); | 110 'the new worker should control a new document'); |
| 48 service_worker_unregister_and_done(t, scope); | 111 unload_iframe(frame); |
| 112 return registration.unregister(); |
| 113 }) |
| 114 .then(function() { |
| 115 t.done(); |
| 49 }) | 116 }) |
| 50 .catch(unreached_rejection(t)); | 117 .catch(unreached_rejection(t)); |
| 51 }, 'Unregister then register a new script URL'); | 118 }, 'Registering a new script URL while an unregistered registration is in use'); |
| 52 | 119 |
| 53 async_test(function(t) { | 120 async_test(function(t) { |
| 54 var scope = 'scope/non-existent-worker'; | 121 var scope = 'scope/unregister-then-register-new-script-that-404s'; |
| 55 var iframe; | 122 var iframe; |
| 56 var registration; | 123 var registration; |
| 57 | 124 |
| 58 service_worker_unregister_and_register(t, worker_url, scope) | 125 service_worker_unregister_and_register(t, worker_url, scope) |
| 59 .then(function(r) { | 126 .then(function(r) { |
| 60 registration = r; | 127 registration = r; |
| 61 return wait_for_update(t, registration); | 128 return wait_for_update(t, registration); |
| 62 }) | 129 }) |
| 63 .then(function(worker) { | 130 .then(function(worker) { |
| 64 return wait_for_state(t, worker, 'activated'); | 131 return wait_for_state(t, worker, 'activated'); |
| 65 }) | 132 }) |
| 66 .then(function() { | 133 .then(function() { |
| 67 return with_iframe(scope); | 134 return with_iframe(scope); |
| 68 }) | 135 }) |
| 69 .then(function(frame) { | 136 .then(function(frame) { |
| 70 iframe = frame; | 137 iframe = frame; |
| 71 return registration.unregister(); | 138 return registration.unregister(); |
| 72 }) | 139 }) |
| 73 .then(function() { | 140 .then(function() { |
| 74 // FIXME: Register should not resolve until controllees are unloaded. | 141 var promise = navigator.serviceWorker.register('this-will-404', |
| 75 return navigator.serviceWorker.register('this-will-404', | 142 { scope: scope }); |
| 76 { scope: scope }); | 143 unload_iframe(iframe); |
| 144 return promise; |
| 77 }) | 145 }) |
| 78 .then( | 146 .then( |
| 79 function() { | 147 function() { |
| 80 assert_unreached('register should reject the promise'); | 148 assert_unreached('register should reject the promise'); |
| 81 }, | 149 }, |
| 82 function() { | 150 function() { |
| 83 return unload_iframe(iframe); | |
| 84 }) | |
| 85 .then(function() { | |
| 86 return with_iframe(scope); | 151 return with_iframe(scope); |
| 87 }) | 152 }) |
| 88 .then(function(frame) { | 153 .then(function(frame) { |
| 89 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | 154 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| 90 null, | 155 null, |
| 91 'document should not load with a controller'); | 156 'document should not load with a controller'); |
| 92 service_worker_unregister_and_done(t, scope); | 157 unload_iframe(frame); |
| 158 t.done(); |
| 93 }) | 159 }) |
| 94 .catch(unreached_rejection(t)); | 160 .catch(unreached_rejection(t)); |
| 95 }, 'Registering a new script URL that 404s does not resurrect an ' + | 161 }, 'Registering a new script URL that 404s does not resurrect an ' + |
| 96 'unregistered registration'); | 162 'unregistered registration'); |
| 97 | 163 |
| 98 async_test(function(t) { | 164 async_test(function(t) { |
| 99 var scope = 'scope/reject-install-worker'; | 165 var scope = 'scope/unregister-then-register-reject-install-worker'; |
| 100 var iframe; | 166 var iframe; |
| 101 var registration; | 167 var registration; |
| 102 | 168 |
| 103 service_worker_unregister_and_register(t, worker_url, scope) | 169 service_worker_unregister_and_register(t, worker_url, scope) |
| 104 .then(function(r) { | 170 .then(function(r) { |
| 105 registration = r; | 171 registration = r; |
| 106 return wait_for_update(t, registration); | 172 return wait_for_update(t, registration); |
| 107 }) | 173 }) |
| 108 .then(function(worker) { | 174 .then(function(worker) { |
| 109 return wait_for_state(t, worker, 'activated'); | 175 return wait_for_state(t, worker, 'activated'); |
| 110 }) | 176 }) |
| 111 .then(function() { | 177 .then(function() { |
| 112 return with_iframe(scope); | 178 return with_iframe(scope); |
| 113 }) | 179 }) |
| 114 .then(function(frame) { | 180 .then(function(frame) { |
| 115 iframe = frame; | 181 iframe = frame; |
| 116 return registration.unregister(); | 182 return registration.unregister(); |
| 117 }) | 183 }) |
| 118 .then(function() { | 184 .then(function() { |
| 119 // FIXME: Register should not resolve until controllees are unloaded. | 185 var promise = navigator.serviceWorker.register( |
| 120 return navigator.serviceWorker.register( | |
| 121 'resources/reject-install-worker.js', { scope: scope }); | 186 'resources/reject-install-worker.js', { scope: scope }); |
| 187 unload_iframe(iframe); |
| 188 return promise; |
| 122 }) | 189 }) |
| 123 .then(function(new_registration) { | 190 .then(function(r) { |
| 124 return wait_for_update(t, new_registration); | 191 registration = r; |
| 192 return wait_for_update(t, registration); |
| 125 }) | 193 }) |
| 126 .then(function(worker) { | 194 .then(function(worker) { |
| 127 return wait_for_state(t, worker, 'redundant'); | 195 return wait_for_state(t, worker, 'redundant'); |
| 128 }) | 196 }) |
| 129 .then(function(worker) { | |
| 130 return unload_iframe(iframe); | |
| 131 }) | |
| 132 .then(function() { | 197 .then(function() { |
| 133 return with_iframe(scope); | 198 return with_iframe(scope); |
| 134 }) | 199 }) |
| 135 .then(function(frame) { | 200 .then(function(frame) { |
| 136 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | 201 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| 137 null, | 202 null, |
| 138 'document should not load with a controller'); | 203 'document should not load with a controller'); |
| 139 service_worker_unregister_and_done(t, scope); | 204 unload_iframe(frame); |
| 205 return registration.unregister(); |
| 206 }) |
| 207 .then(function() { |
| 208 t.done(); |
| 140 }) | 209 }) |
| 141 .catch(unreached_rejection(t)); | 210 .catch(unreached_rejection(t)); |
| 142 }, 'Registering a new script URL that fails to install does not resurrect ' + | 211 }, 'Registering a new script URL that fails to install does not resurrect ' + |
| 143 'an unregistered registration'); | 212 'an unregistered registration'); |
| 144 </script> | 213 </script> |
| OLD | NEW |