test_getUserMedia_GC_MediaStream.html (1706B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="mediaStreamPlayback.js"></script> 5 </head> 6 <body> 7 <pre id="test"> 8 <script type="application/javascript"> 9 "use strict"; 10 11 createHTML({ 12 title: "MediaStreams can be garbage collected", 13 bug: "1407542" 14 }); 15 16 let SpecialStream = SpecialPowers.wrap(MediaStream); 17 18 async function testGC(stream, numCopies, copy) { 19 let startStreams = await SpecialStream.countUnderlyingStreams(); 20 21 let copies = new Array(numCopies).fill(0).map(() => copy(stream)); 22 ok(await SpecialStream.countUnderlyingStreams() > startStreams, 23 "MediaStreamTrack constructor creates more underlying streams"); 24 25 copies = []; 26 await new Promise(r => SpecialPowers.exactGC(r)); 27 is(await SpecialStream.countUnderlyingStreams(), startStreams, 28 "MediaStreamTracks should have been collected"); 29 } 30 31 runTest(async () => { 32 let gUMStream = await getUserMedia({video: true}); 33 info("Testing GC of track-array constructor with cloned tracks"); 34 await testGC(gUMStream, 10, s => new MediaStream(s.getTracks().map(t => t.clone()))); 35 36 info("Testing GC of empty constructor plus addTrack with cloned tracks"); 37 await testGC(gUMStream, 10, s => { 38 let s2 = new MediaStream(); 39 s.getTracks().forEach(t => s2.addTrack(t.clone())); 40 return s2; 41 }); 42 43 info("Testing GC of cloned stream"); 44 await testGC(gUMStream, 10, s => s.clone()); 45 46 info("Testing GC of gUM stream"); 47 gUMStream = null; 48 await new Promise(r => SpecialPowers.exactGC(r)); 49 is(await SpecialStream.countUnderlyingStreams(), 0, 50 "Original gUM stream should be collectable"); 51 }); 52 </script> 53 </pre> 54 </body> 55 </html>