summaryrefslogtreecommitdiffstats
path: root/dom/media/autoplay/test/browser/browser_autoplay_policy.js
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/autoplay/test/browser/browser_autoplay_policy.js')
-rw-r--r--dom/media/autoplay/test/browser/browser_autoplay_policy.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/dom/media/autoplay/test/browser/browser_autoplay_policy.js b/dom/media/autoplay/test/browser/browser_autoplay_policy.js
new file mode 100644
index 0000000000..79b19eedc1
--- /dev/null
+++ b/dom/media/autoplay/test/browser/browser_autoplay_policy.js
@@ -0,0 +1,78 @@
+/**
+ * This test is used to ensure we can get the correct document's autoplay policy
+ * under different situations.
+ * Spec discussion : https://github.com/WICG/autoplay/issues/1
+ */
+const PAGE = GetTestWebBasedURL("file_empty.html");
+
+function setupTestPreferences(isAllowedAutoplay, isAllowedMuted) {
+ let autoplayDefault = SpecialPowers.Ci.nsIAutoplay.ALLOWED;
+ if (!isAllowedAutoplay) {
+ autoplayDefault = isAllowedMuted
+ ? SpecialPowers.Ci.nsIAutoplay.BLOCKED
+ : SpecialPowers.Ci.nsIAutoplay.BLOCKED_ALL;
+ }
+ return SpecialPowers.pushPrefEnv({
+ set: [
+ ["dom.media.autoplay.autoplay-policy-api", true],
+ ["media.autoplay.default", autoplayDefault],
+ ["media.autoplay.blocking_policy", 0],
+ ],
+ });
+}
+
+async function checkAutoplayPolicy(expectedAutoplayPolicy) {
+ is(
+ content.document.autoplayPolicy,
+ expectedAutoplayPolicy,
+ `Autoplay policy is correct.`
+ );
+}
+
+add_task(async function testAutoplayPolicy() {
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ url: PAGE,
+ },
+ async browser => {
+ info(`- Allow all kinds of media to autoplay -`);
+ let isAllowedAutoplay = true;
+ let isAllowedMuted = true;
+ await setupTestPreferences(isAllowedAutoplay, isAllowedMuted);
+ await SpecialPowers.spawn(browser, ["allowed"], checkAutoplayPolicy);
+
+ info(
+ `- Allow all kinds of media to autoplay even if changing the pref for muted media -`
+ );
+ isAllowedAutoplay = true;
+ isAllowedMuted = false;
+ await setupTestPreferences(isAllowedAutoplay, isAllowedMuted);
+ await SpecialPowers.spawn(browser, ["allowed"], checkAutoplayPolicy);
+
+ info(`- Disable autoplay for audible media -`);
+ isAllowedAutoplay = false;
+ isAllowedMuted = true;
+ await setupTestPreferences(isAllowedAutoplay, isAllowedMuted);
+ await SpecialPowers.spawn(
+ browser,
+ ["allowed-muted"],
+ checkAutoplayPolicy
+ );
+
+ info(`- Disable autoplay for all kinds of media -`);
+ isAllowedAutoplay = false;
+ isAllowedMuted = false;
+ await setupTestPreferences(isAllowedAutoplay, isAllowedMuted);
+ await SpecialPowers.spawn(browser, ["disallowed"], checkAutoplayPolicy);
+
+ info(
+ `- Simulate user gesture activation which would allow all kinds of media to autoplay -`
+ );
+ await SpecialPowers.spawn(browser, [], async () => {
+ content.document.notifyUserGestureActivation();
+ });
+ await SpecialPowers.spawn(browser, ["allowed"], checkAutoplayPolicy);
+ }
+ );
+});