1 var captionsButtonElement;
2 var captionsButtonCoordinates;
4 // These reflect the values used to fade in/out the media controls. Should
5 // mirror the values 'fadeInDuration'/'fadeOutDuration' in MediaControlElements.cpp.
6 const controlsFadeInDurationMs = 100;
7 const controlsFadeOutDurationMs = 300;
9 // The timeout for the hide-after-no-mouse-movement behavior. Defined (and
10 // should mirror) the value 'timeWithoutMouseMovementBeforeHidingMediaControls'
11 // in MediaControls.cpp.
12 const controlsMouseMovementTimeoutMs = 3000;
14 function mediaControlsElement(first, id)
16 for (var element = first; element; element = element.nextSibling) {
17 // Not every element in the media controls has a shadow pseudo ID, eg. the
18 // text nodes for the time values, so guard against exceptions.
20 if (internals.shadowPseudoId(element) == id)
22 } catch (exception) { }
24 if (element.firstChild) {
25 var childElement = mediaControlsElement(element.firstChild, id);
34 function mediaControlsButton(element, id)
36 var controlID = "-webkit-media-controls-" + id;
37 var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID);
39 throw "Failed to find media control element ID '" + id + "'";
43 function mediaControlsButtonCoordinates(element, id)
45 var button = mediaControlsButton(element, id);
46 var buttonBoundingRect = button.getBoundingClientRect();
47 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2;
48 var y = buttonBoundingRect.top + buttonBoundingRect.height / 2;
49 return new Array(x, y);
52 function mediaControlsButtonDimensions(element, id)
54 var button = mediaControlsButton(element, id);
55 var buttonBoundingRect = button.getBoundingClientRect();
56 return new Array(buttonBoundingRect.width, buttonBoundingRect.height);
59 function textTrackDisplayElement(parentElement, id, cueNumber)
61 var textTrackContainerID = "-webkit-media-text-track-container";
62 var containerElement = mediaControlsElement(internals.shadowRoot(parentElement).firstChild, textTrackContainerID);
64 if (!containerElement)
65 throw "Failed to find text track container element";
68 return containerElement;
70 if (arguments[1] != 'cue')
71 var controlID = "-webkit-media-text-track-" + arguments[1];
73 var controlID = arguments[1];
75 var displayElement = mediaControlsElement(containerElement.firstChild, controlID);
77 throw "No text track cue with display id '" + controlID + "' is currently visible";
80 for (i = 0; i < cueNumber; i++)
81 displayElement = displayElement.nextSibling;
84 throw "There are not " + cueNumber + " text track cues visible";
87 return displayElement;
90 function testClosedCaptionsButtonVisibility(expected)
93 captionsButtonElement = mediaControlsElement(internals.shadowRoot(mediaElement).firstChild, "-webkit-media-controls-toggle-closed-captions-button");
94 captionsButtonCoordinates = mediaControlsButtonCoordinates(mediaElement, "toggle-closed-captions-button");
96 consoleWrite("Failed to find a closed captions button or its coordinates: " + exception);
103 if (expected == true) {
104 consoleWrite("** Caption button should be visible and enabled.");
105 testExpected("captionsButtonCoordinates[0]", 0, ">");
106 testExpected("captionsButtonCoordinates[1]", 0, ">");
107 testExpected("captionsButtonElement.disabled", false);
109 consoleWrite("** Caption button should not be visible.");
110 testExpected("captionsButtonCoordinates[0]", 0, "<=");
111 testExpected("captionsButtonCoordinates[1]", 0, "<=");
115 function clickCCButton()
117 consoleWrite("*** Click the CC button.");
118 eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
119 eventSender.mouseDown();
120 eventSender.mouseUp();
123 function runAfterControlsHidden(func, mediaElement)
125 if (mediaElement.paused)
126 throw "The media element is not playing";
128 // Compute the time it'll take until the controls will be invisible -
129 // assuming playback has been started prior to invoking this
130 // function. Allow 500ms slack.
131 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDurationMs + 500;
133 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - mediaElement.currentTime))
134 throw "The media will end before the controls have been hidden";
136 setTimeout(func, hideTimeoutMs);