test_ExperimentalAsync.html (4157B)
1 <!DOCTYPE html> 2 <html><head> 3 <meta http-equiv="content-type" content="text/html; charset=windows-1252"> 4 <title>MSE: testing removeAsync and appendBufferAsync</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"><script class="testbody" type="text/javascript"> 11 12 SimpleTest.waitForExplicitFinish(); 13 14 addMSEPrefs( 15 ["media.mediasource.eviction_threshold.audio", 524288], 16 ["media.dormant-on-pause-timeout-ms", -1], // FIXME: bug 1319292 17 ["media.mediasource.experimental.enabled", true] 18 ); 19 20 // We fill up the source buffer with audio data until the buffer is full. 21 // We ensure that QuotaExceededError is thrown once the buffer is full. 22 // We then seek to half the content. By that time, another appendBuffer must succeed 23 // as the auto-eviction would succeed (removing all data prior currentTime) 24 // The test then fills the audio buffer and plays until the end. 25 26 // Fill up the SourceBuffer by appending data repeatedly via doAppendDataFunc until 27 // an exception is thrown. 28 async function fillUpSourceBuffer(sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback) { 29 try { 30 // We are appending data repeatedly in sequence mode, there should be no gaps. 31 while (true) { 32 ok(sourceBuffer.buffered.length <= 1, "there should be no gap in buffered ranges."); 33 await doAppendDataFunc(); 34 } 35 } catch (ex) { 36 ok(true, "appendBuffer promise got rejected"); 37 onCaughtExceptionCallback(ex); 38 } 39 } 40 41 runWithMSE(async function(ms, el) { 42 el.controls = true; 43 await once(ms, "sourceopen"); 44 ok(true, "Receive a sourceopen event"); 45 const audiosb = ms.addSourceBuffer("audio/mp4"); 46 47 // Test removeAsync 48 audiosb.mode = "sequence"; 49 const audioInitBuffer = await fetchWithXHR("bipbop/bipbop_audioinit.mp4"); 50 await audiosb.appendBufferAsync(audioInitBuffer); 51 const audioBuffer = await fetchWithXHR("bipbop/bipbop_audio1.m4s"); 52 fillUpSourceBuffer(audiosb, 53 function() { // doAppendDataFunc 54 return audiosb.appendBufferAsync(audioBuffer); 55 }, 56 async function(ex1) { // onCaughtExceptionCallback 57 is(ex1.name, "QuotaExceededError", "QuotaExceededError thrown"); 58 is(audiosb.buffered.end(0), el.duration, "Duration is end of buffered range"); 59 const seekTime = audiosb.buffered.end(0) / 2; 60 el.currentTime = seekTime; 61 await once(el, "seeked"); 62 dump("dump: seeked to " + seekTime); 63 is(el.currentTime, seekTime, "correctly seeked to " + seekTime); 64 await audiosb.appendBufferAsync(audioBuffer).catch(async function() { 65 ok(false, "Shouldn't throw another time when data can be evicted"); 66 dump(JSON.stringify(await SpecialPowers.wrap(el).mozRequestDebugInfo())); 67 SimpleTest.finish(); 68 }); 69 // Test that an error in remove return a rejected promise 70 await audiosb.removeAsync(5, 0).catch(async function(ex3) { 71 ok(true, "remove promise got rejected with end <= start"); 72 is(ex3.name, "TypeError"); 73 await audiosb.removeAsync(ms.duration + 1, Infinity).catch(async function(ex4) { 74 ok(true, "remove promise got rejected with start > duration"); 75 is(ex4.name, "TypeError"); 76 await audiosb.removeAsync(0, Infinity).catch(function() { 77 ok(false, "shouldn't throw"); 78 }); 79 ok(true, "remove succeeded"); 80 is(audiosb.buffered.length, 0, "buffered should be empty"); 81 audiosb.mode = "segment"; 82 audiosb.timestampOffset = 0; 83 el.currentTime = 0; 84 await fetchAndLoadAsync(audiosb, "bipbop/bipbop_audio", range(1, 4), ".m4s"); 85 ms.endOfStream(); 86 el.play(); 87 await once(el, "ended"); 88 is(el.currentTime, el.duration, "played to the end"); 89 SimpleTest.finish(); 90 throw ex4; // ensure we don't fallback on lines below. 91 }); 92 ok(false, "should have returned an error"); 93 }); 94 ok(false, "should have returned an error"); 95 } 96 ); 97 }); 98 99 </script> 100 </pre> 101 </body> 102 </html>