Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 (function(window) { | 1 (function(window) { |
| 2 // Set the testharness.js timeout to 120 seconds so that it is higher than | 2 // Set the testharness.js timeout to 120 seconds so that it is higher than |
| 3 // the LayoutTest timeout. This prevents testharness.js from prematurely | 3 // the LayoutTest timeout. This prevents testharness.js from prematurely |
| 4 // terminating tests and allows the LayoutTest runner to control when to | 4 // terminating tests and allows the LayoutTest runner to control when to |
| 5 // timeout the test. | 5 // timeout the test. |
| 6 setup({ explicit_timeout: 120000 }); | 6 setup({ explicit_timeout: 120000 }); |
| 7 | 7 |
| 8 var SEGMENT_INFO_LIST = [ | 8 var SEGMENT_INFO_LIST = [ |
| 9 { | 9 { |
| 10 url: '/media/resources/media-source/webm/test.webm', | 10 url: '/media/resources/media-source/webm/test.webm', |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 var info = this.eventTargetList_[i]; | 119 var info = this.eventTargetList_[i]; |
| 120 if (info.target == target) { | 120 if (info.target == target) { |
| 121 return info.expectations; | 121 return info.expectations; |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 var expectations = []; | 124 var expectations = []; |
| 125 this.eventTargetList_.push({ 'target': target, 'expectations': expectati ons }); | 125 this.eventTargetList_.push({ 'target': target, 'expectations': expectati ons }); |
| 126 return expectations; | 126 return expectations; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 function loadData_(test, url, callback, isBinary) | 129 function loadData_(test, url, callback, responseType) |
| 130 { | 130 { |
| 131 var request = new XMLHttpRequest(); | 131 var request = new XMLHttpRequest(); |
| 132 request.open("GET", url, true); | 132 request.open("GET", url, true); |
| 133 if (isBinary) { | 133 if (responseType !== undefined) { |
| 134 request.responseType = 'arraybuffer'; | 134 request.responseType = responseType; |
| 135 } | 135 } |
| 136 request.onload = test.step_func(function(event) | 136 request.onload = test.step_func(function(event) |
| 137 { | 137 { |
| 138 if (request.status != 200) { | 138 if (request.status != 200) { |
| 139 assert_unreached("Unexpected status code : " + request.status); | 139 assert_unreached("Unexpected status code : " + request.status); |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 var response = request.response; | 142 var response = request.response; |
| 143 if (isBinary) { | 143 if (responseType !== undefined && responseType == 'arraybuffer') { |
| 144 response = new Uint8Array(response); | 144 response = new Uint8Array(response); |
| 145 } | 145 } |
| 146 callback(response); | 146 callback(response); |
| 147 }); | 147 }); |
| 148 request.onerror = test.step_func(function(event) | 148 request.onerror = test.step_func(function(event) |
| 149 { | 149 { |
| 150 assert_unreached("Unexpected error"); | 150 assert_unreached("Unexpected error"); |
| 151 }); | 151 }); |
| 152 request.send(); | 152 request.send(); |
| 153 } | 153 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 166 } | 166 } |
| 167 | 167 |
| 168 mediaSource.addEventListener('sourceopen', eventHandler); | 168 mediaSource.addEventListener('sourceopen', eventHandler); |
| 169 mediaTag.src = mediaSourceURL; | 169 mediaTag.src = mediaSourceURL; |
| 170 } | 170 } |
| 171 | 171 |
| 172 var MediaSourceUtil = {}; | 172 var MediaSourceUtil = {}; |
| 173 | 173 |
| 174 MediaSourceUtil.loadTextData = function(test, url, callback) | 174 MediaSourceUtil.loadTextData = function(test, url, callback) |
| 175 { | 175 { |
| 176 loadData_(test, url, callback, false); | 176 loadData_(test, url, callback); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 MediaSourceUtil.loadBinaryData = function(test, url, callback) | 179 MediaSourceUtil.loadBinaryData = function(test, url, callback) |
| 180 { | 180 { |
| 181 loadData_(test, url, callback, true); | 181 loadData_(test, url, callback, 'arraybuffer'); |
| 182 }; | |
| 183 | |
| 184 MediaSourceUtil.loadDataStream = function(test, url, callback) | |
| 185 { | |
| 186 loadData_(test, url, callback, 'legacystream'); | |
| 182 }; | 187 }; |
| 183 | 188 |
| 184 MediaSourceUtil.fetchManifestAndData = function(test, manifestFilename, call back) | 189 MediaSourceUtil.fetchManifestAndData = function(test, manifestFilename, call back) |
| 185 { | 190 { |
| 186 var baseURL = '/media/resources/media-source/'; | 191 var baseURL = '/media/resources/media-source/'; |
| 187 var manifestURL = baseURL + manifestFilename; | 192 var manifestURL = baseURL + manifestFilename; |
| 188 MediaSourceUtil.loadTextData(test, manifestURL, function(manifestText) | 193 MediaSourceUtil.loadTextData(test, manifestURL, function(manifestText) |
| 189 { | 194 { |
| 190 var manifest = JSON.parse(manifestText); | 195 var manifest = JSON.parse(manifestText); |
| 191 | 196 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 214 var numBytes = 0; | 219 var numBytes = 0; |
| 215 var segmentIndex = 0; | 220 var segmentIndex = 0; |
| 216 while (segmentIndex < mediaInfo.length && mediaInfo[segmentIndex].timeco de <= playbackTimeToAdd) | 221 while (segmentIndex < mediaInfo.length && mediaInfo[segmentIndex].timeco de <= playbackTimeToAdd) |
| 217 { | 222 { |
| 218 numBytes += mediaInfo[segmentIndex].size; | 223 numBytes += mediaInfo[segmentIndex].size; |
| 219 ++segmentIndex; | 224 ++segmentIndex; |
| 220 } | 225 } |
| 221 return mediaData.subarray(start, numBytes + start); | 226 return mediaData.subarray(start, numBytes + start); |
| 222 } | 227 } |
| 223 | 228 |
| 229 // Fills up the sourceBuffer by repeatedly calling doAppendDataFunc, which i s expected to append some data | |
| 230 // to the sourceBuffer, until a QuotaExceeded exception is thrown. Then it c alls the onCaughtQuotaExceeded callback. | |
| 231 MediaSourceUtil.fillUpSourceBufferHelper = function(test, sourceBuffer, doAp pendDataFunc, onCaughtQuotaExceeded) | |
| 232 { | |
| 233 // We are appending data repeatedly in sequence mode, there should be no gaps. | |
| 234 assert_equals(sourceBuffer.mode, 'sequence'); | |
| 235 assert_false(sourceBuffer.buffered.length > 1, 'unexpected gap in buffer ed ranges.'); | |
| 236 try { | |
| 237 doAppendDataFunc(); | |
| 238 } catch(ex) { | |
| 239 assert_equals(ex.name, 'QuotaExceededError'); | |
| 240 onCaughtQuotaExceeded(); | |
| 241 } | |
| 242 test.expectEvent(sourceBuffer, 'updateend', 'append ended.'); | |
| 243 test.waitForExpectedEvents(function() { MediaSourceUtil.fillUpSourceBuff erHelper(test, sourceBuffer, doAppendDataFunc, onCaughtQuotaExceeded); }); | |
| 244 }; | |
| 245 | |
| 246 MediaSourceUtil.fillUpSourceBuffer = function(test, mediaSource, onBufferFul l) | |
| 247 { | |
| 248 MediaSourceUtil.fetchManifestAndData(test, 'webm/test-a-5min-44100Hz-1ch -manifest.json', function(type, mediaData) | |
|
wolenetz
2016/08/02 21:56:36
nit: (not a regression, and certainly not a strong
servolk
2016/08/02 22:59:15
Sure we can easily pass in the manifest/stream URL
| |
| 249 { | |
| 250 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil.AUDIO _ONLY_TYPE); | |
| 251 sourceBuffer.mode = 'sequence'; | |
| 252 | |
| 253 var appendedDataSize = 0; | |
| 254 MediaSourceUtil.fillUpSourceBufferHelper(test, sourceBuffer, | |
| 255 function () { // doAppendDataFunc | |
| 256 appendedDataSize += mediaData.length; | |
| 257 sourceBuffer.appendBuffer(mediaData); | |
| 258 }, | |
| 259 function () { // onCaughtQuotaExceeded | |
| 260 onBufferFull(appendedDataSize); | |
| 261 }); | |
| 262 }); | |
| 263 }; | |
| 264 | |
| 265 MediaSourceUtil.fillUpSourceBufferViaAppendStream = function (test, mediaSou rce, sourceBuffer, onBufferFull, appendSize) | |
| 266 { | |
| 267 var mediaURL = "/media/resources/media-source/webm/test-a-5min-44100Hz-1 ch.webm"; | |
| 268 var appendedDataSize = 0; | |
| 269 function appendStreamData() { | |
| 270 MediaSourceUtil.loadDataStream(test, mediaURL, function(response) | |
| 271 { | |
| 272 // We are appending data repeatedly in sequence mode, there shou ld be no gaps. | |
| 273 assert_false(sourceBuffer.buffered.length > 1, "unexpected gap i n buffered ranges."); | |
| 274 try { | |
| 275 if (appendSize !== undefined) { | |
| 276 appendedDataSize += appendSize; | |
| 277 sourceBuffer.appendStream(response, appendSize); | |
| 278 } else { | |
| 279 sourceBuffer.appendStream(response); | |
| 280 } | |
| 281 } catch(ex) { | |
| 282 assert_equals(ex.name, 'QuotaExceededError'); | |
| 283 onBufferFull(appendedDataSize); | |
| 284 } | |
| 285 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 286 test.waitForExpectedEvents(appendStreamData); | |
| 287 }); | |
| 288 } | |
| 289 // Start appending data | |
| 290 appendStreamData(); | |
| 291 }; | |
| 292 | |
| 293 | |
| 224 function getFirstSupportedType(typeList) | 294 function getFirstSupportedType(typeList) |
| 225 { | 295 { |
| 226 for (var i = 0; i < typeList.length; ++i) { | 296 for (var i = 0; i < typeList.length; ++i) { |
| 227 if (MediaSource.isTypeSupported(typeList[i])) | 297 if (MediaSource.isTypeSupported(typeList[i])) |
| 228 return typeList[i]; | 298 return typeList[i]; |
| 229 } | 299 } |
| 230 return ""; | 300 return ""; |
| 231 } | 301 } |
| 232 | 302 |
| 233 function getSegmentInfo() | 303 function getSegmentInfo() |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 assert_equals(actual, expected, description); | 469 assert_equals(actual, expected, description); |
| 400 }; | 470 }; |
| 401 | 471 |
| 402 window['assertSeekableEquals'] = function(obj, expected, description) | 472 window['assertSeekableEquals'] = function(obj, expected, description) |
| 403 { | 473 { |
| 404 var actual = timeRangesToString(obj.seekable); | 474 var actual = timeRangesToString(obj.seekable); |
| 405 assert_equals(actual, expected, description); | 475 assert_equals(actual, expected, description); |
| 406 }; | 476 }; |
| 407 | 477 |
| 408 })(window); | 478 })(window); |
| OLD | NEW |