4 <title>WebVTT : cues with overlapping time should be displayed correctly
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <script src=
"manifest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <video id =
"v" src=
"gizmo.mp4" controls
>
11 <script class=
"testbody" type=
"text/javascript">
13 * This test is used to ensure that when cues with overlapping times, the one
14 * with earlier end timestamp should disappear when the media time reaches its
15 * end time. In this test, we have two cues with overlapping time, when the video
16 * starts, both cues should be displayed. When the time passes
1 seconds, the
17 * first cue should disappear and the second cues should be still displayed.
20 { id:
0, startTime:
0, endTime:
1, text:
"This is cue 0."},
21 { id:
1, startTime:
0, endTime:
6, text:
"This is cue 1."},
24 var video = document.getElementById(
"v");
26 async function startTest() {
27 const cues = createCues();
30 await waitUntilCueIsShowing(cues[
0]);
31 await waitUntilCueIsShowing(cues[
1]);
33 await waitUntilCueIsHiding(cues[
0]);
34 await waitUntilCueIsShowing(cues[
1]);
35 IsVideoStillPlaying();
37 endTestAndClearVideo();
40 SimpleTest.waitForExplicitFinish();
44 * The following are test helper functions.
46 function createCues() {
47 let track = video.addTextTrack(
"subtitles");
48 track.mode =
"showing";
49 let cue0 = new VTTCue(CUES_INFO[
0].startTime, CUES_INFO[
0].endTime,
51 cue0.id = CUES_INFO[
0].id;
52 let cue1 = new VTTCue(CUES_INFO[
1].startTime, CUES_INFO[
1].endTime,
54 cue1.id = CUES_INFO[
1].id;
57 // Convert them to chrome objects in order to use chrome privilege APIs.
58 cue0 = SpecialPowers.wrap(cue0);
59 cue1 = SpecialPowers.wrap(cue1);
63 async function startVideo() {
64 info(`start play video`);
65 const played = video && await video.play().then(() =
> true, () =
> false);
66 ok(played,
"video has started playing");
69 async function waitUntilCueIsShowing(cue) {
70 info(`wait until cue ${cue.id} is showing`);
71 // cue has not been showing yet.
73 await once(cue,
"enter");
75 info(`video current time=${video.currentTime}`);
76 ok(cue.getActive, `cue ${cue.id} is showing`);
79 async function waitUntilCueIsHiding(cue) {
80 info(`wait until cue ${cue.id} is hiding`);
81 // cue has not been hidden yet.
83 await once(cue,
"exit");
85 info(`video current time=${video.currentTime}`);
86 ok(!cue.getActive, `cue ${cue.id} is hidding`);
89 function IsVideoStillPlaying() {
90 ok(!video.paused, `video is still playing, currentTime=${video.currentTime}`);
93 function endTestAndClearVideo() {
94 removeNodeAndSource(video);