blob: 65e1eac9a72149c07fa757eece1972550e660e0e [file] [log] [blame]
<!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("Clicking on a track in the tracks panel.");
const media = document.querySelector("video");
const shadowRoot = window.internals.shadowRoot(media);
let previouslySelectedTrack = 0;
media.addEventListener("play", () => {
media.pause();
dumpAudioTracksEnabledState();
media.audioTracks.addEventListener("change", audioTracksDidChange);
debug("");
shouldBecomeDifferent("shadowRoot.querySelector('button.tracks')", "null", () => {
shouldBecomeDifferent("shadowRoot.querySelector('button.tracks').getBoundingClientRect().width", "0", () => {
clickOnTracksButton(clickOnSecondAudioTrack);
});
});
});
function clickOnTracksButton(continuation)
{
window.requestAnimationFrame(() => {
debug("");
debug("Clicking on the tracks button");
clickOnElement(shadowRoot.lastChild.querySelector("button.tracks"));
window.requestAnimationFrame(continuation);
});
}
function clickOnSecondAudioTrack()
{
debug("Clicking on second audio track in tracks panel");
clickOnAudioTrackAtIndex(1);
}
function clickOnThirdAudioTrack()
{
debug("Clicking on third audio track in tracks panel");
clickOnAudioTrackAtIndex(2);
}
function clickOnAudioTrackAtIndex(index)
{
clickOnElement(shadowRoot.lastChild.querySelectorAll("li")[index]);
}
function clickOnElement(element)
{
const bounds = element.getBoundingClientRect();
eventSender.mouseMoveTo(bounds.left + 1, bounds.top + 1);
eventSender.mouseDown();
eventSender.mouseUp();
}
function audioTracksDidChange()
{
const newSelectedTrack = Array.from(media.audioTracks).findIndex(track => track.enabled);
if (previouslySelectedTrack === newSelectedTrack)
return;
previouslySelectedTrack = newSelectedTrack;
debug("");
debug("Obtained change event on media audio tracks");
dumpAudioTracksEnabledState();
if (media.audioTracks[1].enabled)
shadowRoot.querySelector(".tracks-panel").addEventListener("transitionend", event => clickOnTracksButton(clickOnThirdAudioTrack));
else if (media.audioTracks[2].enabled) {
debug("");
media.remove();
finishJSTest();
}
}
function dumpAudioTracksEnabledState()
{
Array.from(media.audioTracks).forEach((audioTrack, index) => {
debug(`media.audioTracks[${index}].enabled = ${media.audioTracks[index].enabled}`);
});
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>