--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -2,53 +2,59 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
-// Specifies whether we are using fake streams to run this automation
-var FAKE_ENABLED = true;
-var TEST_AUDIO_FREQ = 1000;
-try {
- var audioDevice = SpecialPowers.getCharPref('media.audio_loopback_dev');
- var videoDevice = SpecialPowers.getCharPref('media.video_loopback_dev');
- dump('TEST DEVICES: Using media devices:\n');
- dump('audio: ' + audioDevice + '\nvideo: ' + videoDevice + '\n');
- FAKE_ENABLED = false;
+// Specifies if we want fake audio streams for this run
+let WANT_FAKE_AUDIO = true;
+// Specifies if we want fake video streams for this run
+let WANT_FAKE_VIDEO = true;
+let TEST_AUDIO_FREQ = 1000;
+let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", "");
+if (audioDevice) {
+ WANT_FAKE_AUDIO = false;
// It will be updated to 440 when/if DefaultLoopbackTone is instantiated.
TEST_AUDIO_FREQ = -1;
-} catch (e) {
- dump('TEST DEVICES: No test devices found (in media.{audio,video}_loopback_dev, using fake streams.\n');
- FAKE_ENABLED = true;
+ dump("TEST DEVICES: Got loopback audio: " + audioDevice + "\n");
+} else {
+ dump("TEST DEVICES: No test device found in media.audio_loopback_dev, using fake audio streams.\n");
+}
+let videoDevice = SpecialPowers.getCharPref("media.video_loopback_dev", "");
+if (videoDevice) {
+ WANT_FAKE_VIDEO = false;
+ dump("TEST DEVICES: Got loopback video: " + videoDevice + "\n");
+} else {
+ dump("TEST DEVICES: No test device found in media.video_loopback_dev, using fake video streams.\n");
}
/**
* Global flag to skip LoopbackTone
*/
-var DISABLE_LOOPBACK_TONE = false
+let DISABLE_LOOPBACK_TONE = false;
/**
* Helper class to setup a sine tone of a given frequency.
*/
class LoopbackTone {
constructor(audioContext, frequency) {
if (!audioContext) {
throw new Error("You must provide a valid AudioContext");
}
this.oscNode = audioContext.createOscillator();
var gainNode = audioContext.createGain();
gainNode.gain.value = 0.5;
this.oscNode.connect(gainNode);
gainNode.connect(audioContext.destination);
this.changeFrequency(frequency);
}
- // Method should be used when FAKE_ENABLED is false.
+ // Method should be used when WANT_FAKE_AUDIO is false.
start() {
if (!this.oscNode) {
throw new Error("Attempt to start a stopped LoopbackTone");
}
info(`Start loopback tone at ${this.oscNode.frequency.value}`);
this.oscNode.start();
}
@@ -63,17 +69,17 @@ class LoopbackTone {
stop() {
if (!this.oscNode) {
throw new Error("Attempt to stop a stopped LoopbackTone");
}
this.oscNode.stop();
this.oscNode = null;
}
-};
+}
// Object that holds the default loopback tone.
var DefaultLoopbackTone = null;
/**
* This class provides helpers around analysing the audio content in a stream
* using WebAudio AnalyserNodes.
*
* @constructor
@@ -343,17 +349,17 @@ function createMediaElementForTrack(trac
/**
* Wrapper function for mediaDevices.getUserMedia used by some tests. Whether
* to use fake devices or not is now determined in pref further below instead.
*
* @param {Dictionary} constraints
* The constraints for this mozGetUserMedia callback
*/
function getUserMedia(constraints) {
- if (!FAKE_ENABLED
+ if (!WANT_FAKE_AUDIO
&& !constraints.fake
&& constraints.audio
&& !DISABLE_LOOPBACK_TONE) {
// Loopback device is configured, start the default loopback tone
if (!DefaultLoopbackTone) {
TEST_AUDIO_FREQ = 440;
DefaultLoopbackTone = new LoopbackTone(new AudioContext, TEST_AUDIO_FREQ);
DefaultLoopbackTone.start();
@@ -390,24 +396,26 @@ function setupEnvironment() {
['media.peerconnection.enabled', true],
['media.peerconnection.identity.enabled', true],
['media.peerconnection.identity.timeout', 120000],
['media.peerconnection.ice.stun_client_maximum_transmits', 14],
['media.peerconnection.ice.trickle_grace_period', 30000],
['media.peerconnection.remoteTrackId.enabled', true],
['media.peerconnection.rtpsourcesapi.enabled', true],
['media.navigator.permission.disabled', true],
- ['media.navigator.streams.fake', FAKE_ENABLED],
+ // If either fake audio or video is desired we enable fake streams.
+ // If loopback devices are set they will be chosen instead of fakes in gecko.
+ ['media.navigator.streams.fake', WANT_FAKE_AUDIO || WANT_FAKE_VIDEO],
['media.getusermedia.screensharing.enabled', true],
['media.getusermedia.audiocapture.enabled', true],
['media.recorder.audio_node.enabled', true]
]
};
- if (!FAKE_ENABLED) {
+ if (!WANT_FAKE_AUDIO) {
defaultMochitestPrefs.set.push(
["media.volume_scale", "1"],
);
}
const isAndroid = !!navigator.userAgent.includes("Android");
if (isAndroid) {