OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Tests that tracks can be turned on and off through the track selection me
nu.</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 on and off.</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></video> |
8 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 8 <script> |
9 (Please avoid writing new tests using video-test.js) --> | 9 async_test(function(t) { |
10 <script src=video-test.js></script> | 10 var text = ["First", "Second", "Third"]; |
11 <script> | 11 var video = document.querySelector("video"); |
12 var text = ["First", "Second", "Third"]; | |
13 var displayElement; | |
14 | 12 |
15 function addTextTrack() | 13 video.oncanplaythrough = t.step_func_done(function() { |
16 { | 14 var track = video.addTextTrack("captions"); |
17 var track = video.addTextTrack('captions'); | |
18 | 15 |
19 for (var i = 0; i < 3; i++) { | 16 for (var i = 0; i < 3; i++) { |
20 var cue = new VTTCue(0, 120, text[i]); | 17 var cue = new VTTCue(0, 120, text[i]); |
21 track.addCue(cue); | 18 track.addCue(cue); |
22 } | |
23 } | 19 } |
| 20 assert_true(isClosedCaptionsButtonVisible(video)); |
24 | 21 |
25 function checkCaptionsDisplay() | 22 // The captions track should be listed in textTracks, but not yet loaded
. |
26 { | 23 assert_equals(video.textTracks.length, 1); |
27 for (var i = 0; i < 3; i++) { | 24 assert_equals(video.textTracks[0].mode, "hidden"); |
28 try { | 25 checkCaptionsHidden(); |
29 displayElement = textTrackDisplayElement(video, "display", i
); | 26 |
30 testExpected("displayElement.innerText", text[i]); | 27 // Captions track should become visible after the track is selected. |
31 } catch (e) { | 28 clickTextTrackAtIndex(video, 0); |
32 consoleWrite(e); | 29 checkCaptionsVisible(); |
33 } | 30 |
34 } | 31 // Captions should not be visible after they're turned off through the m
enu. |
| 32 turnClosedCaptionsOff(video); |
| 33 checkCaptionsHidden(); |
| 34 |
| 35 // Captions track should become visible after the track is selected agai
n. |
| 36 clickTextTrackAtIndex(video, 0); |
| 37 checkCaptionsVisible(); |
| 38 }); |
| 39 |
| 40 function checkCaptionsVisible() { |
| 41 for (var i = 0; i < 3; i++) { |
| 42 var cue = textTrackDisplayElement(video, "display", i); |
| 43 assert_equals(cue.innerText, text[i]); |
35 } | 44 } |
| 45 } |
36 | 46 |
37 function startTest() | 47 function checkCaptionsHidden() { |
38 { | 48 for (var i = 0; i < 3; i++) |
39 if (!window.eventSender) { | 49 assert_throws(null, function() { textTrackDisplayElement(video, "dis
play", i); }); |
40 consoleWrite("No eventSender found."); | 50 } |
41 failTest(); | |
42 } | |
43 | 51 |
44 addTextTrack(); | 52 video.src = findMediaFile("video", "content/counting"); |
45 | 53 }); |
46 findMediaElement(); | 54 </script> |
47 testClosedCaptionsButtonVisibility(true); | |
48 | |
49 consoleWrite(""); | |
50 consoleWrite("** The captions track should be listed in textTracks,
but not yet loaded. **"); | |
51 testExpected("video.textTracks.length", 1); | |
52 testExpected("video.textTracks[0].mode", "hidden"); | |
53 checkCaptionsDisplay(); | |
54 | |
55 consoleWrite(""); | |
56 consoleWrite("** Captions track should become visible after the trac
k is selected **"); | |
57 selectTextTrack(video, 0); | |
58 checkCaptionsDisplay(); | |
59 | |
60 consoleWrite(""); | |
61 consoleWrite("** Captions should not be visible after they're turned
off through the menu **"); | |
62 turnClosedCaptionsOff(video); | |
63 checkCaptionsDisplay(); | |
64 | |
65 consoleWrite(""); | |
66 consoleWrite("** Captions track should become visible after the trac
k is selected again **"); | |
67 selectTextTrack(video, 0); | |
68 checkCaptionsDisplay(); | |
69 | |
70 consoleWrite(""); | |
71 endTest(); | |
72 } | |
73 | |
74 function loaded() | |
75 { | |
76 findMediaElement(); | |
77 waitForEvent('canplaythrough', startTest); | |
78 | |
79 video.src = findMediaFile('video', 'content/counting'); | |
80 } | |
81 </script> | |
82 </head> | |
83 <body onload="loaded()"> | |
84 <p>Tests that tracks can be turned on and off through the track selection me
nu</p> | |
85 <video controls></video> | |
86 </body> | |
87 </html> | |
OLD | NEW |