Bug 1526514 [wpt PR 15203] - Portals: Hide portal host before dispatching activate event, a=testonly
authorAdithya Srinivasan <adithyas@chromium.org>
Tue, 12 Feb 2019 14:09:36 +0000
changeset 459276 a4d1c4e3d225dab06209dfff97d4e495559bf85c
parent 459275 4bb3a759197e46e508fe875e2ef0f36c14d951ed
child 459277 86395c2e38cd41334802b93ffacb0b4d69d2d4cb
push id35557
push userdvarga@mozilla.com
push dateFri, 15 Feb 2019 01:42:08 +0000
treeherdermozilla-central@426ca85d2303 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1526514, 15203, 914117, 1412792, 628378
milestone67.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 1526514 [wpt PR 15203] - Portals: Hide portal host before dispatching activate event, a=testonly Automatic update from web-platform-tests Portals: Hide portal host before dispatching activate event window.portalHost returns null in the portal browsing context after it has been activated. Bug: 914117 Change-Id: I2758d2bb29ad0381cff51f0c312fa88c3bacaed4 Reviewed-on: https://chromium-review.googlesource.com/c/1412792 Commit-Queue: Adithya Srinivasan <adithyas@chromium.org> Reviewed-by: Lucas Gadani <lfg@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Cr-Commit-Position: refs/heads/master@{#628378} -- wpt-commits: 4ad2eef86295a88acad1c373fb9fde9ca471a630 wpt-pr: 15203
testing/web-platform/tests/portals/portal-activate-event.html
testing/web-platform/tests/portals/portals-host-hidden-after-activation.html
testing/web-platform/tests/portals/resources/portal-activate-event-window.html
testing/web-platform/tests/portals/resources/portal-embed-and-activate.html
testing/web-platform/tests/portals/resources/portal-host-hidden-after-activation-portal.html
--- a/testing/web-platform/tests/portals/portal-activate-event.html
+++ b/testing/web-platform/tests/portals/portal-activate-event.html
@@ -1,32 +1,38 @@
 <!DOCTYPE html>
 <title>Tests that the PortalActivateEvent is dispatched when a portal is activated</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script>
   async_test(function(t) {
-    var bc = new BroadcastChannel("test-eventlistener");
+    let test = "eventlistener";
+    var bc = new BroadcastChannel(`test-${test}`);
     bc.onmessage = t.step_func_done(function(e) {
       assert_equals(e.data, "passed");
       bc.close();
     });
-    window.open("resources/portal-activate-event-window.html?test=eventlistener");
+    const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
+    window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
   }, "Tests that the PortalActivateEvent is dispatched when a portal is activated.");
 
   async_test(function(t) {
-    var bc = new BroadcastChannel("test-eventhandler");
+    let test = "eventhandler";
+    var bc = new BroadcastChannel(`test-${test}`);
     bc.onmessage = t.step_func_done(function(e) {
       assert_equals(e.data, "passed");
       bc.close();
     });
-    window.open("resources/portal-activate-event-window.html?test=eventhandler");
+    const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
+    window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
   }, "Tests that the portalactivate event handler is dispatched when a portal is activated.");
 
   async_test(function(t) {
-    var bc = new BroadcastChannel("test-bodyeventhandler");
+    let test = "bodyeventhandler";
+    var bc = new BroadcastChannel(`test-${test}`);
     bc.onmessage = t.step_func_done(function(e) {
       assert_equals(e.data, "passed");
       bc.close();
     });
-    window.open("resources/portal-activate-event-window.html?test=bodyeventhandler");
+    const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
+    window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
   }, "Tests that the HTMLBodyElement has the portalactivate event handler.");
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/portals-host-hidden-after-activation.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+  // Waits for 2 messages from portal, one before activation and one after.
+  function waitForMessages() {
+    return new Promise((resolve, reject) => {
+      var results = [];
+      var bc = new BroadcastChannel("portals-host-hidden-after-activation");
+      bc.onmessage = e => {
+        results.push(e.data.hasHost);
+        if (results.length == 2) {
+          bc.close();
+          resolve(results);
+        }
+      };
+    });
+  }
+
+  promise_test(async () => {
+    const portalUrl = encodeURIComponent("portal-host-hidden-after-activation-portal.html");
+    window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}`);
+    var results = await waitForMessages();
+    assert_true(results[0], "portalHost exposed before calling activate()");
+    assert_false(results[1], "portalHost hidden after receiving portalactivate event");
+  }, "window.portalHost should be null after portal is activated");
+</script>
+</body>
deleted file mode 100644
--- a/testing/web-platform/tests/portals/resources/portal-activate-event-window.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<script>
-  window.onload = function(e) {
-    var test = (new URL(location)).searchParams.get("test");
-    var portal = document.createElement("portal");
-    portal.src = "portal-activate-event-portal.html" + location.search;
-    document.body.appendChild(portal);
-
-    var bc = new BroadcastChannel("portal-" + test);
-    bc.onmessage = function(e) {
-      document.querySelector("portal").activate();
-      bc.close();
-    }
-  }
-</script>
-<body>
-</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/resources/portal-embed-and-activate.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<!--
+  Embeds a portal (src specified by query parameter "url") and activates it after
+  receiving a message from the portal. Use query parameter "channelName" to
+  specify the name of the channel used by the portal src send a message
+  indicating that it is ready for activation (default name used is "portal").
+-->
+</title>
+<body>
+  <script>
+    var searchParams = new URL(location).searchParams;
+
+    // TODO(adithyas): Replace this with postmessage once it's implemented for
+    // portals.
+    var channelName = searchParams.get("channelName") || "portal";
+    var bc = new BroadcastChannel(channelName);
+    bc.onmessage = function(e) {
+      document.querySelector("portal").activate();
+      bc.close();
+    }
+
+    let portal = document.createElement("portal");
+    portal.src = searchParams.get("url");
+    document.body.appendChild(portal);
+  </script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/resources/portal-host-hidden-after-activation-portal.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<script>
+  window.addEventListener("portalactivate", function(e) {
+    var bc = new BroadcastChannel("portals-host-hidden-after-activation");
+    bc.postMessage({ hasHost: !!window.portalHost });
+    bc.close();
+  });
+
+  var bc = new BroadcastChannel("portals-host-hidden-after-activation");
+  bc.postMessage({hasHost: !!window.portalHost });
+  bc.close();
+
+  bc = new BroadcastChannel("portal");
+  bc.postMessage("loaded");
+  bc.close();
+
+</script>