Bug 1383585 - use fake media for screen gtest draft
authorNico Grunbaum
Mon, 07 Aug 2017 19:19:20 -0700
changeset 642412 67f6131841e6410f1d613e263fb3bd4e91e8a28d
parent 642337 08ab8a747932d8a65e8940269cd1ea4aea907a0e
child 724982 07df720ea9f91f0455bfde0511fbf89a91147f1e
push id72735
push userna-g@nostrum.com
push dateTue, 08 Aug 2017 05:59:13 +0000
bugs1383585
milestone56.0
Bug 1383585 - use fake media for screen gtest MozReview-Commit-ID: GJE1RTXJTVh
browser/base/content/test/webrtc/head.js
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -1,13 +1,14 @@
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource:///modules/SitePermissions.jsm");
 
 
 const PREF_PERMISSION_FAKE = "media.navigator.permission.fake";
+const PERF_STREAMS_FAKE = "media.navigator.streams.fake";
 const CONTENT_SCRIPT_HELPER = getRootDirectory(gTestPath) + "get_user_media_content_script.js";
 
 function waitForCondition(condition, nextTest, errorMsg, retryTimes) {
   retryTimes = typeof retryTimes !== "undefined" ? retryTimes : 30;
   var tries = 0;
   var interval = setInterval(function() {
     if (tries >= retryTimes) {
       ok(false, errorMsg);
@@ -522,16 +523,30 @@ function promiseReloadFrame(aFrameId) {
            .getElementById(contentFrameId)
            .contentWindow
            .location
            .reload();
   });
 }
 
 async function runTests(tests, options = {}) {
+  info("runTests called with options " + JSON.stringify(options));
+  if (options.fake === undefined) {
+    options.fake = true;
+    try {
+      let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev");
+      let videoDevice = SpecialPowers.getCharPref("media.video_loopback_dev");
+      info("TEST DEVICES: Using media devices " + "audio: " + audioDevice +
+           " video: " + videoDevice);
+      options.fake = false;
+    } catch (e) {
+      dump("TEST DEVICES: No test devices found in \
+            media.{audio,video}_loopback_dev, using fake streams.");
+    }
+  }
   let leaf = options.relativeURI || "get_user_media.html";
 
   let rootDir = getRootDirectory(gTestPath);
   rootDir = rootDir.replace("chrome://mochitests/content/",
                             "https://example.com/");
   let absoluteURI = rootDir + leaf;
   let cleanup = options.cleanup || (() => expectNoObserverCalled());
 
@@ -541,16 +556,17 @@ async function runTests(tests, options =
   browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
 
   is(PopupNotifications._currentNotifications.length, 0,
      "should start the test without any prior popup notification");
   ok(gIdentityHandler._identityPopup.hidden,
      "should start the test with the control center hidden");
 
   await SpecialPowers.pushPrefEnv({"set": [[PREF_PERMISSION_FAKE, true]]});
+  await SpecialPowers.pushPrefEnv({"set": [[PERF_STREAMS_FAKE, options.fake]]});
 
   for (let testCase of tests) {
     info(testCase.desc);
     await testCase.run(browser);
     await cleanup();
   }
 
   // Some tests destroy the original tab and leave a new one in its place.