Index: LayoutTests/http/tests/serviceworker/minimal-end-to-end.html |
diff --git a/LayoutTests/http/tests/serviceworker/minimal-end-to-end.html b/LayoutTests/http/tests/serviceworker/minimal-end-to-end.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..657c19cb9a9a6eed179139620ccb70c882e0752d |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/minimal-end-to-end.html |
@@ -0,0 +1,89 @@ |
+<!DOCTYPE html> |
+<title>Service Worker: minimal end-to-end</title> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="resources/support.js"></script> |
+<script> |
+var t = async_test('Minimal end-to-end registration'); |
+t.step(function() { |
+ |
+ var stateChanges = recordStateChanges(); |
+ var serviceWorkerStates = []; |
+ var lastServiceWorkerState = ''; |
+ var receivedMessageFromPort = ''; |
+ var receivedMessage = ''; |
+ |
+ assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer); |
+ assert_equals(typeof navigator.serviceWorker.register, 'function'); |
+ assert_equals(typeof navigator.serviceWorker.unregister, 'function'); |
+ |
+ // This always tests fresh registration, so unregister it first. |
+ |
+ // FIXME: This currently hits an ASSERT. |
+ //navigator.serviceWorker.unregister('/scope/*').then( |
+ Promise.resolve().then( |
+ // FIXME: Use a variant of step_func here to catch test bugs. |
+ function() { |
+ return navigator.serviceWorker.register( |
+ 'resources/end-to-end-worker.js', |
+ {scope: '/scope/*'}); |
+ } |
+ ).then( |
+ t.step_func(onRegister) |
+ ).catch( |
+ fail(t, 'Registration failed') |
+ ); |
+ |
+ function onRegister(serviceWorker) { |
+ serviceWorkerStates.push(serviceWorker.state); |
+ lastServiceWorkerState = serviceWorker.state; |
+ |
+ sendMessagePort(serviceWorker, 'registering doc').onmessage = t.step_func(function (e) { |
+ if (e.data === 'ping') |
+ serviceWorker.postMessage('pong'); |
+ else |
+ receivedMessageFromPort = e.data; |
+ }); |
+ |
+ serviceWorker.onstatechange = t.step_func(function() { |
+ serviceWorkerStates.push(serviceWorker.state); |
+ |
+ switch (serviceWorker.state) { |
+ case 'installed': |
+ assert_equals(lastServiceWorkerState, 'installing'); |
+ break; |
+ case 'activating': |
+ assert_equals(lastServiceWorkerState, 'installed'); |
+ break; |
+ case 'active': |
+ assert_equals(lastServiceWorkerState, 'activating'); |
+ break; |
+ default: |
+ fail(t, 'Unexpected state: ' + serviceWorker.state); |
+ } |
+ |
+ lastServiceWorkerState = serviceWorker.state; |
+ if (serviceWorker.state === 'active') |
+ finishTest(); |
+ }); |
+ } |
+ |
+ window.onmessage = t.step_func(function(e) { |
+ receivedMessage = e.message; |
+ }); |
+ |
+ function finishTest() { |
+ assert_equals(receivedMessageFromPort, 'Ack for: registering doc'); |
+ //assert_equals(receivedMessage, 'Ack for: registering doc'); |
+ |
+ assert_array_equals(serviceWorkerStates, |
+ ['installing', 'installed', 'activating', 'active'], |
+ 'Service worker should pass through four states'); |
+ assert_equals(stateChanges.pendingStateChangeCount, 0, |
+ 'Out-of-scope document should not see pending state changes'); |
+ assert_equals(stateChanges.activeStateChangeCount, 0, |
+ 'Out-of-scope document should not see pending state changes'); |
kinuko
2014/04/16 03:28:38
I think we can remove the latter two asserts for n
jsbell
2014/04/16 17:04:19
Done.
|
+ t.done(); |
+ } |
+}); |
+</script> |