chromium/third_party/blink/web_tests/http/tests/media/video-seek-to-middle.html

<!DOCTYPE html>
<title>Test event dispatches and attribute changes for seek to middle.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<video></video>
<script>
async_test(function(t) {
    var video = document.querySelector("video");

    video.onended = t.unreached_func();

    var watcher = new EventWatcher(t, video, ["durationchange", "loadedmetadata", "loadeddata", "seeking", "timeupdate", "seeked"]);

    watcher.wait_for(["durationchange", "loadedmetadata", "loadeddata"]).then(t.step_func(function() {
        assert_less_than(video.currentTime, video.duration);
        assert_false(video.ended);
        assert_false(video.seeking);
        assert_false(video.paused);
        // Starting seek to middle by setting video.currentTime to half the duration.
        video.currentTime = video.duration / 2;
        testCommonAttributes(true);
        assert_less_than(video.currentTime, video.duration);
        assert_greater_than(video.currentTime, 0);
        return watcher.wait_for("seeking");
    })).then(t.step_func(function() {
        testCommonAttributes(true);
        return watcher.wait_for("timeupdate");
    })).then(t.step_func(function() {
        testCommonAttributes(false);
        return watcher.wait_for("seeked");
    })).then(t.step_func_done(function() {
        testCommonAttributes(false);
    }));

    function testCommonAttributes(seekingExpected) {
        assert_equals(video.seeking, seekingExpected);
        assert_false(video.ended);
        const tolerance = 0.0001;
        if (seekingExpected) {
            assert_approx_equals(video.currentTime, video.duration / 2, tolerance);
        } else {
            // If seek has completed, the currentTime may have advanced slightly
            // beyond the initial seek point since the video is not paused.
            assert_greater_than_equal(
                video.currentTime, video.duration / 2 - tolerance);
        }
        assert_false(video.paused);
    }

    video.src = "resources/test.ogv";
    video.play();
});
</script>