Bug 1463919 - Test that starting play from tab audio indicator overrides block autoplay. r?mconley draft
authorChris Pearce <cpearce@mozilla.com>
Mon, 25 Jun 2018 13:25:34 +1200
changeset 811167 a0cedd4adabb59ddad2c06e8d254136db1ed987f
parent 811166 10df89785583a4edb2607b765b4dd56e3369376f
child 811168 e09e70e18c2c96ff027eb9a65f0f0c6ec4e8a282
push id114216
push userbmo:cpearce@mozilla.com
push dateWed, 27 Jun 2018 03:52:23 +0000
reviewersmconley
bugs1463919
milestone62.0a1
Bug 1463919 - Test that starting play from tab audio indicator overrides block autoplay. r?mconley MozReview-Commit-ID: 4k7c7qw6cCq
toolkit/content/tests/browser/browser_block_autoplay_media.js
--- a/toolkit/content/tests/browser/browser_block_autoplay_media.js
+++ b/toolkit/content/tests/browser/browser_block_autoplay_media.js
@@ -12,16 +12,24 @@ function check_audio_suspended(suspended
   if (!autoPlay) {
     ok(false, "Can't get the audio element!");
   }
 
   is(autoPlay.computedSuspended, suspendedType,
      "The suspeded state of autoplay audio is correct.");
 }
 
+function check_audio_not_paused() {
+  var autoPlay = content.document.getElementById("autoplay");
+  if (!autoPlay) {
+    ok(false, "Can't get the audio element!");
+  }
+  ok(!audio.paused, "Audio is resumed correctly.");
+}
+
 add_task(async function setup_test_preference() {
   await SpecialPowers.pushPrefEnv({"set": [
     ["media.useAudioChannelService.testing", true],
     ["media.block-autoplay-until-in-foreground", true]
   ]});
 });
 
 add_task(async function block_autoplay_media() {
@@ -59,13 +67,36 @@ add_task(async function block_autoplay_m
   await ContentTask.spawn(tab1.linkedBrowser, SuspendedType.NONE_SUSPENDED,
                           check_audio_suspended);
 
   info("- should still block media from tab2 -");
   await waitForTabPlayingEvent(tab2, false);
   await ContentTask.spawn(tab2.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,
                           check_audio_suspended);
 
+
+  // Test 4: Disable autoplay, enable asking for permission, and verify
+  // that when a tab is opened in the background has had its playback
+  // start delayed, resuming via the audio tab indicator overrides the
+  // autoplay blocking logic.
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["media.autoplay.enabled", false],
+    ["media.autoplay.enabled.user-gestures-needed", true],
+    ["media.autoplay.ask-permission", true],
+  ]});
+
+  info("- open new background tab4 -");
+  let tab4 = window.gBrowser.addTab("about:blank");
+  tab4.linkedBrowser.loadURI(PAGE);
+  await BrowserTestUtils.browserLoaded(tab4.linkedBrowser);
+  info("- should block autoplay for non-visited tab4 -");
+  await ContentTask.spawn(tab4.linkedBrowser, SuspendedType.SUSPENDED_BLOCK,
+                          check_audio_suspended);
+  tab4.linkedBrowser.resumeMedia();
+  info("- should not block media from tab4 -");
+  await waitForTabPlayingEvent(tab4, true);
+
   info("- remove tabs -");
   BrowserTestUtils.removeTab(tab1);
   BrowserTestUtils.removeTab(tab2);
   BrowserTestUtils.removeTab(tab3);
+  BrowserTestUtils.removeTab(tab4);
 });