| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 <title>Test closed caption button toggling.</title> | 5 <title>Test closed caption button toggling.</title> |
| 6 <script src=media-file.js></script> | 6 <script src=media-file.js></script> |
| 7 <script src=media-controls.js></script> | 7 <script src=media-controls.js></script> |
| 8 <script src=video-test.js></script> | 8 <script src=video-test.js></script> |
| 9 <script> | 9 <script> |
| 10 var captionsButtonElement; | 10 var captionsButtonElement; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 function removeHTMLTrackElement() | 40 function removeHTMLTrackElement() |
| 41 { | 41 { |
| 42 consoleWrite(""); | 42 consoleWrite(""); |
| 43 consoleWrite("** Remove DOM node representing the track element **")
; | 43 consoleWrite("** Remove DOM node representing the track element **")
; |
| 44 var htmlTrack = video.children[0]; | 44 var htmlTrack = video.children[0]; |
| 45 video.removeChild(htmlTrack); | 45 video.removeChild(htmlTrack); |
| 46 } | 46 } |
| 47 | 47 |
| 48 function testClosedCaptionsButtonVisibility(expected) | 48 function checkCaptionsDisplay() |
| 49 { | 49 { |
| 50 try { | 50 // When no tracks are loaded, this should report no text track conta
iner, |
| 51 captionsButtonElement = mediaControlsElement(internals.shadowRoo
t(video).firstChild, "-webkit-media-controls-toggle-closed-captions-button"); | 51 // when tracks are loaded but not visible, should report no cues vis
ible, |
| 52 captionsButtonCoordinates = mediaControlsButtonCoordinates(video
, "toggle-closed-captions-button"); | 52 // when tracks are loaded and visible, should properly check the tex
t. |
| 53 } catch (exception) { | 53 testExpected("textTrackDisplayElement(video, 'display').innerText",
"Lorem"); |
| 54 consoleWrite("Failed to find a closed captions button or its coo
rdinates: " + exception); | |
| 55 if (expected) | |
| 56 failTest(); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 consoleWrite(""); | |
| 61 if (expected == true) { | |
| 62 consoleWrite("** Caption button should be visible and enabled be
cause we have a captions track."); | |
| 63 testExpected("captionsButtonCoordinates[0]", 0, ">"); | |
| 64 testExpected("captionsButtonCoordinates[1]", 0, ">"); | |
| 65 testExpected("captionsButtonElement.disabled", false); | |
| 66 } else { | |
| 67 consoleWrite("** Caption button should not be visible as there a
re no caption tracks."); | |
| 68 testExpected("captionsButtonCoordinates[0]", 0, "<="); | |
| 69 testExpected("captionsButtonCoordinates[1]", 0, "<="); | |
| 70 } | |
| 71 } | 54 } |
| 72 | 55 |
| 73 function startTest() | 56 function startTest() |
| 74 { | 57 { |
| 75 if (!window.eventSender) { | 58 if (!window.eventSender) { |
| 76 consoleWrite("No eventSender found."); | 59 consoleWrite("No eventSender found."); |
| 77 failTest(); | 60 failTest(); |
| 78 } | 61 } |
| 79 | 62 |
| 80 findMediaElement(); | 63 findMediaElement(); |
| 81 testClosedCaptionsButtonVisibility(true); | 64 testClosedCaptionsButtonVisibility(true); |
| 82 | 65 |
| 83 consoleWrite(""); | 66 consoleWrite(""); |
| 84 consoleWrite("** The captions track should be listed in textTracks,
but not yet loaded. **"); | 67 consoleWrite("** The captions track should be listed in textTracks,
but not yet loaded. **"); |
| 85 testExpected("video.textTracks.length", 1); | 68 testExpected("video.textTracks.length", 1); |
| 86 testExpected("video.textTracks[0].mode", "disabled"); | 69 testExpected("video.textTracks[0].mode", "disabled"); |
| 87 checkCaptionsDisplay(); | 70 checkCaptionsDisplay(); |
| 88 | 71 |
| 89 consoleWrite(""); | 72 consoleWrite(""); |
| 90 consoleWrite("** Captions track should load and captions should beco
me visible after button is clicked **"); | 73 consoleWrite("** Captions track should load and captions should beco
me visible after button is clicked **"); |
| 74 |
| 75 // Note: the test flow continues with "testCCButtonToggling" when th
e |
| 76 // "load" event of the single TextTrack fires up. While the test str
ucture |
| 77 // might seem weird, this avoids timeouts. |
| 91 clickCCButton(); | 78 clickCCButton(); |
| 92 } | 79 } |
| 93 | 80 |
| 94 function clickCCButton() | 81 function testCCButtonToggling() |
| 95 { | |
| 96 consoleWrite("*** Click the CC button."); | |
| 97 eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButton
Coordinates[1]); | |
| 98 eventSender.mouseDown(); | |
| 99 eventSender.mouseUp(); | |
| 100 } | |
| 101 | |
| 102 function checkCaptionsDisplay() | |
| 103 { | |
| 104 // When no tracks are loaded, this should report no text track conta
iner, | |
| 105 // when tracks are loaded but not visible, should report no cues vis
ible, | |
| 106 // when tracks are loaded and visible, should properly check the tex
t. | |
| 107 testExpected("textTrackDisplayElement(video, 'display').innerText",
"Lorem"); | |
| 108 } | |
| 109 | |
| 110 function trackLoaded() | |
| 111 { | 82 { |
| 112 checkCaptionsDisplay(); | 83 checkCaptionsDisplay(); |
| 113 | 84 |
| 114 consoleWrite(""); | 85 consoleWrite(""); |
| 115 consoleWrite("** Captions should not be visible after button is clic
ked again **"); | 86 consoleWrite("** Captions should not be visible after button is clic
ked again **"); |
| 116 clickCCButton(); | 87 clickCCButton(); |
| 117 checkCaptionsDisplay(); | 88 checkCaptionsDisplay(); |
| 118 | 89 |
| 119 removeHTMLTrackElement(); | 90 removeHTMLTrackElement(); |
| 120 testClosedCaptionsButtonVisibility(false); | 91 testClosedCaptionsButtonVisibility(false); |
| 121 | 92 |
| 122 addUnloadableHTMLTrackElement(); | 93 addUnloadableHTMLTrackElement(); |
| 123 testClosedCaptionsButtonVisibility(true); | 94 testClosedCaptionsButtonVisibility(true); |
| 124 | 95 |
| 125 consoleWrite(""); | 96 consoleWrite(""); |
| 126 clickCCButton(); | 97 clickCCButton(); |
| 127 } | 98 } |
| 128 | 99 |
| 129 function trackError() | 100 function trackError() |
| 130 { | 101 { |
| 131 consoleWrite("** Track failed to load **"); | 102 consoleWrite("** Track failed to load **"); |
| 132 testClosedCaptionsButtonVisibility(false); | 103 testClosedCaptionsButtonVisibility(false); |
| 133 | 104 |
| 134 addTextTrackThroughJS(); | 105 addTextTrackThroughJS(); |
| 135 testClosedCaptionsButtonVisibility(true); | 106 testClosedCaptionsButtonVisibility(true); |
| 136 | 107 |
| 137 endTest(); | 108 endTest(); |
| 138 } | 109 } |
| 139 | 110 |
| 140 | |
| 141 function loaded() | 111 function loaded() |
| 142 { | 112 { |
| 143 findMediaElement(); | 113 findMediaElement(); |
| 144 consoleWrite("Set the user language preference so that the track wil
l be chosen when the CC button is clicked."); | |
| 145 run("internals.setUserPreferredLanguages(['en'])"); | |
| 146 | |
| 147 waitForEvent('canplaythrough', startTest); | 114 waitForEvent('canplaythrough', startTest); |
| 148 | 115 |
| 149 video.src = findMediaFile('video', 'content/counting'); | 116 video.src = findMediaFile('video', 'content/counting'); |
| 150 } | 117 } |
| 151 </script> | 118 </script> |
| 152 </head> | 119 </head> |
| 153 <body onload="loaded()"> | 120 <body onload="loaded()"> |
| 154 <p>Tests that the closed captions button, when toggled, updates the text tra
ck display area.</p> | 121 <p>Tests that the closed captions button, when toggled, updates the text tra
ck display area.</p> |
| 155 <video controls > | 122 <video controls> |
| 156 <track src="track/captions-webvtt/captions-fast.vtt" kind="captions" src
lang="en" onload="trackLoaded()"> | 123 <track src="track/captions-webvtt/captions-fast.vtt" kind="captions" onl
oad="testCCButtonToggling()"> |
| 157 </video> | 124 </video> |
| 158 | |
| 159 </body> | 125 </body> |
| 160 </html> | 126 </html> |
| OLD | NEW |