Chromium Code Reviews| 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() { |
| 41 return with_iframe(scope); | 69 return with_iframe(scope); |
| 42 }) | 70 }) |
| 43 .then(function(frame) { | 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() { | |
| 104 return with_iframe(scope); | |
| 105 }) | |
| 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', { scop e: scope }); |
|
nhiroki
2014/08/21 09:26:04
nit: 80-columns.
falken
2014/08/21 09:42:57
Done.
| |
| 75 return navigator.serviceWorker.register('this-will-404', | 142 unload_iframe(iframe); |
| 76 { scope: scope }); | 143 return promise; |
| 77 }) | 144 }) |
| 78 .then( | 145 .then( |
| 79 function() { | 146 function() { |
| 80 assert_unreached('register should reject the promise'); | 147 assert_unreached('register should reject the promise'); |
| 81 }, | 148 }, |
| 82 function() { | 149 function() { |
| 83 return unload_iframe(iframe); | |
| 84 }) | |
| 85 .then(function() { | |
| 86 return with_iframe(scope); | 150 return with_iframe(scope); |
| 87 }) | 151 }) |
| 88 .then(function(frame) { | 152 .then(function(frame) { |
| 89 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | 153 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| 90 null, | 154 null, |
| 91 'document should not load with a controller'); | 155 'document should not load with a controller'); |
| 92 service_worker_unregister_and_done(t, scope); | 156 unload_iframe(frame); |
| 157 t.done(); | |
| 93 }) | 158 }) |
| 94 .catch(unreached_rejection(t)); | 159 .catch(unreached_rejection(t)); |
| 95 }, 'Registering a new script URL that 404s does not resurrect an ' + | 160 }, 'Registering a new script URL that 404s does not resurrect an ' + |
| 96 'unregistered registration'); | 161 'unregistered registration'); |
| 97 | 162 |
| 98 async_test(function(t) { | 163 async_test(function(t) { |
| 99 var scope = 'scope/reject-install-worker'; | 164 var scope = 'scope/unregister-then-register-reject-install-worker'; |
| 100 var iframe; | 165 var iframe; |
| 101 var registration; | 166 var registration; |
| 102 | 167 |
| 103 service_worker_unregister_and_register(t, worker_url, scope) | 168 service_worker_unregister_and_register(t, worker_url, scope) |
| 104 .then(function(r) { | 169 .then(function(r) { |
| 105 registration = r; | 170 registration = r; |
| 106 return wait_for_update(t, registration); | 171 return wait_for_update(t, registration); |
| 107 }) | 172 }) |
| 108 .then(function(worker) { | 173 .then(function(worker) { |
| 109 return wait_for_state(t, worker, 'activated'); | 174 return wait_for_state(t, worker, 'activated'); |
| 110 }) | 175 }) |
| 111 .then(function() { | 176 .then(function() { |
| 112 return with_iframe(scope); | 177 return with_iframe(scope); |
| 113 }) | 178 }) |
| 114 .then(function(frame) { | 179 .then(function(frame) { |
| 115 iframe = frame; | 180 iframe = frame; |
| 116 return registration.unregister(); | 181 return registration.unregister(); |
| 117 }) | 182 }) |
| 118 .then(function() { | 183 .then(function() { |
| 119 // FIXME: Register should not resolve until controllees are unloaded. | 184 var promise = navigator.serviceWorker.register( |
| 120 return navigator.serviceWorker.register( | |
| 121 'resources/reject-install-worker.js', { scope: scope }); | 185 'resources/reject-install-worker.js', { scope: scope }); |
| 186 unload_iframe(iframe); | |
| 187 return promise; | |
| 122 }) | 188 }) |
| 123 .then(function(new_registration) { | 189 .then(function(r) { |
| 124 return wait_for_update(t, new_registration); | 190 registration = r; |
| 191 return wait_for_update(t, registration); | |
| 125 }) | 192 }) |
| 126 .then(function(worker) { | 193 .then(function(worker) { |
| 127 return wait_for_state(t, worker, 'redundant'); | 194 return wait_for_state(t, worker, 'redundant'); |
| 128 }) | 195 }) |
| 129 .then(function(worker) { | |
| 130 return unload_iframe(iframe); | |
| 131 }) | |
| 132 .then(function() { | 196 .then(function() { |
| 133 return with_iframe(scope); | 197 return with_iframe(scope); |
| 134 }) | 198 }) |
| 135 .then(function(frame) { | 199 .then(function(frame) { |
| 136 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | 200 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| 137 null, | 201 null, |
| 138 'document should not load with a controller'); | 202 'document should not load with a controller'); |
| 139 service_worker_unregister_and_done(t, scope); | 203 unload_iframe(frame); |
| 204 return registration.unregister(); | |
| 205 }) | |
| 206 .then(function() { | |
| 207 t.done(); | |
| 140 }) | 208 }) |
| 141 .catch(unreached_rejection(t)); | 209 .catch(unreached_rejection(t)); |
| 142 }, 'Registering a new script URL that fails to install does not resurrect ' + | 210 }, 'Registering a new script URL that fails to install does not resurrect ' + |
| 143 'an unregistered registration'); | 211 'an unregistered registration'); |
| 212 | |
| 144 </script> | 213 </script> |
| OLD | NEW |