Bug 1347673 - Visibility state of extra video control buttons should be recalculated each time the video controls are adjusted. r=jaws, a=gchang
authorRay Lin <ralin@mozilla.com>
Thu, 16 Mar 2017 18:19:56 +0800
changeset 395508 e733c38a51474cc7a537dcd9193daf2566a2e1a7
parent 395507 d2727be705bd42e5888f3dfd5502d82509344697
child 395509 3fa6fdf65c06d8225a944ddc0918d1378b773454
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, gchang
bugs1347673
milestone54.0a2
Bug 1347673 - Visibility state of extra video control buttons should be recalculated each time the video controls are adjusted. r=jaws, a=gchang MozReview-Commit-ID: Lj7kttJ9skU
toolkit/content/tests/reftests/reftest.list
toolkit/content/tests/reftests/videocontrols-dynamically-add-cc-ref.html
toolkit/content/tests/reftests/videocontrols-dynamically-add-cc.html
toolkit/content/widgets/videocontrols.xml
--- a/toolkit/content/tests/reftests/reftest.list
+++ b/toolkit/content/tests/reftests/reftest.list
@@ -1,2 +1,3 @@
 random-if(cocoaWidget) == bug-442419-progressmeter-max.xul bug-442419-progressmeter-max-ref.xul # fails most of the time on Mac because progress meter animates
 != textbox-multiline-default-value.xul textbox-multiline-empty.xul
+== videocontrols-dynamically-add-cc.html videocontrols-dynamically-add-cc-ref.html
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/reftests/videocontrols-dynamically-add-cc-ref.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+  html, body {
+    margin: 0;
+    padding: 0;
+  }
+
+  video {
+    width: 320px;
+    height: 240px;
+  }
+
+  #mask {
+    position: absolute;
+    z-index: 3;
+    width: 320px;
+    height: 200px;
+    background-color: green;
+    top: 0;
+    left: 0;
+  }
+</style>
+<script>
+  function addCCToVid(videoElem) {
+    videoElem.addTextTrack("subtitles", "English", "en");
+  }
+</script>
+</head>
+<body>
+  <video id="vid" controls></video>
+  <div id="mask"></div>
+  <script>
+    var vid = document.getElementById("vid");
+    addCCToVid(vid);
+  </script>
+</body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/reftests/videocontrols-dynamically-add-cc.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<head>
+<style>
+  html, body {
+    margin: 0;
+    padding: 0;
+  }
+
+  video {
+    width: 320px;
+    height:240px;
+  }
+
+  #mask {
+    position: absolute;
+    z-index: 3;
+    width: 320px;
+    height: 200px;
+    background-color: green;
+    top: 0;
+    left: 0;
+  }
+</style>
+<script>
+  function addCCToVid(videoElem) {
+    videoElem.addTextTrack("subtitles", "English", "en");
+  }
+</script>
+</head>
+<body>
+  <video id="vid" controls></video>
+  <div id="mask"></div>
+  <script>
+    function doTest() {
+      var vid = document.getElementById("vid");
+
+      // Videocontrols binding's "addtrack" handler synchronously fires
+      // "adjustControlSize()" first, and then the layout is ready for
+      // the reftest snapshot.
+      vid.textTracks.addEventListener("addtrack", function() {
+        document.documentElement.removeAttribute("class");
+      });
+
+      addCCToVid(vid);
+    }
+
+    window.addEventListener("MozReftestInvalidate", doTest);
+  </script>
+</body>
+</html>
+
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1458,18 +1458,16 @@
 
       setClosedCaptionButtonState() {
         this.adjustControlSize();
 
         if (!this.isClosedCaptionAvailable) {
           return;
         }
 
-        this.closedCaptionButton.removeAttribute("hidden");
-
         if (this.isClosedCaptionOn()) {
           this.closedCaptionButton.setAttribute("enabled", "true");
         } else {
           this.closedCaptionButton.removeAttribute("enabled");
         }
 
         let ttItems = this.textTrackList.childNodes;
 
@@ -1669,25 +1667,19 @@
           this.fullscreenButton,
           this.closedCaptionButton,
           this.positionDurationBox,
           this.scrubberStack,
           this.durationSpan,
           this.volumeStack
         ];
 
-        if (this.controlBar.hasAttribute("fullscreen-unavailable")) {
-          this.fullscreenButton.isWanted = false;
-        }
-        if (!this.isClosedCaptionAvailable) {
-          this.closedCaptionButton.isWanted = false;
-        }
-        if (this.muteButton.hasAttribute("noAudio")) {
-          this.volumeStack.isWanted = false;
-        }
+        this.fullscreenButton.isWanted = !this.controlBar.hasAttribute("fullscreen-unavailable");
+        this.closedCaptionButton.isWanted = this.isClosedCaptionAvailable;
+        this.volumeStack.isWanted = !this.muteButton.hasAttribute("noAudio");
 
         let widthUsed = minControlBarPaddingWidth;
         let preventAppendControl = false;
 
         for (let control of prioritizedControls) {
           if (!control.isWanted) {
             control.hideByAdjustment = true;
             continue;