Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
| diff --git a/LayoutTests/http/tests/serviceworker/current-on-load.html b/LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
| similarity index 57% |
| copy from LayoutTests/http/tests/serviceworker/current-on-load.html |
| copy to LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
| index 5c43c4d47d9ff8db6634e418f5e483b59380dfbd..18beb9141d45e7a407a85fe20945411c26bff3f4 100644 |
| --- a/LayoutTests/http/tests/serviceworker/current-on-load.html |
| +++ b/LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
| @@ -1,21 +1,20 @@ |
| <!DOCTYPE html> |
| -<title>Service Worker: Current on load</title> |
| +<title>Service Worker: postMessage to Client</title> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="resources/test-helpers.js"></script> |
| -<body> |
| <script> |
| -var t = async_test('current is set for a controlled document'); |
| +var t = async_test('postMessage from ServiceWorker to Client'); |
| t.step(function() { |
| var scope = 'resources/blank.html' |
| navigator.serviceWorker.unregister(scope).then( |
| - doTest, |
| + doRegister, |
| unreached_rejection(t, 'Unregister should not fail') |
| ); |
| - function doTest() { |
| + function doRegister() { |
| navigator.serviceWorker.register( |
| - 'resources/worker-no-op.js', {scope: scope} |
| + 'resources/postmessage-to-client-worker.js', {scope: scope} |
| ).then( |
| onRegister, |
| unreached_rejection(t, 'Registration should succeed, but failed') |
| @@ -32,11 +31,23 @@ t.step(function() { |
| function onActive() { |
| with_iframe(scope, t.step_func(function(frame) { |
| var w = frame.contentWindow; |
| - assert_true(w.navigator.serviceWorker.current instanceof w.ServiceWorker, |
| - 'current should be a ServiceWorker object'); |
| - t.done(); |
| + w.onmessage = t.step_func(onMessage); |
| + w.navigator.serviceWorker.current.postMessage('ping'); |
|
marja
2014/05/06 16:29:16
Is it also possible to post a message port?
|
| })); |
| } |
| + |
| + var result = []; |
| + var expected = ['Sending message via clients']; |
| + |
| + function onMessage(e) { |
| + var message = e.data; |
| + if (message === 'quit') { |
| + assert_array_equals(result, expected, 'Worker should post back expected messages.'); |
| + t.done(); |
| + } else { |
| + result.push(message); |
| + } |
| + } |
| }); |
| </script> |
| -</body> |
| + |