|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <title>Selecting from a list of tracks</title> |
| 5 | + <script src="media-controls.js"></script> |
| 6 | + <script src="media-file.js"></script> |
| 7 | + <script src="video-test.js"></script> |
| 8 | + <script> |
| 9 | + var captionsButtonCoordinates; |
| 10 | + |
| 11 | + if (window.testRunner) |
| 12 | + testRunner.dumpAsText(); |
| 13 | + |
| 14 | + function clickCCButton() |
| 15 | + { |
| 16 | + consoleWrite("*** Click the CC button."); |
| 17 | + eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]); |
| 18 | + eventSender.mouseDown(); |
| 19 | + eventSender.mouseUp(); |
| 20 | + } |
| 21 | + |
| 22 | + function startTest() |
| 23 | + { |
| 24 | + if (window.eventSender) { |
| 25 | + consoleWrite("*** Set the user language preference."); |
| 26 | + run("internals.setUserPreferredLanguages(['en'])"); |
| 27 | + |
| 28 | + try { |
| 29 | + captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggle-closed-captions-button"); |
| 30 | + } catch (exception) { |
| 31 | + failTest(exception.description); |
| 32 | + return; |
| 33 | + } |
| 34 | + clickCCButton(); |
| 35 | + window.setTimeout(turnCaptionsOn, 100); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + function selectCaptionMenuItem(index, nextStep) |
| 40 | + { |
| 41 | + var trackListElement; |
| 42 | + try { |
| 43 | + trackListElement = mediaControlsElement(internals.shadowRoot(video).firstChild, "-webkit-media-controls-closed-captions-track-list"); |
| 44 | + } catch (exception) { |
| 45 | + failTest(exception.description); |
| 46 | + return; |
| 47 | + } |
| 48 | + // Track list should have a <ul> with four <li> children (One of them is "Off"). |
| 49 | + var trackList = trackListElement.querySelector("ul"); |
| 50 | + if (!trackList) { |
| 51 | + failTest("Could not find a child ul element in track list menu"); |
| 52 | + return; |
| 53 | + } |
| 54 | + logResult(true, "Found tracklist menu and list of tracks"); |
| 55 | + var trackListItems = trackList.querySelectorAll("li"); |
| 56 | + if (!trackListItems) { |
| 57 | + failTest("Could not find a child li elements in track list menu"); |
| 58 | + return; |
| 59 | + } |
| 60 | + if (trackListItems.length != 4) { |
| 61 | + failTest("Expected 4 tracks in menu but found " + trackListItems.length); |
| 62 | + return; |
| 63 | + } |
| 64 | + logResult(true, "Found four available tracks in menu"); |
| 65 | + // Click on the selected item |
| 66 | + var selectedTrackItem = trackListItems[index]; |
| 67 | + var boundingRect = selectedTrackItem.getBoundingClientRect(); |
| 68 | + var x = boundingRect.left + boundingRect.width / 2; |
| 69 | + var y = boundingRect.top + boundingRect.height / 2; |
| 70 | + eventSender.mouseMoveTo(x, y); |
| 71 | + eventSender.mouseDown(); |
| 72 | + eventSender.mouseUp(); |
| 73 | + window.setTimeout(nextStep, 100); |
| 74 | + } |
| 75 | + |
| 76 | + function turnCaptionsOn() |
| 77 | + { |
| 78 | + consoleWrite("*** Turning captions on"); |
| 79 | + // Click on the third item, which is the second track (Off is the first item in the menu) |
| 80 | + selectCaptionMenuItem(2, testCaptionsVisible); |
| 81 | + } |
| 82 | + |
| 83 | + function testCaptionsVisible() |
| 84 | + { |
| 85 | + testExpected("video.textTracks.length", 3); |
| 86 | + consoleWrite("Track 0 should be disabled"); |
| 87 | + testExpected("video.textTracks[0].mode", "disabled"); |
| 88 | + consoleWrite("Track 1 should be showing"); |
| 89 | + testExpected("video.textTracks[1].mode", "showing"); |
| 90 | + consoleWrite("Track 2 should be disabled"); |
| 91 | + testExpected("video.textTracks[2].mode", "disabled"); |
| 92 | + testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem"); |
| 93 | + clickCCButton(); |
| 94 | + window.setTimeout(turnCaptionsOff, 100); |
| 95 | + } |
| 96 | + |
| 97 | + function turnCaptionsOff() |
| 98 | + { |
| 99 | + consoleWrite("*** Turning captions on"); |
| 100 | + // Click the Off button |
| 101 | + selectCaptionMenuItem(0, testCaptionsDisabled); |
| 102 | + } |
| 103 | + |
| 104 | + function testCaptionsDisabled() |
| 105 | + { |
| 106 | + testExpected("video.textTracks.length", 3); |
| 107 | + consoleWrite("Track 0 should be disabled"); |
| 108 | + testExpected("video.textTracks[0].mode", "disabled"); |
| 109 | + consoleWrite("Track 1 should be disabled"); |
| 110 | + testExpected("video.textTracks[1].mode", "disabled"); |
| 111 | + consoleWrite("Track 2 should be disabled"); |
| 112 | + testExpected("video.textTracks[2].mode", "disabled"); |
| 113 | + testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem"); |
| 114 | + testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem"); |
| 115 | + endTest(); |
| 116 | + } |
| 117 | + |
| 118 | + function start() |
| 119 | + { |
| 120 | + findMediaElement(); |
| 121 | + waitForEvent('canplaythrough', startTest); |
| 122 | + } |
| 123 | + </script> |
| 124 | + </head> |
| 125 | + |
| 126 | + <body onload="start()"> |
| 127 | + <p>Test that we are able to trigger the list of captions, and select from the list.</p> |
| 128 | + <video width="500" height="300" controls> |
| 129 | + <source src="content/test.mp4" type="video/mp4"> |
| 130 | + <source src="content/test.ogv" type="video/ogg"> |
| 131 | + <track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en"> |
| 132 | + <track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au"> |
| 133 | + <track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja"> |
| 134 | + </video> |
| 135 | + </body> |
| 136 | +</html> |
| 137 | + |
0 commit comments