Bug 1412210 - Respect video error state while adjusting controls to determine the visibility of clickToPlay button. r=jaws draft
authorRay Lin <ralin@mozilla.com>
Fri, 27 Oct 2017 15:41:25 +0800
changeset 693066 8b3d4d955b44a5141b3d344e523ae55f92e32863
parent 693006 66f496680fae6e7d8f02bc17ff58b9234ee07c70
child 738941 052724f19d40aa8718b9bf279b8c6b90b7a83618
push id87698
push userbmo:ralin@mozilla.com
push dateSat, 04 Nov 2017 02:16:39 +0000
reviewersjaws
bugs1412210
milestone58.0a1
Bug 1412210 - Respect video error state while adjusting controls to determine the visibility of clickToPlay button. r=jaws MozReview-Commit-ID: HhKHVYmEsKD
toolkit/content/tests/widgets/test_videocontrols_error.html
toolkit/content/tests/widgets/test_videocontrols_vtt.html
toolkit/content/widgets/videocontrols.xml
--- a/toolkit/content/tests/widgets/test_videocontrols_error.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_error.html
@@ -1,66 +1,57 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Video controls test - Error</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
   <script type="text/javascript" src="head.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <p id="display"></p>
 
 <div id="content">
   <video id="video" controls preload="auto"></video>
 </div>
 
 <pre id="test">
 <script clas="testbody" type="application/javascript">
-  SimpleTest.waitForExplicitFinish();
-
   const video = document.getElementById("video");
   const statusOverlay = getAnonElementWithinVideoByAttribute(video, "anonid", "statusOverlay");
   const statusIcon = getAnonElementWithinVideoByAttribute(video, "anonid", "statusIcon");
+  const clickToPlay = getAnonElementWithinVideoByAttribute(video, "anonid", "clickToPlay");
 
-  const testCases = [];
+  add_task(async function setup() {
+    await new Promise(resolve => window.addEventListener("load", resolve, {once: true}));
+    await SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]});
+  });
 
-  testCases.push(() => new Promise(resolve => {
+  add_task(async function check_normal_status() {
+    await new Promise(resolve => {
+      video.src = "seek_with_sound.ogg";
+      video.addEventListener("loadedmetadata", resolve);
+    });
+
     ok(statusOverlay.hidden, "statusOverlay shoud not present without error");
     ok(!statusOverlay.hasAttribute("error"), "statusOverlay should not in error state");
     isnot(statusIcon.getAttribute("type"), "error", "should not show error icon");
-
-    resolve();
-  }));
+  });
 
-  testCases.push(() => new Promise(resolve => {
-    video.src = "invalid-path.ogg";
-    video.addEventListener("error", resolve);
-  }));
-
-  testCases.push(() => new Promise(resolve => {
+  add_task(async function invalid_source() {
     const errorType = "errorNoSource";
 
+    await new Promise(resolve => {
+      video.src = "invalid_source.ogg";
+      video.addEventListener("error", resolve)
+    });
+
+    ok(clickToPlay.hasAttribute("hidden"), `click to play button should hide`);
     ok(!statusOverlay.hidden, `statusOverlay should show when ${errorType}`);
     is(statusOverlay.getAttribute("error"), errorType, `statusOverlay should have correct error state: ${errorType}`);
     is(statusIcon.getAttribute("type"), "error", `should show error icon when ${errorType}`);
-
-    resolve();
-  }));
-
-  function executeTestCases(tasks) {
-    return tasks.reduce((promise, task) => promise.then(task), Promise.resolve());
-  }
-
-  function startTest() {
-    executeTestCases(testCases).then(SimpleTest.finish);
-  }
-
-  function loadevent() {
-    SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, startTest);
-  }
-
-  window.addEventListener("load", loadevent);
+  });
 </script>
 </pre>
 </body>
 </html>
--- a/toolkit/content/tests/widgets/test_videocontrols_vtt.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_vtt.html
@@ -17,17 +17,16 @@
 
 <pre id="test">
 <script clas="testbody" type="application/javascript">
   SimpleTest.waitForExplicitFinish();
 
   const video = document.getElementById("video");
   const ccBtn = getAnonElementWithinVideoByAttribute(video, "anonid", "closedCaptionButton");
   const ttList = getAnonElementWithinVideoByAttribute(video, "anonid", "textTrackList");
-  const testCases = [];
 
   add_task(async function wait_for_media_ready() {
     await new Promise(resolve => window.addEventListener("load", resolve, {once: true}));
     await SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]});
     await new Promise(resolve => {
       video.src = "seek_with_sound.ogg";
       video.addEventListener("loadedmetadata", resolve);
     });
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1735,17 +1735,18 @@
         const clickToPlayViewRatio = 0.15;
         const clickToPlayScaledSize = Math.max(
         this.clickToPlay.minWidth, minVideoSideLength * clickToPlayViewRatio);
 
         if (clickToPlayScaledSize >= videoWidth ||
            (clickToPlayScaledSize + this.controlBarMinHeight / 2 >= videoHeight / 2 )) {
           this.clickToPlay.hideByAdjustment = true;
         } else {
-          if (this.clickToPlay.hidden && !this.video.played.length && this.video.paused) {
+          if (this.clickToPlay.hidden && !this.video.played.length &&
+              this.video.paused && this.clickToPlay.hideByAdjustment) {
             this.clickToPlay.hideByAdjustment = false;
           }
           this.clickToPlay.style.width = `${clickToPlayScaledSize}px`;
           this.clickToPlay.style.height = `${clickToPlayScaledSize}px`;
         }
       },
 
       init(binding) {