<script src="../../../../../resources/js-test-pre.js"></script>
<script src="/media-resources/modern-media-controls/resources/media-controls-loader.js"></script>
<body>
<video src="../../resources/hls/generate-vod.py?duration=8000" style="width: 320px; height: 240px;" controls></video>
<div id="shadow"></div>
<script type="text/javascript">

window.jsTestIsAsync = true;

description("Testing the <code>SkipBackSupport</code> behavior by clicking on the mute button.");

const shadowRoot = document.querySelector("div#shadow").attachShadow({ mode: "open" });
const media = document.querySelector("video");
const mediaController = createControls(shadowRoot, media, null);

let numberOfEvents = 0;
function mediaDidSeek()
{
    debug("Media seeked to currentTime = " + media.currentTime);

    numberOfEvents++;
    if (numberOfEvents == 3) {
        debug("");
        shadowRoot.host.remove();
        media.remove();
        finishJSTest();
        return;
    }

    debug("");
    debug("Dispatching click event to the skip back button");
    mediaController.controls.skipBackButton.element.click();
}

function mediaCanPlay()
{
    media.removeEventListener("canplaythrough", mediaCanPlay);
    media.addEventListener("seeked", mediaDidSeek);
    media.currentTime = 25;
}

media.addEventListener("canplaythrough", mediaCanPlay);

</script>
<script src="../../../../../resources/js-test-post.js"></script>
</body>
