| <!DOCTYPE html> |
| <script src="../../../resources/js-test-pre.js"></script> |
| <body> |
| <video src="../../content/CC+Subtitles.mov" style="position: absolute; left: 0; top: 0; width: 640px; height: 360px;" controls autoplay></video> |
| <script type="text/javascript"> |
| |
| window.jsTestIsAsync = true; |
| |
| description(`This test checks that setting an embedded text track as selected via the HTMLMediaElement JS APIs will correctly show this track as selected, and that selecting the |
| "Automatic (Recommended)" track will revert back to selecting that entry.`); |
| |
| const media = document.querySelector("video"); |
| const shadowRoot = window.internals.shadowRoot(media); |
| |
| media.addEventListener("play", () => { |
| media.pause(); |
| |
| shouldBecomeDifferent("shadowRoot.querySelector('button.tracks')", "null", () => { |
| shouldBecomeDifferent("shadowRoot.querySelector('button.tracks').getBoundingClientRect().width", "0", runTest); |
| }); |
| }); |
| |
| async function runTest() |
| { |
| // Start by selecting one of the text tracks using the media JS API. |
| // This will cause textTracksDidChange to be called for the first time. |
| media.textTracks[0].mode = "showing"; |
| |
| // Next, bring up the tracks menu by clicking on the tracks button. |
| await clickOnTracksButton(); |
| // Dump the state of the tracks menu for text tracks, which should show the first embedded text track as selected. |
| dumpTextTracksListNodes("Initial state"); |
| // Now, select the "Automatic (Recommended)" text track. |
| await clickOnTextTrackAtIndex(1); |
| // Wait for the selection to have gone through and the panel to have transitioned out of view. |
| await new Promise(resolve => shadowRoot.querySelector(".tracks-panel").addEventListener("transitionend", resolve, { once: true })); |
| |
| // Now, bring up the tracks menu again by clicking on the tracks button. |
| await clickOnTracksButton(); |
| // Dump the state of the tracks menu for text tracks, which should now show "Automatic (Recommended)" as selected. |
| dumpTextTracksListNodes("After picking auto track interactively"); |
| |
| finishTest(); |
| } |
| |
| function textTracksListNodes() |
| { |
| return shadowRoot.querySelectorAll(".tracks-panel section:last-of-type > ul > li"); |
| } |
| |
| function dumpTextTracksListNodes(msg) |
| { |
| debug(""); |
| debug(`=== ${msg} ===`); |
| debug(""); |
| Array.from(textTracksListNodes()).forEach(li => debug(`${li.classList.contains("selected") ? "[x]" : "[-]"} ${li.textContent}`)); |
| } |
| |
| async function clickOnTracksButton() |
| { |
| await new Promise(requestAnimationFrame); |
| clickOnElement(shadowRoot.lastChild.querySelector("button.tracks")); |
| await new Promise(requestAnimationFrame); |
| } |
| |
| function clickOnTextTrackAtIndex(index) |
| { |
| clickOnElement(textTracksListNodes()[index]); |
| } |
| |
| function clickOnElement(element) |
| { |
| const bounds = element.getBoundingClientRect(); |
| eventSender.mouseMoveTo(bounds.left + 1, bounds.top + 1); |
| eventSender.mouseDown(); |
| eventSender.mouseUp(); |
| } |
| |
| function finishTest() |
| { |
| debug(""); |
| media.remove(); |
| finishJSTest(); |
| } |
| |
| </script> |
| <script src="../../../resources/js-test-post.js"></script> |
| </body> |