Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
| diff --git a/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html b/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
| index 0f2fd5a3706a7812bec20a8a964f6f3bd7f3e8bb..690c877299aafdd429e24ffe27517d5b8d5cea5e 100644 |
| --- a/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
| +++ b/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
| @@ -4,26 +4,23 @@ |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="resources/test-helpers.js"></script> |
| <script> |
| -var t = async_test('postMessage MessagePorts from ServiceWorker to Client'); |
| -t.step(function() { |
| - var scope = 'resources/blank.html' |
| +async_test(function(t) { |
| + var scope = 'resources/blank.html'; |
| service_worker_unregister_and_register( |
| - t, 'resources/postmessage-msgport-to-client-worker.js', scope).then(t.step_func(onRegister)); |
| - |
| - function onRegister(worker) { |
| - worker.addEventListener('statechange', t.step_func(function(event) { |
| - if (event.target.state == 'activated') |
| - onActive(); |
| - })); |
| - } |
| - |
| - function onActive() { |
| - with_iframe(scope, t.step_func(function(frame) { |
| - var w = frame.contentWindow; |
| - w.onmessage = t.step_func(onMessage); |
| - w.navigator.serviceWorker.controller.postMessage('ping'); |
| - })); |
| - } |
| + t, 'resources/postmessage-msgport-to-client-worker.js', scope) |
|
falken
2014/08/14 14:23:14
indent
nhiroki
2014/08/14 16:37:53
Done.
|
| + .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) { |
| + var w = frame.contentWindow; |
| + w.onmessage = t.step_func(onMessage); |
| + w.navigator.serviceWorker.controller.postMessage('ping'); |
| + }) |
| + .catch(unreached_rejection(t)); |
| var result = []; |
| var expected = [ |
| @@ -32,20 +29,22 @@ t.step(function() { |
| ]; |
| function onMessage(e) { |
| - var message = e.data; |
| - if ('port' in message) { |
| - var port = message.port; |
| - port.postMessage({value: 1}); |
| - port.postMessage({value: 2}); |
| - port.postMessage({done: true}); |
| - } else if ('ack' in message) { |
| - result.push(message.ack); |
| - } else if ('done' in message) { |
| - assert_array_equals(result, expected, 'Worker should post back expected values via MessagePort.'); |
| - service_worker_unregister_and_done(t, scope); |
| - } else { |
| - assert_unreached('Got unexpected message from ServiceWorker'); |
| - } |
| + var message = e.data; |
| + if ('port' in message) { |
| + var port = message.port; |
| + port.postMessage({value: 1}); |
| + port.postMessage({value: 2}); |
| + port.postMessage({done: true}); |
| + } else if ('ack' in message) { |
| + result.push(message.ack); |
| + } else if ('done' in message) { |
| + assert_array_equals( |
| + result, expected, |
|
falken
2014/08/14 14:23:14
indent
nhiroki
2014/08/14 16:37:53
Done.
|
| + 'Worker should post back expected values via MessagePort.'); |
| + service_worker_unregister_and_done(t, scope); |
| + } else { |
| + assert_unreached('Got unexpected message from ServiceWorker'); |
| + } |
| } |
| -}); |
| + }, 'postMessage MessagePorts from ServiceWorker to Client'); |
| </script> |