OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Tests that a track appended after the initial track configuration does no
t change other tracks.</title> |
3 <head> | 3 <script src="../media-file.js"></script> |
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <video> |
| 7 <track kind="metadata" src="captions-webvtt/metadata.vtt"> |
| 8 </video> |
| 9 <script> |
| 10 async_test(function(t) { |
| 11 var video = document.querySelector('video'); |
5 | 12 |
6 <script src=../media-file.js></script> | 13 var track1 = document.querySelectorAll('track')[0]; |
7 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 | 14 assert_equals(track1.readyState, HTMLTrackElement.NONE); |
8 (Please avoid writing new tests using video-test.js) --> | 15 assert_equals(track1.track.mode, 'disabled'); |
9 <script src=../video-test.js></script> | |
10 <script> | |
11 | 16 |
12 function trackAdded() | 17 video.src = findMediaFile('video', '../content/test'); |
13 { | 18 video.oncanplaythrough = t.step_func(canplaythrough); |
14 consoleWrite("EVENT(" + event.type + ")"); | 19 track1.onload = t.step_func(metadataTrackLoaded); |
15 consoleWrite("<i>**check that metadata track state has not chang
ed<" + "/i>"); | |
16 testExpected("track1.readyState", HTMLTrackElement.LOADED); | |
17 testExpected("track1.track.mode", "hidden"); | |
18 consoleWrite("<i>**and that the caption track state has not chan
ged<" + "/i>"); | |
19 testExpected("track2.readyState", HTMLTrackElement.LOADED); | |
20 testExpected("track2.track.mode", "showing"); | |
21 consoleWrite("<i>**and that the subtitle track state is correct<
" + "/i>"); | |
22 testExpected("event.target", video.textTracks); | |
23 testExpected("event instanceof window.TrackEvent", true); | |
24 testExpected("event.track", video.textTracks[video.textTracks.le
ngth - 1]); | |
25 testExpected("track3.mode", "showing"); | |
26 | 20 |
27 consoleWrite(""); | 21 function canplaythrough() { |
28 endTest(); | 22 // check initial metadata track state. |
29 } | 23 assert_equals(track1.readyState, HTMLTrackElement.NONE); |
| 24 assert_equals(track1.track.mode, 'disabled'); |
| 25 assert_equals(track1.track.cues, null); |
| 26 track1.track.mode = 'hidden'; |
| 27 } |
30 | 28 |
31 function captionsTrackLoaded() | 29 function metadataTrackLoaded() { |
32 { | 30 // check metadata track state. |
33 consoleWrite("EVENT(load) -- <track kind='captions' >"); | 31 assert_equals(track1.readyState, HTMLTrackElement.LOADED); |
34 consoleWrite("<i>**check that metadata track state has not chang
ed<" + "/i>"); | 32 assert_equals(track1.track.mode, 'hidden'); |
35 testExpected("track1.readyState", HTMLTrackElement.LOADED); | 33 assert_equals(track1.track.cues.length, 12); |
36 testExpected("track1.track.mode", "hidden"); | 34 assert_equals(track1.track.cues[11].startTime, 22); |
37 consoleWrite("<i>**and that the caption track state is correct<"
+ "/i>"); | |
38 testExpected("track2.readyState", HTMLTrackElement.LOADED); | |
39 testExpected("track2.track.mode", "showing"); | |
40 consoleWrite(""); | |
41 | 35 |
42 video.textTracks.addEventListener("addtrack", trackAdded); | 36 // Add a caption track, configured to load automatically. |
43 consoleWrite("<i>**add a subtitle track with video.addTextTrack(
)<" + "/i>"); | 37 track2 = document.createElement('track'); |
44 run("track3 = video.addTextTrack('subtitles', 'Subtitle Track',
'en')"); | 38 track2.setAttribute('kind', 'captions'); |
45 run("track3.mode = 'showing'"); | 39 track2.setAttribute('default', 'default'); |
| 40 track2.setAttribute('src', 'captions-webvtt/tc004-webvtt-file.vtt'); |
| 41 track2.onload = t.step_func(captionsTrackLoaded); |
| 42 video.appendChild(track2); |
| 43 } |
46 | 44 |
47 consoleWrite(""); | 45 function captionsTrackLoaded() { |
48 } | 46 // Check that metadata track state has not changed. |
| 47 assert_equals(track1.readyState, HTMLTrackElement.LOADED); |
| 48 assert_equals(track1.track.mode, 'hidden'); |
| 49 // and that the caption track state is correct. |
| 50 assert_equals(track2.readyState, HTMLTrackElement.LOADED); |
| 51 assert_equals(track2.track.mode, 'showing'); |
49 | 52 |
50 function metadataTrackLoaded() | 53 video.textTracks.onaddtrack = t.step_func_done(trackAdded); |
51 { | 54 // add a subtitle track with video.addTextTrack(). |
52 consoleWrite("EVENT(load) -- <track kind='metadata' >"); | 55 track3 = video.addTextTrack('subtitles', 'Subtitle Track', 'en'); |
53 consoleWrite("<i>**check metadata track state<" + "/i>"); | 56 track3.mode = 'showing'; |
54 testExpected("track1.readyState", HTMLTrackElement.LOADED); | 57 } |
55 testExpected("track1.track.mode", "hidden"); | |
56 testExpected("track1.track.cues.length", 12); | |
57 testExpected("track1.track.cues[11].startTime", 22); | |
58 | 58 |
59 consoleWrite("<br><i>**add a caption track, configured to load a
utomatically<" + "/i>"); | 59 function trackAdded() { |
60 run("track2 = document.createElement('track')"); | 60 // Check that metadata track state has not changed. |
61 run("track2.setAttribute('kind', 'captions')"); | 61 assert_equals(track1.readyState, HTMLTrackElement.LOADED); |
62 run("track2.setAttribute('default', 'default')"); | 62 assert_equals(track1.track.mode, 'hidden'); |
63 run("track2.setAttribute('onload', 'captionsTrackLoaded()')"); | 63 // and that the caption track state has not changed. |
64 run("track2.setAttribute('src', 'captions-webvtt/tc004-webvtt-fi
le.vtt')"); | 64 assert_equals(track2.readyState, HTMLTrackElement.LOADED); |
65 run("video.appendChild(track2)"); | 65 assert_equals(track2.track.mode, 'showing'); |
66 | 66 // and that the subtitle track state is correct. |
67 consoleWrite(""); | 67 assert_equals(event.target, video.textTracks); |
68 } | 68 assert_true(event instanceof window.TrackEvent); |
69 | 69 assert_equals(event.track, video.textTracks[video.textTracks.length - 1]
); |
70 function canplaythrough() | 70 assert_equals(track3.mode, 'showing'); |
71 { | 71 } |
72 consoleWrite("EVENT(canplaythrough) -- <video>"); | 72 }); |
73 consoleWrite("<i>**check initial metadata track state<" + "/i>")
; | 73 </script> |
74 testExpected("track1.readyState", HTMLTrackElement.NONE); | |
75 testExpected("track1.track.mode", "disabled"); | |
76 testExpected("track1.track.cues", null); | |
77 run("track1.track.mode = 'hidden'"); | |
78 consoleWrite(""); | |
79 } | |
80 | |
81 function start() | |
82 { | |
83 consoleWrite("<br>EVENT(load) -- <body>"); | |
84 findMediaElement(); | |
85 | |
86 track1 = document.querySelectorAll('track')[0]; | |
87 testExpected("track1.readyState", HTMLTrackElement.NONE); | |
88 testExpected("track1.track.mode", "disabled"); | |
89 | |
90 video.src = findMediaFile("video", "../content/test"); | |
91 consoleWrite(""); | |
92 } | |
93 </script> | |
94 </head> | |
95 | |
96 <body onload="start()"> | |
97 <p>Tests that a track appended after the initial track configuration doe
s not change other tracks.</p> | |
98 <video oncanplaythrough="canplaythrough()" > | |
99 <track kind="metadata" src="captions-webvtt/metadata.vtt" onload="me
tadataTrackLoaded()"> | |
100 </video> | |
101 </body> | |
102 </html> | |
OLD | NEW |