Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage.html |
index 6e6fade17883af323524b827fd86030a13b7cfd6..16b4df9a994679066899b9690004a01a0c7fed19 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage.html |
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage.html |
@@ -4,57 +4,52 @@ |
<script src="../resources/testharnessreport.js"></script> |
<script src="resources/test-helpers.js"></script> |
<script> |
-async_test(function(t) { |
+ |
+promise_test(t => { |
+ var script = 'resources/postmessage-worker.js'; |
var scope = 'resources/blank.html'; |
var registration; |
var worker; |
- service_worker_unregister_and_register( |
- t, 'resources/postmessage-worker.js', scope) |
- .then(function(r) { |
+ var port; |
+ |
+ return service_worker_unregister_and_register(t, script, scope) |
+ .then(r => { |
+ add_completion_callback(() => r.unregister()); |
registration = r; |
worker = registration.installing; |
+ |
var messageChannel = new MessageChannel(); |
- messageChannel.port1.onmessage = t.step_func(onMessage); |
- worker.postMessage({port: messageChannel.port2}, |
- [messageChannel.port2]); |
- worker.postMessage({value: 1}); |
- worker.postMessage({value: 2}); |
- worker.postMessage({done: true}); |
+ port = messageChannel.port1; |
+ return new Promise(resolve => { |
+ port.onmessage = resolve; |
+ worker.postMessage({port: messageChannel.port2}, |
+ [messageChannel.port2]); |
+ worker.postMessage({value: 1}); |
+ worker.postMessage({value: 2}); |
+ worker.postMessage({done: true}); |
+ }); |
}) |
- .catch(unreached_rejection(t)); |
- |
- var result = []; |
- var expected = [ |
- 'Acking value: 1', |
- 'Acking value: 2', |
- ]; |
- |
- function onMessage(e) { |
- var message = e.data; |
- if (message === 'quit') { |
- assert_array_equals(result, expected, |
- 'Worker should post back expected values.'); |
- postMessageToRedundantWorker(); |
- } else { |
- result.push(message); |
- } |
- }; |
- |
- function postMessageToRedundantWorker() { |
- registration.unregister(scope) |
- .then(function() { |
- return wait_for_state(t, worker, 'redundant'); |
- }) |
- .then(function() { |
- assert_equals(worker.state, 'redundant'); |
- assert_throws( |
- {name:'InvalidStateError'}, |
- function() { worker.postMessage(''); }, |
- 'Calling postMessage on a redundant ServiceWorker should ' + |
- 'throw InvalidStateError.'); |
- t.done(); |
- }) |
- .catch(unreached_rejection(t)); |
- } |
+ .then(e => { |
+ assert_equals(e.data, 'Acking value: 1'); |
+ return new Promise(resolve => { port.onmessage = resolve; }); |
+ }) |
+ .then(e => { |
+ assert_equals(e.data, 'Acking value: 2'); |
+ return new Promise(resolve => { port.onmessage = resolve; }); |
+ }) |
+ .then(e => { |
+ assert_equals(e.data, 'quit'); |
+ return registration.unregister(scope); |
+ }) |
+ .then(() => { return wait_for_state(t, worker, 'redundant'); }) |
+ .then(() => { |
+ assert_equals(worker.state, 'redundant'); |
+ assert_throws( |
+ {name:'InvalidStateError'}, |
+ function() { worker.postMessage(''); }, |
+ 'Calling postMessage on a redundant ServiceWorker should ' + |
+ 'throw InvalidStateError.'); |
+ }); |
}, 'postMessage to a ServiceWorker (and back via MessagePort)'); |
+ |
</script> |