summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/portals/portal-activate-default.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/portals/portal-activate-default.html
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/portals/portal-activate-default.html')
-rw-r--r--testing/web-platform/tests/portals/portal-activate-default.html58
1 files changed, 58 insertions, 0 deletions
diff --git a/testing/web-platform/tests/portals/portal-activate-default.html b/testing/web-platform/tests/portals/portal-activate-default.html
new file mode 100644
index 0000000000..b1a8feb1f4
--- /dev/null
+++ b/testing/web-platform/tests/portals/portal-activate-default.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/open-blank-host.js"></script>
+<script>
+promise_test(async t => {
+ assert_implements("HTMLPortalElement" in self);
+ const w = await openBlankPortalHost();
+ try {
+ const bc = new BroadcastChannel('click-activate');
+ const portal = w.document.createElement('portal');
+ portal.src = new URL(`resources/portal-activate-broadcastchannel.html?bc=${bc.name}`, location.href);
+ w.document.body.appendChild(portal);
+ await new Promise(resolve => portal.onload = resolve);
+ let activated = new Promise(resolve => bc.onmessage = e => resolve(e.data));
+ portal.click();
+ let {event, data} = await activated;
+ assert_equals(event, 'portalactivate');
+ assert_equals(data, undefined);
+ } finally {
+ w.close();
+ }
+}, "Clicking should activate with undefined data.");
+
+promise_test(async t => {
+ assert_implements("HTMLPortalElement" in self);
+ const w = await openBlankPortalHost();
+ try {
+ const bc = new BroadcastChannel('prevent-no-activate');
+ const portal = w.document.createElement('portal');
+ portal.src = new URL(`resources/portal-activate-broadcastchannel.html?bc=${bc.name}`, location.href);
+ portal.onclick = e => e.preventDefault();
+ w.document.body.appendChild(portal);
+ await new Promise(resolve => portal.onload = resolve);
+ bc.onmessage = t.unreached_func('activation should not occur');
+ portal.click();
+ await new Promise(resolve => t.step_timeout(resolve, 3000));
+ } finally {
+ w.close();
+ }
+}, "Clicking shouldn't activate if prevented.");
+
+// Script didn't create the promise so it shouldn't observe one.
+// This forecloses a naive implementation of this behavior that simply calls the WebIDL operation.
+promise_test(async t => {
+ assert_implements("HTMLPortalElement" in self);
+ const w = await openBlankPortalHost();
+ try {
+ const portal = w.document.createElement('portal');
+ w.onunhandledrejection = t.unreached_func('unhandledrejection event should not fire');
+ portal.click();
+ await new Promise(resolve => t.step_timeout(resolve, 3000));
+ } finally {
+ w.close();
+ }
+}, "Failed activation should not surface as an unhandled promise rejection.");
+</script>