summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/media-source/mediasource-redundant-seek.html
blob: 05eae9714f9c2aeb4e949b7fec3fee77608f7bb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<html>
    <head>
        <title>Test MediaSource behavior when receiving multiple seek requests during a pending seek.</title>
        <meta name="timeout" content="long">
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="mediasource-util.js"></script>
    </head>
    <body>
        <div id="log"></div>
        <script>

            mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
            {
                mediaElement.play();

                // Append all media data for complete playback.
                test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer end update.');
                test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA');
                test.expectEvent(mediaElement, 'playing', 'Playing media.');
                sourceBuffer.appendBuffer(mediaData);

                test.waitForExpectedEvents(function()
                {
                    var bufferedRanges = mediaElement.buffered;

                    assert_greater_than_equal(mediaElement.duration, 4.0, 'Duration is >= 4.0s');
                    assert_equals(bufferedRanges.length, 1, 'Just one buffered range');
                    assert_less_than_equal(bufferedRanges.start(0), 1.0, 'Buffered range starts <= 1.0s');
                    assert_greater_than_equal(bufferedRanges.end(0), 4.0, 'Buffered range ends >= 4.0s');

                    test.expectEvent(mediaElement, 'seeking', 'seeking');
                    test.expectEvent(mediaElement, 'timeupdate', 'timeupdate');
                    test.expectEvent(mediaElement, 'seeked', 'seeked');

                    // Request seeks.
                    mediaElement.currentTime = 1.0;

                    // This 'ephemeral' seek should be invisible to javascript, except any latency incurred in its processing.
                    mediaElement.currentTime = 3.0;

                    mediaElement.currentTime = 1.0;

                    assert_true(mediaElement.seeking, 'Element is seeking');
                    assert_equals(mediaElement.currentTime, 1.0, 'Element time is at last seek time');
                });

                test.waitForExpectedEvents(function()
                {
                    // No more seeking or seeked events should occur.
                    mediaElement.addEventListener('seeking', test.unreached_func("Unexpected event 'seeking'"));
                    mediaElement.addEventListener('seeked', test.unreached_func("Unexpected event 'seeked'"));

                    assert_false(mediaElement.seeking, 'Element is not seeking');
                    assert_greater_than_equal(mediaElement.currentTime, 1.0, 'Element time is at or after last seek time');
                    assert_less_than(mediaElement.currentTime, 3.0, 'Element time is before the ephemeral seek time');

                    var timeBeforeWait = mediaElement.currentTime;
                    test.waitForCurrentTimeChange(mediaElement, function()
                    {
                        // Time should have advanced a little, but not yet reached the ephemeral seek time.
                        assert_greater_than(mediaElement.currentTime, timeBeforeWait, 'Element time has increased');
                        assert_less_than(mediaElement.currentTime, 3.0, 'Element time is still before the ephemeral seek time');
                        test.done();
                    });
                });
            }, 'Test redundant fully prebuffered seek');

        </script>
    </body>
</html>