Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/postmessage-to-client.https.html |
| diff --git a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/postmessage-to-client.https.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/postmessage-to-client.https.html |
| index 8eac04a63d912026cb6e5f0a1ceeb2d2eb6e90b1..a935891dfed37474af9f44f411ee7f8db2ea74a0 100644 |
| --- a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/postmessage-to-client.https.html |
| +++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/postmessage-to-client.https.html |
| @@ -5,48 +5,50 @@ |
| <script src="/common/get-host-info.sub.js"></script> |
| <script src="resources/test-helpers.sub.js"></script> |
| <script> |
| -var frame; |
| -var t = async_test('postMessage from ServiceWorker to Client'); |
| -t.step(function() { |
| +promise_test(t => { |
| + var script = 'resources/postmessage-to-client-worker.js'; |
| var scope = 'resources/blank.html'; |
| - var host_info = get_host_info(); |
| - var sw; |
| - service_worker_unregister_and_register( |
| - t, 'resources/postmessage-to-client-worker.js', scope) |
| - .then(function(registration) { |
| + var w; |
| + |
| + return service_worker_unregister_and_register(t, script, scope) |
| + .then(registration => { |
| + add_completion_callback(() => registration.unregister()); |
|
falken
2017/05/15 05:10:33
t.add_cleanup() ?
mike3
2017/05/15 20:07:45
They are functionally equivalent today, though `t.
|
| return wait_for_state(t, registration.installing, 'activated'); |
| }) |
| - .then(function() { return with_iframe(scope); }) |
| - .then(function(f) { |
| - frame = f; |
| - sw = frame.contentWindow.navigator.serviceWorker; |
| - sw.onmessage = t.step_func(onMessage); |
| - sw.controller.postMessage('ping'); |
| - }) |
| - .catch(unreached_rejection(t)); |
| - |
| - var result = []; |
| - var expected = ['Sending message via clients']; |
| + .then(() => with_iframe(scope)) |
| + .then(frame => { |
| + t.add_cleanup(() => frame.remove()); |
| - function onMessage(e) { |
| - assert_equals(e.constructor, frame.contentWindow.MessageEvent, |
| - 'message events should use MessageEvent interface.'); |
| - assert_equals(e.bubbles, false, 'message events should not bubble.'); |
| - assert_equals(e.cancelable, false, |
| - 'message events should not be cancelable.'); |
| - assert_equals(e.origin, host_info['HTTPS_ORIGIN'], |
| - 'message event\'s origin should be set correctly.'); |
| - assert_equals(e.source, sw.controller, 'source should be ServiceWorker.'); |
| - |
| - var message = e.data; |
| - if (message === 'quit') { |
| - assert_array_equals(result, expected, |
| - 'Worker should post back expected messages.'); |
| - frame.remove(); |
| - service_worker_unregister_and_done(t, scope); |
| - } else { |
| - result.push(message); |
| - } |
| - } |
| - }); |
| + return new Promise(resolve => { |
| + w = frame.contentWindow; |
| + w.navigator.serviceWorker.onmessage = resolve; |
| + w.navigator.serviceWorker.controller.postMessage('ping'); |
| + }); |
| + }) |
| + .then(e => { |
| + var message = e.data; |
| + assert_equals(e.constructor, w.MessageEvent, |
| + 'message events should use MessageEvent interface.'); |
| + assert_equals(e.type, 'message', 'type should be "message".'); |
| + assert_equals(e.bubbles, false, 'message events should not bubble.'); |
| + assert_equals(e.cancelable, false, |
| + 'message events should not be cancelable.'); |
| + 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(e.source.constructor, w.ServiceWorker, |
| + 'source should use ServiceWorker interface.'); |
| + assert_equals( |
| + e.source, w.navigator.serviceWorker.controller, |
| + 'source should be the service worker that sent the message.'); |
| + assert_equals(e.ports.length, 0, 'ports should be an empty array.'); |
| + 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.'); |
| </script> |