Bug 1552081 - part2. Modify test 'test_webvtt_update_display_after_adding_or_removing_cue.html'. r=jya
authorAlastor Wu <alwu@mozilla.com>
Fri, 17 May 2019 00:56:27 +0000
changeset 474282 7b72fa29c64be23ef4ac7f2373e5622adb48b337
parent 474281 95ccc685eb11f356e7b8c8be9ed2bea601585a4e
child 474283 ba078373f2c242bdada0f3cd73a2b28b03029480
push id113144
push usershindli@mozilla.com
push dateFri, 17 May 2019 16:44:55 +0000
treeherdermozilla-inbound@f4c4b796f845 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1552081
milestone68.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 1552081 - part2. Modify test 'test_webvtt_update_display_after_adding_or_removing_cue.html'. r=jya Now adding or removing cue would trigger processing cues only when media element's `show-poster` flag is false, so we have to modify the test to reset the flag in order to test the correct behavior. Differential Revision: https://phabricator.services.mozilla.com/D31511
dom/media/test/test_webvtt_update_display_after_adding_or_removing_cue.html
--- a/dom/media/test/test_webvtt_update_display_after_adding_or_removing_cue.html
+++ b/dom/media/test/test_webvtt_update_display_after_adding_or_removing_cue.html
@@ -5,33 +5,35 @@
   <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <script src="manifest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <script class="testbody" type="text/javascript">
 /**
  * This test is used to ensure that we will update cue display immediately after
- * adding or removing cue, even if the video hasn't started yet. In this test,
- * we start with adding a cue [0:5] to video, which should be showed in the
- * beginning, and then remove the cue later.
+ * adding or removing cue after video starts, because `show-poster` flag would be
+ * reset after video starts, which allows us to process cues instead of showing
+ * a poster. In this test, we start with adding a cue [0:5] to video, which
+ * should be showed in the beginning, and then remove the cue later. The cue
+ * should be removed immediately, not show
  */
 async function startTest() {
   const video = await createVideo();
+  await startVideo(video);
 
   info(`cue should be showed immediately after it was added.`);
   const cue = createCueAndAddCueToVideo(video);
   await waitUntilCueShows(cue);
 
   info(`cue should be hid immediately after it was removed.`);
   removeCueFromVideo(cue, video);
-  checkIfCueHides(cue);
+  checkIfCueHides(cue, video);
 
-  removeNodeAndSource(video);
-  SimpleTest.finish();
+  endTestAndClearVideo(video);
 }
 
 SimpleTest.waitForExplicitFinish();
 onload = startTest;
 
 /**
  * The following are test helper functions.
  */
@@ -41,37 +43,51 @@ async function createVideo() {
   video.controls = true;
   document.body.appendChild(video);
   // wait until media has loaded any data, because we won't update cue if it has
   // not got any data.
   await once(video, "loadedmetadata");
   return video;
 }
 
+async function startVideo(video) {
+  info(`start play video`);
+  const played = video && await video.play().then(() => true, () => false);
+  ok(played, "video has started playing");
+}
+
 function createCueAndAddCueToVideo(video) {
   let track = video.addTextTrack("subtitles");
   track.mode = "showing";
   let cue = new VTTCue(0, 5, "Test");
   track.addCue(cue);
   return cue;
 }
 
 function removeCueFromVideo(cue, video) {
   let track = video.textTracks[0];
   track.removeCue(cue);
 }
 
 async function waitUntilCueShows(cue) {
+  info(`wait until cue shows`);
   // cue has not been showed yet.
   cue = SpecialPowers.wrap(cue);
   if (!cue.getActive) {
     await once(cue, "enter");
   }
   ok(cue.getActive, `cue has been showed,`);
 }
 
-function checkIfCueHides(cue) {
+function checkIfCueHides(cue, video) {
   ok(!SpecialPowers.wrap(cue).getActive, `cue has been hidden.`);
+  ok(video.currentTime < cue.endTime,
+    `cue is removed at ${video.currentTime}s before reaching its endtime.`);
+}
+
+function endTestAndClearVideo(video) {
+  removeNodeAndSource(video);
+  SimpleTest.finish();
 }
 
 </script>
 </body>
 </html>