Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/skip-waiting.html |
| diff --git a/LayoutTests/http/tests/serviceworker/skip-waiting.html b/LayoutTests/http/tests/serviceworker/skip-waiting.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..38799adc6e06aa347c3392e5f348a982b5550dec |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/skip-waiting.html |
| @@ -0,0 +1,176 @@ |
| +<!DOCTYPE html> |
| +<title>Service Worker: Skip waiting</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script> |
| + |
| +async_test(function(t) { |
|
jsbell
2014/11/13 23:07:51
Can you use the service_worker_test() helper to re
xiang
2014/11/28 08:00:48
Thanks for the suggestion, I split them to smaller
|
| + var scope = 'resources/skip-waiting-no-client'; |
| + var url = 'resources/skip-waiting.js'; |
| + function onMessage(e) { |
| + var message = e.data; |
|
jsbell
2014/11/13 23:07:51
Only need 2 more spaces of indent here (6 total)
|
| + assert_equals(message, 'done', |
| + 'skipWaiting promise should be resolved'); |
| + service_worker_unregister_and_done(t, scope); |
| + } |
| + service_worker_unregister_and_register(t, url, scope) |
| + .then(function(registration) { |
| + return wait_for_update(t, registration); |
| + }) |
| + .then(function(sw) { |
| + var messageChannel = new MessageChannel(); |
| + messageChannel.port1.onmessage = t.step_func(onMessage); |
| + sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Test skipWaiting when no client attached'); |
| + |
| +async_test(function(t) { |
| + var scope = 'resources/multiple-skip-waiting'; |
| + var url = 'resources/skip-waiting.js'; |
| + function onMessage(e) { |
| + var message = e.data; |
| + assert_equals(message, 'done', |
| + 'multiple skipWaiting promises should be resolved'); |
|
jsbell
2014/11/13 23:07:51
This message would be a lot clearer if it was in t
|
| + service_worker_unregister_and_done(t, scope); |
| + } |
| + service_worker_unregister_and_register(t, url, scope) |
| + .then(function(registration) { |
| + return wait_for_update(t, registration); |
| + }) |
| + .then(function(sw) { |
| + var messageChannel = new MessageChannel(); |
| + messageChannel.port1.onmessage = t.step_func(onMessage); |
| + sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Test multiple skipWaiting be called'); |
|
jsbell
2014/11/13 23:07:50
How about: 'skipWaiting() called multiple times' ?
|
| + |
| +async_test(function(t) { |
| + var scope = 'resources/doctype.html'; |
| + var url1 = 'resources/empty.js'; |
| + var url2 = 'resources/skip-waiting.js'; |
| + var iframeContainer; |
| + function onControllerChanged() { |
| + assert_equals( |
| + iframeContainer.controller.scriptURL, normalizeURL(url2), |
| + 'Controller scriptURL should change to the second one'); |
| + service_worker_unregister_and_done(t, scope); |
| + } |
| + service_worker_unregister_and_register(t, url1, scope) |
| + .then(function(registration) { |
| + return wait_for_update(t, registration); |
| + }) |
| + .then(function(sw) { |
| + return wait_for_state(t, sw, 'activated'); |
| + }) |
| + .then(function() { |
| + return with_iframe(scope); |
| + }) |
| + .then(function(frame) { |
| + iframeContainer = frame.contentWindow.navigator.serviceWorker; |
| + assert_equals( |
| + iframeContainer.controller.scriptURL, normalizeURL(url1), |
| + 'Document controller scriptURL should equal to the first one'); |
| + iframeContainer.oncontrollerchange = t.step_func(onControllerChanged); |
| + return navigator.serviceWorker.register(url2, { scope : scope }); |
|
jsbell
2014/11/13 23:07:50
Nit: no space after {, after :, or before } in obj
xiang
2014/11/28 08:00:48
Done.
|
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Test skipWaiting while client is using registration'); |
| + |
| +async_test(function(t) { |
| + var scope1 = 'resources/simple'; |
| + var scope2 = 'resources/simple.html'; |
| + var url1 = 'resources/empty.js'; |
| + var url2 = 'resources/skip-waiting.js'; |
| + var iframeContainer; |
| + function onControllerChanged() { |
| + assert_equals( |
| + iframeContainer.controller.scriptURL, normalizeURL(url2), |
| + 'Controller scriptURL should change to the second one'); |
| + service_worker_unregister_and_done(t, scope2); |
| + } |
| + |
| + service_worker_unregister_and_register(t, url1, scope1) |
| + .then(function(registration) { |
| + return wait_for_update(t, registration); |
| + }) |
| + .then(function(sw) { |
| + return wait_for_state(t, sw, 'activated'); |
| + }) |
| + .then(function() { |
| + return with_iframe(scope2); |
| + }) |
| + .then(function(frame) { |
| + iframeContainer = frame.contentWindow.navigator.serviceWorker; |
| + assert_equals( |
| + iframeContainer.controller.scriptURL, normalizeURL(url1), |
| + 'Document controller scriptURL should equal to the first one'); |
| + iframeContainer.oncontrollerchange = t.step_func(onControllerChanged); |
| + return navigator.serviceWorker.register(url2, { scope : scope2 }); |
| + }) |
| + .catch(unreached_rejection(t)); |
| +}, 'Test skipWaiting when client is using different registration'); |
| + |
| +async_test(function(t) { |
| + var scope = 'resources/blank.html'; |
| + var url1 = 'resources/empty.js'; |
| + var url2 = 'resources/skip-waiting.js'; |
| + var iframeContainer, serviceWorker, onMessage, onControllerChanged; |
| + var promise1 = new Promise(function(resolve) { |
| + onMessage = function(e) { |
| + var message = e.data; |
| + assert_equals( |
| + message, 'activating', |
| + 'skipWaiting promise should be resolved after activated'); |
| + resolve(); |
| + }; |
| + }); |
| + var promise2 = new Promise(function(resolve) { |
| + onControllerChanged = function() { |
| + assert_equals( |
| + iframeContainer.controller.scriptURL, normalizeURL(url2), |
| + 'Controller scriptURL should change to the second one'); |
| + resolve(); |
| + }; |
| + }); |
| + service_worker_unregister_and_register(t, url1, scope) |
| + .then(function(registration) { |
| + return wait_for_update(t, registration); |
| + }) |
| + .then(function(sw) { |
| + return wait_for_state(t, sw, 'activated'); |
| + }) |
| + .then(function() { |
| + return with_iframe(scope); |
| + }) |
| + .then(function(frame) { |
| + iframeContainer = frame.contentWindow.navigator.serviceWorker; |
| + assert_equals( |
| + iframeContainer.controller.scriptURL, normalizeURL(url1), |
| + 'Document controller scriptURL should equal to the first one'); |
| + iframeContainer.oncontrollerchange = t.step_func(onControllerChanged); |
| + return navigator.serviceWorker.register(url2, { scope : scope }); |
| + }) |
| + .then(function(registration) { |
| + return wait_for_update(t, registration); |
| + }) |
| + .then(function(sw) { |
| + serviceWorker = sw; |
| + return wait_for_state(t, sw, 'installed'); |
| + }) |
| + .then(function() { |
| + var messageChannel = new MessageChannel(); |
| + messageChannel.port1.onmessage = t.step_func(onMessage); |
| + serviceWorker.postMessage( |
| + {port: messageChannel.port2}, [messageChannel.port2]); |
| + return Promise.all([promise1, promise2]); |
| + }) |
| + .then(function() { |
| + return service_worker_unregister_and_done(t, scope); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Test skipWaiting when worker is waiting'); |
| + |
| +</script> |