OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Tests that the closed captions button enables track switching.</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 <title>Test closed caption track selection functionality.</title> | 5 <script src="media-file.js"></script> |
6 <script src=media-file.js></script> | 6 <script src="media-controls.js"></script> |
7 <script src=media-controls.js></script> | 7 <video controls> |
8 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 8 <track src="track/captions-webvtt/captions-fast.vtt" kind="captions"> |
9 (Please avoid writing new tests using video-test.js) --> | 9 </video> |
10 <script src=video-test.js></script> | 10 <script> |
11 <script> | 11 async_test(function(t) { |
12 var track; | 12 var video = document.querySelector("video"); |
13 | 13 |
14 function addTextTrackThroughJS() | 14 video.oncanplaythrough = t.step_func(function() { |
15 { | 15 assert_true(isClosedCaptionsButtonVisible(video)); |
16 consoleWrite(""); | |
17 consoleWrite("** Add a text track through JS to the video element **
"); | |
18 var t = video.addTextTrack('captions', 'English', 'en'); | |
19 t.addCue(new VTTCue(0.0, 10.0, 'Some random caption text')); | |
20 } | |
21 | 16 |
22 function addUnloadableHTMLTrackElement() | 17 // The captions track should be listed in textTracks, but not yet loaded
. |
23 { | 18 assert_equals(video.textTracks.length, 1); |
24 consoleWrite(""); | 19 assert_equals(video.textTracks[0].mode, "disabled"); |
25 consoleWrite("** Add non-default text track through HTML with unload
able URI **"); | 20 assert_equals(textTrackContainerElement(video), null); |
26 | 21 |
27 track = document.createElement("track"); | 22 var track = document.querySelector("track"); |
28 track.setAttribute("kind", "captions"); | 23 track.onload = t.step_func(function() { |
29 track.setAttribute("srclang", "en"); | 24 assert_equals(textTrackCueElementByIndex(video, 0).innerText, "Lorem
"); |
30 track.setAttribute("src", "invalid.vtt"); | |
31 | 25 |
32 track.addEventListener("error", trackError); | 26 // Captions should not be visible after Off is clicked. |
| 27 turnClosedCaptionsOff(video); |
| 28 assert_equals(textTrackCueDisplayElement(video), null); |
33 | 29 |
34 video.appendChild(track); | 30 // Remove DOM node representing the track element. |
35 testExpected("track.readyState", HTMLTrackElement.NONE); | 31 track.remove(); |
36 testExpected("track.track.mode", "disabled"); | 32 assert_false(isClosedCaptionsButtonVisible(video)); |
37 testExpected("video.textTracks.length", 1); | |
38 } | |
39 | |
40 function removeHTMLTrackElement() | |
41 { | |
42 consoleWrite(""); | |
43 consoleWrite("** Remove DOM node representing the track element **")
; | |
44 var htmlTrack = video.children[0]; | |
45 video.removeChild(htmlTrack); | |
46 } | |
47 | |
48 function checkCaptionsDisplay() | |
49 { | |
50 // When no tracks are loaded, this should report no text track conta
iner, | |
51 // when tracks are loaded but not visible, should report no cues vis
ible, | |
52 // when tracks are loaded and visible, should properly check the tex
t. | |
53 testExpected("textTrackDisplayElement(video, 'display').innerText",
"Lorem"); | |
54 } | |
55 | |
56 function startTest() | |
57 { | |
58 if (!window.eventSender) { | |
59 consoleWrite("No eventSender found."); | |
60 failTest(); | |
61 } | |
62 | |
63 findMediaElement(); | |
64 testClosedCaptionsButtonVisibility(true); | |
65 | |
66 consoleWrite(""); | |
67 consoleWrite("** The captions track should be listed in textTracks,
but not yet loaded. **"); | |
68 testExpected("video.textTracks.length", 1); | |
69 testExpected("video.textTracks[0].mode", "disabled"); | |
70 checkCaptionsDisplay(); | |
71 | |
72 consoleWrite(""); | |
73 consoleWrite("** Captions track should load and captions should beco
me visible after a track is selected **"); | |
74 | |
75 // Note: the test flow continues with "testCCTrackSelectionFunctiona
lity" when the | |
76 // "load" event of the single TextTrack fires up. While the test str
ucture | |
77 // might seem weird, this avoids timeouts. | |
78 selectTextTrack(video, 0); | |
79 } | |
80 | |
81 function testCCTrackSelectionFunctionality() | |
82 { | |
83 checkCaptionsDisplay(); | |
84 | |
85 consoleWrite(""); | |
86 consoleWrite("** Captions should not be visible after Off is clicked
**"); | |
87 turnClosedCaptionsOff(video); | |
88 checkCaptionsDisplay(); | |
89 | |
90 removeHTMLTrackElement(); | |
91 testClosedCaptionsButtonVisibility(false); | |
92 | 33 |
93 addUnloadableHTMLTrackElement(); | 34 addUnloadableHTMLTrackElement(); |
94 testClosedCaptionsButtonVisibility(true); | 35 assert_true(isClosedCaptionsButtonVisible(video)); |
95 | 36 |
96 consoleWrite(""); | 37 clickTextTrackAtIndex(video, 0); |
97 selectTextTrack(video, 0); | 38 }); |
98 } | |
99 | 39 |
100 function trackError() | 40 // Captions track should load and captions should become visible after a
track is selected. |
101 { | 41 clickTextTrackAtIndex(video, 0); |
102 consoleWrite("** Track failed to load **"); | 42 }); |
103 testClosedCaptionsButtonVisibility(false); | |
104 | 43 |
105 addTextTrackThroughJS(); | 44 function addUnloadableHTMLTrackElement() { |
106 testClosedCaptionsButtonVisibility(true); | 45 // Add non-default text track through HTML with unloadable URI. |
| 46 var track = document.createElement("track"); |
| 47 track.setAttribute("kind", "captions"); |
| 48 track.setAttribute("srclang", "en"); |
| 49 track.setAttribute("src", "invalid.vtt"); |
107 | 50 |
108 endTest(); | 51 track.onerror = t.step_func_done(function() { |
109 } | 52 // Track failed to load. |
| 53 assert_false(isClosedCaptionsButtonVisible(video)); |
| 54 // Add a text track through JS to the video element. |
| 55 var newTrack = video.addTextTrack("captions", "English", "en"); |
| 56 assert_true(isClosedCaptionsButtonVisible(video)); |
| 57 }); |
110 | 58 |
111 function loaded() | 59 video.appendChild(track); |
112 { | 60 assert_equals(track.readyState, HTMLTrackElement.NONE); |
113 findMediaElement(); | 61 assert_equals(track.track.mode, "disabled"); |
114 waitForEvent('canplaythrough', startTest); | 62 assert_equals(video.textTracks.length, 1); |
| 63 } |
115 | 64 |
116 video.src = findMediaFile('video', 'content/counting'); | 65 video.src = findMediaFile("video", "content/counting"); |
117 } | 66 }); |
118 </script> | 67 </script> |
119 </head> | |
120 <body onload="loaded()"> | |
121 <p>Tests that the closed captions button enables track switching</p> | |
122 <video controls> | |
123 <track src="track/captions-webvtt/captions-fast.vtt" kind="captions" onl
oad="testCCTrackSelectionFunctionality()"> | |
124 </video> | |
125 </body> | |
126 </html> | |
OLD | NEW |