1 var captionsButtonElement;
2 var captionsButtonCoordinates;
4 // As specified in mediaControls.css, this is how long it takes to fade out controls
5 const controlsFadeOutDurationMs = 300;
7 // The timeout for the hide-after-no-mouse-movement behavior. Defined (and
8 // should mirror) the value 'timeWithoutMouseMovementBeforeHidingMediaControls'
9 // in MediaControls.cpp.
10 const controlsMouseMovementTimeoutMs = 3000;
12 function overlayCastButton(videoElement)
14 var controlID = '-internal-media-controls-overlay-cast-button';
15 var button = mediaControlsElement(window.internals.shadowRoot(videoElement).firstChild, controlID);
17 throw 'Failed to find cast button';
21 function mediaControlsElement(first, id)
23 for (var element = first; element; element = element.nextSibling) {
24 // Not every element in the media controls has a shadow pseudo ID, eg. the
25 // text nodes for the time values, so guard against exceptions.
27 if (internals.shadowPseudoId(element) == id)
29 } catch (exception) { }
31 if (element.firstChild) {
32 var childElement = mediaControlsElement(element.firstChild, id);
41 function mediaControlsButton(element, id)
43 var controlID = "-webkit-media-controls-" + id;
44 var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID);
46 throw "Failed to find media control element ID '" + id + "'";
50 function mediaControlsButtonCoordinates(element, id)
52 var button = mediaControlsButton(element, id);
53 var buttonBoundingRect = button.getBoundingClientRect();
54 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2;
55 var y = buttonBoundingRect.top + buttonBoundingRect.height / 2;
56 return new Array(x, y);
59 function mediaControlsButtonDimensions(element, id)
61 var button = mediaControlsButton(element, id);
62 var buttonBoundingRect = button.getBoundingClientRect();
63 return new Array(buttonBoundingRect.width, buttonBoundingRect.height);
66 function textTrackDisplayElement(parentElement, id, cueNumber)
68 var textTrackContainerID = "-webkit-media-text-track-container";
69 var containerElement = mediaControlsElement(internals.shadowRoot(parentElement).firstChild, textTrackContainerID);
71 if (!containerElement)
72 throw "Failed to find text track container element";
75 return containerElement;
77 if (arguments[1] != 'cue')
78 var controlID = "-webkit-media-text-track-" + arguments[1];
80 var controlID = arguments[1];
82 var displayElement = mediaControlsElement(containerElement.firstChild, controlID);
84 throw "No text track cue with display id '" + controlID + "' is currently visible";
87 for (i = 0; i < cueNumber; i++)
88 displayElement = displayElement.nextSibling;
91 throw "There are not " + cueNumber + " text track cues visible";
94 return displayElement;
97 function testClosedCaptionsButtonVisibility(expected)
100 captionsButtonElement = mediaControlsButton(mediaElement, "toggle-closed-captions-button");
101 captionsButtonCoordinates = mediaControlsButtonCoordinates(mediaElement, "toggle-closed-captions-button");
102 } catch (exception) {
103 consoleWrite("Failed to find a closed captions button or its coordinates: " + exception);
110 if (expected == true) {
111 consoleWrite("** Caption button should be visible and enabled.");
112 testExpected("captionsButtonCoordinates[0]", 0, ">");
113 testExpected("captionsButtonCoordinates[1]", 0, ">");
114 testExpected("captionsButtonElement.disabled", false);
116 consoleWrite("** Caption button should not be visible.");
117 testExpected("captionsButtonCoordinates[0]", 0, "<=");
118 testExpected("captionsButtonCoordinates[1]", 0, "<=");
122 function clickCCButton()
124 consoleWrite("*** Click the CC button.");
125 eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
126 eventSender.mouseDown();
127 eventSender.mouseUp();
130 function runAfterHideMediaControlsTimerFired(func, mediaElement)
132 if (mediaElement.paused)
133 throw "The media element is not playing";
135 // Compute the time it'll take until the controls will be invisible -
136 // assuming playback has been started prior to invoking this
137 // function. Allow 500ms slack.
138 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDurationMs + 500;
140 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - mediaElement.currentTime))
141 throw "The media will end before the controls have been hidden";
143 setTimeout(func, hideTimeoutMs);