summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/badging
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/badging
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/badging')
-rw-r--r--testing/web-platform/tests/badging/META.yml4
-rw-r--r--testing/web-platform/tests/badging/badge-error.https.html36
-rw-r--r--testing/web-platform/tests/badging/badge-success.https.html62
-rw-r--r--testing/web-platform/tests/badging/idlharness.https.any.js17
-rw-r--r--testing/web-platform/tests/badging/non-fully-active.https.html19
-rw-r--r--testing/web-platform/tests/badging/resources/setAppBadge_iframe.html33
-rw-r--r--testing/web-platform/tests/badging/setAppBadge_cross_origin.sub.https.html64
7 files changed, 235 insertions, 0 deletions
diff --git a/testing/web-platform/tests/badging/META.yml b/testing/web-platform/tests/badging/META.yml
new file mode 100644
index 0000000000..840e187cba
--- /dev/null
+++ b/testing/web-platform/tests/badging/META.yml
@@ -0,0 +1,4 @@
+spec: https://w3c.github.io/badging/
+suggested_reviewers:
+ - marcoscaceres
+ - diekus
diff --git a/testing/web-platform/tests/badging/badge-error.https.html b/testing/web-platform/tests/badging/badge-error.https.html
new file mode 100644
index 0000000000..3da5cf61e8
--- /dev/null
+++ b/testing/web-platform/tests/badging/badge-error.https.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<title>Badging: Unsupported values</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+promise_test(t => {
+ return promise_rejects_js(t, TypeError, navigator.setAppBadge(-1));
+}, "Negative value not allowed");
+
+promise_test(t => {
+ return promise_rejects_js(t, TypeError, navigator.setAppBadge(
+ Number.MAX_SAFE_INTEGER + 1));
+}, "Value too large (2^53)");
+
+promise_test(t => {
+ return promise_rejects_js(t, TypeError, navigator.setAppBadge(Infinity));
+}, "Positive infinity");
+
+promise_test(t => {
+ return promise_rejects_js(t, TypeError, navigator.setAppBadge(-Infinity));
+}, "Negative infinity");
+
+promise_test(t => {
+ return promise_rejects_js(t, TypeError, navigator.setAppBadge(NaN));
+}, "NaN");
+
+promise_test(t => {
+ return promise_rejects_js(t, TypeError, navigator.setAppBadge("Foo"));
+}, 'Cannot convert to long: "Foo"');
+
+promise_test(t => {
+ return promise_rejects_js(t, TypeError, navigator.setAppBadge({}));
+}, "Cannot convert to long: object");
+
+</script>
diff --git a/testing/web-platform/tests/badging/badge-success.https.html b/testing/web-platform/tests/badging/badge-success.https.html
new file mode 100644
index 0000000000..6a25962e7b
--- /dev/null
+++ b/testing/web-platform/tests/badging/badge-success.https.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<title>Badging: Supported values</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge();
+ assert_equals(result, undefined);
+}, "No parameter should show a flag with no numeric value.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(undefined);
+ assert_equals(result, undefined);
+}, "undefined should show a flag with no numeric value.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(1);
+ assert_equals(result, undefined);
+}, "An integer value of 3 should show the badge vale 3.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(10.6);
+ assert_equals(result, undefined);
+}, "Non-whole number should round down to nearest integer (10).");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(Number.MAX_SAFE_INTEGER);
+ assert_equals(result, undefined);
+}, "Maximum allowed value (2^53 - 1) should display saturated value: '99+'.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(0);
+ assert_equals(result, undefined);
+}, "Set to zero should clear the badge.");
+
+promise_test(async t => {
+ const result = await navigator.clearAppBadge();
+ assert_equals(result, undefined);
+}, "Should clear the badge.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(null);
+ assert_equals(result, undefined);
+}, "Setting to null should clear the badge.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(false);
+ assert_equals(result, undefined);
+}, "Setting to false should clear the badge.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge(true);
+ assert_equals(result, undefined);
+}, "Setting to true should display a value of 1.");
+
+promise_test(async t => {
+ const result = await navigator.setAppBadge("3");
+ assert_equals(result, undefined);
+}, "Setting to the string '3' should display a value of 3.");
+
+</script>
diff --git a/testing/web-platform/tests/badging/idlharness.https.any.js b/testing/web-platform/tests/badging/idlharness.https.any.js
new file mode 100644
index 0000000000..3e3ee9e7c4
--- /dev/null
+++ b/testing/web-platform/tests/badging/idlharness.https.any.js
@@ -0,0 +1,17 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+// META: timeout=long
+
+'use strict';
+
+idl_test(
+ ['badging'],
+ ['html', 'dom'],
+ idl_array => {
+ if (self.GLOBAL.isWorker()) {
+ idl_array.add_objects({ WorkerNavigator: ['navigator'] });
+ } else {
+ idl_array.add_objects({ Navigator: ['navigator'] });
+ }
+ }
+);
diff --git a/testing/web-platform/tests/badging/non-fully-active.https.html b/testing/web-platform/tests/badging/non-fully-active.https.html
new file mode 100644
index 0000000000..d870e52273
--- /dev/null
+++ b/testing/web-platform/tests/badging/non-fully-active.https.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<title>Badging: attempting to badge non-fully active document</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body></body>
+<script>
+promise_test(async t => {
+ const iframe = document.createElement("iframe");
+ document.body.appendChild(iframe);
+ await new Promise(resolve => {
+ iframe.onload = resolve;
+ iframe.src = "about:blank";
+ });
+ const exceptionCtor = iframe.contentWindow.DOMException;
+ const {navigator: nav} = iframe.contentWindow;
+ iframe.remove();
+ return promise_rejects_dom(t, "InvalidStateError", exceptionCtor, nav.setAppBadge(1));
+}, "badging a non-fully active document should reject with InvalidStateError");
+</script>
diff --git a/testing/web-platform/tests/badging/resources/setAppBadge_iframe.html b/testing/web-platform/tests/badging/resources/setAppBadge_iframe.html
new file mode 100644
index 0000000000..8738099658
--- /dev/null
+++ b/testing/web-platform/tests/badging/resources/setAppBadge_iframe.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>setAppBadge iframe</title>
+<script>
+ async function callSetAppBadge() {
+ const postMessageData = { message: "callSetAppBadge" };
+
+ try {
+ await navigator.setAppBadge();
+ postMessageData.status = "success";
+ } catch (e) {
+ if (e instanceof DOMException) {
+ postMessageData.status = "error";
+ postMessageData.exceptionType = e.name;
+ } else {
+ postMessageData.status = "unknown_error";
+ postMessageData.error = e.toString();
+ }
+ } finally {
+ window.parent.postMessage(postMessageData, "*");
+ }
+ }
+
+ window.addEventListener("message", async (event) => {
+ switch (event.data) {
+ case "callSetAppBadge":
+ await callSetAppBadge();
+ break;
+ default:
+ throw new Error(`Unexpected message: ${event.data}`);
+ }
+ });
+</script>
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>