OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Tests TextTrack's addCue and removeCue.</title> |
3 <head> | 3 <script src="../../resources/testharness.js"></script> |
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 4 <script src="../../resources/testharnessreport.js"></script> |
5 <script> | |
6 async_test(function(t) { | |
7 var video = document.createElement("video"); | |
8 var trackElement = document.createElement("track"); | |
5 | 9 |
6 <script src=../media-file.js></script> | 10 trackElement.onload = t.step_func_done(function() { |
7 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 | 11 var cues = trackElement.track.cues; |
8 (Please avoid writing new tests using video-test.js) --> | 12 assert_equals(cues.length, 4); |
9 <script src=../video-test.js></script> | 13 assert_equals(cues.getCueById("1").startTime, 0); |
10 <script> | 14 assert_equals(cues[1].startTime, 31); |
15 assert_equals(cues[2].startTime, 61); | |
16 assert_equals(cues.getCueById("4").startTime, 121); | |
17 assert_object_equals(cues.getCueById("junk"), undefined); | |
11 | 18 |
12 var cues; | 19 var textCue = new VTTCue(33, 3.4, "Sausage?"); |
20 assert_equals(textCue.track, null); | |
21 assert_equals(textCue.id, ""); | |
22 assert_equals(textCue.startTime, 33); | |
23 assert_equals(textCue.endTime, 3.4); | |
24 assert_equals(textCue.pauseOnExit, false); | |
25 assert_equals(textCue.vertical, ""); | |
26 assert_equals(textCue.snapToLines, true); | |
27 assert_equals(textCue.line, "auto"); | |
28 assert_equals(textCue.position, "auto"); | |
29 assert_equals(textCue.size, 100); | |
30 assert_equals(textCue.align, "middle"); | |
13 | 31 |
14 function trackLoaded() | 32 assert_throws("NotFoundError", function() { trackElement.track.removeCue (textCue); }); |
15 { | |
16 var testTrack = document.getElementById('testTrack'); | |
17 cues = testTrack.track.cues; | |
18 | 33 |
19 consoleWrite("<br>*** Test cues loaded from the file."); | 34 trackElement.track.addCue(textCue); |
philipj_slow
2016/04/11 12:34:00
Can you add back these consoleWrite things as comm
Srirama
2016/04/11 13:34:24
Done.
| |
20 testExpected("cues.length", 4); | 35 assert_equals(textCue.track, trackElement.track); |
21 testExpected("cues.getCueById('1').startTime", 0); | 36 assert_equals(cues[1].startTime, 31); |
22 testExpected("cues[1].startTime", 31); | 37 assert_equals(cues[2].startTime, 33); |
23 testExpected("cues[2].startTime", 61); | 38 assert_equals(cues[3].startTime, 61); |
24 testExpected("cues.getCueById('4').startTime", 121); | |
25 testExpected("cues.getCueById('junk')", undefined); | |
26 | 39 |
27 consoleWrite("<br>*** Create a new cue, check values"); | 40 var newTrack = video.addTextTrack("subtitles", "French subtitles", "fr") ; |
28 run("textCue = new VTTCue(33, 3.4, 'Sausage?')"); | 41 newTrack.mode = "showing"; |
29 testExpected("textCue.track", null); | 42 newTrack.addCue(new VTTCue(0, 1, "Test!")); |
30 testExpected("textCue.id", ''); | 43 var newCue = newTrack.cues[0]; |
philipj_slow
2016/04/11 12:34:00
This could be simpler I think by just assigning ne
Srirama
2016/04/11 13:34:24
Done.
| |
31 testExpected("textCue.startTime", 33); | 44 assert_equals(newCue.track, newTrack); |
32 testExpected("textCue.endTime", 3.4); | 45 assert_equals(newCue.id, ""); |
33 testExpected("textCue.pauseOnExit", false); | 46 assert_equals(newCue.startTime, 0); |
34 testExpected("textCue.vertical", ""); | 47 assert_equals(newCue.endTime, 1); |
35 testExpected("textCue.snapToLines", true); | 48 assert_equals(newCue.pauseOnExit, false); |
36 testExpected("textCue.line", "auto"); | 49 assert_equals(newCue.vertical, ""); |
37 testExpected("textCue.position", "auto"); | 50 assert_equals(newCue.snapToLines, true); |
38 testExpected("textCue.size", 100); | 51 assert_equals(newCue.line, "auto"); |
39 testExpected("textCue.align", "middle"); | 52 assert_equals(newCue.position, "auto"); |
53 assert_equals(newCue.size, 100); | |
54 assert_equals(newCue.align, "middle"); | |
40 | 55 |
41 consoleWrite("<br>*** Remove the unadded track, make sure it thr ows correctly."); | 56 trackElement.track.removeCue(textCue); |
42 testException("testTrack.track.removeCue(textCue)", '"NotFoundEr ror: Failed to execute \'removeCue\' on \'TextTrack\': The specified cue is not listed in the TextTrack\'s list of cues."'); | 57 assert_equals(textCue.track, null); |
58 assert_equals(cues[1].startTime, 31); | |
59 assert_equals(cues[2].startTime, 61); | |
43 | 60 |
44 consoleWrite("<br>*** Add the new cue to a track, make sure it i s inserted correctly."); | 61 textCue = cues[2]; |
45 run("testTrack.track.addCue(textCue)"); | 62 trackElement.track.removeCue(textCue); |
46 testExpected("textCue.track", testTrack.track); | 63 assert_equals(textCue.track, null); |
47 testExpected("cues[1].startTime", 31); | 64 assert_equals(cues[1].startTime, 31); |
48 testExpected("cues[2].startTime", 33); | 65 assert_equals(cues[2].startTime, 121); |
49 testExpected("cues[3].startTime", 61); | |
50 | 66 |
51 consoleWrite("<br>*** create a new cue and add it to a track cre ated with video.addTextTrack, make sure it is inserted correctly."); | 67 assert_throws("NotFoundError", function() { trackElement.track.removeCue (textCue); }); |
52 findMediaElement(); | |
53 run('newTrack = video.addTextTrack("subtitles", "French subtitle s", "fr")'); | |
54 run('newTrack.mode = "showing"'); | |
55 run('newTrack.addCue(new VTTCue(0.0, 1.0, "Test!"))'); | |
56 run('newCue = newTrack.cues[0]'); | |
57 testExpected("newCue.track", newTrack); | |
58 testExpected("newCue.id", ""); | |
59 testExpected("newCue.startTime", 0.0); | |
60 testExpected("newCue.endTime", 1.0); | |
61 testExpected("newCue.pauseOnExit", false); | |
62 testExpected("newCue.vertical", ""); | |
63 testExpected("newCue.snapToLines", true); | |
64 testExpected("newCue.line", "auto"); | |
65 testExpected("newCue.position", "auto"); | |
66 testExpected("newCue.size", 100); | |
67 testExpected("newCue.align", "middle"); | |
68 | 68 |
69 consoleWrite("<br>*** Remove a cue created with addCue()."); | 69 trackElement.track.addCue(new VTTCue(0, 31, "I am first")); |
70 run("testTrack.track.removeCue(textCue)"); | 70 assert_equals(cues[0].startTime, 0); |
71 testExpected("textCue.track", null); | 71 assert_equals(cues[0].endTime, 31); |
72 testExpected("cues[1].startTime", 31); | 72 assert_equals(cues[1].startTime, 0); |
73 testExpected("cues[2].startTime", 61); | 73 assert_equals(cues[1].endTime, 30.5); |
74 assert_equals(cues[2].startTime, 31); | |
75 }); | |
74 | 76 |
75 consoleWrite("<br>*** Remove a cue added from the WebVTT file.") ; | 77 trackElement.src = "captions-webvtt/tc013-settings.vtt"; |
76 run("textCue = cues[2]"); | 78 trackElement.kind = "captions"; |
77 run("testTrack.track.removeCue(textCue)"); | 79 trackElement.default = true; |
78 testExpected("textCue.track", null); | 80 video.appendChild(trackElement); |
79 testExpected("cues[1].startTime", 31); | 81 }); |
80 testExpected("cues[2].startTime", 121); | 82 </script> |
81 | |
82 consoleWrite("<br>*** Try to remove the cue again."); | |
83 testDOMException("testTrack.track.removeCue(textCue)", "DOMExcep tion.NOT_FOUND_ERR"); | |
84 | |
85 consoleWrite("<br>*** Add a cue before all the existing cues."); | |
86 run("testTrack.track.addCue(new VTTCue(0, 31, 'I am first'))"); | |
87 testExpected("cues[0].startTime", 0); | |
88 testExpected("cues[0].endTime", 31); | |
89 testExpected("cues[1].startTime", 0); | |
90 testExpected("cues[1].endTime", 30.5); | |
91 testExpected("cues[2].startTime", 31); | |
92 endTest(); | |
93 } | |
94 | |
95 </script> | |
96 </head> | |
97 <body> | |
98 <p>Tests TextTrack's addCue and removeCue</p> | |
99 <video> | |
100 <track id="testTrack" src="captions-webvtt/tc013-settings.vtt" kind= "captions" onload="trackLoaded()" default> | |
101 </video> | |
102 </body> | |
103 </html> | |
OLD | NEW |