Bug 1531863 - part5 : modify test 'test_videocontrols_vtt.html'. r=jaws
authorAlastor Wu <alwu@mozilla.com>
Tue, 12 Mar 2019 00:28:26 +0000
changeset 524463 7ae9bc24596f95a6bb69fcf1ce3d810ee478b6a0
parent 524462 859e7f4b9cb191e13ae9da7757c26312683b7b3f
child 524464 e7f9e5754e7741b0fb521b797deb68802738046f
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1531863
milestone67.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 1531863 - part5 : modify test 'test_videocontrols_vtt.html'. r=jaws According to the spec [1] step3, the 'change' event won't be dispatched immediately, so we should run the following check until we get the 'change' event. [1] https://html.spec.whatwg.org/multipage/media.html#pending-text-track-change-notification-flag Differential Revision: https://phabricator.services.mozilla.com/D22640
toolkit/content/tests/widgets/head.js
toolkit/content/tests/widgets/test_videocontrols_vtt.html
--- a/toolkit/content/tests/widgets/head.js
+++ b/toolkit/content/tests/widgets/head.js
@@ -31,8 +31,20 @@ function getElementWithinVideo(video, aV
   return shadowRoot.getElementById(aValue);
 }
 
 function executeTests() {
   return tests
     .map(fn => () => new Promise(fn))
     .reduce((promise, task) => promise.then(task), Promise.resolve());
 }
+
+function once(target, name, cb) {
+  let p = new Promise(function(resolve, reject) {
+    target.addEventListener(name, function() {
+      resolve();
+    }, {once: true});
+  });
+  if (cb) {
+    p.then(cb);
+  }
+  return p;
+}
--- a/toolkit/content/tests/widgets/test_videocontrols_vtt.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_vtt.html
@@ -79,30 +79,33 @@
   });
 
   add_task(async function check_select_texttrack() {
     const tt = ttList.children[1];
 
     ok(!tt.hasAttribute("on"), "Item should be off before click");
     synthesizeMouseAtCenter(tt, {});
 
+    await once(video.textTracks, "change");
     await new Promise(SimpleTest.executeSoon);
     ok(tt.hasAttribute("on"), "Selected item should be enabled");
     ok(ttList.hidden, "Should hide texttrack menu once clicked on an item");
   });
 
   add_task(async function check_change_texttrack_mode() {
     const tts = [...video.textTracks];
 
     tts.forEach(tt => tt.mode = "hidden");
+    await once(video.textTracks, "change");
     await new Promise(SimpleTest.executeSoon);
     ok(!ccBtn.hasAttribute("enabled"), "CC button should be disabled");
 
     // enable the last text track.
     tts[tts.length - 1].mode = "showing";
+    await once(video.textTracks, "change");
     await new Promise(SimpleTest.executeSoon);
     ok(ccBtn.hasAttribute("enabled"), "CC button should be enabled");
     ok(ttList.lastChild.hasAttribute("on"), "The last item should be highlighted");
   });
 
 </script>
 </pre>
 </body>