Bug 1407542 - Add mochitest checking that MediaStreams can be GCed. r=jib
authorAndreas Pehrson <pehrsons@mozilla.com>
Tue, 24 Oct 2017 10:35:02 +0200
changeset 443122 21762797d5ec694d319a209ef80c3c94b0229bf4
parent 443121 858589325edc571c825fb19c525ae1630f925283
child 443123 5cb403db2f66b5418d05604693e8127ed4d1dd8b
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1407542
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1407542 - Add mochitest checking that MediaStreams can be GCed. r=jib MozReview-Commit-ID: Aypf1QAG7o8
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_GC_MediaStream.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -58,16 +58,17 @@ skip-if = toolkit == 'android' # no scre
 [test_getUserMedia_basicTabshare.html]
 skip-if = toolkit == 'android' # no windowshare on android
 [test_getUserMedia_basicWindowshare.html]
 skip-if = toolkit == 'android' # no windowshare on android
 [test_getUserMedia_basicVideoAudio.html]
 [test_getUserMedia_bug1223696.html]
 [test_getUserMedia_constraints.html]
 [test_getUserMedia_callbacks.html]
+[test_getUserMedia_GC_MediaStream.html]
 [test_getUserMedia_getTrackById.html]
 [test_getUserMedia_gumWithinGum.html]
 [test_getUserMedia_loadedmetadata.html]
 [test_getUserMedia_mediaElementCapture_audio.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_mediaElementCapture_tracks.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_mediaElementCapture_video.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_GC_MediaStream.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+  "use strict";
+
+  createHTML({
+    title: "MediaStreams can be garbage collected",
+    bug: "1407542"
+  });
+
+  let SpecialStream = SpecialPowers.wrap(MediaStream);
+
+  async function testGC(stream, numCopies, copy) {
+    let startStreams = await SpecialStream.countUnderlyingStreams();
+
+    let copies = new Array(numCopies).fill(0).map(() => copy(stream));
+    ok(await SpecialStream.countUnderlyingStreams() > startStreams,
+        "MediaStream constructor creates more underlying streams");
+
+    copies = [];
+    await new Promise(r => SpecialPowers.exactGC(r));
+    is(await SpecialStream.countUnderlyingStreams(), startStreams,
+       "MediaStreams should have been collected");
+  }
+
+  runTest(async () => {
+    let gUMStream = await getUserMedia({video: true});
+    info("Testing GC of copy constructor");
+    await testGC(gUMStream, 10, s => new MediaStream(s));
+
+    info("Testing GC of track-array constructor");
+    await testGC(gUMStream, 10, s => new MediaStream(s.getTracks()));
+
+    info("Testing GC of empty constructor plus addTrack");
+    await testGC(gUMStream, 10, s => {
+      let s2 = new MediaStream();
+      s.getTracks().forEach(t => s2.addTrack(t));
+      return s2;
+    });
+
+    info("Testing GC of track-array constructor with cloned tracks");
+    await testGC(gUMStream, 10, s => new MediaStream(s.getTracks().map(t => t.clone())));
+
+    info("Testing GC of empty constructor plus addTrack with cloned tracks");
+    await testGC(gUMStream, 10, s => {
+      let s2 = new MediaStream();
+      s.getTracks().forEach(t => s2.addTrack(t.clone()));
+      return s2;
+    });
+
+    info("Testing GC of cloned stream");
+    await testGC(gUMStream, 10, s => s.clone());
+
+    info("Testing GC of gUM stream");
+    gUMStream = null;
+    await new Promise(r => SpecialPowers.exactGC(r));
+    is(await SpecialStream.countUnderlyingStreams(), 0,
+       "Original gUM stream should be collectable");
+  });
+</script>
+</pre>
+</body>
+</html>