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 worker_url = 'resources/empty-worker.js'; | |
| 7 | |
| 8 // Test that calling unregister() when the active worker has a controllee | |
| 9 // is cancelable by calling register() while the worker still has a controllee. | |
| 10 async_test(function(t) { | |
| 11 var scope = 'unregister-then-register'; | |
| 12 var iframe; | |
| 13 var worker; | |
| 14 | |
| 15 service_worker_unregister_and_register(t, worker_url, scope) | |
| 16 .then(function(registered_worker) { | |
| 17 worker = registered_worker; | |
| 18 return wait_for_state(t, worker, 'activated'); | |
| 19 }) | |
| 20 .then(function() { | |
| 21 // Create a controllee. | |
| 22 return with_iframe(scope); | |
| 23 }) | |
| 24 .then(function(frame) { | |
| 25 iframe = frame; | |
| 26 // There's a controllee so unregistration won't take effect immediately. | |
| 27 return navigator.serviceWorker.unregister(scope); | |
| 28 }) | |
| 29 .then(function() { | |
| 30 // Reverse the unregister. | |
| 31 return navigator.serviceWorker.register(worker_url, { scope: scope }); | |
| 32 }) | |
| 33 .then(function(registered_worker) { | |
| 34 assert_equals(registered_worker, worker, | |
| 35 'register should resolve to the same worker'); | |
| 36 return unload_iframe(iframe); | |
| 37 }) | |
| 38 .then(function() { | |
| 39 // Make a new controllee to prove unregistration didn't happen. | |
| 40 return with_iframe(scope); | |
| 41 }) | |
| 42 .then(function(frame) { | |
| 43 var controller = frame.contentWindow.navigator.serviceWorker.controller; | |
| 44 assert_equals(controller.state, 'activated', | |
| 45 'document should load with an active controller'); | |
| 46 service_worker_unregister_and_done(t, scope); | |
| 47 }) | |
| 48 .catch(unreached_rejection(t)); | |
| 49 }, 'Unregister is cancelable by register'); | |
| 50 | |
| 51 // Test that unregister() is canceled by register() for a new script URL, even | |
| 52 // if registration fails due to a 404 error when fetching the script. | |
|
michaeln
2014/07/30 02:49:42
I agree this is the result of the specified algos,
| |
| 53 async_test(function(t) { | |
| 54 var scope = 'non-existent-worker' | |
| 55 var iframe; | |
| 56 | |
| 57 service_worker_unregister_and_register(t, worker_url, scope) | |
| 58 .then(function(worker) { | |
| 59 return wait_for_state(t, worker, 'activated'); | |
| 60 }) | |
| 61 .then(function() { | |
| 62 return with_iframe(scope); | |
| 63 }) | |
| 64 .then(function(frame) { | |
| 65 iframe = frame; | |
| 66 return navigator.serviceWorker.unregister(scope); | |
| 67 }) | |
| 68 .then(function() { | |
| 69 return navigator.serviceWorker.register('nothing-here', | |
| 70 { scope: scope }); | |
| 71 }) | |
| 72 .then( | |
| 73 function() { | |
| 74 assert_unreached('register should reject the promise'); | |
| 75 }, | |
| 76 function() { | |
| 77 return unload_iframe(iframe); | |
| 78 }) | |
| 79 .then(function() { | |
| 80 return with_iframe(scope); | |
| 81 }) | |
| 82 .then(function(frame) { | |
| 83 var controller = frame.contentWindow.navigator.serviceWorker.controller; | |
| 84 // FIXME: When crbug.com/398355 is fixed, assert that document *does* | |
| 85 // load with a controller, whose script is worker_url. | |
| 86 assert_equals(controller, null, | |
| 87 'document should load with a controller'); | |
| 88 service_worker_unregister_and_done(t, scope); | |
| 89 }) | |
| 90 .catch(unreached_rejection(t)); | |
| 91 }, 'Registering a new script URL that 404s does not affect the original ' + | |
| 92 'registration'); | |
| 93 | |
| 94 // Test that unregister() is canceled by register() for a new script URL, even | |
| 95 // if installation of the new worker fails. | |
|
michaeln
2014/07/30 02:49:42
ditto
| |
| 96 async_test(function(t) { | |
| 97 var scope = 'reject-install-worker' | |
| 98 var iframe; | |
| 99 | |
| 100 service_worker_unregister_and_register(t, worker_url, scope) | |
| 101 .then(function(worker) { | |
| 102 return wait_for_state(t, worker, 'activated'); | |
| 103 }) | |
| 104 .then(function() { | |
| 105 return with_iframe(scope); | |
| 106 }) | |
| 107 .then(function(frame) { | |
| 108 iframe = frame; | |
| 109 return navigator.serviceWorker.unregister(); | |
| 110 }) | |
| 111 .then(function() { | |
| 112 return navigator.serviceWorker.register( | |
| 113 'resources/reject-install-worker.js', { scope: scope }); | |
| 114 }) | |
| 115 .then(function(worker) { | |
| 116 return wait_for_state(t, worker, 'redundant'); | |
| 117 }) | |
| 118 .then(function(worker) { | |
| 119 return unload_iframe(iframe); | |
| 120 }) | |
| 121 .then(function() { | |
| 122 return with_iframe(scope); | |
| 123 }) | |
| 124 .then(function(frame) { | |
| 125 var controller = frame.contentWindow.navigator.serviceWorker.controller; | |
| 126 // FIXME: When crbug.com/398355 is fixed, assert that document *does* | |
| 127 // load with a controller, whose script is worker_url. | |
| 128 assert_equals(controller, null, | |
| 129 'document should load with a controller'); | |
| 130 service_worker_unregister_and_done(t, scope); | |
| 131 }) | |
| 132 .catch(unreached_rejection(t)); | |
| 133 }, 'Registering a new script URL that fails to install does not affect the ' + | |
| 134 'original registration'); | |
| 135 | |
| 136 // Test that unregister() is canceled by register() for a new script URL. | |
| 137 async_test(function(t) { | |
| 138 var scope = 'new-script' | |
| 139 var new_worker_url = worker_url + '?new'; | |
| 140 var iframe; | |
| 141 | |
| 142 service_worker_unregister_and_register(t, worker_url, scope) | |
| 143 .then(function(worker) { | |
| 144 return wait_for_state(t, worker, 'activated'); | |
| 145 }) | |
| 146 .then(function() { | |
| 147 return with_iframe(scope); | |
| 148 }) | |
| 149 .then(function(frame) { | |
| 150 iframe = frame; | |
| 151 return navigator.serviceWorker.unregister(); | |
| 152 }) | |
| 153 .then(function() { | |
| 154 return navigator.serviceWorker.register(new_worker_url, | |
| 155 { scope: scope }); | |
| 156 }) | |
| 157 .then(function(worker) { | |
| 158 return wait_for_state(t, worker, 'installed'); | |
| 159 }) | |
| 160 .then(function() { | |
| 161 return with_iframe(scope); | |
| 162 }) | |
| 163 .then(function(frame) { | |
| 164 // FIXME: When crbug.com/398355 is fixed, assert that controller | |
| 165 // uses the old url and waiting uses the new url. | |
| 166 var controller = frame.contentWindow.navigator.serviceWorker.controller; | |
| 167 assert_equals(controller.url, normalizeURL(new_worker_url), | |
| 168 'controller should have the old url'); | |
| 169 return unload_iframe(frame); | |
| 170 }) | |
| 171 .then(function() { | |
| 172 return unload_iframe(iframe); | |
| 173 }) | |
| 174 .then(function() { | |
| 175 return with_iframe(scope); | |
| 176 }) | |
| 177 .then(function(frame) { | |
| 178 var controller = frame.contentWindow.navigator.serviceWorker.controller; | |
| 179 // FIXME: When crbug.com/398355 is fixed, assert that controller | |
| 180 // uses the new url and waiting is null. | |
| 181 assert_equals(controller.url, normalizeURL(new_worker_url), | |
| 182 'document should load with a controller'); | |
| 183 service_worker_unregister_and_done(t, scope); | |
| 184 }) | |
| 185 .catch(unreached_rejection(t)); | |
| 186 }, 'Registering a new script URL creates a waiting worker'); | |
| 187 </script> | |
| OLD | NEW |