Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Unified Diff: LayoutTests/http/tests/serviceworker/unregister-then-register.html

Issue 416003003: Test for register canceling an unregister. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: more tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/http/tests/serviceworker/unregister-controller.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/serviceworker/unregister-then-register.html
diff --git a/LayoutTests/http/tests/serviceworker/unregister-then-register.html b/LayoutTests/http/tests/serviceworker/unregister-then-register.html
new file mode 100644
index 0000000000000000000000000000000000000000..2adb4a93ca2d40b98adfba7973b76c1a9c3228ce
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/unregister-then-register.html
@@ -0,0 +1,187 @@
+<!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';
+
+// Test that calling unregister() when the active worker has a controllee
+// is cancelable by calling register() while the worker still has a controllee.
+async_test(function(t) {
+ var scope = 'unregister-then-register';
+ var iframe;
+ var worker;
+
+ service_worker_unregister_and_register(t, worker_url, scope)
+ .then(function(registered_worker) {
+ worker = registered_worker;
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(function() {
+ // Create a controllee.
+ return with_iframe(scope);
+ })
+ .then(function(frame) {
+ iframe = frame;
+ // There's a controllee so unregistration won't take effect immediately.
+ return navigator.serviceWorker.unregister(scope);
+ })
+ .then(function() {
+ // Reverse the unregister.
+ return navigator.serviceWorker.register(worker_url, { scope: scope });
+ })
+ .then(function(registered_worker) {
+ assert_equals(registered_worker, worker,
+ 'register should resolve to the same worker');
+ return unload_iframe(iframe);
+ })
+ .then(function() {
+ // Make a new controllee to prove unregistration didn't happen.
+ return with_iframe(scope);
+ })
+ .then(function(frame) {
+ var controller = frame.contentWindow.navigator.serviceWorker.controller;
+ assert_equals(controller.state, 'activated',
+ 'document should load with an active controller');
+ service_worker_unregister_and_done(t, scope);
+ })
+ .catch(unreached_rejection(t));
+}, 'Unregister is cancelable by register');
+
+// Test that unregister() is canceled by register() for a new script URL, even
+// 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,
+async_test(function(t) {
+ var scope = 'non-existent-worker'
+ var iframe;
+
+ service_worker_unregister_and_register(t, worker_url, scope)
+ .then(function(worker) {
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(function() {
+ return with_iframe(scope);
+ })
+ .then(function(frame) {
+ iframe = frame;
+ return navigator.serviceWorker.unregister(scope);
+ })
+ .then(function() {
+ return navigator.serviceWorker.register('nothing-here',
+ { 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) {
+ var controller = frame.contentWindow.navigator.serviceWorker.controller;
+ // FIXME: When crbug.com/398355 is fixed, assert that document *does*
+ // load with a controller, whose script is worker_url.
+ assert_equals(controller, null,
+ 'document should load with a controller');
+ service_worker_unregister_and_done(t, scope);
+ })
+ .catch(unreached_rejection(t));
+}, 'Registering a new script URL that 404s does not affect the original ' +
+ 'registration');
+
+// Test that unregister() is canceled by register() for a new script URL, even
+// if installation of the new worker fails.
michaeln 2014/07/30 02:49:42 ditto
+async_test(function(t) {
+ var scope = 'reject-install-worker'
+ var iframe;
+
+ service_worker_unregister_and_register(t, worker_url, scope)
+ .then(function(worker) {
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(function() {
+ return with_iframe(scope);
+ })
+ .then(function(frame) {
+ iframe = frame;
+ return navigator.serviceWorker.unregister();
+ })
+ .then(function() {
+ return navigator.serviceWorker.register(
+ 'resources/reject-install-worker.js', { scope: scope });
+ })
+ .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) {
+ var controller = frame.contentWindow.navigator.serviceWorker.controller;
+ // FIXME: When crbug.com/398355 is fixed, assert that document *does*
+ // load with a controller, whose script is worker_url.
+ assert_equals(controller, null,
+ 'document should 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 affect the ' +
+ 'original registration');
+
+// Test that unregister() is canceled by register() for a new script URL.
+async_test(function(t) {
+ var scope = 'new-script'
+ var new_worker_url = worker_url + '?new';
+ var iframe;
+
+ service_worker_unregister_and_register(t, worker_url, scope)
+ .then(function(worker) {
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(function() {
+ return with_iframe(scope);
+ })
+ .then(function(frame) {
+ iframe = frame;
+ return navigator.serviceWorker.unregister();
+ })
+ .then(function() {
+ return navigator.serviceWorker.register(new_worker_url,
+ { scope: scope });
+ })
+ .then(function(worker) {
+ return wait_for_state(t, worker, 'installed');
+ })
+ .then(function() {
+ return with_iframe(scope);
+ })
+ .then(function(frame) {
+ // FIXME: When crbug.com/398355 is fixed, assert that controller
+ // uses the old url and waiting uses the new url.
+ var controller = frame.contentWindow.navigator.serviceWorker.controller;
+ assert_equals(controller.url, normalizeURL(new_worker_url),
+ 'controller should have the old url');
+ return unload_iframe(frame);
+ })
+ .then(function() {
+ return unload_iframe(iframe);
+ })
+ .then(function() {
+ return with_iframe(scope);
+ })
+ .then(function(frame) {
+ var controller = frame.contentWindow.navigator.serviceWorker.controller;
+ // FIXME: When crbug.com/398355 is fixed, assert that controller
+ // uses the new url and waiting is null.
+ assert_equals(controller.url, normalizeURL(new_worker_url),
+ 'document should load with a controller');
+ service_worker_unregister_and_done(t, scope);
+ })
+ .catch(unreached_rejection(t));
+}, 'Registering a new script URL creates a waiting worker');
+</script>
« no previous file with comments | « LayoutTests/http/tests/serviceworker/unregister-controller.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698