test_bug1512958.html (2145B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test that pausing and resuming a captured media element with audio doesn't stall</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 <script type="text/javascript" src="manifest.js"></script> 8 </head> 9 <body> 10 <audio id="a"></audio> 11 <pre id="test"> 12 <script class="testbody" type="text/javascript"> 13 function dumpEvent({target, type}) { 14 info(`${target.name} GOT EVENT ${type} currentTime=${target.currentTime} ` + 15 `paused=${target.paused} ended=${target.ended} ` + 16 `readyState=${target.readyState}`); 17 } 18 19 function wait(ms) { 20 return new Promise(resolve => setTimeout(resolve, ms)); 21 } 22 23 const a = document.getElementById('a'); 24 25 const events = ["timeupdate", "seeking", "seeked", "ended", "playing", "pause"]; 26 for (let ev of events) { 27 a.addEventListener(ev, dumpEvent); 28 } 29 30 (async () => { 31 try { 32 SimpleTest.waitForExplicitFinish(); 33 SimpleTest.requestFlakyTimeout("Timeouts for shortcutting test-timeout"); 34 35 const test = getPlayableAudio(gTrackTests.filter(t => t.duration > 2)); 36 if (!test) { 37 todo(false, "No playable audio"); 38 return; 39 } 40 41 // Start playing and capture 42 a.src = test.name; 43 a.name = test.name; 44 const ac = new AudioContext(); 45 ac.createMediaElementSource(a); 46 a.play(); 47 do { 48 await new Promise(r => a.ontimeupdate = r); 49 } while(a.currentTime == 0) 50 51 // Pause to trigger recreating tracks in DecodedStream 52 a.pause(); 53 await new Promise(r => a.onpause = r); 54 55 // Resuming should now work. Bug 1512958 would cause a stall because the 56 // original track wasn't ended and we'd block on it. 57 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1512958#c5 58 a.play(); 59 await new Promise(r => a.onplaying = r); 60 a.currentTime = test.duration - 1; 61 await Promise.race([ 62 new Promise(res => a.onended = res), 63 wait(30000).then(() => Promise.reject(new Error("Timeout"))), 64 ]); 65 } catch(e) { 66 ok(false, e); 67 } finally { 68 SimpleTest.finish(); 69 } 70 })(); 71 </script> 72 </pre> 73 </body> 74 </html>