[email protected] | 24b5bce | 2013-04-20 22:41:12 | [diff] [blame] | 1 | var captionsButtonElement; |
| 2 | var captionsButtonCoordinates; |
[email protected] | aaa56ad | 2011-05-16 07:01:28 | [diff] [blame] | 3 | |
[email protected] | 7710fe0 | 2014-08-06 16:01:10 | [diff] [blame] | 4 | // As specified in mediaControls.css, this is how long it takes to fade out controls |
[email protected] | 9ae5e0f | 2014-06-03 13:26:21 | [diff] [blame] | 5 | const 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. |
| 10 | const controlsMouseMovementTimeoutMs = 3000; |
| 11 | |
[email protected] | 317d2e3c | 2014-12-17 11:27:58 | [diff] [blame] | 12 | function 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] | b069f0a | 2011-09-14 19:25:46 | [diff] [blame] | 21 | function mediaControlsElement(first, id) |
[email protected] | aaa56ad | 2011-05-16 07:01:28 | [diff] [blame] | 22 | { |
[email protected] | b069f0a | 2011-09-14 19:25:46 | [diff] [blame] | 23 | for (var element = first; element; element = element.nextSibling) { |
[email protected] | b069f0a | 2011-09-14 19:25:46 | [diff] [blame] | 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. |
| 26 | try { |
[email protected] | 21a41bf | 2011-12-19 17:25:37 | [diff] [blame] | 27 | if (internals.shadowPseudoId(element) == id) |
[email protected] | b069f0a | 2011-09-14 19:25:46 | [diff] [blame] | 28 | 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] | aaa56ad | 2011-05-16 07:01:28 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
[email protected] | b069f0a | 2011-09-14 19:25:46 | [diff] [blame] | 38 | return null; |
| 39 | } |
| 40 | |
[email protected] | 0b7e9cd | 2014-05-22 01:52:44 | [diff] [blame] | 41 | function mediaControlsButton(element, id) |
[email protected] | b069f0a | 2011-09-14 19:25:46 | [diff] [blame] | 42 | { |
[email protected] | 21a41bf | 2011-12-19 17:25:37 | [diff] [blame] | 43 | var controlID = "-webkit-media-controls-" + id; |
| 44 | var button = mediaControlsElement(internals.shadowRoot(element).firstChild, controlID); |
[email protected] | aaa56ad | 2011-05-16 07:01:28 | [diff] [blame] | 45 | if (!button) |
[email protected] | b069f0a | 2011-09-14 19:25:46 | [diff] [blame] | 46 | throw "Failed to find media control element ID '" + id + "'"; |
[email protected] | 0b7e9cd | 2014-05-22 01:52:44 | [diff] [blame] | 47 | return button; |
| 48 | } |
[email protected] | aaa56ad | 2011-05-16 07:01:28 | [diff] [blame] | 49 | |
[email protected] | 0b7e9cd | 2014-05-22 01:52:44 | [diff] [blame] | 50 | function mediaControlsButtonCoordinates(element, id) |
| 51 | { |
| 52 | var button = mediaControlsButton(element, id); |
[email protected] | aaa56ad | 2011-05-16 07:01:28 | [diff] [blame] | 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); |
| 57 | } |
[email protected] | 21a41bf | 2011-12-19 17:25:37 | [diff] [blame] | 58 | |
[email protected] | 3846eae | 2012-06-06 01:40:38 | [diff] [blame] | 59 | function mediaControlsButtonDimensions(element, id) |
| 60 | { |
[email protected] | 0b7e9cd | 2014-05-22 01:52:44 | [diff] [blame] | 61 | var button = mediaControlsButton(element, id); |
[email protected] | 3846eae | 2012-06-06 01:40:38 | [diff] [blame] | 62 | var buttonBoundingRect = button.getBoundingClientRect(); |
| 63 | return new Array(buttonBoundingRect.width, buttonBoundingRect.height); |
| 64 | } |
| 65 | |
[email protected] | 529b1a3b | 2012-04-19 16:27:25 | [diff] [blame] | 66 | function textTrackDisplayElement(parentElement, id, cueNumber) |
[email protected] | 21a41bf | 2011-12-19 17:25:37 | [diff] [blame] | 67 | { |
[email protected] | 222361b | 2012-03-12 04:47:28 | [diff] [blame] | 68 | var textTrackContainerID = "-webkit-media-text-track-container"; |
[email protected] | 7debb8b | 2013-06-04 01:21:41 | [diff] [blame] | 69 | var containerElement = mediaControlsElement(internals.shadowRoot(parentElement).firstChild, textTrackContainerID); |
[email protected] | 222361b | 2012-03-12 04:47:28 | [diff] [blame] | 70 | |
| 71 | if (!containerElement) |
| 72 | throw "Failed to find text track container element"; |
| 73 | |
| 74 | if (!id) |
| 75 | return containerElement; |
| 76 | |
[email protected] | 0a60b8a | 2013-03-11 20:43:43 | [diff] [blame] | 77 | if (arguments[1] != 'cue') |
| 78 | var controlID = "-webkit-media-text-track-" + arguments[1]; |
| 79 | else |
| 80 | var controlID = arguments[1]; |
[email protected] | 222361b | 2012-03-12 04:47:28 | [diff] [blame] | 81 | |
| 82 | var displayElement = mediaControlsElement(containerElement.firstChild, controlID); |
[email protected] | 21a41bf | 2011-12-19 17:25:37 | [diff] [blame] | 83 | if (!displayElement) |
[email protected] | 222361b | 2012-03-12 04:47:28 | [diff] [blame] | 84 | throw "No text track cue with display id '" + controlID + "' is currently visible"; |
| 85 | |
[email protected] | 529b1a3b | 2012-04-19 16:27:25 | [diff] [blame] | 86 | 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] | 21a41bf | 2011-12-19 17:25:37 | [diff] [blame] | 94 | return displayElement; |
[email protected] | 222361b | 2012-03-12 04:47:28 | [diff] [blame] | 95 | } |
[email protected] | 24b5bce | 2013-04-20 22:41:12 | [diff] [blame] | 96 | |
| 97 | function testClosedCaptionsButtonVisibility(expected) |
| 98 | { |
| 99 | try { |
[email protected] | 2514c4c | 2014-07-23 18:53:31 | [diff] [blame] | 100 | captionsButtonElement = mediaControlsButton(mediaElement, "toggle-closed-captions-button"); |
[email protected] | 0030bda | 2013-11-04 11:25:31 | [diff] [blame] | 101 | captionsButtonCoordinates = mediaControlsButtonCoordinates(mediaElement, "toggle-closed-captions-button"); |
[email protected] | 24b5bce | 2013-04-20 22:41:12 | [diff] [blame] | 102 | } 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] | 0030bda | 2013-11-04 11:25:31 | [diff] [blame] | 111 | consoleWrite("** Caption button should be visible and enabled."); |
[email protected] | 24b5bce | 2013-04-20 22:41:12 | [diff] [blame] | 112 | testExpected("captionsButtonCoordinates[0]", 0, ">"); |
| 113 | testExpected("captionsButtonCoordinates[1]", 0, ">"); |
| 114 | testExpected("captionsButtonElement.disabled", false); |
| 115 | } else { |
[email protected] | 0030bda | 2013-11-04 11:25:31 | [diff] [blame] | 116 | consoleWrite("** Caption button should not be visible."); |
[email protected] | 24b5bce | 2013-04-20 22:41:12 | [diff] [blame] | 117 | testExpected("captionsButtonCoordinates[0]", 0, "<="); |
| 118 | testExpected("captionsButtonCoordinates[1]", 0, "<="); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | function clickCCButton() |
| 123 | { |
| 124 | consoleWrite("*** Click the CC button."); |
| 125 | eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]); |
| 126 | eventSender.mouseDown(); |
| 127 | eventSender.mouseUp(); |
| 128 | } |
[email protected] | 9ae5e0f | 2014-06-03 13:26:21 | [diff] [blame] | 129 | |
[email protected] | e4f4ff2f | 2014-08-21 16:04:52 | [diff] [blame] | 130 | function runAfterHideMediaControlsTimerFired(func, mediaElement) |
[email protected] | 9ae5e0f | 2014-06-03 13:26:21 | [diff] [blame] | 131 | { |
| 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 | } |