Index: third_party/WebKit/LayoutTests/media/media-controls.js |
diff --git a/third_party/WebKit/LayoutTests/media/media-controls.js b/third_party/WebKit/LayoutTests/media/media-controls.js |
index eb96ca8c85a578b982d225581f7f1e0f0d0dc993..809e297c0b9b059d38844db8180f6dea3b52891b 100644 |
--- a/third_party/WebKit/LayoutTests/media/media-controls.js |
+++ b/third_party/WebKit/LayoutTests/media/media-controls.js |
@@ -47,13 +47,18 @@ function mediaControlsButton(element, id) |
return button; |
} |
+function elementCoordinates(element) |
+{ |
+ var elementBoundingRect = element.getBoundingClientRect(); |
+ var x = elementBoundingRect.left + elementBoundingRect.width / 2; |
+ var y = elementBoundingRect.top + elementBoundingRect.height / 2; |
+ return new Array(x, y); |
+} |
+ |
function mediaControlsButtonCoordinates(element, id) |
{ |
var button = mediaControlsButton(element, id); |
- var buttonBoundingRect = button.getBoundingClientRect(); |
- var x = buttonBoundingRect.left + buttonBoundingRect.width / 2; |
- var y = buttonBoundingRect.top + buttonBoundingRect.height / 2; |
- return new Array(x, y); |
+ return elementCoordinates(button); |
} |
function mediaControlsButtonDimensions(element, id) |
@@ -119,14 +124,48 @@ function testClosedCaptionsButtonVisibility(expected) |
} |
} |
-function clickCCButton() |
+function clickAtCoordinates(x, y) |
{ |
- consoleWrite("*** Click the CC button."); |
- eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]); |
+ eventSender.mouseMoveTo(x, y); |
eventSender.mouseDown(); |
eventSender.mouseUp(); |
} |
+function clickCCButton() |
+{ |
+ consoleWrite("*** Click the CC button."); |
+ clickAtCoordinates(captionsButtonCoordinates[0], captionsButtonCoordinates[1]); |
+} |
+ |
+function textTrackListItemAtIndex(video, index) |
+{ |
+ var textTrackListElementID = "-internal-media-controls-text-track-list"; |
+ var textTrackListElement = mediaControlsElement(internals.shadowRoot(video).firstChild, textTrackListElementID); |
+ if (!textTrackListElement) |
+ throw "Failed to find text track list element"; |
+ |
+ var tracksSectionElement = textTrackListElement.lastChild; |
+ var trackListItems = tracksSectionElement.childNodes; |
+ for (var i = 0; i < trackListItems.length; i++) { |
+ var trackListItem = trackListItems[i]; |
+ if (trackListItem.firstChild.getAttribute("data-track-index") == index) |
+ return trackListItem; |
+ } |
+} |
+ |
+function selectTextTrack(video, index) |
+{ |
+ clickCCButton(); |
+ var trackListItemElement = textTrackListItemAtIndex(video, index); |
+ var trackListItemCoordinates = elementCoordinates(trackListItemElement); |
+ clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1]); |
+} |
+ |
+function turnClosedCaptionsOff(video) |
+{ |
+ selectTextTrack(video, -1); |
+} |
+ |
function runAfterHideMediaControlsTimerFired(func, mediaElement) |
{ |
if (mediaElement.paused) |