Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/postmessage-to-client.https.html

Issue 2875383002: Upstream service worker `postMessage` tests to WPT (Closed)
Patch Set: Incorporate review feedback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..15d2e889337078869e3c3e97d312649e6a8bd8b2 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 => {
+ t.add_cleanup(() => registration.unregister());
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>

Powered by Google App Engine
This is Rietveld 408576698