blob: eb96ca8c85a578b982d225581f7f1e0f0d0dc993 [file] [log] [blame]
[email protected]24b5bce2013-04-20 22:41:121var captionsButtonElement;
2var captionsButtonCoordinates;
[email protected]aaa56ad2011-05-16 07:01:283
[email protected]7710fe02014-08-06 16:01:104// As specified in mediaControls.css, this is how long it takes to fade out controls
[email protected]9ae5e0f2014-06-03 13:26:215const controlsFadeOutDurationMs = 300;
6
7// The timeout for the hide-after-no-mouse-movement behavior. Defined (and
8// should mirror) the value 'timeWithoutMouseMovementBeforeHidingMediaControls'
9// in MediaControls.cpp.
10const controlsMouseMovementTimeoutMs = 3000;
11
[email protected]317d2e3c2014-12-17 11:27:5812function overlayCastButton(videoElement)
13{
14 var controlID = '-internal-media-controls-overlay-cast-button';
15 var button = mediaControlsElement(window.internals.shadowRoot(videoElement).firstChild, controlID);
16 if (!button)
17 throw 'Failed to find cast button';
18 return button;
19}
20
[email protected]b069f0a2011-09-14 19:25:4621function mediaControlsElement(first, id)
[email protected]aaa56ad2011-05-16 07:01:2822{
[email protected]b069f0a2011-09-14 19:25:4623 for (var element = first; element; element = element.nextSibling) {
[email protected]b069f0a2011-09-14 19:25:4624 // 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.
26 try {
[email protected]21a41bf2011-12-19 17:25:3727 if (internals.shadowPseudoId(element) == id)
[email protected]b069f0a2011-09-14 19:25:4628 return element;
29 } catch (exception) { }
30
31 if (element.firstChild) {
32 var childElement = mediaControlsElement(element.firstChild, id);
33 if (childElement)
34 return childElement;
[email protected]aaa56ad2011-05-16 07:01:2835 }
36 }
37
[email protected]b069f0a2011-09-14 19:25:4638 return null;
39}
40
[email protected]0b7e9cd2014-05-22 01:52:4441function mediaControlsButton(element, id)
[email protected]b069f0a2011-09-14 19:25:4642{
[email protected]21a41bf2011-12-19 17:25:3743 var controlID = "-webkit-media-controls-" + id;
44 var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID);
[email protected]aaa56ad2011-05-16 07:01:2845 if (!button)
[email protected]b069f0a2011-09-14 19:25:4646 throw "Failed to find media control element ID '" + id + "'";
[email protected]0b7e9cd2014-05-22 01:52:4447 return button;
48}
[email protected]aaa56ad2011-05-16 07:01:2849
[email protected]0b7e9cd2014-05-22 01:52:4450function mediaControlsButtonCoordinates(element, id)
51{
52 var button = mediaControlsButton(element, id);
[email protected]aaa56ad2011-05-16 07:01:2853 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);
57}
[email protected]21a41bf2011-12-19 17:25:3758
[email protected]3846eae2012-06-06 01:40:3859function mediaControlsButtonDimensions(element, id)
60{
[email protected]0b7e9cd2014-05-22 01:52:4461 var button = mediaControlsButton(element, id);
[email protected]3846eae2012-06-06 01:40:3862 var buttonBoundingRect = button.getBoundingClientRect();
63 return new Array(buttonBoundingRect.width, buttonBoundingRect.height);
64}
65
[email protected]529b1a3b2012-04-19 16:27:2566function textTrackDisplayElement(parentElement, id, cueNumber)
[email protected]21a41bf2011-12-19 17:25:3767{
[email protected]222361b2012-03-12 04:47:2868 var textTrackContainerID = "-webkit-media-text-track-container";
[email protected]7debb8b2013-06-04 01:21:4169 var containerElement = mediaControlsElement(internals.shadowRoot(parentElement).firstChild, textTrackContainerID);
[email protected]222361b2012-03-12 04:47:2870
71 if (!containerElement)
72 throw "Failed to find text track container element";
73
74 if (!id)
75 return containerElement;
76
[email protected]0a60b8a2013-03-11 20:43:4377 if (arguments[1] != 'cue')
78 var controlID = "-webkit-media-text-track-" + arguments[1];
79 else
80 var controlID = arguments[1];
[email protected]222361b2012-03-12 04:47:2881
82 var displayElement = mediaControlsElement(containerElement.firstChild, controlID);
[email protected]21a41bf2011-12-19 17:25:3783 if (!displayElement)
[email protected]222361b2012-03-12 04:47:2884 throw "No text track cue with display id '" + controlID + "' is currently visible";
85
[email protected]529b1a3b2012-04-19 16:27:2586 if (cueNumber) {
87 for (i = 0; i < cueNumber; i++)
88 displayElement = displayElement.nextSibling;
89
90 if (!displayElement)
91 throw "There are not " + cueNumber + " text track cues visible";
92 }
93
[email protected]21a41bf2011-12-19 17:25:3794 return displayElement;
[email protected]222361b2012-03-12 04:47:2895}
[email protected]24b5bce2013-04-20 22:41:1296
97function testClosedCaptionsButtonVisibility(expected)
98{
99 try {
[email protected]2514c4c2014-07-23 18:53:31100 captionsButtonElement = mediaControlsButton(mediaElement, "toggle-closed-captions-button");
[email protected]0030bda2013-11-04 11:25:31101 captionsButtonCoordinates = mediaControlsButtonCoordinates(mediaElement, "toggle-closed-captions-button");
[email protected]24b5bce2013-04-20 22:41:12102 } catch (exception) {
103 consoleWrite("Failed to find a closed captions button or its coordinates: " + exception);
104 if (expected)
105 failTest();
106 return;
107 }
108
109 consoleWrite("");
110 if (expected == true) {
[email protected]0030bda2013-11-04 11:25:31111 consoleWrite("** Caption button should be visible and enabled.");
[email protected]24b5bce2013-04-20 22:41:12112 testExpected("captionsButtonCoordinates[0]", 0, ">");
113 testExpected("captionsButtonCoordinates[1]", 0, ">");
114 testExpected("captionsButtonElement.disabled", false);
115 } else {
[email protected]0030bda2013-11-04 11:25:31116 consoleWrite("** Caption button should not be visible.");
[email protected]24b5bce2013-04-20 22:41:12117 testExpected("captionsButtonCoordinates[0]", 0, "<=");
118 testExpected("captionsButtonCoordinates[1]", 0, "<=");
119 }
120}
121
122function clickCCButton()
123{
124 consoleWrite("*** Click the CC button.");
125 eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
126 eventSender.mouseDown();
127 eventSender.mouseUp();
128}
[email protected]9ae5e0f2014-06-03 13:26:21129
[email protected]e4f4ff2f2014-08-21 16:04:52130function runAfterHideMediaControlsTimerFired(func, mediaElement)
[email protected]9ae5e0f2014-06-03 13:26:21131{
132 if (mediaElement.paused)
133 throw "The media element is not playing";
134
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;
139
140 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - mediaElement.currentTime))
141 throw "The media will end before the controls have been hidden";
142
143 setTimeout(func, hideTimeoutMs);
144}