summaryrefslogtreecommitdiffstats
path: root/dom/webshare/test/mochitest/test_navigator_share_consume_user_activation.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/webshare/test/mochitest/test_navigator_share_consume_user_activation.html
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--dom/webshare/test/mochitest/test_navigator_share_consume_user_activation.html43
1 files changed, 43 insertions, 0 deletions
diff --git a/dom/webshare/test/mochitest/test_navigator_share_consume_user_activation.html b/dom/webshare/test/mochitest/test_navigator_share_consume_user_activation.html
new file mode 100644
index 0000000000..9cb3f04d96
--- /dev/null
+++ b/dom/webshare/test/mochitest/test_navigator_share_consume_user_activation.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<title>Web Share: consume transient activation</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="/tests/SimpleTest/EventUtils.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
+<body>
+ <button id="share">Share</button>
+</body>
+<script>
+ // TODO: add a task that tests share() consume the transient user activation.
+ // Because OS-level prompt can't be cancelled, it's currently not possible to
+ // test this. We need to add a Web share Mocking service:
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1646229
+
+ // test that share() would be blocked with an already-consumed-activation.
+ add_task(async function blockedIfAlreadyConsumed() {
+ const wrappedDoc = SpecialPowers.wrap(document);
+ const button = document.getElementById("share");
+
+ // Kick off transient activation
+ synthesizeMouseAtCenter(button, {});
+
+ ok(
+ wrappedDoc.hasValidTransientUserGestureActivation,
+ "Activated by a gesture"
+ );
+
+ wrappedDoc.consumeTransientUserGestureActivation();
+
+ try {
+ const sharePromise = navigator.share({ title: "test" });
+ await sharePromise;
+ ok(false, "must throw because activation was already consumed");
+ } catch (err) {
+ is(err.name, "NotAllowedError", "Expected NotAllowedError DOMException");
+ } finally {
+ ok(
+ !wrappedDoc.hasValidTransientUserGestureActivation,
+ "share() must consume the activation"
+ );
+ }
+ });
+</script>