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