diff options
Diffstat (limited to 'testing/web-platform/tests/service-workers/service-worker/postmessage-msgport-to-client.https.html')
-rw-r--r-- | testing/web-platform/tests/service-workers/service-worker/postmessage-msgport-to-client.https.html | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/testing/web-platform/tests/service-workers/service-worker/postmessage-msgport-to-client.https.html b/testing/web-platform/tests/service-workers/service-worker/postmessage-msgport-to-client.https.html new file mode 100644 index 0000000000..29c056080c --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/postmessage-msgport-to-client.https.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<title>Service Worker: postMessage via MessagePort to Client</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/test-helpers.sub.js"></script> +<script> +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(() => with_iframe(scope)) + .then(frame => { + t.add_cleanup(() => frame.remove()); + return new Promise(resolve => { + var w = frame.contentWindow; + w.navigator.serviceWorker.onmessage = resolve; + w.navigator.serviceWorker.controller.postMessage('ping'); + }); + }) + .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, 'done'); }); + }, 'postMessage MessagePorts from ServiceWorker to Client'); +</script> |