Bug 1548923 - part3 : add test 'test_webvtt_update_display_after_adding_or_removing_cue.html'. r=jya
authoralwu <alwu@mozilla.com>
Wed, 08 May 2019 17:46:39 +0000
changeset 532074 1a3bb9e678fe8a4d999dbf399d4c3f4d5a1aa6b5
parent 532073 894e0713977b72b7045412e8b70898723a9aacde
child 532075 c64974ef15b2e1d1b58c8fa5ed16a641179af213
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1548923
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 1548923 - part3 : add test 'test_webvtt_update_display_after_adding_or_removing_cue.html'. r=jya Differential Revision: https://phabricator.services.mozilla.com/D29883
dom/media/test/mochitest.ini
dom/media/test/test_webvtt_update_display_after_adding_or_removing_cue.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -1261,16 +1261,19 @@ skip-if = android_version == '17' # andr
 skip-if = toolkit == 'android' # android(bug 1232305)
 [test_vp9_superframes.html]
 [test_vttparser.html]
 skip-if = android_version == '22' # android(bug 1368010)
 tags = webvtt
 [test_webvtt_empty_displaystate.html]
 skip-if = android_version == '17' || android_version == '22' # android(bug 1368010, bug 1372457)
 tags = webvtt
+[test_webvtt_update_display_after_adding_or_removing_cue.html]
+skip-if = android_version == '22' # android(bug 1368010)
+tags = webvtt
 [test_webvtt_positionalign.html]
 skip-if = android_version == '22' # android(bug 1368010)
 tags = webvtt
 [test_webvtt_seeking.html]
 skip-if = android_version == '22' # android(bug 1368010)
 tags = webvtt
 # The tests below contain backend-specific tests. Write backend independent
 # tests rather than adding to this list.
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_webvtt_update_display_after_adding_or_removing_cue.html
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>WebVTT : cue display should be updated immediately after adding or removing cue</title>
+  <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.
+ */
+async function startTest() {
+  const video = await createVideo();
+
+  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);
+
+  removeNodeAndSource(video);
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+onload = startTest;
+
+/**
+ * The following are test helper functions.
+ */
+async function createVideo() {
+  let video = document.createElement("video");
+  video.src = "gizmo.mp4";
+  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;
+}
+
+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) {
+  // 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) {
+  ok(!SpecialPowers.wrap(cue).getActive, `cue has been hidden.`);
+}
+
+</script>
+</body>
+</html>