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'>
12 mediasource_test(function(test, mediaElement, mediaSource)
14 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
16 assert_throws("InvalidAccessError", function()
18 sourceBuffer.remove(-1, 2);
22 }, "Test remove with an negative start.");
25 mediasource_test(function(test, mediaElement, mediaSource)
27 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
29 mediaSource.duration = 10;
31 assert_throws("InvalidAccessError", function()
33 sourceBuffer.remove(11, 12);
37 }, "Test remove with a start beyond the duration.");
39 mediasource_test(function(test, mediaElement, mediaSource)
41 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
43 mediaSource.duration = 10;
45 assert_throws("InvalidAccessError", function()
47 sourceBuffer.remove(2, 1);
51 }, "Test remove with a start larger than the end.");
54 mediasource_test(function(test, mediaElement, mediaSource)
56 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
58 mediaSource.duration = 10;
60 mediaSource.removeSourceBuffer(sourceBuffer);
62 assert_throws("InvalidStateError", function()
64 sourceBuffer.remove(1, 2);
68 }, "Test remove after SourceBuffer removed from mediaSource.");
71 mediasource_test(function(test, mediaElement, mediaSource)
73 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
75 mediaSource.duration = 10;
77 test.expectEvent(sourceBuffer, "updatestart");
78 test.expectEvent(sourceBuffer, "update");
79 test.expectEvent(sourceBuffer, "updateend");
80 sourceBuffer.remove(1, 2);
82 assert_true(sourceBuffer.updating, "updating");
84 assert_throws("InvalidStateError", function()
86 sourceBuffer.remove(3, 4);
89 test.waitForExpectedEvents(function()
93 }, "Test remove while update pending.");
95 mediasource_test(function(test, mediaElement, mediaSource)
97 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE);
99 mediaSource.duration = 10;
101 test.expectEvent(sourceBuffer, "updatestart");
102 test.expectEvent(sourceBuffer, "abort");
103 test.expectEvent(sourceBuffer, "updateend");
104 sourceBuffer.remove(1, 2);
106 assert_true(sourceBuffer.updating, "updating");
108 sourceBuffer.abort();
110 assert_false(sourceBuffer.updating, "updating");
112 test.waitForExpectedEvents(function()
116 }, "Test aborting a remove operation.");
119 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
121 test.expectEvent(sourceBuffer, "updatestart");
122 test.expectEvent(sourceBuffer, "update");
123 test.expectEvent(sourceBuffer, "updateend");
124 sourceBuffer.appendBuffer(mediaData);
126 test.waitForExpectedEvents(function()
128 mediaSource.endOfStream();
130 assert_equals(mediaSource.readyState, "ended");
132 test.expectEvent(sourceBuffer, "updatestart");
133 test.expectEvent(sourceBuffer, "update");
134 test.expectEvent(sourceBuffer, "updateend");
135 sourceBuffer.remove(1, 2);
137 assert_true(sourceBuffer.updating, "updating");
138 assert_equals(mediaSource.readyState, "open");
141 test.waitForExpectedEvents(function()
143 assert_false(sourceBuffer.updating, "updating");
146 }, "Test remove transitioning readyState from 'ended' to 'open'.");
148 function removeAppendedDataTests(callback, description)
150 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
152 test.expectEvent(sourceBuffer, "updatestart");
153 test.expectEvent(sourceBuffer, "update");
154 test.expectEvent(sourceBuffer, "updateend");
155 sourceBuffer.appendBuffer(mediaData);
157 test.waitForExpectedEvents(function()
159 var duration = segmentInfo.duration.toFixed(3);
160 var subType = MediaSourceUtil.getSubType(segmentInfo.type);
162 assertBufferedEquals(sourceBuffer, "{ [0.000, " + duration + ") }", "Initial buffered range.");
163 callback(test, sourceBuffer, duration, subType);
168 function removeAndCheckBufferedRanges(test, sourceBuffer, start, end, expected)
170 test.expectEvent(sourceBuffer, "updatestart");
171 test.expectEvent(sourceBuffer, "update");
172 test.expectEvent(sourceBuffer, "updateend");
173 sourceBuffer.remove(start, end);
175 test.waitForExpectedEvents(function()
177 assertBufferedEquals(sourceBuffer, expected, "Buffered ranges after remove().");
182 removeAppendedDataTests(function(test, sourceBuffer, duration, subType)
184 removeAndCheckBufferedRanges(test, sourceBuffer, 0, Number.POSITIVE_INFINITY, "{ }");
185 }, "Test removing all appended data.");
187 removeAppendedDataTests(function(test, sourceBuffer, duration, subType)
190 webm: ("{ [3.187, " + duration + ") }"),
191 mp4: ("{ [3.021, " + duration + ") }"),
194 // Note: Range doesn't start exactly at the end of the remove range because there isn't
195 // a keyframe there. The resulting range starts at the first keyframe >= the end time.
196 removeAndCheckBufferedRanges(test, sourceBuffer, 0, 3, expectations[subType]);
197 }, "Test removing beginning of appended data.");
199 removeAppendedDataTests(function(test, sourceBuffer, duration, subType)
202 webm: ("{ [0.000, 1.012) [3.187, " + duration + ") }"),
203 mp4: ("{ [0.000, 1.022) [3.021, " + duration + ") }"),
206 // Note: The first resulting range ends slightly after start because the removal algorithm only removes
207 // frames with a timestamp >= the start time. If a frame starts before and ends after the remove() start
208 // timestamp, then it stays in the buffer.
209 removeAndCheckBufferedRanges(test, sourceBuffer, 1, 3, expectations[subType]);
210 }, "Test removing the middle of appended data.");
212 removeAppendedDataTests(function(test, sourceBuffer, duration, subType)
215 webm: "{ [0.000, 1.012) }",
216 mp4: "{ [0.000, 1.022) }",
219 removeAndCheckBufferedRanges(test, sourceBuffer, 1, Number.POSITIVE_INFINITY, expectations[subType]);
220 }, "Test removing the end of appended data.");