4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
5 <title>Test closed caption button toggling.
</title>
6 <script src=media-file.js
></script>
7 <script src=media-controls.js
></script>
8 <script src=video-test.js
></script>
12 function addTextTrackThroughJS()
15 consoleWrite("** Add a text track through JS to the video element **");
16 var t
= video
.addTextTrack('captions', 'English', 'en');
17 t
.addCue(new VTTCue(0.0, 10.0, 'Some random caption text'));
20 function addUnloadableHTMLTrackElement()
23 consoleWrite("** Add non-default text track through HTML with unloadable URI **");
25 track
= document
.createElement("track");
26 track
.setAttribute("kind", "captions");
27 track
.setAttribute("srclang", "en");
28 track
.setAttribute("src", "invalid.vtt");
30 track
.addEventListener("error", trackError
);
32 video
.appendChild(track
);
33 testExpected("track.readyState", HTMLTrackElement
.NONE
);
34 testExpected("track.track.mode", "disabled");
35 testExpected("video.textTracks.length", 1);
38 function removeHTMLTrackElement()
41 consoleWrite("** Remove DOM node representing the track element **");
42 var htmlTrack
= video
.children
[0];
43 video
.removeChild(htmlTrack
);
46 function checkCaptionsDisplay()
48 // When no tracks are loaded, this should report no text track container,
49 // when tracks are loaded but not visible, should report no cues visible,
50 // when tracks are loaded and visible, should properly check the text.
51 testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
56 if (!window
.eventSender
) {
57 consoleWrite("No eventSender found.");
62 testClosedCaptionsButtonVisibility(true);
65 consoleWrite("** The captions track should be listed in textTracks, but not yet loaded. **");
66 testExpected("video.textTracks.length", 1);
67 testExpected("video.textTracks[0].mode", "disabled");
68 checkCaptionsDisplay();
71 consoleWrite("** Captions track should load and captions should become visible after button is clicked **");
73 // Note: the test flow continues with "testCCButtonToggling" when the
74 // "load" event of the single TextTrack fires up. While the test structure
75 // might seem weird, this avoids timeouts.
79 function testCCButtonToggling()
81 checkCaptionsDisplay();
84 consoleWrite("** Captions should not be visible after button is clicked again **");
86 checkCaptionsDisplay();
88 removeHTMLTrackElement();
89 testClosedCaptionsButtonVisibility(false);
91 addUnloadableHTMLTrackElement();
92 testClosedCaptionsButtonVisibility(true);
100 consoleWrite("** Track failed to load **");
101 testClosedCaptionsButtonVisibility(false);
103 addTextTrackThroughJS();
104 testClosedCaptionsButtonVisibility(true);
112 waitForEvent('canplaythrough', startTest
);
114 video
.src
= findMediaFile('video', 'content/counting');
118 <body onload=
"loaded()">
119 <p>Tests that the closed captions button, when toggled, updates the text track display area.
</p>
121 <track src=
"track/captions-webvtt/captions-fast.vtt" kind=
"captions" onload=
"testCCButtonToggling()">