Bug 1654959 - part3 : add test cases for enabling muted media into fullscreen/PIP mode. r=bryce
authoralwu <alwu@mozilla.com>
Fri, 24 Jul 2020 02:42:05 +0000
changeset 541871 77366f40af71b75e4308dc9304d6151a0324d58d
parent 541870 f10c1afc8bf0943e077a76f0978f49230aff2060
child 541872 13e76078fe27098c4614cfd7a0645b76738d74c1
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1654959
milestone80.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 1654959 - part3 : add test cases for enabling muted media into fullscreen/PIP mode. r=bryce Add two new test cases for inaudible media being used in fullscreen/PIP mode. In addition, after applying D84115, we fix the issue of incorrectly controlling media which doesn't be started yet and is not in the fullscreen. So modify the current test case. Differential Revision: https://phabricator.services.mozilla.com/D84369
dom/media/mediacontrol/tests/browser_media_control_before_media_starts.js
dom/media/mediacontrol/tests/file_iframe_media.html
--- a/dom/media/mediacontrol/tests/browser_media_control_before_media_starts.js
+++ b/dom/media/mediacontrol/tests/browser_media_control_before_media_starts.js
@@ -38,31 +38,64 @@ add_task(async function testMediaEntersP
   await generateMediaControlKeyEvent("play");
   await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
 
   info(`remove tab`);
   await BrowserTestUtils.closeWindow(winPIP);
   await BrowserTestUtils.removeTab(tab);
 });
 
+add_task(async function testMutedMediaEntersPIPMode() {
+  info(`open media page and mute video`);
+  const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
+  await muteMedia(tab, testVideoId);
+
+  info(`trigger PIP mode`);
+  const winPIP = await triggerPictureInPicture(tab.linkedBrowser, testVideoId);
+
+  info(`press 'play' and wait until media starts`);
+  await generateMediaControlKeyEvent("play");
+  await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
+
+  info(`remove tab`);
+  await BrowserTestUtils.closeWindow(winPIP);
+  await BrowserTestUtils.removeTab(tab);
+});
+
 add_task(async function testMediaEntersFullScreen() {
   info(`open media page`);
   const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
 
   info(`make video fullscreen`);
   await enableFullScreen(tab, testVideoId);
 
   info(`press 'play' and wait until media starts`);
   await generateMediaControlKeyEvent("play");
   await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
 
   info(`remove tab`);
   await BrowserTestUtils.removeTab(tab);
 });
 
+add_task(async function testMutedMediaEntersFullScreen() {
+  info(`open media page and mute video`);
+  const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
+  await muteMedia(tab, testVideoId);
+
+  info(`make video fullscreen`);
+  await enableFullScreen(tab, testVideoId);
+
+  info(`press 'play' and wait until media starts`);
+  await generateMediaControlKeyEvent("play");
+  await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
+
+  info(`remove tab`);
+  await BrowserTestUtils.removeTab(tab);
+});
+
 add_task(async function testNonMediaEntersFullScreen() {
   info(`open media page`);
   const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
 
   info(`make non-media element fullscreen`);
   const nonMediaElementId = "image";
   await enableFullScreen(tab, nonMediaElementId);
 
@@ -80,32 +113,39 @@ add_task(async function testMediaInIfram
   info(`open media page`);
   const tab = await createTabAndLoad(PAGE_NON_AUTOPLAY);
 
   info(`make video in iframe fullscreen`);
   await enableMediaFullScreenInIframe(tab, testVideoId);
 
   info(`press 'play' and wait until media starts`);
   await generateMediaControlKeyEvent("play");
-  await checkOrWaitUntilMediaStartedPlaying(tab, testVideoId);
+
+  info(`full screen media in inframe should be started`);
+  await waitUntilIframeMediaStartedPlaying(tab);
+
+  info(`media not in fullscreen should keep paused`);
+  await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
 
   info(`remove iframe that contains fullscreen video`);
   await removeIframeFromDocument(tab);
 
-  info(`press 'pause' which should still affect video in the main frame`);
-  await generateMediaControlKeyEvent("pause");
-  await checkOrWaitUntilMediaStoppedPlaying(tab, testVideoId);
-
   info(`remove tab`);
   await BrowserTestUtils.removeTab(tab);
 });
 
 /**
  * The following are helper functions.
  */
+function muteMedia(tab, videoId) {
+  return SpecialPowers.spawn(tab.linkedBrowser, [videoId], videoId => {
+    content.document.getElementById(videoId).muted = true;
+  });
+}
+
 function enableFullScreen(tab, elementId) {
   return SpecialPowers.spawn(tab.linkedBrowser, [elementId], elementId => {
     return new Promise(r => {
       const element = content.document.getElementById(elementId);
       element.requestFullscreen();
       element.onfullscreenchange = () => {
         element.onfullscreenchange = null;
         element.onfullscreenerror = null;
@@ -137,14 +177,28 @@ function enableMediaFullScreenInIframe(t
           `media in iframe entered fullscreen`
         );
         r();
       };
     });
   });
 }
 
+function waitUntilIframeMediaStartedPlaying(tab) {
+  return SpecialPowers.spawn(tab.linkedBrowser, [IFRAME_URL], async url => {
+    info(`check if media in iframe starts playing`);
+    const iframe = content.document.getElementById("iframe");
+    iframe.contentWindow.postMessage("check-playing", "*");
+    return new Promise(r => {
+      content.onmessage = event => {
+        is(event.data, "checked-playing", `media in iframe is playing`);
+        r();
+      };
+    });
+  });
+}
+
 function removeIframeFromDocument(tab) {
   return SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     info(`remove iframe from document`);
     content.document.getElementById("iframe").remove();
   });
 }
--- a/dom/media/mediacontrol/tests/file_iframe_media.html
+++ b/dom/media/mediacontrol/tests/file_iframe_media.html
@@ -16,14 +16,23 @@ window.onmessage = event => {
       video.onfullscreenchange = null;
       video.onfullscreenerror = null;
       w.postMessage("entered-fullscreen", "*");
     }
     video.onfullscreenerror = () => {
       // Retry until the element successfully enters fullscreen.
       video.requestFullscreen();
     }
+  } else if (event.data == "check-playing") {
+    if (!video.paused) {
+      w.postMessage("checked-playing", "*");
+    } else {
+      video.onplaying = () => {
+        video.onplaying = null;
+        w.postMessage("checked-playing", "*");
+      }
+    }
   }
 }
 
 </script>
 </body>
 </html>