Bug 1383585 - use fake media for screen gtest
MozReview-Commit-ID: GJE1RTXJTVh
--- 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.