Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / video-controls-captions.html
blob52baabface7f07333aba814db872748c72e2cdef
1 <!DOCTYPE html>
2 <html>
3 <head>
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>
9 <script>
10 var track;
12 function addTextTrackThroughJS()
14 consoleWrite("");
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()
22 consoleWrite("");
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()
40 consoleWrite("");
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");
54 function startTest()
56 if (!window.eventSender) {
57 consoleWrite("No eventSender found.");
58 failTest();
61 findMediaElement();
62 testClosedCaptionsButtonVisibility(true);
64 consoleWrite("");
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();
70 consoleWrite("");
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.
76 clickCCButton();
79 function testCCButtonToggling()
81 checkCaptionsDisplay();
83 consoleWrite("");
84 consoleWrite("** Captions should not be visible after button is clicked again **");
85 clickCCButton();
86 checkCaptionsDisplay();
88 removeHTMLTrackElement();
89 testClosedCaptionsButtonVisibility(false);
91 addUnloadableHTMLTrackElement();
92 testClosedCaptionsButtonVisibility(true);
94 consoleWrite("");
95 clickCCButton();
98 function trackError()
100 consoleWrite("** Track failed to load **");
101 testClosedCaptionsButtonVisibility(false);
103 addTextTrackThroughJS();
104 testClosedCaptionsButtonVisibility(true);
106 endTest();
109 function loaded()
111 findMediaElement();
112 waitForEvent('canplaythrough', startTest);
114 video.src = findMediaFile('video', 'content/counting');
116 </script>
117 </head>
118 <body onload="loaded()">
119 <p>Tests that the closed captions button, when toggled, updates the text track display area.</p>
120 <video controls>
121 <track src="track/captions-webvtt/captions-fast.vtt" kind="captions" onload="testCCButtonToggling()">
122 </video>
123 </body>
124 </html>