OLD | NEW |
---|---|
1 var captionsButtonElement; | 1 var captionsButtonElement; |
2 var captionsButtonCoordinates; | 2 var captionsButtonCoordinates; |
3 | 3 |
4 // As specified in mediaControls.css, this is how long it takes to fade out cont rols | 4 // As specified in mediaControls.css, this is how long it takes to fade out cont rols |
5 const controlsFadeOutDurationMs = 300; | 5 const controlsFadeOutDurationMs = 300; |
6 | 6 |
7 // The timeout for the hide-after-no-mouse-movement behavior. Defined (and | 7 // The timeout for the hide-after-no-mouse-movement behavior. Defined (and |
8 // should mirror) the value 'timeWithoutMouseMovementBeforeHidingMediaControls' | 8 // should mirror) the value 'timeWithoutMouseMovementBeforeHidingMediaControls' |
9 // in MediaControls.cpp. | 9 // in MediaControls.cpp. |
10 const controlsMouseMovementTimeoutMs = 3000; | 10 const controlsMouseMovementTimeoutMs = 3000; |
(...skipping 29 matching lines...) Expand all Loading... | |
40 | 40 |
41 function mediaControlsButton(element, id) | 41 function mediaControlsButton(element, id) |
42 { | 42 { |
43 var controlID = "-webkit-media-controls-" + id; | 43 var controlID = "-webkit-media-controls-" + id; |
44 var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID); | 44 var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID); |
45 if (!button) | 45 if (!button) |
46 throw "Failed to find media control element ID '" + id + "'"; | 46 throw "Failed to find media control element ID '" + id + "'"; |
47 return button; | 47 return button; |
48 } | 48 } |
49 | 49 |
50 function elementCoordinates(element) | |
51 { | |
52 var elementBoundingRect = element.getBoundingClientRect(); | |
53 var x = elementBoundingRect.left + elementBoundingRect.width / 2; | |
54 var y = elementBoundingRect.top + elementBoundingRect.height / 2; | |
55 return new Array(x, y); | |
56 } | |
57 | |
50 function mediaControlsButtonCoordinates(element, id) | 58 function mediaControlsButtonCoordinates(element, id) |
51 { | 59 { |
52 var button = mediaControlsButton(element, id); | 60 var button = mediaControlsButton(element, id); |
53 var buttonBoundingRect = button.getBoundingClientRect(); | 61 return elementCoordinates(button); |
54 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2; | |
55 var y = buttonBoundingRect.top + buttonBoundingRect.height / 2; | |
56 return new Array(x, y); | |
57 } | 62 } |
58 | 63 |
59 function mediaControlsButtonDimensions(element, id) | 64 function mediaControlsButtonDimensions(element, id) |
60 { | 65 { |
61 var button = mediaControlsButton(element, id); | 66 var button = mediaControlsButton(element, id); |
62 var buttonBoundingRect = button.getBoundingClientRect(); | 67 var buttonBoundingRect = button.getBoundingClientRect(); |
63 return new Array(buttonBoundingRect.width, buttonBoundingRect.height); | 68 return new Array(buttonBoundingRect.width, buttonBoundingRect.height); |
64 } | 69 } |
65 | 70 |
66 function textTrackDisplayElement(parentElement, id, cueNumber) | 71 function textTrackDisplayElement(parentElement, id, cueNumber) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 testExpected("captionsButtonCoordinates[0]", 0, ">"); | 117 testExpected("captionsButtonCoordinates[0]", 0, ">"); |
113 testExpected("captionsButtonCoordinates[1]", 0, ">"); | 118 testExpected("captionsButtonCoordinates[1]", 0, ">"); |
114 testExpected("captionsButtonElement.disabled", false); | 119 testExpected("captionsButtonElement.disabled", false); |
115 } else { | 120 } else { |
116 consoleWrite("** Caption button should not be visible."); | 121 consoleWrite("** Caption button should not be visible."); |
117 testExpected("captionsButtonCoordinates[0]", 0, "<="); | 122 testExpected("captionsButtonCoordinates[0]", 0, "<="); |
118 testExpected("captionsButtonCoordinates[1]", 0, "<="); | 123 testExpected("captionsButtonCoordinates[1]", 0, "<="); |
119 } | 124 } |
120 } | 125 } |
121 | 126 |
127 function clickAtCoordinates(x, y) | |
128 { | |
129 eventSender.mouseMoveTo(x, y); | |
130 eventSender.mouseDown(); | |
131 eventSender.mouseUp(); | |
132 } | |
133 | |
122 function clickCCButton() | 134 function clickCCButton() |
123 { | 135 { |
124 consoleWrite("*** Click the CC button."); | 136 consoleWrite("*** Click the CC button."); |
125 eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordina tes[1]); | 137 clickAtCoordinates(captionsButtonCoordinates[0], captionsButtonCoordinates[1 ]); |
126 eventSender.mouseDown(); | 138 } |
127 eventSender.mouseUp(); | 139 |
140 function textTrackListItem(video, index) | |
fs
2016/02/23 13:16:43
...AtIndex? ...WithIndex?
srivats
2016/02/24 05:20:16
Done.
| |
141 { | |
142 var textTrackListElementID = "-internal-media-controls-text-track-list"; | |
143 var textTrackListElement = mediaControlsElement(internals.shadowRoot(video). firstChild, textTrackListElementID); | |
144 if (!textTrackListElement) | |
145 throw "Failed to find text track list element"; | |
146 | |
147 var tracksSectionElement = textTrackListElement.lastChild; | |
148 var trackListItems = tracksSectionElement.childNodes; | |
149 for (var i = 0; i < trackListItems.length; i++) { | |
150 var trackListItem = trackListItems[i]; | |
151 if (trackListItem.firstChild.getAttribute("data-track-index") == index) | |
152 return trackListItem; | |
153 } | |
154 } | |
155 | |
156 function selectTextTrack(video, index) | |
157 { | |
158 clickCCButton(); | |
159 var trackListItemElement = textTrackListItem(video, index); | |
160 var trackListItemCoordinates = elementCoordinates(trackListItemElement); | |
161 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1]) ; | |
162 } | |
163 | |
164 function turnClosedCaptionsOff(video) | |
165 { | |
166 selectTextTrack(video, -1); | |
128 } | 167 } |
129 | 168 |
130 function runAfterHideMediaControlsTimerFired(func, mediaElement) | 169 function runAfterHideMediaControlsTimerFired(func, mediaElement) |
131 { | 170 { |
132 if (mediaElement.paused) | 171 if (mediaElement.paused) |
133 throw "The media element is not playing"; | 172 throw "The media element is not playing"; |
134 | 173 |
135 // Compute the time it'll take until the controls will be invisible - | 174 // Compute the time it'll take until the controls will be invisible - |
136 // assuming playback has been started prior to invoking this | 175 // assuming playback has been started prior to invoking this |
137 // function. Allow 500ms slack. | 176 // function. Allow 500ms slack. |
138 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration Ms + 500; | 177 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration Ms + 500; |
139 | 178 |
140 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m ediaElement.currentTime)) | 179 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m ediaElement.currentTime)) |
141 throw "The media will end before the controls have been hidden"; | 180 throw "The media will end before the controls have been hidden"; |
142 | 181 |
143 setTimeout(func, hideTimeoutMs); | 182 setTimeout(func, hideTimeoutMs); |
144 } | 183 } |
OLD | NEW |