| OLD | NEW |
| (Empty) |
| 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 createMediaXHR() { | |
| 13 var mediaURL = MediaSourceUtil.SEGMENT_INFO.url; | |
| 14 var xhr = new XMLHttpRequest(); | |
| 15 xhr.open('GET', mediaURL, true); | |
| 16 xhr.responseType = 'legacystream'; | |
| 17 | |
| 18 assert_equals(xhr.responseType, "legacystream", "Verify response t
ype was set."); | |
| 19 | |
| 20 return xhr; | |
| 21 } | |
| 22 | |
| 23 function waitForLoadingState(test, xhr, callback) | |
| 24 { | |
| 25 var eventHandler = test.step_func(function(e) | |
| 26 { | |
| 27 if (e.target.readyState < e.target.LOADING) | |
| 28 return; | |
| 29 xhr.removeEventListener('readystatechange', eventHandler); | |
| 30 callback(); | |
| 31 }); | |
| 32 xhr.addEventListener('readystatechange', eventHandler); | |
| 33 } | |
| 34 | |
| 35 function appendStream(test, sourceBuffer, callback) | |
| 36 { | |
| 37 var xhr = createMediaXHR(); | |
| 38 test.failOnEvent(xhr, 'error'); | |
| 39 | |
| 40 xhr.send(); | |
| 41 | |
| 42 waitForLoadingState(test, xhr, function() | |
| 43 { | |
| 44 assert_true(xhr.response != null, "xhr.response is not null"); | |
| 45 | |
| 46 test.expectEvent(xhr, "load", "XHR load completed."); | |
| 47 test.expectEvent(xhr, "loadend", "XHR load ended."); | |
| 48 | |
| 49 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 50 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 51 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 52 sourceBuffer.appendStream(xhr.response); | |
| 53 | |
| 54 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 55 | |
| 56 test.waitForExpectedEvents(function() | |
| 57 { | |
| 58 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 59 callback(); | |
| 60 }); | |
| 61 }); | |
| 62 } | |
| 63 | |
| 64 function appendStreamTest(callback, description) | |
| 65 { | |
| 66 mediasource_test(function(test, mediaElement, mediaSource) | |
| 67 { | |
| 68 var sourceBuffer = mediaSource.addSourceBuffer(MediaSourceUtil
.SEGMENT_INFO.type); | |
| 69 test.failOnEvent(mediaElement, 'error'); | |
| 70 callback(test, mediaElement, mediaSource, sourceBuffer); | |
| 71 }, description); | |
| 72 } | |
| 73 | |
| 74 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 75 { | |
| 76 test.expectEvent(mediaElement, "canplaythrough", "Reached HAVE_ENO
UGH_DATA."); | |
| 77 appendStream(test, sourceBuffer, function() { test.done(); }); | |
| 78 }, "Test SourceBuffer.appendStream() event dispatching."); | |
| 79 | |
| 80 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 81 { | |
| 82 var xhr = createMediaXHR(); | |
| 83 test.failOnEvent(xhr, 'error'); | |
| 84 xhr.send(); | |
| 85 waitForLoadingState(test, xhr, function() | |
| 86 { | |
| 87 var xhr2 = createMediaXHR(); | |
| 88 xhr2.send(); | |
| 89 waitForLoadingState(test, xhr2, function() | |
| 90 { | |
| 91 test.expectEvent(sourceBuffer, "updatestart", "Append star
ted."); | |
| 92 test.expectEvent(sourceBuffer, "update", "Append success."
); | |
| 93 test.expectEvent(sourceBuffer, "updateend", "Append ended.
"); | |
| 94 sourceBuffer.appendStream(xhr.response); | |
| 95 | |
| 96 assert_true(sourceBuffer.updating, "updating attribute is
true"); | |
| 97 | |
| 98 assert_throws("InvalidStateError", | |
| 99 function() { sourceBuffer.appendStream(xhr2.response);
}, | |
| 100 "appendStream() throws an exception because there is a
pending append."); | |
| 101 | |
| 102 assert_true(sourceBuffer.updating, "updating attribute is
true"); | |
| 103 | |
| 104 test.waitForExpectedEvents(function() | |
| 105 { | |
| 106 assert_false(sourceBuffer.updating, "updating attribut
e is false"); | |
| 107 test.done(); | |
| 108 }); | |
| 109 }); | |
| 110 }); | |
| 111 }, "Test SourceBuffer.appendStream() call during a pending appendStrea
m()."); | |
| 112 | |
| 113 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 114 { | |
| 115 var xhr = createMediaXHR(); | |
| 116 test.failOnEvent(xhr, 'error'); | |
| 117 xhr.send(); | |
| 118 waitForLoadingState(test, xhr, function() | |
| 119 { | |
| 120 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 121 test.expectEvent(sourceBuffer, "abort", "Append aborted."); | |
| 122 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 123 sourceBuffer.appendStream(xhr.response); | |
| 124 | |
| 125 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 126 | |
| 127 sourceBuffer.abort(); | |
| 128 | |
| 129 assert_false(sourceBuffer.updating, "updating attribute is fal
se"); | |
| 130 | |
| 131 test.waitForExpectedEvents(function() | |
| 132 { | |
| 133 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 134 test.done(); | |
| 135 }); | |
| 136 }); | |
| 137 }, "Test SourceBuffer.abort() call during a pending appendStream()."); | |
| 138 | |
| 139 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 140 { | |
| 141 appendStream(test, sourceBuffer, function() | |
| 142 { | |
| 143 test.expectEvent(mediaSource, "sourceended", "MediaSource sour
ceended event"); | |
| 144 mediaSource.endOfStream(); | |
| 145 assert_equals(mediaSource.readyState, "ended", "MediaSource re
adyState is 'ended'"); | |
| 146 | |
| 147 test.waitForExpectedEvents(function() | |
| 148 { | |
| 149 assert_equals(mediaSource.readyState, "ended", "MediaSourc
e readyState is 'ended'"); | |
| 150 | |
| 151 var xhr2 = createMediaXHR(); | |
| 152 xhr2.send(); | |
| 153 waitForLoadingState(test, xhr2, function() | |
| 154 { | |
| 155 test.expectEvent(mediaSource, "sourceopen", "MediaSour
ce sourceopen event"); | |
| 156 test.expectEvent(sourceBuffer, "updatestart", "Append
started."); | |
| 157 test.expectEvent(sourceBuffer, "update", "Append succe
ss."); | |
| 158 test.expectEvent(sourceBuffer, "updateend", "Append en
ded."); | |
| 159 sourceBuffer.appendStream(xhr2.response); | |
| 160 | |
| 161 assert_equals(mediaSource.readyState, "open", "MediaSo
urce readyState is 'open'"); | |
| 162 assert_true(sourceBuffer.updating, "updating attribute
is true"); | |
| 163 | |
| 164 test.waitForExpectedEvents(function() | |
| 165 { | |
| 166 assert_equals(mediaSource.readyState, "open", "Med
iaSource readyState is 'open'"); | |
| 167 assert_false(sourceBuffer.updating, "updating attr
ibute is false"); | |
| 168 test.done(); | |
| 169 }); | |
| 170 }); | |
| 171 }); | |
| 172 }); | |
| 173 }, "Test SourceBuffer.appendStream() triggering an 'ended' to 'open' t
ransition."); | |
| 174 | |
| 175 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 176 { | |
| 177 var xhr = createMediaXHR(); | |
| 178 test.failOnEvent(xhr, 'error'); | |
| 179 xhr.send(); | |
| 180 waitForLoadingState(test, xhr, function() | |
| 181 { | |
| 182 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 183 test.expectEvent(sourceBuffer, "abort", "Append aborted."); | |
| 184 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 185 sourceBuffer.appendStream(xhr.response); | |
| 186 | |
| 187 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 188 assert_equals(mediaSource.activeSourceBuffers.length, 0, "acti
veSourceBuffers.length"); | |
| 189 | |
| 190 test.expectEvent(mediaSource.sourceBuffers, "removesourcebuffe
r", "sourceBuffers"); | |
| 191 mediaSource.removeSourceBuffer(sourceBuffer); | |
| 192 | |
| 193 assert_false(sourceBuffer.updating, "updating attribute is fal
se"); | |
| 194 | |
| 195 var xhr2 = createMediaXHR(); | |
| 196 test.failOnEvent(xhr2, 'error'); | |
| 197 xhr2.send(); | |
| 198 waitForLoadingState(test, xhr2, function() | |
| 199 { | |
| 200 assert_throws("InvalidStateError", | |
| 201 function() { sourceBuffer.appendStream(xhr2.response);
}, | |
| 202 "appendStream() throws an exception because it isn't a
ttached to the mediaSource anymore."); | |
| 203 | |
| 204 test.waitForExpectedEvents(function() | |
| 205 { | |
| 206 assert_false(sourceBuffer.updating, "updating attribut
e is false"); | |
| 207 test.done(); | |
| 208 }); | |
| 209 }); | |
| 210 }); | |
| 211 }, "Test MediaSource.removeSourceBuffer() call during a pending append
Stream()."); | |
| 212 | |
| 213 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 214 { | |
| 215 var xhr = createMediaXHR(); | |
| 216 test.failOnEvent(xhr, 'error'); | |
| 217 xhr.send(); | |
| 218 waitForLoadingState(test, xhr, function() | |
| 219 { | |
| 220 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 221 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 222 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 223 sourceBuffer.appendStream(xhr.response); | |
| 224 | |
| 225 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 226 | |
| 227 assert_throws("InvalidStateError", | |
| 228 function() { mediaSource.duration = 1.0; }, | |
| 229 "set duration throws an exception when updating attribute
is true."); | |
| 230 | |
| 231 test.waitForExpectedEvents(function() | |
| 232 { | |
| 233 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 234 test.done(); | |
| 235 }); | |
| 236 }); | |
| 237 }, "Test setting MediaSource.duration during a pending appendStream()
for one of its SourceBuffers."); | |
| 238 | |
| 239 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 240 { | |
| 241 var xhr = createMediaXHR(); | |
| 242 test.failOnEvent(xhr, "error"); | |
| 243 test.failOnEvent(mediaSource, "sourceended"); | |
| 244 xhr.send(); | |
| 245 waitForLoadingState(test, xhr, function() | |
| 246 { | |
| 247 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 248 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 249 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 250 sourceBuffer.appendStream(xhr.response); | |
| 251 | |
| 252 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 253 | |
| 254 assert_throws("InvalidStateError", | |
| 255 function() { mediaSource.endOfStream(); }, | |
| 256 "endOfStream() throws an exception when updating attribute
is true."); | |
| 257 | |
| 258 assert_equals(mediaSource.readyState, "open"); | |
| 259 | |
| 260 test.waitForExpectedEvents(function() | |
| 261 { | |
| 262 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 263 assert_equals(mediaSource.readyState, "open"); | |
| 264 test.done(); | |
| 265 }); | |
| 266 }); | |
| 267 }, "Test MediaSource.endOfStream() during a pending appendStream() for
one of its SourceBuffers."); | |
| 268 | |
| 269 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 270 { | |
| 271 var xhr = createMediaXHR(); | |
| 272 test.failOnEvent(xhr, 'error'); | |
| 273 xhr.send(); | |
| 274 waitForLoadingState(test, xhr, function() | |
| 275 { | |
| 276 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 277 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 278 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 279 sourceBuffer.appendStream(xhr.response); | |
| 280 | |
| 281 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 282 | |
| 283 assert_throws("InvalidStateError", | |
| 284 function() { sourceBuffer.timestampOffset = 10.0; }, | |
| 285 "set timestampOffset throws an exception when updating att
ribute is true."); | |
| 286 | |
| 287 test.waitForExpectedEvents(function() | |
| 288 { | |
| 289 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 290 test.done(); | |
| 291 }); | |
| 292 }); | |
| 293 }, "Test setting SourceBuffer.timestampOffset during a pending appendS
tream()."); | |
| 294 | |
| 295 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 296 { | |
| 297 var xhr = createMediaXHR(); | |
| 298 test.failOnEvent(xhr, 'error'); | |
| 299 xhr.send(); | |
| 300 waitForLoadingState(test, xhr, function() | |
| 301 { | |
| 302 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 303 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 304 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 305 sourceBuffer.appendStream(xhr.response, 0); | |
| 306 | |
| 307 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 308 | |
| 309 test.waitForExpectedEvents(function() | |
| 310 { | |
| 311 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 312 test.done(); | |
| 313 }); | |
| 314 }); | |
| 315 }, "Test appending a Stream with maxSize equal to 0."); | |
| 316 | |
| 317 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 318 { | |
| 319 var xhr = createMediaXHR(); | |
| 320 test.failOnEvent(xhr, 'error'); | |
| 321 xhr.send(); | |
| 322 waitForLoadingState(test, xhr, function() | |
| 323 { | |
| 324 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 325 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 326 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 327 sourceBuffer.appendStream(xhr.response, 10); | |
| 328 | |
| 329 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 330 | |
| 331 test.waitForExpectedEvents(function() | |
| 332 { | |
| 333 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 334 test.done(); | |
| 335 }); | |
| 336 }); | |
| 337 }, "Test appending a Stream with maxSize value less than the size of t
he XHR response."); | |
| 338 | |
| 339 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 340 { | |
| 341 var xhr = createMediaXHR(); | |
| 342 test.failOnEvent(xhr, 'error'); | |
| 343 xhr.send(); | |
| 344 waitForLoadingState(test, xhr, function() | |
| 345 { | |
| 346 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 347 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 348 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 349 sourceBuffer.appendStream(xhr.response, 10 * 1024 * 1024); | |
| 350 | |
| 351 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 352 | |
| 353 test.waitForExpectedEvents(function() | |
| 354 { | |
| 355 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 356 test.done(); | |
| 357 }); | |
| 358 }); | |
| 359 }, "Test appending a Stream with maxSize value greater than the size o
f the XHR response."); | |
| 360 | |
| 361 appendStreamTest(function(test, mediaElement, mediaSource, sourceBuffe
r) | |
| 362 { | |
| 363 var xhr = createMediaXHR(); | |
| 364 test.failOnEvent(xhr, 'error'); | |
| 365 xhr.send(); | |
| 366 waitForLoadingState(test, xhr, function() | |
| 367 { | |
| 368 test.expectEvent(sourceBuffer, "updatestart", "Append started.
"); | |
| 369 test.expectEvent(sourceBuffer, "update", "Append success."); | |
| 370 test.expectEvent(sourceBuffer, "updateend", "Append ended."); | |
| 371 sourceBuffer.appendStream(xhr.response, "test"); | |
| 372 | |
| 373 assert_true(sourceBuffer.updating, "updating attribute is true
"); | |
| 374 | |
| 375 test.waitForExpectedEvents(function() | |
| 376 { | |
| 377 assert_false(sourceBuffer.updating, "updating attribute is
false"); | |
| 378 test.done(); | |
| 379 }); | |
| 380 }); | |
| 381 }, "Test appending a Stream with an invalid maxSize."); | |
| 382 | |
| 383 </script> | |
| 384 </body> | |
| 385 </html> | |
| OLD | NEW |