Bug 1532558 [wpt PR 15626] - Portals: Add checks for failure scenarios for activate(), a=testonly
authorAdithya Srinivasan <adithyas@chromium.org>
Thu, 18 Apr 2019 10:14:48 +0000
changeset 471071 b2f45b1b95378953c5ef65f4f6b455df6fc4e5ef
parent 471070 c369493f36a6c40aa3875f7c1a89544d5068c054
child 471072 991aa847f160d252898c6d0a6064e2674490fb3c
push id35911
push usercbrindusan@mozilla.com
push dateWed, 24 Apr 2019 21:55:25 +0000
treeherdermozilla-central@c7a9affeb604 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1532558, 15626, 914122, 1496482, 643545
milestone68.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 1532558 [wpt PR 15626] - Portals: Add checks for failure scenarios for activate(), a=testonly Automatic update from web-platform-tests Portals: Add checks for failure scenarios for activate() The promise returned by activate() rejects with an error if: - activate() is called on a portal that is already activating - activate() is called on a portal when another portal in the document is already activating - activate() is called on a nested portal Bug: 914122 Change-Id: I43136bc363be9f710dae6c107058b7b1a6674263 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1496482 Commit-Queue: Adithya Srinivasan <adithyas@chromium.org> Reviewed-by: Nasko Oskov <nasko@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Reviewed-by: Lucas Gadani <lfg@chromium.org> Cr-Commit-Position: refs/heads/master@{#643545} -- wpt-commits: f0aa35ac335f10c527e1fc1b30d29d5d2678f58d wpt-pr: 15626
testing/web-platform/tests/portals/portals-activate-inside-portal.html
testing/web-platform/tests/portals/portals-activate-twice.html
testing/web-platform/tests/portals/resources/portal-activate-inside-portal.html
testing/web-platform/tests/portals/resources/portal-activate-twice-window-1.html
testing/web-platform/tests/portals/resources/portal-activate-twice-window-2.html
testing/web-platform/tests/portals/resources/simple-portal.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/portals-activate-inside-portal.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+  <script>
+    promise_test(async () => {
+      var portal = document.createElement("portal");
+      portal.src = "resources/portal-activate-inside-portal.html";
+      let waitForMessage = new Promise((resolve, reject) => {
+        var bc = new BroadcastChannel("portals-activate-inside-portal");
+        bc.onmessage = e => {
+          bc.close();
+          resolve(e.data);
+        }
+        document.body.appendChild(portal);
+      });
+      var error = await waitForMessage;
+      assert_equals(error, "InvalidStateError");
+    }, "activating a nested portal should throw an error");
+  </script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/portals-activate-twice.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+promise_test(async t => {
+  let waitForMessage = new Promise((resolve, reject) => {
+    var bc = new BroadcastChannel("portals-activate-twice");
+    bc.onmessage = e => {
+      resolve(e.data);
+    }
+  });
+  window.open("resources/portal-activate-twice-window-1.html");
+  let error = await waitForMessage;
+  assert_equals(error, "InvalidStateError");
+}, "Calling activate when a portal is already activating should fail");
+
+promise_test(async t => {
+  let waitForMessage = new Promise((resolve, reject) => {
+    var bc = new BroadcastChannel("portals-activate-twice");
+    bc.onmessage = e => {
+      resolve(e.data);
+    }
+  });
+  window.open("resources/portal-activate-twice-window-2.html");
+  let error = await waitForMessage;
+  assert_equals(error, "InvalidStateError");
+});
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/resources/portal-activate-inside-portal.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<body>
+  <script>
+    var portal = document.createElement("portal");
+    portal.src = "simple-portal.html";
+    var bc = new BroadcastChannel("simple-portal");
+    bc.onmessage = () => {
+      bc.close();
+      portal.activate().catch(e => {
+        var bc2 = new BroadcastChannel("portals-activate-inside-portal");
+        bc2.postMessage(e.name);
+        bc2.close();
+      });
+    }
+    document.body.appendChild(portal);
+  </script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/resources/portal-activate-twice-window-1.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<body>
+  <script>
+    var portal = document.createElement("portal");
+    portal.src = "simple-portal.html"
+
+    var bc = new BroadcastChannel("simple-portal");
+    bc.onmessage = () => {
+      bc.close();
+      portal.activate();
+      portal.activate().catch(e => {
+        var bc2 = new BroadcastChannel("portals-activate-twice");
+        bc2.postMessage(e.name, "*");
+        bc2.close();
+      });
+    }
+
+    document.body.append(portal);
+  </script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/resources/portal-activate-twice-window-2.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<body>
+  <script>
+    var portal1 = document.createElement("portal");
+    portal1.src = "simple-portal.html"
+    var portal2 = document.createElement("portal");
+    portal2.src = "simple-portal.html"
+
+    var bc = new BroadcastChannel("simple-portal");
+    var waitForPortalsToLoad = new Promise((resolve, reject) => {
+      var count = 0;
+      bc.onmessage = () => {
+        count++;
+        if (count == 2) {
+          bc.close();
+          resolve();
+        }
+      }
+    });
+
+    waitForPortalsToLoad.then(() => {
+      portal1.activate();
+      portal2.activate().catch(e => {
+        var bc2 = new BroadcastChannel("portals-activate-twice");
+        bc2.postMessage(e.name, "*");
+        bc2.close();
+      });
+    });
+
+    document.body.append(portal1);
+    document.body.append(portal2);
+  </script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/portals/resources/simple-portal.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<body>
+  <script>
+    var bc = new BroadcastChannel("simple-portal");
+    bc.postMessage("loaded");
+    bc.close();
+  </script>
+</body>