summaryrefslogtreecommitdiffstats
path: root/dom/media/autoplay/test/browser/browser_autoplay_policy_detection_global_sticky.js
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/media/autoplay/test/browser/browser_autoplay_policy_detection_global_sticky.js
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 'dom/media/autoplay/test/browser/browser_autoplay_policy_detection_global_sticky.js')
-rw-r--r--dom/media/autoplay/test/browser/browser_autoplay_policy_detection_global_sticky.js105
1 files changed, 105 insertions, 0 deletions
diff --git a/dom/media/autoplay/test/browser/browser_autoplay_policy_detection_global_sticky.js b/dom/media/autoplay/test/browser/browser_autoplay_policy_detection_global_sticky.js
new file mode 100644
index 0000000000..ab9fe6b418
--- /dev/null
+++ b/dom/media/autoplay/test/browser/browser_autoplay_policy_detection_global_sticky.js
@@ -0,0 +1,105 @@
+/**
+ * This test checks whether Autoplay Policy Detection API works correctly under
+ * different situations of having global permission set for block autoplay.
+ * This test only checks the sticky user gesture blocking model.
+ */
+"use strict";
+
+add_setup(async function setSharedPrefs() {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["dom.media.autoplay-policy-detection.enabled", true],
+ ["media.autoplay.blocking_policy", 0],
+ ["media.autoplay.block-webaudio", true],
+ ],
+ });
+});
+
+add_task(async function testGlobalPermissionIsAllowed() {
+ await SpecialPowers.pushPrefEnv({
+ set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.ALLOWED]],
+ });
+ let tab = await createTabAndSetupPolicyAssertFunc("about:blank");
+ await SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
+ info("global setting allows any autoplay");
+ content.assertAutoplayPolicy({
+ resultForElementType: "allowed",
+ resultForElement: "allowed",
+ resultForContextType: "allowed",
+ resultForContext: "allowed",
+ });
+ });
+ BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function testGlobalPermissionIsBlocked() {
+ await SpecialPowers.pushPrefEnv({
+ set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED]],
+ });
+ let tab = await createTabAndSetupPolicyAssertFunc("about:blank");
+ await SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
+ info(
+ "global setting allows inaudible autoplay but audible autoplay is still not allowed"
+ );
+ content.assertAutoplayPolicy({
+ resultForElementType: "allowed-muted",
+ resultForElement: "allowed-muted",
+ resultForContextType: "disallowed",
+ resultForContext: "disallowed",
+ });
+
+ info("tweaking video's muted attribute won't change the result");
+ content.video.muted = true;
+ is(
+ "allowed-muted",
+ content.navigator.getAutoplayPolicy(content.video),
+ "getAutoplayPolicy(video) returns correct value"
+ );
+ content.video.muted = false;
+ is(
+ "allowed-muted",
+ content.navigator.getAutoplayPolicy(content.video),
+ "getAutoplayPolicy(video) returns correct value"
+ );
+
+ info(
+ "activate document by using user gesture, all autoplay will be allowed"
+ );
+ content.document.notifyUserGestureActivation();
+ content.assertAutoplayPolicy({
+ resultForElementType: "allowed",
+ resultForElement: "allowed",
+ resultForContextType: "allowed",
+ resultForContext: "allowed",
+ });
+ });
+ BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function testGlobalPermissionIsBlockedAll() {
+ await SpecialPowers.pushPrefEnv({
+ set: [["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED_ALL]],
+ });
+ let tab = await createTabAndSetupPolicyAssertFunc("about:blank");
+ await SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
+ info("global setting doesn't allow any autoplay");
+ content.assertAutoplayPolicy({
+ resultForElementType: "disallowed",
+ resultForElement: "disallowed",
+ resultForContextType: "disallowed",
+ resultForContext: "disallowed",
+ });
+
+ info(
+ "activate document by using user gesture, all autoplay will be allowed"
+ );
+ content.document.notifyUserGestureActivation();
+ content.assertAutoplayPolicy({
+ resultForElementType: "allowed",
+ resultForElement: "allowed",
+ resultForContextType: "allowed",
+ resultForContext: "allowed",
+ });
+ });
+ BrowserTestUtils.removeTab(tab);
+});