| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| Aaron Colwell | aa3c90b | 2014-08-04 17:58:37 | [diff] [blame^] | 4 | <title>SourceBuffer.remove() test cases.</title> |
| Aaron Colwell | 06f8ec2 | 2014-03-07 18:09:47 | [diff] [blame] | 5 | <script src="/resources/testharness.js"></script> |
| 6 | <script src="/resources/testharnessreport.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 7 | <script src="mediasource-util.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 8 | </head> |
| 9 | <body> |
| 10 | <div id="log"></div> |
| 11 | <script> |
| 12 | mediasource_test(function(test, mediaElement, mediaSource) |
| 13 | { |
| 14 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 15 | |
| 16 | assert_throws("InvalidAccessError", function() |
| 17 | { |
| 18 | sourceBuffer.remove(-1, 2); |
| 19 | }, "remove"); |
| 20 | |
| 21 | test.done(); |
| 22 | }, "Test remove with an negative start."); |
| 23 | |
| 24 | |
| 25 | mediasource_test(function(test, mediaElement, mediaSource) |
| 26 | { |
| 27 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 28 | |
| 29 | mediaSource.duration = 10; |
| 30 | |
| 31 | assert_throws("InvalidAccessError", function() |
| 32 | { |
| 33 | sourceBuffer.remove(11, 12); |
| 34 | }, "remove"); |
| 35 | |
| 36 | test.done(); |
| 37 | }, "Test remove with a start beyond the duration."); |
| 38 | |
| 39 | mediasource_test(function(test, mediaElement, mediaSource) |
| 40 | { |
| 41 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 42 | |
| 43 | mediaSource.duration = 10; |
| 44 | |
| 45 | assert_throws("InvalidAccessError", function() |
| 46 | { |
| 47 | sourceBuffer.remove(2, 1); |
| 48 | }, "remove"); |
| 49 | |
| 50 | test.done(); |
| 51 | }, "Test remove with a start larger than the end."); |
| 52 | |
| 53 | |
| 54 | mediasource_test(function(test, mediaElement, mediaSource) |
| 55 | { |
| 56 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 57 | |
| 58 | mediaSource.duration = 10; |
| 59 | |
| 60 | mediaSource.removeSourceBuffer(sourceBuffer); |
| 61 | |
| 62 | assert_throws("InvalidStateError", function() |
| 63 | { |
| 64 | sourceBuffer.remove(1, 2); |
| 65 | }, "remove"); |
| 66 | |
| 67 | test.done(); |
| 68 | }, "Test remove after SourceBuffer removed from mediaSource."); |
| 69 | |
| 70 | |
| 71 | mediasource_test(function(test, mediaElement, mediaSource) |
| 72 | { |
| 73 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 74 | |
| 75 | mediaSource.duration = 10; |
| 76 | |
| 77 | test.expectEvent(sourceBuffer, "updatestart"); |
| 78 | test.expectEvent(sourceBuffer, "update"); |
| 79 | test.expectEvent(sourceBuffer, "updateend"); |
| 80 | sourceBuffer.remove(1, 2); |
| 81 | |
| 82 | assert_true(sourceBuffer.updating, "updating"); |
| 83 | |
| 84 | assert_throws("InvalidStateError", function() |
| 85 | { |
| 86 | sourceBuffer.remove(3, 4); |
| 87 | }, "remove"); |
| 88 | |
| 89 | test.waitForExpectedEvents(function() |
| 90 | { |
| 91 | test.done(); |
| 92 | }); |
| 93 | }, "Test remove while update pending."); |
| 94 | |
| 95 | mediasource_test(function(test, mediaElement, mediaSource) |
| 96 | { |
| 97 | var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO_VIDEO_TYPE); |
| 98 | |
| 99 | mediaSource.duration = 10; |
| 100 | |
| 101 | test.expectEvent(sourceBuffer, "updatestart"); |
| 102 | test.expectEvent(sourceBuffer, "abort"); |
| 103 | test.expectEvent(sourceBuffer, "updateend"); |
| 104 | sourceBuffer.remove(1, 2); |
| 105 | |
| 106 | assert_true(sourceBuffer.updating, "updating"); |
| 107 | |
| 108 | sourceBuffer.abort(); |
| 109 | |
| 110 | assert_false(sourceBuffer.updating, "updating"); |
| 111 | |
| 112 | test.waitForExpectedEvents(function() |
| 113 | { |
| 114 | test.done(); |
| 115 | }); |
| 116 | }, "Test aborting a remove operation."); |
| 117 | |
| 118 | |
| 119 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 120 | { |
| 121 | test.expectEvent(sourceBuffer, "updatestart"); |
| 122 | test.expectEvent(sourceBuffer, "update"); |
| 123 | test.expectEvent(sourceBuffer, "updateend"); |
| 124 | sourceBuffer.appendBuffer(mediaData); |
| 125 | |
| 126 | test.waitForExpectedEvents(function() |
| 127 | { |
| 128 | mediaSource.endOfStream(); |
| 129 | |
| 130 | assert_equals(mediaSource.readyState, "ended"); |
| 131 | |
| 132 | test.expectEvent(sourceBuffer, "updatestart"); |
| 133 | test.expectEvent(sourceBuffer, "update"); |
| 134 | test.expectEvent(sourceBuffer, "updateend"); |
| 135 | sourceBuffer.remove(1, 2); |
| 136 | |
| 137 | assert_true(sourceBuffer.updating, "updating"); |
| 138 | assert_equals(mediaSource.readyState, "open"); |
| 139 | }); |
| 140 | |
| 141 | test.waitForExpectedEvents(function() |
| 142 | { |
| 143 | assert_false(sourceBuffer.updating, "updating"); |
| 144 | test.done(); |
| 145 | }); |
| 146 | }, "Test remove transitioning readyState from 'ended' to 'open'."); |
| 147 | |
| 148 | function removeAppendedDataTests(callback, description) |
| 149 | { |
| 150 | mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) |
| 151 | { |
| 152 | test.expectEvent(sourceBuffer, "updatestart"); |
| 153 | test.expectEvent(sourceBuffer, "update"); |
| 154 | test.expectEvent(sourceBuffer, "updateend"); |
| 155 | sourceBuffer.appendBuffer(mediaData); |
| 156 | |
| 157 | test.waitForExpectedEvents(function() |
| 158 | { |
| 159 | var duration = segmentInfo.duration.toFixed(3); |
| 160 | var subType = MediaSourceUtil.getSubType(segmentInfo.type); |
| 161 | |
| 162 | assertBufferedEquals(sourceBuffer, "{ [0.000, " + duration + ") }", "Initial buffered range."); |
| 163 | callback(test, sourceBuffer, duration, subType); |
| 164 | }); |
| 165 | }, description); |
| 166 | }; |
| 167 | |
| 168 | function removeAndCheckBufferedRanges(test, sourceBuffer, start, end, expected) |
| 169 | { |
| 170 | test.expectEvent(sourceBuffer, "updatestart"); |
| 171 | test.expectEvent(sourceBuffer, "update"); |
| 172 | test.expectEvent(sourceBuffer, "updateend"); |
| 173 | sourceBuffer.remove(start, end); |
| 174 | |
| 175 | test.waitForExpectedEvents(function() |
| 176 | { |
| 177 | assertBufferedEquals(sourceBuffer, expected, "Buffered ranges after remove()."); |
| 178 | test.done(); |
| 179 | }); |
| 180 | } |
| 181 | |
| 182 | removeAppendedDataTests(function(test, sourceBuffer, duration, subType) |
| 183 | { |
| 184 | removeAndCheckBufferedRanges(test, sourceBuffer, 0, Number.POSITIVE_INFINITY, "{ }"); |
| 185 | }, "Test removing all appended data."); |
| 186 | |
| 187 | removeAppendedDataTests(function(test, sourceBuffer, duration, subType) |
| 188 | { |
| 189 | var expectations = { |
| 190 | webm: ("{ [3.187, " + duration + ") }"), |
| 191 | mp4: ("{ [3.021, " + duration + ") }"), |
| 192 | }; |
| 193 | |
| 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."); |
| 198 | |
| 199 | removeAppendedDataTests(function(test, sourceBuffer, duration, subType) |
| 200 | { |
| 201 | var expectations = { |
| 202 | webm: ("{ [0.000, 1.012) [3.187, " + duration + ") }"), |
| 203 | mp4: ("{ [0.000, 1.022) [3.021, " + duration + ") }"), |
| 204 | }; |
| 205 | |
| 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."); |
| 211 | |
| 212 | removeAppendedDataTests(function(test, sourceBuffer, duration, subType) |
| 213 | { |
| 214 | var expectations = { |
| 215 | webm: "{ [0.000, 1.012) }", |
| 216 | mp4: "{ [0.000, 1.022) }", |
| 217 | }; |
| 218 | |
| 219 | removeAndCheckBufferedRanges(test, sourceBuffer, 1, Number.POSITIVE_INFINITY, expectations[subType]); |
| 220 | }, "Test removing the end of appended data."); |
| 221 | </script> |
| 222 | </body> |
| 223 | </html> |