Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-to-client.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
index 397b41970dfb2e9d60d2c7345c3cefd46a769bc4..fadc7d2a51cdea387b23bb4bfcd14449598a26e4 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/postmessage-to-client.html |
@@ -4,38 +4,37 @@ |
<script src="../resources/testharnessreport.js"></script> |
<script src="resources/test-helpers.js"></script> |
<script> |
-var t = async_test('postMessage from ServiceWorker to Client'); |
-t.step(function() { |
- var scope = 'resources/blank.html' |
- service_worker_unregister_and_register( |
- t, 'resources/postmessage-to-client-worker.js', scope) |
- .then(function(registration) { |
+ |
+promise_test(t => { |
+ var script = 'resources/postmessage-to-client-worker.js'; |
+ var scope = 'resources/blank.html'; |
+ var w; |
+ |
+ 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 => { |
+ w = frame.contentWindow; |
+ w.navigator.serviceWorker.onmessage = resolve; |
+ w.navigator.serviceWorker.controller.postMessage('ping'); |
+ }); |
}) |
- .catch(unreached_rejection(t)); |
- |
- var result = []; |
- var expected = ['Sending message via clients']; |
+ .then(e => { |
+ var message = e.data; |
+ assert_equals(e.origin, location.origin, |
+ 'origin of message should be origin of Service Worker'); |
+ assert_equals(e.lastEventId, '', |
+ 'lastEventId should be an empty string'); |
+ assert_equals(message, 'Sending message via clients'); |
+ return new Promise(resolve => { |
+ w.navigator.serviceWorker.onmessage = resolve; |
+ }); |
+ }) |
+ .then(e => { assert_equals(e.data, 'quit'); }); |
+ }, 'postMessage from ServiceWorker to Client'); |
- function onMessage(e) { |
- var message = e.data; |
- assert_equals(e.origin, location.origin, |
- 'origin of message should be origin of Service Worker'); |
- assert_equals(e.lastEventId, '', |
- 'lastEventId should be an empty string'); |
- if (message === 'quit') { |
- assert_array_equals(result, expected, |
- 'Worker should post back expected messages.'); |
- service_worker_unregister_and_done(t, scope); |
- } else { |
- result.push(message); |
- } |
- } |
- }); |
</script> |