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