summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html')
-rw-r--r--testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html64
1 files changed, 64 insertions, 0 deletions
diff --git a/testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html b/testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html
new file mode 100644
index 0000000000..7e548879bc
--- /dev/null
+++ b/testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Test cross-origin and same-origin use of setAppBadge</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<iframe id="testIframe"></iframe>
+<script>
+ const iframe = document.getElementById("testIframe");
+
+ function sendMessageToIframe(message) {
+ return new Promise((resolve) => {
+ window.addEventListener("message", function listener(event) {
+ const { messageId } = event.data;
+ if (event.data.message !== message) return;
+ window.removeEventListener("message", listener);
+ resolve(event);
+ });
+ iframe.contentWindow.postMessage("callSetAppBadge", "*");
+ });
+ }
+
+ function loadIframe(src) {
+ return new Promise((resolve) => {
+ iframe.addEventListener("load", resolve);
+ iframe.src = src;
+ });
+ }
+
+ test(() => {
+ assert_true(
+ "setAppBadge" in navigator,
+ "navigator.setAppBadge should be available"
+ );
+ }, "Test that navigator.setAppBadge is available");
+
+ promise_test(async () => {
+ await loadIframe(
+ `https://{{hosts[][]}}:{{ports[https][1]}}/badging/resources/setAppBadge_iframe.html`
+ );
+ const event = await sendMessageToIframe("callSetAppBadge");
+ const { exceptionType, status } = event.data;
+ assert_equals(
+ status,
+ "error",
+ "setAppBadge should have rejected with an error"
+ );
+ assert_equals(
+ exceptionType,
+ "SecurityError",
+ "setAppBadge should throw a SecurityError when called in a cross-origin iframe"
+ );
+ }, "Test that calling setAppBadge in a cross-origin iframe throws a SecurityError");
+
+ promise_test(async () => {
+ await loadIframe("./resources/setAppBadge_iframe.html");
+ const event = await sendMessageToIframe("callSetAppBadge");
+ const { status } = event.data;
+ assert_equals(
+ status,
+ "success",
+ "setAppBadge should succeed when called in a same-origin iframe"
+ );
+ }, "Test that calling setAppBadge in a same-origin iframe succeeds");
+</script>