Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / media-source / mediasource-sequencemode-append-buffer.html
blob80d5281f6984d252f287835fd609877acbc51db0
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/w3c/resources/testharness.js"></script>
5 <script src="/w3c/resources/testharnessreport.js"></script>
6 <script src="mediasource-util.js"></script>
7 <link rel='stylesheet' href='/w3c/resources/testharness.css'>
8 </head>
9 <body>
10 <div id="log"></div>
11 <script>
12 function mediasource_sequencemode_test(testFunction, description, options)
14 return mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
16 assert_greater_than(segmentInfo.media.length, 3, 'at least 3 media segments for supported type');
17 test.failOnEvent(mediaElement, 'error');
18 sourceBuffer.mode = 'sequence';
19 assert_equals(sourceBuffer.mode, 'sequence', 'mode after setting it to \'sequence\'');
21 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
22 test.expectEvent(sourceBuffer, 'updatestart', 'initSegment append started.');
23 test.expectEvent(sourceBuffer, 'update', 'initSegment append success.');
24 test.expectEvent(sourceBuffer, 'updateend', 'initSegment append ended.');
25 sourceBuffer.appendBuffer(initSegment);
26 test.waitForExpectedEvents(function()
28 assert_equals(sourceBuffer.timestampOffset, 0, 'timestampOffset initially 0');
29 testFunction(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData);
30 });
31 }, description, options);
34 function append_segment(test, sourceBuffer, mediaData, info, callback)
36 var mediaSegment = MediaSourceUtil.extractSegmentData(mediaData, info);
37 test.expectEvent(sourceBuffer, 'updatestart', 'media segment append started.');
38 test.expectEvent(sourceBuffer, 'update', 'media segment append success.');
39 test.expectEvent(sourceBuffer, 'updateend', 'media segment append ended.');
40 sourceBuffer.appendBuffer(mediaSegment);
41 test.waitForExpectedEvents(callback);
44 function threeDecimalPlaces(number)
46 return Number(number.toFixed(3));
49 // Verifies expected times to 3 decimal places before and after mediaSource.endOfStream(),
50 // and calls |callback| on success.
51 function verify_offset_and_buffered(test, mediaSource, sourceBuffer,
52 expectedTimestampOffset, expectedBufferedRangeStartTime,
53 expectedBufferedRangeMaxEndTimeBeforeEOS,
54 expectedBufferedRangeEndTimeAfterEOS,
55 callback) {
56 assert_equals(threeDecimalPlaces(sourceBuffer.timestampOffset),
57 threeDecimalPlaces(expectedTimestampOffset),
58 'expectedTimestampOffset');
60 // Prior to EOS, the buffered range end time may not have fully reached the next media
61 // segment's timecode (adjusted by any timestampOffset). It should not exceed it though.
62 // Therefore, an exact assertBufferedEquals() will not work here.
63 assert_equals(sourceBuffer.buffered.length, 1, 'sourceBuffer.buffered has 1 range before EOS');
64 assert_equals(threeDecimalPlaces(sourceBuffer.buffered.start(0)),
65 threeDecimalPlaces(expectedBufferedRangeStartTime),
66 'sourceBuffer.buffered range begins where expected before EOS');
67 assert_less_than_equal(threeDecimalPlaces(sourceBuffer.buffered.end(0)),
68 threeDecimalPlaces(expectedBufferedRangeMaxEndTimeBeforeEOS),
69 'sourceBuffer.buffered range ends at or before expected upper bound before EOS');
71 test.expectEvent(mediaSource, 'sourceended', 'mediaSource endOfStream');
72 mediaSource.endOfStream();
73 test.waitForExpectedEvents(function()
75 assertBufferedEquals(sourceBuffer,
76 '{ [' + expectedBufferedRangeStartTime.toFixed(3) + ', ' + expectedBufferedRangeEndTimeAfterEOS.toFixed(3) + ') }',
77 'sourceBuffer.buffered after EOS');
78 callback();
79 });
82 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
84 assert_equals(segmentInfo.media[0].timecode, 0, 'segment starts at time 0');
85 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[0], function()
87 verify_offset_and_buffered(test, mediaSource, sourceBuffer,
88 0, 0,
89 segmentInfo.media[1].timecode + sourceBuffer.timestampOffset,
90 segmentInfo.media[0].highest_end_time + sourceBuffer.timestampOffset,
91 test.done);
92 });
93 }, 'Test sequence AppendMode appendBuffer(first media segment)');
95 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
97 assert_greater_than(segmentInfo.media[1].timecode, 0, 'segment starts after time 0');
98 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[1], function()
100 verify_offset_and_buffered(test, mediaSource, sourceBuffer,
101 -segmentInfo.media[1].timecode, 0,
102 segmentInfo.media[2].timecode + sourceBuffer.timestampOffset,
103 segmentInfo.media[1].highest_end_time + sourceBuffer.timestampOffset,
104 test.done);
106 }, 'Test sequence AppendMode appendBuffer(second media segment)');
108 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
110 assert_greater_than(segmentInfo.media[1].timecode, 0, 'segment starts after time 0');
111 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[1], function()
113 assert_equals(segmentInfo.media[0].timecode, 0, 'segment starts at time 0');
114 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[0], function()
116 // Current timestampOffset should reflect offset required to put media[0]
117 // immediately after media[1]'s highest frame end timestamp (as was adjusted
118 // by an earlier timestampOffset).
119 verify_offset_and_buffered(test, mediaSource, sourceBuffer,
120 segmentInfo.media[1].highest_end_time - segmentInfo.media[1].timecode, 0,
121 segmentInfo.media[1].timecode + sourceBuffer.timestampOffset,
122 segmentInfo.media[0].highest_end_time + sourceBuffer.timestampOffset,
123 test.done);
126 }, 'Test sequence AppendMode appendBuffer(second media segment, then first media segment)');
128 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
130 assert_equals(segmentInfo.media[0].timecode, 0, 'segment starts at time 0');
131 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[0], function()
133 assert_greater_than(segmentInfo.media[1].timecode, 0, 'segment starts after time 0');
134 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[1], function()
136 verify_offset_and_buffered(test, mediaSource, sourceBuffer,
137 0, 0,
138 segmentInfo.media[2].timecode + sourceBuffer.timestampOffset,
139 segmentInfo.media[1].highest_end_time + sourceBuffer.timestampOffset,
140 test.done);
143 }, 'Test sequence AppendMode appendBuffer back-to-back(first media segment, then second media segment)');
145 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
147 assert_greater_than(segmentInfo.media[1].timecode, 0, 'segment starts after time 0');
148 sourceBuffer.timestampOffset = 10;
149 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[1], function()
151 verify_offset_and_buffered(test, mediaSource, sourceBuffer,
152 10 - segmentInfo.media[1].timecode,
154 segmentInfo.media[2].timecode + sourceBuffer.timestampOffset,
155 segmentInfo.media[1].highest_end_time + sourceBuffer.timestampOffset,
156 test.done);
158 }, 'Test sequence AppendMode appendBuffer after setting TSO > 0');
160 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
162 assert_equals(segmentInfo.media[0].timecode, 0, 'segment starts at time 0');
163 assert_greater_than(segmentInfo.media[4].timecode,
164 3 * segmentInfo.media[0].highest_end_time,
165 '2nd segment should start after 3 times first segment\'s end time');
166 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[0], function()
168 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[4], function()
170 verify_offset_and_buffered(test, mediaSource, sourceBuffer,
171 segmentInfo.media[0].highest_end_time - segmentInfo.media[4].timecode,
173 segmentInfo.media[5].timecode + sourceBuffer.timestampOffset,
174 segmentInfo.media[4].highest_end_time + sourceBuffer.timestampOffset,
175 test.done);
178 }, 'Test sequence AppendMode appendBuffer with large gap between segments.');
180 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
182 sourceBuffer.appendWindowStart = 10;
183 assert_equals(segmentInfo.media[0].timecode, 0, 'segment starts at time 0');
184 assert_less_than(segmentInfo.media[0].highest_end_time, 10, 'segment ends before time 10');
186 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[0], function()
188 assert_equals(sourceBuffer.timestampOffset, 0, 'timestampOffset is 0');
189 assertBufferedEquals(sourceBuffer, '{ }', 'sourceBuffer.buffered');
191 test.done();
192 }, 'Test sequence AppendMode appendBuffer fully before the appendwindow.');
194 mediasource_sequencemode_test(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
196 sourceBuffer.appendWindowEnd = 0.2;
197 assert_greater_than(segmentInfo.media[1].timecode, 0.2, 'segment starts after time 0.2');
198 assert_greater_than(segmentInfo.media[1].highest_end_time, 0.2, 'segment ends after time 0.2');
200 append_segment(test, sourceBuffer, mediaData, segmentInfo.media[1], function()
202 assert_equals(sourceBuffer.timestampOffset, 0, 'timestampOffset is 0');
203 assertBufferedEquals(sourceBuffer, '{ }', 'sourceBuffer.buffered');
205 test.done();
206 }, 'Test sequence AppendMode appendBuffer fully after the appendwindow.');
207 </script>
208 </body>
209 </html>