Bug 1535005 - part2 : add test. r=jya
authorAlastor Wu <alwu@mozilla.com>
Wed, 01 May 2019 23:02:38 +0000
changeset 531018 f188012d248d72153c9a5068b38ba247dac4deb9
parent 531017 2885da69f0f3b60a9d500e4b9212f219b3476cdc
child 531019 5a20b5f43280e18252fc1637a82f7dfa69e920fd
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
bugs1535005
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 1535005 - part2 : add test. r=jya Differential Revision: https://phabricator.services.mozilla.com/D29095
dom/media/test/mochitest.ini
dom/media/test/test_webvtt_seeking.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -1264,17 +1264,19 @@ skip-if = toolkit == 'android' # android
 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_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.
 [test_can_play_type_webm.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
 [test_can_play_type_wave.html]
 skip-if = android_version == '17' # android(bug 1232305)
 [test_fragment_noplay.html]
 skip-if = android_version == '17' # android(bug 1232305)
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_webvtt_seeking.html
@@ -0,0 +1,108 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>WebVTT : cue should be displayed properly after seeking</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 the cue should be showed or hid correctly
+ * after seeking. In this test, we have two cues which are not overlapped, so
+ * there should only have one cue showing at a time.
+ */
+var CUES_INFO = [
+  { id: 0, startTime: 1, endTime: 3, text: "This is cue 0."},
+  { id: 1, startTime: 4, endTime: 6, text: "This is cue 1."},
+];
+
+async function startTest() {
+  const video = createVideo();
+  const cues = createCues(video);
+  await startVideo(video);
+
+  seekVideo(video, cues[0].startTime);
+  await waitUntilCueIsShowing(cues[0]);
+  checkActiveCueAndInactiveCue(cues[0], cues[1]);
+
+  seekVideo(video, cues[1].startTime);
+  await waitUntilCueIsShowing(cues[1]);
+  checkActiveCueAndInactiveCue(cues[1], cues[0]);
+
+  // seek forward again
+  seekVideo(video, cues[0].startTime);
+  await waitUntilCueIsShowing(cues[0]);
+  checkActiveCueAndInactiveCue(cues[0], cues[1]);
+
+  removeNodeAndSource(video);
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+onload = startTest;
+/**
+ * The following are test helper functions.
+ */
+function checkActiveCueAndInactiveCue(activeCue, inactiveCue) {
+  ok(activeCue.getActive,
+     `cue ${activeCue.id} [${activeCue.startTime}:${activeCue.endTime}] is active`);
+  ok(!inactiveCue.getActive,
+     `cue ${inactiveCue.id} [${inactiveCue.startTime}:${inactiveCue.endTime}] is inactive`);
+}
+
+function createVideo() {
+  let video = document.createElement("video");
+  video.src = "gizmo.mp4";
+  video.controls = true;
+  document.body.appendChild(video);
+  return video;
+}
+
+function createCues(video) {
+  let track = video.addTextTrack("subtitles");
+  track.mode = "showing";
+  let cue0 = new VTTCue(CUES_INFO[0].startTime, CUES_INFO[0].endTime,
+                        CUES_INFO[0].text);
+  cue0.id = CUES_INFO[0].id;
+  let cue1 = new VTTCue(CUES_INFO[1].startTime, CUES_INFO[1].endTime,
+                        CUES_INFO[1].text);
+  cue1.id = CUES_INFO[1].id;
+  track.addCue(cue0);
+  track.addCue(cue1);
+  // Convert them to chrome objects in order to use chrome privilege APIs.
+  cue0 = SpecialPowers.wrap(cue0);
+  cue1 = SpecialPowers.wrap(cue1);
+  return [cue0, cue1];
+}
+
+async function startVideo(video) {
+  info(`start play video`);
+  const played = video && await video.play().then(() => true, () => false);
+  ok(played, "video has started playing");
+}
+
+async function waitUntilCueIsShowing(cue) {
+  // cue has not been showing yet.
+  if (!cue.getActive) {
+    await once(cue, "enter");
+  }
+  info(`cue ${cue.id} is showing`);
+}
+
+async function seekVideo(video, time) {
+  ok(isInRange(time, CUES_INFO[0].startTime, CUES_INFO[0].endTime) ||
+     isInRange(time, CUES_INFO[1].startTime, CUES_INFO[1].endTime),
+     `seek target time ${time} is within the correct range`)
+  info(`seek video to ${time}`);
+  video.currentTime = time;
+  await once(video, "seeked");
+}
+
+function isInRange(value, lowerBound, higherBound) {
+  return lowerBound <= value && value <= higherBound;
+}
+</script>
+</body>
+</html>