blob: b34c5fee88f0e2f54e1c9e70793c0e2089213cc8 [file] [log] [blame]
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<meta name="viewport" content="width=device-width">
<script src="../resources/media-controls-utils.js"></script>
<script src="../../../resources/ui-helper.js"></script>
<script src="../../../resources/js-test-pre.js"></script>
<body>
<video src="../../content/counting-subtitled.m4v" style="position: absolute; left: 0; top: 0; width: 600px;" autoplay controls muted playsinline></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);
window.internals.setMediaControlsMaximumRightContainerButtonCountOverride(media, 100); // A finite value larger than anything likely.
let contextmenu = null;
function subtitleTrack(language) {
return Array.from(media.textTracks).find((textTrack) => textTrack.kind === "subtitles" && textTrack.language === language);
}
function contextmenuItem(title) {
return contextmenu[0].children.find((item) => item.title === title);
}
media.addEventListener("play", () => {
media.pause();
shouldBecomeDifferent("shadowRoot.querySelector('button.tracks')", "null", () => {
shouldBecomeDifferent("shadowRoot.querySelector('button.tracks').getBoundingClientRect().width", "0", async () => {
debug("Setting mode to 'showing' for 'English' text track via JavaScript...");
subtitleTrack("en").mode = "showing";
{
debug("Tapping tracks button...");
await pressOnElement(shadowRoot.querySelector("button.tracks"));
contextmenu = await getTracksContextMenu();
shouldBeTrue("contextmenuItem('English').checked");
shouldBeUndefined("contextmenuItem('French').checked");
debug("Selecting 'French' text track...");
await UIHelper.chooseMenuAction("French");
await UIHelper.waitForContextMenuToHide();
}
shouldBe("subtitleTrack('en').mode", "'disabled'");
shouldBe("subtitleTrack('fr').mode", "'showing'");
{
debug("Tapping tracks button...");
await pressOnElement(shadowRoot.querySelector("button.tracks"));
contextmenu = await getTracksContextMenu();
shouldBeUndefined("contextmenuItem('English').checked");
shouldBeTrue("contextmenuItem('French').checked");
}
media.remove();
finishJSTest();
});
});
});
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>