Bug 1550346 [wpt PR 16644] - Portals: Simplify tests (1/5), a=testonly
authorAdithya Srinivasan <adithyas@chromium.org>
Mon, 20 May 2019 14:55:37 +0000
changeset 477396 9f3c2bb59bf3114ee4fccc1e4244ce6096a53454
parent 477395 f0dab2ad6ae719d1410ddd07396631eab5172b74
child 477397 7278db0c6145aa85550883cf8d0835182659ba31
push id36116
push usershindli@mozilla.com
push dateThu, 06 Jun 2019 10:00:05 +0000
treeherdermozilla-central@fee989d27558 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1550346, 16644, 1591876, 656389
milestone69.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 1550346 [wpt PR 16644] - Portals: Simplify tests (1/5), a=testonly Automatic update from web-platform-tests Portals: Simplify tests (1/5) Uses portal/portalHost.postMessage instead of broadcast channels in the following tests: - portals-cross-origin-load.html - portals-host-exposure.html - portals-rendering.html Change-Id: I1c2a74f07d3566d7046e48d2355508c5f0e6149e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1591876 Reviewed-by: Lucas Gadani <lfg@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Commit-Queue: Adithya Srinivasan <adithyas@chromium.org> Cr-Commit-Position: refs/heads/master@{#656389} -- wpt-commits: d43024d3b540e0afb53210650802b0f8c012fb33 wpt-pr: 16644
testing/web-platform/tests/portals/portals-cross-origin-load.sub.html
testing/web-platform/tests/portals/portals-host-exposure.sub.html
testing/web-platform/tests/portals/portals-rendering.html
testing/web-platform/tests/portals/resources/portal-cross-origin.sub.html
testing/web-platform/tests/portals/resources/portal-host-cross-origin-navigate.sub.html
testing/web-platform/tests/portals/resources/portal-host-cross-origin.sub.html
testing/web-platform/tests/portals/resources/portal-host.html
testing/web-platform/tests/portals/resources/portals-rendering-portal.html
--- a/testing/web-platform/tests/portals/portals-cross-origin-load.sub.html
+++ b/testing/web-platform/tests/portals/portals-cross-origin-load.sub.html
@@ -1,20 +1,17 @@
 <!DOCTYPE html>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <body>
 <script>
   promise_test(async () => {
-    var bc = new BroadcastChannel("portals-cross-origin-load");
-    var receiveMessage = new Promise((resolve, reject) => {
-      bc.onmessage = e => {
-        bc.close();
-        resolve();
-      }
-    });
     var portal = document.createElement("portal");
     portal.src = "http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-cross-origin.sub.html";
+    var receiveMessage = new Promise((resolve, reject) => {
+      portal.onmessage = e => { resolve(e.data) };
+    });
     document.body.appendChild(portal);
-    return receiveMessage;
+    var message = await receiveMessage;
+    assert_equals(message, "loaded");
   });
 </script>
 </body>
--- a/testing/web-platform/tests/portals/portals-host-exposure.sub.html
+++ b/testing/web-platform/tests/portals/portals-host-exposure.sub.html
@@ -1,44 +1,31 @@
 <!DOCTYPE html>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <body>
 <script>
-  let channelIndex = 0;
-  async function openPortalAndReceiveMessage(portalSrc) {
-    let channelName = `portals-host-exposure-${channelIndex++}`
-    let broadcastChannel = new BroadcastChannel(channelName);
-    try {
-      let received = new Promise((resolve, reject) => {
-        broadcastChannel.addEventListener('message', e => {
-          resolve(e.data);
-        }, {once: true})
-      });
-      let portal = document.createElement('portal');
-      portal.src = `${portalSrc}?broadcastchannel=${channelName}`;
+  function openPortalAndReceiveMessage(portalSrc) {
+    let portal = document.createElement('portal');
+    portal.src = portalSrc;
+    let received = new Promise((resolve, reject) => {
+      portal.onmessage = resolve;
       document.body.appendChild(portal);
-      return await received;
-    } finally {
-      broadcastChannel.close();
-    }
+    });
+    return received;
   }
 
-  promise_test(async t => {
-    let {hasHost} = await openPortalAndReceiveMessage(
-        'resources/portal-host.html');
-    assert_true(hasHost, "window.portalHost should be defined");
+  promise_test(() => {
+    return openPortalAndReceiveMessage("resources/portal-host.html");
   }, "window.portalHost should be exposed in same-origin portal");
 
-  promise_test(async t => {
-    let {hasHost} = await openPortalAndReceiveMessage(
-        'http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host-cross-origin.sub.html');
-    assert_true(hasHost, "window.portalHost should be defined");
+  promise_test(() => {
+    return openPortalAndReceiveMessage(
+        "http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host.html");
   }, "window.portalHost should be exposed in cross-origin portal");
 
-  promise_test(async t => {
-    let {hasHost} = await openPortalAndReceiveMessage(
+  promise_test(() => {
+    return openPortalAndReceiveMessage(
         'resources/portal-host-cross-origin-navigate.sub.html');
-    assert_true(hasHost, "window.portalHost should be defined");
   }, "window.portalHost should be exposed in portal after cross-origin navigation");
 
 </script>
 </body>
--- a/testing/web-platform/tests/portals/portals-rendering.html
+++ b/testing/web-platform/tests/portals/portals-rendering.html
@@ -1,16 +1,17 @@
 <!DOCTYPE html>
 <html class="reftest-wait">
 <title>Portals rendering test</title>
 <link rel="match" href="references/portals-rendering.html">
 <body>
-  <portal src="resources/portals-rendering-portal.html" style="background-color: red; width: 100px; height: 100px"></portal>
   <script>
-    var bc = new BroadcastChannel('portal');
-    bc.onmessage = function(e) {
+    var portal = document.createElement('portal');
+    portal.src = 'resources/portals-rendering-portal.html';
+    portal.style = 'background-color: red; width: 100px; height: 100px';
+    portal.onmessage = e => {
       window.requestAnimationFrame(function(ts) {
         document.documentElement.classList.remove('reftest-wait');
       });
-      bc.close();
     }
+    document.body.appendChild(portal);
   </script>
 </body>
--- a/testing/web-platform/tests/portals/resources/portal-cross-origin.sub.html
+++ b/testing/web-platform/tests/portals/resources/portal-cross-origin.sub.html
@@ -1,11 +1,6 @@
 <!DOCTYPE html>
 <body>
   <script>
-    var iframe = document.createElement("iframe");
-    iframe.src = "http://{{host}}:{{ports[http][0]}}/portals/resources/portal-forward-with-broadcast.html?broadcastchannel=portals-cross-origin-load";
-    iframe.onload = e => {
-      iframe.contentWindow.postMessage("loaded", "*");
-    }
-    document.body.appendChild(iframe);
+    window.portalHost.postMessage("loaded", "*");
   </script>
 </body>
--- a/testing/web-platform/tests/portals/resources/portal-host-cross-origin-navigate.sub.html
+++ b/testing/web-platform/tests/portals/resources/portal-host-cross-origin-navigate.sub.html
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <body>
   <script>
     let channelName = new URL(location).searchParams.get('broadcastchannel');
-    window.location.href = `http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host-cross-origin.sub.html?broadcastchannel=${channelName}`;
+    window.location.href = `http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host.html`;
   </script>
 </body>
deleted file mode 100644
--- a/testing/web-platform/tests/portals/resources/portal-host-cross-origin.sub.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<body>
-  <script>
-    let forwardingIframe = document.createElement('iframe');
-    let channelName = new URL(location).searchParams.get('broadcastchannel');
-    forwardingIframe.src = `http://{{host}}:{{ports[http][0]}}/portals/resources/portal-forward-with-broadcast.html?broadcastchannel=${channelName}`;
-    forwardingIframe.onload = () => {
-      let message = {
-        hasHost: !!window.portalHost
-      };
-      forwardingIframe.contentWindow.postMessage(message, '*');
-    }
-    document.body.appendChild(forwardingIframe);
-  </script>
-</body>
--- a/testing/web-platform/tests/portals/resources/portal-host.html
+++ b/testing/web-platform/tests/portals/resources/portal-host.html
@@ -1,14 +1,7 @@
 <!DOCTYPE html>
 <body>
   <script>
-    let message = {
-      hasHost: !!window.portalHost
-    };
-    let broadcastChannel = new BroadcastChannel(new URL(location).searchParams.get('broadcastchannel'));
-    try {
-      broadcastChannel.postMessage(message);
-    } finally {
-      broadcastChannel.close();
-    }
+    if (window.portalHost)
+      window.portalHost.postMessage("has host", "*");
   </script>
 </body>
--- a/testing/web-platform/tests/portals/resources/portals-rendering-portal.html
+++ b/testing/web-platform/tests/portals/resources/portals-rendering-portal.html
@@ -1,10 +1,8 @@
 <!DOCTYPE html>
 <body style="background-color: green">
   <script>
     window.requestAnimationFrame(function(ts) {
-      var bc = new BroadcastChannel('portal');
-      bc.postMessage('loaded');
-      bc.close();
+      window.portalHost.postMessage("loaded", "*");
     });
   </script>
 </body>