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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..64efe6f456e0ef8f14e4d0ba8b28d4f8e6b3a2fc |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/unregister-then-register-new-script.html |
| @@ -0,0 +1,144 @@ |
| +<!DOCTYPE html> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script> |
| +var worker_url = 'resources/empty-worker.js'; |
| + |
| +async_test(function(t) { |
| + var scope = 'scope/new-worker'; |
| + 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'); |
| + }) |
| + .then(function() { |
| + return with_iframe(scope); |
| + }) |
| + .then(function(frame) { |
| + iframe = frame; |
| + return registration.unregister(scope); |
|
nhiroki
2014/08/15 09:53:40
ditto.
|
| + }) |
| + .then(function() { |
| + // FIXME: Register should not resolve until controllees are unloaded. |
| + return navigator.serviceWorker.register(new_worker_url, |
| + { scope: scope }); |
| + }) |
| + .then(function(new_registration) { |
| + return wait_for_update(t, new_registration); |
| + }) |
| + .then(function(worker) { |
| + 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); |
| + }) |
| + .catch(unreached_rejection(t)); |
| +}, 'Unregister then register a new script URL'); |
| + |
| +async_test(function(t) { |
| + var scope = 'scope/non-existent-worker'; |
| + 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'); |
| + }) |
| + .then(function() { |
| + return with_iframe(scope); |
| + }) |
| + .then(function(frame) { |
| + iframe = frame; |
| + return registration.unregister(); |
| + }) |
| + .then(function() { |
| + // FIXME: Register should not resolve until controllees are unloaded. |
| + return navigator.serviceWorker.register('this-will-404', |
| + { scope: scope }); |
| + }) |
| + .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); |
| + }) |
| + .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 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'); |
| + }) |
| + .then(function() { |
| + return with_iframe(scope); |
| + }) |
| + .then(function(frame) { |
| + iframe = frame; |
| + return registration.unregister(); |
| + }) |
| + .then(function() { |
| + // FIXME: Register should not resolve until controllees are unloaded. |
| + return navigator.serviceWorker.register( |
| + 'resources/reject-install-worker.js', { scope: scope }); |
| + }) |
| + .then(function(new_registration) { |
| + return wait_for_update(t, new_registration); |
| + }) |
| + .then(function(worker) { |
| + return wait_for_state(t, worker, 'redundant'); |
| + }) |
| + .then(function(worker) { |
| + 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); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Registering a new script URL that fails to install does not resurrect ' + |
| + 'an unregistered registration'); |
| +</script> |