Bug 1513039 - part7 : modify web audio autoplay test for removal of doorhanger r=karlt
authoralwu <alwu@mozilla.com>
Mon, 07 Jan 2019 18:36:11 +0000
changeset 509877 1a70b4c3fc0ec88667508ebb87deefc2923693a7
parent 509876 54817f010dde7ba75d4b506be0e55eac3a890471
child 509878 460739b430085464419cab4495a5c46cc77e15cc
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)
reviewerskarlt
bugs1513039
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 1513039 - part7 : modify web audio autoplay test for removal of doorhanger r=karlt Check whether web audio starts when calling calling resume() or AudioScheduledNode.start() after granting user activation. Differential Revision: https://phabricator.services.mozilla.com/D14332
toolkit/content/tests/browser/browser_autoplay_policy_web_audio.js
--- a/toolkit/content/tests/browser/browser_autoplay_policy_web_audio.js
+++ b/toolkit/content/tests/browser/browser_autoplay_policy_web_audio.js
@@ -1,27 +1,25 @@
 /**
  * This test is used for testing whether WebAudio can be started correctly in
  * different scenarios, such as
  * 1) site has existing 'autoplay-media' permission for allowing autoplay
  * 2) site has existing 'autoplay-media' permission for blocking autoplay
- * 3) site doesn't have permission, user clicks 'allow' button on the doorhanger
- * 4) site doesn't have permission, user clicks 'deny' button on the doorhanger
- * 5) site doesn't have permission, user ignores the doorhanger
+ * 3) site doesn't have permission, start audio context by calling resume() or
+ *    AudioScheduledNode.start() after granting user activation.
  */
 "use strict";
 
 ChromeUtils.import("resource:///modules/SitePermissions.jsm", this);
 const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_empty.html";
 
 function setup_test_preference() {
   return SpecialPowers.pushPrefEnv({"set": [
-    ["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.PROMPT],
+    ["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
     ["media.autoplay.enabled.user-gestures-needed", true],
-    ["media.autoplay.ask-permission", true],
     ["media.autoplay.block-webaudio", true],
     ["media.autoplay.block-event.enabled", true],
   ]});
 }
 
 function createAudioContext() {
   content.ac = new content.AudioContext();
   const ac = content.ac;
@@ -118,51 +116,43 @@ async function testAutoplayExistingPermi
   await ContentTask.spawn(browser, isAllowedToStart,
                           resumeAudioContext);
 
   info(`- remove tab -`);
   SitePermissions.remove(browser.currentURI, "autoplay-media");
   await BrowserTestUtils.removeTab(tab);
 }
 
-async function testAutoplayUnknownPermission({name, button, method}) {
+async function testAutoplayUnknownPermission({name, method}) {
   info(`- starting \"${name}\" -`);
   const tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, PAGE);
   const browser = tab.linkedBrowser;
 
   info(`- set the 'autoplay-media' permission to UNKNOWN -`);
   const promptShow = () =>
     PopupNotifications.getNotification("autoplay-media", browser);
   SitePermissions.set(browser.currentURI, "autoplay-media", SitePermissions.UNKNOWN);
   ok(!promptShow(), `should not be showing permission prompt yet`);
 
-  info(`- create AudioContext which should not start until user approves -`);
+  info(`- create AudioContext which should not start -`);
   loadFrameScript(browser, createAudioContext);
   await ContentTask.spawn(browser, false, checkIfAudioContextIsAllowedToStart);
 
-  info(`- try to start AudioContext and show doorhanger to ask for user's approval -`);
-  const popupShow = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
-  await ContentTask.spawn(browser, method, startAudioContext);
-  await popupShow;
-  ok(promptShow(), `should now be showing permission prompt`);
+  info(`- simulate user activate the page -`);
+  await ContentTask.spawn(browser, null, () => {
+    content.document.notifyUserGestureActivation();
+  });
 
-  info(`- simulate clicking button on doorhanger -`);
-  if (button == "allow") {
-    PopupNotifications.panel.firstElementChild.button.click();
-  } else if (button == "block") {
-    PopupNotifications.panel.firstChild.secondaryButton.click();
-  } else {
-    ok(false, `invalid button field`);
-  }
+  info(`- try to start AudioContext -`);
+  await ContentTask.spawn(browser, method, startAudioContext);
 
   info(`- check AudioContext status -`);
-  const isAllowedToStart = button === "allow";
-  await ContentTask.spawn(browser, isAllowedToStart,
+  await ContentTask.spawn(browser, true /* allow to start */,
                           checkIfAudioContextIsAllowedToStart);
-  await ContentTask.spawn(browser, isAllowedToStart,
+  await ContentTask.spawn(browser, true /* allow to start */,
                           resumeAudioContext);
 
   info(`- remove tab -`);
   SitePermissions.remove(browser.currentURI, "autoplay-media");
   await BrowserTestUtils.removeTab(tab);
 }
 
 add_task(async function start_tests() {
@@ -176,19 +166,13 @@ add_task(async function start_tests() {
   await testAutoplayExistingPermission({
     name: "Prexisting block permission",
     permission: SitePermissions.BLOCK,
   });
   const startMethods = ["AudioContext", "AudioBufferSourceNode",
                         "ConstantSourceNode", "OscillatorNode"];
   for (let method of startMethods) {
     await testAutoplayUnknownPermission({
-      name: "Unknown permission and click allow button on doorhanger",
-      button: "allow",
-      method,
-    });
-    await testAutoplayUnknownPermission({
-      name: "Unknown permission and click block button on doorhanger",
-      button: "block",
+      name: "Unknown permission and start AudioContext after granting user activation",
       method,
     });
   }
 });