summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/notify-event-iframe.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /testing/web-platform/tests/fenced-frame/notify-event-iframe.https.html
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-upstream/125.0.1.tar.xz
firefox-upstream/125.0.1.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/fenced-frame/notify-event-iframe.https.html')
-rw-r--r--testing/web-platform/tests/fenced-frame/notify-event-iframe.https.html102
1 files changed, 102 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fenced-frame/notify-event-iframe.https.html b/testing/web-platform/tests/fenced-frame/notify-event-iframe.https.html
new file mode 100644
index 0000000000..854db2f303
--- /dev/null
+++ b/testing/web-platform/tests/fenced-frame/notify-event-iframe.https.html
@@ -0,0 +1,102 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-actions.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="/common/utils.js"></script>
+<script src="/common/dispatcher/dispatcher.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="resources/utils.js"></script>
+<title>Test fenced frame notifyEvent() functionality with iframes</title>
+
+<body>
+ <script>
+ async function runNestedIFrameTest(frame_type) {
+ // Create a fenced frame that will respond to window.fence.notifyEvent().
+ const fencedframe = await attachFencedFrameContext(
+ {generator_api: 'fledge'});
+ let notified = false;
+ fencedframe.element.addEventListener('fencedtreeclick', () => notified = true);
+
+ await fencedframe.execute(async (frame_type) => {
+ window.addEventListener('message', (event) => {
+ window.click_error = event.data;
+ });
+
+ let iframe = null;
+ if (frame_type === 'same-origin') {
+ iframe = await attachIFrameContext({
+ origin: get_host_info().HTTPS_ORIGIN
+ });
+ } else if (frame_type === 'cross-origin') {
+ iframe = await attachIFrameContext({
+ origin: get_host_info().HTTPS_REMOTE_ORIGIN
+ });
+ }
+
+ // Calling notifyEvent() on click in the iframe should fail, but we need
+ // to move the exception out of the click handler to assert on it.
+ await iframe.execute(() => {
+ document.addEventListener('click', (e) => {
+ try {
+ window.fence.notifyEvent(e);
+ } catch (err) {
+ window.parent.postMessage(err, '*');
+ return;
+ }
+ window.parent.postMessage(new TypeError('No exception'), '*');
+ });
+ });
+ }, [frame_type]);
+
+ await multiClick(10, 10, fencedframe.element);
+
+ // Ensure the correct exception was thrown.
+ await fencedframe.execute(() => {
+ assert_equals(window.click_error.name, 'SecurityError');
+ assert_equals(window.click_error.message,
+ "Failed to execute 'notifyEvent' on 'Fence': notifyEvent is only available in fenced frame roots.");
+ });
+
+ // Because the notifyEvent() call failed, no event was sent to the
+ // top-level fenced frame.
+ assert_false(notified);
+ }
+
+ promise_test(async (t) => {
+ return runNestedIFrameTest('same-origin');
+ }, "Test that fenced frame notifyEvent() fails in a nested same-origin iframe.");
+
+ promise_test(async (t) => {
+ return runNestedIFrameTest('cross-origin');
+ }, "Test that fenced frame notifyEvent() fails in a nested cross-origin iframe.");
+
+ promise_test(async (t) => {
+ window.addEventListener('message', (event) => {
+ window.click_error = event.data;
+ });
+
+ const urn_iframe = await attachIFrameContext(
+ {generator_api: 'fledge'});
+
+ await urn_iframe.execute(() => {
+ document.addEventListener('click', (e) => {
+ try {
+ window.fence.notifyEvent(e);
+ } catch (err) {
+ window.parent.postMessage(err, '*');
+ return;
+ }
+ window.parent.postMessage(new TypeError('No exception'), '*');
+ });
+ });
+
+ await multiClick(10, 10, urn_iframe.element);
+
+ assert_equals(window.click_error.name, 'SecurityError');
+ assert_equals(window.click_error.message,
+ "Failed to execute 'notifyEvent' on 'Fence': notifyEvent is only available in fenced frame roots.");
+ }, "Test that notifyEvent() fails in a URN iframe.");
+ </script>
+</body>