Chromium Code Reviews| 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 script1 = normalizeURL('resources/empty-worker.js'); | |
| 7 var script2 = normalizeURL('resources/empty-worker.js?new'); | |
| 8 | |
| 9 // FIXME: The spec is in flux, this test's asserts may not be as per-spec. | |
| 10 async_test(function(t) { | |
| 11 var scope = 'scope/register-new-script-concurrently'; | |
| 12 var registration; | |
| 13 var register_promise1; | |
| 14 var register_promise2; | |
| 15 | |
| 16 navigator.serviceWorker.unregister(scope) | |
| 17 .then(function() { | |
| 18 register_promise1 = navigator.serviceWorker.register(script1, {scope: scope}); | |
| 19 register_promise2 = navigator.serviceWorker.register(script2, {scope: scope}); | |
|
nhiroki
2014/08/21 09:26:03
nit: Can you wrap at 80-columns?
falken
2014/08/21 09:42:56
Done.
| |
| 20 return register_promise1; | |
| 21 }) | |
| 22 .then(function(r) { | |
| 23 registration = r; | |
| 24 return wait_for_update(t, registration); | |
| 25 }) | |
| 26 .then(function() { | |
| 27 assert_equals(registration.installing.scriptURL, script1, | |
| 28 'on first update, first script should be installing'); | |
| 29 assert_equals(registration.waiting, null, | |
| 30 'on first update, waiting should be null'); | |
| 31 assert_equals(registration.active, null, | |
| 32 'on first update, active should be null'); | |
| 33 return register_promise2; | |
| 34 }) | |
| 35 .then(function(r) { | |
| 36 assert_equals(r, registration); | |
| 37 return wait_for_update(t, registration); | |
| 38 }) | |
| 39 .then(function() { | |
| 40 assert_equals(registration.installing.scriptURL, script2, | |
| 41 'on second update, second script should be installing'); | |
| 42 assert_equals(registration.waiting, null, | |
| 43 'on second update, waiting should be null'); | |
| 44 assert_equals(registration.active.scriptURL, script1, | |
| 45 'on second update, first script should be active'); | |
| 46 return registration.unregister(); | |
| 47 }) | |
| 48 .then(function() { | |
| 49 t.done(); | |
| 50 }) | |
| 51 .catch(unreached_rejection(t)); | |
| 52 }, 'Register different scripts concurrently'); | |
| 53 | |
| 54 async_test(function(t) { | |
| 55 var scope = 'scope/register-then-register-new-script'; | |
| 56 var registration; | |
| 57 | |
| 58 service_worker_unregister_and_register(t, script1, scope) | |
| 59 .then(function(r) { | |
| 60 registration = r; | |
| 61 return wait_for_update(t, registration); | |
| 62 }) | |
| 63 .then(function() { | |
| 64 return wait_for_state(t, registration.installing, 'activated'); | |
| 65 }) | |
| 66 .then(function() { | |
| 67 assert_equals(registration.installing, null, | |
| 68 'on activated, installing should be null'); | |
| 69 assert_equals(registration.waiting, null, | |
| 70 'on activated, waiting should be null'); | |
| 71 assert_equals(registration.active.scriptURL, script1, | |
| 72 'on activated, the first script should be active'); | |
| 73 return navigator.serviceWorker.register(script2, {scope:scope}); | |
| 74 }) | |
| 75 .then(function(r) { | |
| 76 assert_equals(r, registration, | |
| 77 'register() should resolve to the same registration'); | |
| 78 return wait_for_update(t, registration); | |
| 79 }) | |
| 80 .then(function() { | |
| 81 assert_equals(registration.installing.scriptURL, script2, | |
| 82 'on update, the second script should be installing'); | |
| 83 assert_equals(registration.waiting, null, | |
| 84 'on update waiting should be null'); | |
| 85 assert_equals(registration.active.scriptURL, script1, | |
| 86 'on update, the first script should be active'); | |
| 87 return wait_for_state(t, registration.installing, 'installed'); | |
| 88 }) | |
| 89 .then(function() { | |
| 90 assert_equals(registration.installing, null, | |
| 91 'on installed, installing should be null'); | |
| 92 assert_equals(registration.waiting.scriptURL, script2, | |
| 93 'on installed, the second script should be waiting'); | |
| 94 assert_equals(registration.active.scriptURL, script1, | |
| 95 'on installed, the first script should be active'); | |
| 96 return registration.unregister(); | |
| 97 }) | |
| 98 .then(function() { | |
| 99 t.done(); | |
| 100 }) | |
| 101 .catch(unreached_rejection(t)); | |
| 102 }, 'Register then register new script URL'); | |
| 103 | |
| 104 async_test(function(t) { | |
| 105 var scope = 'scope/register-then-register-new-script-404'; | |
| 106 var registration; | |
| 107 | |
| 108 service_worker_unregister_and_register(t, script1, scope) | |
| 109 .then(function(r) { | |
| 110 registration = r; | |
| 111 return wait_for_update(t, registration); | |
| 112 }) | |
| 113 .then(function() { | |
| 114 return wait_for_state(t, registration.installing, 'activated'); | |
| 115 }) | |
| 116 .then(function() { | |
| 117 assert_equals(registration.installing, null, | |
| 118 'on activated, installing should be null'); | |
| 119 assert_equals(registration.waiting, null, | |
| 120 'on activated, waiting should be null'); | |
| 121 assert_equals(registration.active.scriptURL, script1, | |
| 122 'on activated, the first script should be active'); | |
| 123 return navigator.serviceWorker.register('this-will-404.js', | |
| 124 {scope:scope}); | |
| 125 }) | |
| 126 .then( | |
| 127 function() { assert_unreached('register should reject'); }, | |
| 128 function(error) { | |
| 129 assert_equals(registration.installing, null, | |
| 130 'on rejected, installing should be null'); | |
| 131 assert_equals(registration.waiting, null, | |
| 132 'on rejected, waiting should be null'); | |
| 133 assert_equals(registration.active.scriptURL, script1, | |
| 134 'on rejected, the first script should be active'); | |
| 135 return registration.unregister(); | |
| 136 }) | |
| 137 .then(function() { | |
| 138 t.done(); | |
| 139 }) | |
| 140 .catch(unreached_rejection(t)); | |
| 141 }, 'Register then register new script URL that 404s'); | |
| 142 | |
| 143 async_test(function(t) { | |
| 144 var scope = 'scope/register-then-register-new-script-reject-install'; | |
| 145 var reject_script = normalizeURL('resources/reject-install-worker.js'); | |
| 146 var registration; | |
| 147 | |
| 148 service_worker_unregister_and_register(t, script1, scope) | |
| 149 .then(function(r) { | |
| 150 registration = r; | |
| 151 return wait_for_update(t, registration); | |
| 152 }) | |
| 153 .then(function() { | |
| 154 return wait_for_state(t, registration.installing, 'activated'); | |
| 155 }) | |
| 156 .then(function() { | |
| 157 assert_equals(registration.installing, null, | |
| 158 'on activated, installing should be null'); | |
| 159 assert_equals(registration.waiting, null, | |
| 160 'on activated, waiting should be null'); | |
| 161 assert_equals(registration.active.scriptURL, script1, | |
| 162 'on activated, the first script should be active'); | |
| 163 return navigator.serviceWorker.register(reject_script, {scope:scope}); | |
| 164 }) | |
| 165 .then(function(r) { | |
| 166 assert_equals(r, registration, | |
| 167 'register() should resolve to the same registration'); | |
| 168 return wait_for_update(t, registration); | |
| 169 }) | |
| 170 .then(function() { | |
| 171 assert_equals(registration.installing.scriptURL, reject_script, | |
| 172 'on update, the second script should be installing'); | |
| 173 assert_equals(registration.waiting, null, | |
| 174 'on update, waiting should be null'); | |
| 175 assert_equals(registration.active.scriptURL, script1, | |
| 176 'on update, the first script should be active'); | |
| 177 return wait_for_state(t, registration.installing, 'redundant'); | |
| 178 }) | |
| 179 .then(function() { | |
| 180 assert_equals(registration.installing, null, | |
| 181 'on redundant, installing should be null'); | |
| 182 assert_equals(registration.waiting, null, | |
| 183 'on redundant, waiting should be null'); | |
| 184 assert_equals(registration.active.scriptURL, script1, | |
| 185 'on redundant, the first script should be active'); | |
| 186 return registration.unregister(); | |
| 187 }) | |
| 188 .then(function() { | |
| 189 t.done(); | |
| 190 }) | |
| 191 .catch(unreached_rejection(t)); | |
| 192 }, 'Register then register new script that does not install'); | |
| 193 | |
| 194 async_test(function(t) { | |
| 195 var scope = 'scope/register-new-script-controller'; | |
| 196 var iframe; | |
| 197 var registration; | |
| 198 | |
| 199 service_worker_unregister_and_register(t, script1, scope) | |
| 200 .then(function(r) { | |
| 201 registration = r; | |
| 202 return wait_for_update(t, registration); | |
| 203 }) | |
| 204 .then(function(installing_worker) { | |
| 205 return wait_for_state(t, installing_worker, 'activated'); | |
|
nhiroki
2014/08/21 09:26:03
nit: installing_worker -> registration.installing
falken
2014/08/21 09:42:57
Done.
| |
| 206 }) | |
| 207 .then(function() { | |
| 208 return with_iframe(scope); | |
| 209 }) | |
| 210 .then(function(frame) { | |
| 211 iframe = frame; | |
| 212 return navigator.serviceWorker.register(script2, { scope: scope }) | |
| 213 }) | |
| 214 .then(function() { | |
| 215 return wait_for_update(t, registration); | |
| 216 }) | |
| 217 .then(function(installing_worker) { | |
|
nhiroki
2014/08/21 09:26:03
nit: 'installing_worker' is never used.
falken
2014/08/21 09:42:56
Done.
| |
| 218 return wait_for_state(t, registration.installing, 'installed'); | |
| 219 }) | |
| 220 .then(function() { | |
| 221 var sw_container = iframe.contentWindow.navigator.serviceWorker; | |
| 222 assert_equals(sw_container.controller.scriptURL, normalizeURL(script1) , | |
|
nhiroki
2014/08/21 09:26:03
nit: |script1| was already normalized at line 6.
falken
2014/08/21 09:42:57
Good point. Done.
| |
| 223 'the old version should control the old doc'); | |
| 224 return with_iframe(scope); | |
| 225 }) | |
| 226 .then(function(frame) { | |
| 227 var sw_container = frame.contentWindow.navigator.serviceWorker; | |
| 228 assert_equals(sw_container.controller.scriptURL, normalizeURL(script1) , | |
|
nhiroki
2014/08/21 09:26:03
ditto (normalizeURL).
falken
2014/08/21 09:42:56
Done.
| |
| 229 'the old version should control a new doc'); | |
| 230 var active_seen = wait_for_state(t, | |
| 231 registration.waiting, | |
| 232 'activated'); | |
| 233 unload_iframe(frame); | |
| 234 unload_iframe(iframe); | |
| 235 return active_seen; | |
| 236 }) | |
| 237 .then(function() { | |
| 238 return with_iframe(scope); | |
| 239 }) | |
| 240 .then(function(frame) { | |
| 241 var sw_container = frame.contentWindow.navigator.serviceWorker; | |
| 242 assert_equals(sw_container.controller.scriptURL, normalizeURL(script2) , | |
|
nhiroki
2014/08/21 09:26:03
ditto (normalizeURL).
falken
2014/08/21 09:42:57
Done.
| |
| 243 'the new version should control a new doc'); | |
| 244 unload_iframe(frame); | |
| 245 return registration.unregister(); | |
| 246 }) | |
| 247 .then(function() { | |
| 248 t.done(); | |
| 249 }) | |
| 250 .catch(unreached_rejection(t)); | |
| 251 }, 'Register same-scope new script url effect on controller'); | |
| 252 </script> | |
| OLD | NEW |