Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/unregister-then-register-new-script.html |
| diff --git a/LayoutTests/http/tests/serviceworker/unregister-then-register-new-script.html b/LayoutTests/http/tests/serviceworker/unregister-then-register-new-script.html |
| index baf22ff77fe961dc5f99caaacf9961bafd55719f..678a2f6efca51453949e41d67eb49c790c20c933 100644 |
| --- a/LayoutTests/http/tests/serviceworker/unregister-then-register-new-script.html |
| +++ b/LayoutTests/http/tests/serviceworker/unregister-then-register-new-script.html |
| @@ -6,10 +6,11 @@ |
| var worker_url = 'resources/empty-worker.js'; |
| async_test(function(t) { |
| - var scope = 'scope/new-worker'; |
| + var scope = 'scope/register-waits-for-unregistered-registration-to-clear'; |
| var new_worker_url = worker_url + '?new'; |
| var iframe; |
| var registration; |
| + var unloaded = false; |
| service_worker_unregister_and_register(t, worker_url, scope) |
| .then(function(r) { |
| @@ -27,12 +28,39 @@ async_test(function(t) { |
| return registration.unregister(); |
| }) |
| .then(function() { |
| - // FIXME: Register should not resolve until controllees are unloaded. |
| + setTimeout(function() { |
| + unloaded = true; |
| + unload_iframe(iframe); |
| + }, 10); |
| return navigator.serviceWorker.register(new_worker_url, |
| { scope: scope }); |
| }) |
| .then(function(new_registration) { |
| - return wait_for_update(t, new_registration); |
| + assert_true(unloaded, |
| + 'register should not resolve until iframe unloaded'); |
| + assert_equals(registration.installing, null, |
| + 'registration.installing'); |
| + assert_equals(registration.waiting, null, 'registration.waiting'); |
| + assert_equals(registration.active, null, 'registration.active'); |
| + return new_registration.unregister(); |
| + }) |
| + .then(function() { |
| + t.done(); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Registering a new script URL does not resolve until unregistered ' + |
| + 'registration is cleared'); |
| + |
| +async_test(function(t) { |
| + var scope = 'scope/unregister-then-register-new-script'; |
| + var new_worker_url = worker_url + '?new'; |
| + var iframe; |
| + var registration; |
| + |
| + service_worker_unregister_and_register(t, worker_url, scope) |
| + .then(function(r) { |
| + registration = r; |
| + return wait_for_update(t, registration); |
| }) |
| .then(function(worker) { |
| return wait_for_state(t, worker, 'activated'); |
| @@ -41,17 +69,56 @@ async_test(function(t) { |
| return with_iframe(scope); |
| }) |
| .then(function(frame) { |
| + iframe = frame; |
| + return registration.unregister(); |
| + }) |
| + .then(function() { |
| + var promise = navigator.serviceWorker.register(new_worker_url, |
| + { scope: scope }); |
| + unload_iframe(iframe); |
| + return promise; |
| + }) |
| + .then(function(new_registration) { |
| + assert_not_equals(registration, new_registration, |
| + 'register() should resolve to a new registration'); |
| + assert_equals(registration.installing, null, |
| + 'old registration.installing'); |
| + assert_equals(registration.waiting, null, |
| + 'old registration.waiting'); |
| + assert_equals(registration.active, null, |
| + 'old registration.active'); |
| + registration = new_registration; |
| + return wait_for_update(t, registration); |
| + }) |
| + .then(function(worker) { |
| + assert_equals(registration.installing.scriptURL, |
| + normalizeURL(new_worker_url), |
| + 'new registration.installing'); |
| + assert_equals(registration.waiting, null, |
| + 'new registration.waiting'); |
| + assert_equals(registration.active, null, |
| + 'new registration.active'); |
| + return wait_for_state(t, worker, 'activated'); |
| + }) |
| + .then(function() { |
| + return with_iframe(scope); |
| + }) |
| + .then(function(frame) { |
| assert_equals( |
| frame.contentWindow.navigator.serviceWorker.controller.scriptURL, |
| normalizeURL(new_worker_url), |
| - 'document controller is the new worker'); |
| - service_worker_unregister_and_done(t, scope); |
| + 'the new worker should control a new document'); |
| + unload_iframe(frame); |
| + return registration.unregister(); |
| + }) |
| + .then(function() { |
| + t.done(); |
| }) |
| .catch(unreached_rejection(t)); |
| -}, 'Unregister then register a new script URL'); |
| +}, 'Registering a new script URL while an unregistered registration is in use'); |
| async_test(function(t) { |
| - var scope = 'scope/non-existent-worker'; |
| + var scope = 'scope/unregister-then-register-new-script-that-404s'; |
| var iframe; |
| var registration; |
| @@ -71,32 +138,30 @@ async_test(function(t) { |
| return registration.unregister(); |
| }) |
| .then(function() { |
| - // FIXME: Register should not resolve until controllees are unloaded. |
| - return navigator.serviceWorker.register('this-will-404', |
| - { scope: scope }); |
| + var promise = navigator.serviceWorker.register('this-will-404', { scope: scope }); |
|
nhiroki
2014/08/21 09:26:04
nit: 80-columns.
falken
2014/08/21 09:42:57
Done.
|
| + unload_iframe(iframe); |
| + return promise; |
| }) |
| .then( |
| function() { |
| assert_unreached('register should reject the promise'); |
| }, |
| function() { |
| - return unload_iframe(iframe); |
| - }) |
| - .then(function() { |
| return with_iframe(scope); |
| }) |
| .then(function(frame) { |
| assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| null, |
| 'document should not load with a controller'); |
| - service_worker_unregister_and_done(t, scope); |
| + unload_iframe(frame); |
| + t.done(); |
| }) |
| .catch(unreached_rejection(t)); |
| }, 'Registering a new script URL that 404s does not resurrect an ' + |
| 'unregistered registration'); |
| async_test(function(t) { |
| - var scope = 'scope/reject-install-worker'; |
| + var scope = 'scope/unregister-then-register-reject-install-worker'; |
| var iframe; |
| var registration; |
| @@ -116,19 +181,18 @@ async_test(function(t) { |
| return registration.unregister(); |
| }) |
| .then(function() { |
| - // FIXME: Register should not resolve until controllees are unloaded. |
| - return navigator.serviceWorker.register( |
| + var promise = navigator.serviceWorker.register( |
| 'resources/reject-install-worker.js', { scope: scope }); |
| + unload_iframe(iframe); |
| + return promise; |
| }) |
| - .then(function(new_registration) { |
| - return wait_for_update(t, new_registration); |
| + .then(function(r) { |
| + registration = r; |
| + return wait_for_update(t, registration); |
| }) |
| .then(function(worker) { |
| return wait_for_state(t, worker, 'redundant'); |
| }) |
| - .then(function(worker) { |
| - return unload_iframe(iframe); |
| - }) |
| .then(function() { |
| return with_iframe(scope); |
| }) |
| @@ -136,9 +200,14 @@ async_test(function(t) { |
| assert_equals(frame.contentWindow.navigator.serviceWorker.controller, |
| null, |
| 'document should not load with a controller'); |
| - service_worker_unregister_and_done(t, scope); |
| + unload_iframe(frame); |
| + return registration.unregister(); |
| + }) |
| + .then(function() { |
| + t.done(); |
| }) |
| .catch(unreached_rejection(t)); |
| }, 'Registering a new script URL that fails to install does not resurrect ' + |
| 'an unregistered registration'); |
| + |
| </script> |