Change fast seek logic to prevent ping-ponging.
[WebKit-https.git] / LayoutTests / media / media-source / media-source-fastseek.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <title>mock-media-source</title>
5     <script src="mock-media-source.js"></script>
6     <script src="../video-test.js"></script>
7     <script>
8     var source;
9     var sourceBuffer;
10     var initSegment;
11     var samples;
12
13     if (window.internals)
14         internals.initializeMockMediaSource();
15
16     function runTest() {
17         findMediaElement();
18
19         source = new MediaSource();
20         testExpected('source.readyState', 'closed');
21
22         waitForEventOn(source, 'sourceopen', sourceOpen);
23         var videoSource = document.createElement('source');
24         videoSource.type = 'video/mock; codecs=mock';
25         videoSource.src = URL.createObjectURL(source);
26         video.appendChild(videoSource);
27     }
28
29     function sourceOpen() {
30         run('sourceBuffer = source.addSourceBuffer("video/mock; codecs=mock")');
31         waitForEventOn(sourceBuffer, 'updateend', loadSamples, false, true);
32         initSegment = makeAInit(8, [makeATrack(1, 'mock', TRACK_KIND.VIDEO)]);
33         run('sourceBuffer.appendBuffer(initSegment)');
34     }
35
36     function loadSamples() {
37         samples = concatenateSamples([
38             makeASample(0, 0, 1, 1, SAMPLE_FLAG.SYNC),
39             makeASample(1, 1, 1, 1, SAMPLE_FLAG.NONE),
40             makeASample(2, 2, 1, 1, SAMPLE_FLAG.NONE),
41             makeASample(3, 3, 1, 1, SAMPLE_FLAG.NONE),
42             makeASample(4, 4, 1, 1, SAMPLE_FLAG.SYNC),
43             makeASample(5, 5, 1, 1, SAMPLE_FLAG.NONE),
44             makeASample(6, 6, 1, 1, SAMPLE_FLAG.NONE),
45             makeASample(7, 7, 1, 1, SAMPLE_FLAG.NONE),
46         ]);
47         waitForEventOn(sourceBuffer, 'updateend', play, false, true);
48         run('sourceBuffer.appendBuffer(samples)');
49     }
50
51     function play() {
52         waitForEvent('ended', endTest);
53         run('source.duration = 8');
54         run('source.endOfStream()');
55         waitForEventOnce('seeked', seeked1);
56         run('video.currentTime = 1');
57     }
58
59     function seeked1() {
60         testExpected('video.currentTime.toFixed(1)', 1);
61         waitForEventOnce('seeked', seeked2);
62         run('video.fastSeek(5)');
63     }
64
65     function seeked2() {
66         testExpected('video.currentTime.toFixed(1)', 4);
67         waitForEventOnce('seeked', seeked3);
68         run('video.currentTime = 3');
69     }
70
71     function seeked3() {
72         testExpected('video.currentTime.toFixed(1)', 3);
73         waitForEventOnce('seeked', seeked4);
74         run('video.fastSeek(2)');
75     }
76
77     function seeked4() {
78         testExpected('video.currentTime.toFixed(1)', 0);
79         endTest();
80     }
81     
82     </script>
83 </head>
84 <body onload="runTest()">
85     <video></video>
86 </body>
87 </html>