Bug 1482237 [wpt PR 12385] - Add a PostMessageOptions API to workers and message_port, a=testonly
authorDave Tapuska <dtapuska@chromium.org>
Wed, 15 Aug 2018 10:01:47 +0000
changeset 431762 8a49d6c83ccbfad19178a65c50d5feccfaa578d3
parent 431761 aca35b57deb2f37ba7541a7ca622aa32de4e4cfb
child 431763 e33f08d4713b525760077ca8e4f68d5f0ba7d7c0
push id34451
push userebalazs@mozilla.com
push dateThu, 16 Aug 2018 09:25:15 +0000
treeherdermozilla-central@161817e6d127 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1482237, 12385, 861735, 1169304, 582619
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1482237 [wpt PR 12385] - Add a PostMessageOptions API to workers and message_port, a=testonly Automatic update from web-platform-testsAdd a PostMessageOptions API to workers and message_port The current pull request against the HTML spec is here: https://github.com/whatwg/html/issues/3799 Rename the RuntimeEnabledFeature from WindowPostMessageOptions to PostMessageOptions BUG=861735 Change-Id: Ia7980a85c10535f6d531c87f3790efcf6ed2d54d Reviewed-on: https://chromium-review.googlesource.com/1169304 Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Cr-Commit-Position: refs/heads/master@{#582619} -- wpt-commits: aaac36358ac55215fbb28d62d235470859001e91 wpt-pr: 12385
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/service-workers/service-worker/postmessage.https.html
testing/web-platform/tests/service-workers/service-worker/resources/postmessage-dictionary-transferables-worker.js
testing/web-platform/tests/webmessaging/message-channels/dictionary-transferrable.html
testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html
testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -299606,16 +299606,21 @@
      {}
     ]
    ],
    "service-workers/service-worker/resources/postmessage-blob-url.js": [
     [
      {}
     ]
    ],
+   "service-workers/service-worker/resources/postmessage-dictionary-transferables-worker.js": [
+    [
+     {}
+    ]
+   ],
    "service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js": [
     [
      {}
     ]
    ],
    "service-workers/service-worker/resources/postmessage-to-client-worker.js": [
     [
      {}
@@ -395141,16 +395146,22 @@
     ]
    ],
    "webmessaging/message-channels/close.html": [
     [
      "/webmessaging/message-channels/close.html",
      {}
     ]
    ],
+   "webmessaging/message-channels/dictionary-transferrable.html": [
+    [
+     "/webmessaging/message-channels/dictionary-transferrable.html",
+     {}
+    ]
+   ],
    "webmessaging/message-channels/worker.html": [
     [
      "/webmessaging/message-channels/worker.html",
      {}
     ]
    ],
    "webmessaging/messageerror.html": [
     [
@@ -399687,16 +399698,22 @@
     ]
    ],
    "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/return-value.worker.js": [
     [
      "/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/return-value.worker.html",
      {}
     ]
    ],
+   "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html": [
+    [
+     "/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html",
+     {}
+    ]
+   ],
    "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.html": [
     [
      "/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.html",
      {}
     ]
    ],
    "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html": [
     [
@@ -629693,17 +629710,17 @@
    "29c056080c79d581975e0929dcebd84d63b86a20",
    "testharness"
   ],
   "service-workers/service-worker/postmessage-to-client.https.html": [
    "15d2e889337078869e3c3e97d312649e6a8bd8b2",
    "testharness"
   ],
   "service-workers/service-worker/postmessage.https.html": [
-   "6b2f6d78e12210647a47e2eb317c6387e8487ca2",
+   "3d73afe9796114f42e614292ef4b180dd78cdee5",
    "testharness"
   ],
   "service-workers/service-worker/ready.https.html": [
    "ff5c793f2c2208e9ac298e6b82adf745ae4c65e9",
    "testharness"
   ],
   "service-workers/service-worker/redirected-response.https.html": [
    "f7370e023b1ab4454b839bc6daa432cf539e1d7f",
@@ -630572,16 +630589,20 @@
   "service-workers/service-worker/resources/performance-timeline-worker.js": [
    "a752b436524e628959e35c9de73e15ccc7dd783f",
    "support"
   ],
   "service-workers/service-worker/resources/postmessage-blob-url.js": [
    "9095194a4c03f3375fa76b37978642ce5f989b98",
    "support"
   ],
+  "service-workers/service-worker/resources/postmessage-dictionary-transferables-worker.js": [
+   "87a4500d754ab02465e109899e7f1ffdc0bdca53",
+   "support"
+  ],
   "service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js": [
    "7af935f4f8fc01756980e46dcce5018ddc620e67",
    "support"
   ],
   "service-workers/service-worker/resources/postmessage-to-client-worker.js": [
    "17913063583a8276675adcc65a66e843d83a303f",
    "support"
   ],
@@ -646996,16 +647017,20 @@
   "webmessaging/message-channels/004.html": [
    "19921fef85baf316121d36a00c2f2abc5c5ffb5f",
    "testharness"
   ],
   "webmessaging/message-channels/close.html": [
    "d975ea728327d95def65af0e5875a16dfdfa0289",
    "testharness"
   ],
+  "webmessaging/message-channels/dictionary-transferrable.html": [
+   "f7ab1086f7e7978f00a4901d7aa47d8675ee1373",
+   "testharness"
+  ],
   "webmessaging/message-channels/worker.html": [
    "0502021fff138a29b5bd815c589d0f556922db9b",
    "testharness"
   ],
   "webmessaging/messageerror.html": [
    "2cb51ee3c06c366529f66815587cef455e267666",
    "testharness"
   ],
@@ -652508,22 +652533,26 @@
   "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/message-event.js": [
    "54a250005e8de85931f4f051b9d424d1e1dd3cd6",
    "support"
   ],
   "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/return-value.worker.js": [
    "521251699a083de973151c5a052e2012e1d1722a",
    "testharness"
   ],
+  "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html": [
+   "e086dc13db658ef7e87a3046a89c5d85bd25cca7",
+   "testharness"
+  ],
   "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null-in-array.html": [
    "df4c9f83e6f4b633e32c9d01c2f02d0de8da8f62",
    "testharness"
   ],
   "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html": [
-   "e81a56bad3d3d11193194777f7342c8fc190e512",
+   "4a03c830a29fb2937bc07cc50ed167201bd8486f",
    "testharness"
   ],
   "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-undefined.html": [
    "7d01eba7aff85216cb5e36cdb87e230ec84714d0",
    "testharness"
   ],
   "workers/interfaces/DedicatedWorkerGlobalScope/postMessage/setting-postMessage.html": [
    "d1a3f0f5c70a6f85a3a016f88b551fbc4d5f64bd",
--- a/testing/web-platform/tests/service-workers/service-worker/postmessage.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/postmessage.https.html
@@ -143,9 +143,51 @@ promise_test(t => {
         })
       .then(e => {
           // Verify that the array buffer on ServiceWorker is neutered.
           assert_equals(e.data.content, '');
           assert_equals(e.data.byteLength, 0);
         });
   }, 'postMessage a transferable ArrayBuffer between ServiceWorker and Client' +
      ' over MessagePort');
+
+  promise_test(t => {
+    var script = 'resources/postmessage-dictionary-transferables-worker.js';
+    var scope = 'resources/blank.html';
+    var sw = navigator.serviceWorker;
+
+    var message = 'Hello, world!';
+    var text_encoder = new TextEncoder;
+    var text_decoder = new TextDecoder;
+
+    return service_worker_unregister_and_register(t, script, scope)
+      .then(r => {
+          t.add_cleanup(() => r.unregister());
+
+          var ab = text_encoder.encode(message);
+          assert_equals(ab.byteLength, message.length);
+          r.installing.postMessage(ab, {transfer: [ab.buffer]});
+          assert_equals(text_decoder.decode(ab), '');
+          assert_equals(ab.byteLength, 0);
+
+          return new Promise(resolve => { sw.onmessage = resolve; });
+        })
+      .then(e => {
+          // Verify the integrity of the transferred array buffer.
+          assert_equals(e.data.content, message);
+          assert_equals(e.data.byteLength, message.length);
+          return new Promise(resolve => { sw.onmessage = resolve; });
+        })
+      .then(e => {
+          // Verify the integrity of the array buffer sent back from
+          // ServiceWorker via Client.postMessage.
+          assert_equals(text_decoder.decode(e.data), message);
+          assert_equals(e.data.byteLength, message.length);
+          return new Promise(resolve => { sw.onmessage = resolve; });
+        })
+      .then(e => {
+          // Verify that the array buffer on ServiceWorker is neutered.
+          assert_equals(e.data.content, '');
+          assert_equals(e.data.byteLength, 0);
+        });
+  }, 'postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client');
+
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/postmessage-dictionary-transferables-worker.js
@@ -0,0 +1,24 @@
+var messageHandler = function(port, e) {
+    var text_decoder = new TextDecoder;
+    port.postMessage({
+      content: text_decoder.decode(e.data),
+      byteLength: e.data.byteLength
+    });
+
+    // Send back the array buffer via Client.postMessage.
+    port.postMessage(e.data, {transfer: [e.data.buffer]});
+
+    port.postMessage({
+      content: text_decoder.decode(e.data),
+      byteLength: e.data.byteLength
+    });
+};
+
+self.addEventListener('message', e => {
+    if (e.ports[0]) {
+      // Wait for messages sent via MessagePort.
+      e.ports[0].onmessage = messageHandler.bind(null, e.ports[0]);
+      return;
+    }
+    messageHandler(e.source, e);
+  });
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/message-channels/dictionary-transferrable.html
@@ -0,0 +1,18 @@
+<!doctype html>
+<title>basic messagechannel with transfer</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+async_test(function(t) {
+  var channel = new MessageChannel();
+  var ab = new ArrayBuffer(1);
+  channel.port1.postMessage(ab, {transfer: [ab]});
+  channel.port2.onmessage = t.step_func(
+    function(e) {
+      assert_equals(e.data.byteLength, 1);
+      t.done();
+    });
+  channel.port2.start();
+});
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html
@@ -0,0 +1,29 @@
+<!--
+onmessage = (event) => {
+  try {
+    postMessage(event.data, {transfer: [event.data]});
+  } catch(e) {
+    postMessage(''+e);
+  }
+}
+/*
+-->
+<!doctype html>
+<title>Using dictionary as postMessage's second argument</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+(async_test()).step(function() {
+  var worker = new Worker('#');
+  var ab = new ArrayBuffer(1);
+  worker.postMessage(ab, {transfer: [ab]});
+  worker.onmessage = this.step_func(function(e) {
+    assert_equals(e.data.byteLength, 1);
+    this.done();
+  });
+});
+</script>
+<!--
+*/
+//-->
--- a/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html
+++ b/testing/web-platform/tests/workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-null.html
@@ -10,16 +10,16 @@ try {
 <title>Using null in postMessage's second argument</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id="log"></div>
 <script>
 (async_test()).step(function() {
   var worker = new Worker('#');
   worker.onmessage = this.step_func(function(e) {
-    assert_true(e.data);
+    assert_equals(1, e.data);
     this.done();
   });
 });
 </script>
 <!--
 */
 //-->