test_DurationChange.html (3121B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>MSE: check that duration change behaves properly</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script type="text/javascript" src="mediasource.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 <pre id="test"> 11 <script class="testbody" type="text/javascript"> 12 13 SimpleTest.waitForExplicitFinish(); 14 15 runWithMSE(async (ms, v) => { 16 await once(ms, "sourceopen"); 17 const sb = ms.addSourceBuffer("video/webm"); 18 19 const arrayBuffer = await fetchWithXHR("seek.webm"); 20 sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318)); 21 await Promise.all([once(v, "loadedmetadata"), once(sb, "updateend")]); 22 is(v.duration, ms.duration, "video duration is mediasource one"); 23 must_not_throw(() => ms.duration = 0, "duration = 0 is valid initially"); 24 is(v.duration, 0, "reducing duration with no data buffered is valid"); 25 sb.appendBuffer(new Uint8Array(arrayBuffer, 318)); 26 // Adding more data will fire durationchange. 27 await once(sb, "updateend"); 28 ok(true, "got updateend"); 29 // XXX: Duration should be exactly 4.0, see bug 1065207. 30 ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration"); 31 must_throw(() => ms.duration = 0, 32 "Must use remove for range removal", 33 "InvalidStateError"); 34 ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration"); 35 must_not_throw(() => ms.duration = 10, "setting duration past data is valid"); 36 is(v.duration, 10, "extending duration is always valid"); 37 // The last sample has a start time of 3.967000s and a end time of 4.001 (see bug 1065207). 38 must_not_throw(() => ms.duration = 3.967000, 39 "setting duration with >= highest frame presentation time is valid"); 40 is(v.duration, sb.buffered.end(0), 41 "duration is the highest end time reported by the buffered attribute "); 42 must_not_throw(() => ms.duration = 3.97, 43 "setting duration with >= highest frame presentation time is valid"); 44 is(v.duration, sb.buffered.end(0), 45 "duration is the highest end time reported by the buffered attribute "); 46 must_throw(() => ms.duration = 3.96, 47 "setting duration with < highest frame presentation time is not valid", 48 "InvalidStateError"); 49 is(v.duration, sb.buffered.end(0), 50 "duration is the highest end time reported by the buffered attribute "); 51 must_throw(() => ms.duration = -1, "can't set a negative duration", "TypeError"); 52 sb.remove(sb.buffered.end(0), Infinity); 53 is(sb.updating, true, "updating is true"); 54 must_throw(() => ms.duration = Infinity, 55 "setting the duration while updating is not allowed", 56 "InvalidStateError"); 57 must_throw(() => sb.abort(), 58 "Can't use abort while range removal is in progress", 59 "InvalidStateError"); 60 is(v.duration, sb.buffered.end(0), 61 "duration is the highest end time reported by the buffered attribute "); 62 await once(sb, "updateend"); 63 ms.endOfStream(); 64 await once(ms, "sourceended"); 65 SimpleTest.finish(); 66 }); 67 68 </script> 69 </pre> 70 </body> 71 </html>