Bug 1520088 - part4 : modify test. r=cpearce
authorAlastor Wu <alwu@mozilla.com>
Wed, 16 Jan 2019 02:17:56 +0000
changeset 511252 5e0eb1c0074453818e7135ad87a97e4f3b1e674b
parent 511251 2ce9b482cda2d1ca16f063754be1bd43515de585
child 511253 5a384547b8b35e566a1afa2398067c82244091ba
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1520088
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1520088 - part4 : modify test. r=cpearce Differential Revision: https://phabricator.services.mozilla.com/D16581
toolkit/content/tests/browser/browser_autoplay_policy_request_permission.js
--- a/toolkit/content/tests/browser/browser_autoplay_policy_request_permission.js
+++ b/toolkit/content/tests/browser/browser_autoplay_policy_request_permission.js
@@ -3,23 +3,26 @@
  */
 
 "use strict";
 
 ChromeUtils.import("resource:///modules/SitePermissions.jsm", this);
 
 const VIDEO_PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_empty.html";
 
-add_task(() => {
+function setTestingPreferences(defaultSetting) {
+  info(`set default autoplay setting to '${defaultSetting}'`);
+  let defaultValue = defaultSetting == "blocked" ?
+    SpecialPowers.Ci.nsIAutoplay.BLOCKED : SpecialPowers.Ci.nsIAutoplay.ALLOWED;
   return SpecialPowers.pushPrefEnv({"set": [
-    ["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
+    ["media.autoplay.default", defaultValue],
     ["media.autoplay.enabled.user-gestures-needed", true],
     ["media.autoplay.block-event.enabled", true],
   ]});
-});
+}
 
 async function testAutoplayExistingPermission(args) {
   info("- Starting '" + args.name + "' -");
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: VIDEO_PAGE,
   }, async (browser) => {
     let promptShowing = () =>
@@ -33,20 +36,26 @@ async function testAutoplayExistingPermi
 
     // Reset permission.
     SitePermissions.remove(browser.currentURI, "autoplay-media");
 
     info("- Finished '" + args.name + "' -");
   });
 }
 
+async function testAutoplayExistingPermissionAgainstDefaultSetting(args) {
+  await setTestingPreferences(args.defaultSetting);
+  await testAutoplayExistingPermission(args);
+}
+
 // Test the simple ALLOW/BLOCK cases; when permission is already set to ALLOW,
 // we shoud be able to autoplay via calling play(), or via the autoplay attribute,
 // and when it's set to BLOCK, we should not.
 add_task(async () => {
+  await setTestingPreferences("blocked" /* default setting */);
   await testAutoplayExistingPermission({
     name: "Prexisting allow permission autoplay attribute",
     permission: SitePermissions.ALLOW,
     shouldPlay: true,
     mode: "autoplay attribute",
   });
   await testAutoplayExistingPermission({
     name: "Prexisting allow permission call play",
@@ -62,8 +71,29 @@ add_task(async () => {
   });
   await testAutoplayExistingPermission({
     name: "Prexisting block permission call play",
     permission: SitePermissions.BLOCK,
     shouldPlay: false,
     mode: "call play",
   });
 });
+
+/**
+ * These tests are used to ensure the autoplay setting for specific site can
+ * always override the default autoplay setting.
+ */
+add_task(async () => {
+  await testAutoplayExistingPermissionAgainstDefaultSetting({
+    name: "Site has prexisting allow permission but default setting is 'blocked'",
+    permission: SitePermissions.ALLOW,
+    defaultSetting: "blocked",
+    shouldPlay: true,
+    mode: "autoplay attribute",
+  });
+  await testAutoplayExistingPermissionAgainstDefaultSetting({
+    name: "Site has prexisting block permission but default setting is 'allowed'",
+    permission: SitePermissions.BLOCK,
+    defaultSetting: "allowed",
+    shouldPlay: false,
+    mode: "autoplay attribute",
+  });
+});