Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
index e1726bbe313f5380c171df77e7c7fcf9ab0ccaef..e00d72c2d4d1488f745135293c7e128c30301063 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-msgport-to-client.html |
@@ -4,45 +4,41 @@ |
<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' |
- service_worker_unregister_and_register( |
- t, 'resources/postmessage-msgport-to-client-worker.js', scope) |
- .then(function(registration) { |
+ |
+promise_test(t => { |
+ var script = 'resources/postmessage-msgport-to-client-worker.js'; |
+ var scope = 'resources/blank.html'; |
+ var port; |
+ |
+ return service_worker_unregister_and_register(t, script, scope) |
+ .then(registration => { |
+ add_completion_callback(() => registration.unregister()); |
return wait_for_state(t, registration.installing, 'activated'); |
}) |
- .then(function() { return with_iframe(scope); }) |
- .then(function(frame) { |
- var w = frame.contentWindow; |
- w.navigator.serviceWorker.onmessage = t.step_func(onMessage); |
- w.navigator.serviceWorker.controller.postMessage('ping'); |
+ .then(() => with_iframe(scope)) |
+ .then(frame => { |
+ return new Promise(resolve => { |
+ var w = frame.contentWindow; |
+ w.navigator.serviceWorker.onmessage = resolve; |
+ w.navigator.serviceWorker.controller.postMessage('ping'); |
+ }); |
}) |
- .catch(unreached_rejection(t)); |
- |
- var result = []; |
- var expected = [ |
- 'Acking value: 1', |
- 'Acking value: 2', |
- ]; |
+ .then(e => { |
+ port = e.ports[0]; |
+ port.postMessage({value: 1}); |
+ port.postMessage({value: 2}); |
+ port.postMessage({done: true}); |
+ return new Promise(resolve => { port.onmessage = resolve; }); |
+ }) |
+ .then(e => { |
+ assert_equals(e.data.ack, 'Acking value: 1'); |
+ return new Promise(resolve => { port.onmessage = resolve; }); |
+ }) |
+ .then(e => { |
+ assert_equals(e.data.ack, 'Acking value: 2'); |
+ return new Promise(resolve => { port.onmessage = resolve; }); |
+ }) |
+ .then(e => { assert_true(e.data.done); }); |
+ }, 'postMessage MessagePorts from ServiceWorker to Client'); |
- 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'); |
- } |
- } |
- }); |
</script> |