Bug 1295352 - Check that there is no active gUM after each runTest test. draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Fri, 05 Aug 2016 00:46:25 -0400
changeset 401548 dd574e92185152653dbf070d55bf93fb3e28edd6
parent 400825 054d4856cea6150a6638e5daf7913713281af97d
child 401549 f0a1407718aa20927de2a74da20e6073537958e8
push id26481
push userjbruaroey@mozilla.com
push dateWed, 17 Aug 2016 03:44:37 +0000
bugs1295352
milestone51.0a1
Bug 1295352 - Check that there is no active gUM after each runTest test. MozReview-Commit-ID: 4VVb2ZJWiCL
dom/media/tests/mochitest/mediaStreamPlayback.js
--- a/dom/media/tests/mochitest/mediaStreamPlayback.js
+++ b/dom/media/tests/mochitest/mediaStreamPlayback.js
@@ -249,11 +249,28 @@ var scriptsReady = Promise.all([
   document.head.appendChild(el);
   return new Promise(r => el.onload = r);
 }));
 
 function createHTML(options) {
   return scriptsReady.then(() => realCreateHTML(options));
 }
 
+var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));
+
+// noGum - Helper to detect whether active guM tracks still exist.
+//
+// It relies on the fact that, by spec, device labels from enumerateDevices are
+// only visible during active gum calls. They're also visible when persistent
+// permissions are granted, so turn off media.navigator.permission.disabled
+// (which is normally on otherwise in our tests). Lastly, we must turn on
+// media.navigator.permission.fake otherwise fake devices don't count as active.
+
+var noGum = () => pushPrefs(["media.navigator.permission.disabled", false],
+                            ["media.navigator.permission.fake", true])
+  .then(() => navigator.mediaDevices.enumerateDevices())
+  .then(([device]) => device &&
+      is(device.label, "", "Test must leave no active gUM streams behind."));
+
 var runTest = testFunction => scriptsReady
   .then(() => runTestWhenReady(testFunction))
+  .then(() => noGum())
   .then(() => finish());