Bug 1436523 - Update head.js to better handle pref changes for fake/loopback devices during tests. r?achronop
Update head.js so that calls to the gUM helper will check the loopback and fake
device prefs and update the frequency output by test devices accordingly. This
should hopefully avoid issues where tests could change prefs, and the output
tone would no longer be correct for the new configuration.
No longer have audioDevice and videoDevice as globals, this way tests
explicitly fetch direct from prefs.
MozReview-Commit-ID: 9jhVScaBfTX
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -7,32 +7,41 @@
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
// 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;
- 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");
+
+/**
+ * Reads the current values of preferences affecting fake and loopback devices
+ * and sets the WANT_FAKE_AUDIO and WANT_FAKE_VIDEO gloabals appropriately.
+*/
+function updateConfigFromFakeAndLoopbackPrefs() {
+ let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", "");
+ if (audioDevice) {
+ WANT_FAKE_AUDIO = false;
+ dump("TEST DEVICES: Got loopback audio: " + audioDevice + "\n");
+ } else {
+ WANT_FAKE_AUDIO = true;
+ 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 {
+ WANT_FAKE_VIDEO = true;
+ dump("TEST DEVICES: No test device found in media.video_loopback_dev, using fake video 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");
-}
+
+updateConfigFromFakeAndLoopbackPrefs();
/**
* Global flag to skip LoopbackTone
*/
let DISABLE_LOOPBACK_TONE = false;
/**
* Helper class to setup a sine tone of a given frequency.
*/
@@ -349,32 +358,37 @@ 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) {
+ // Tests may have changed the values of prefs, so recheck
+ updateConfigFromFakeAndLoopbackPrefs();
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();
}
// Disable input processing mode when it's not explicity enabled.
// This is to avoid distortion of the loopback tone
constraints.audio = Object.assign({}, {autoGainControl: false}
, {echoCancellation: false}
, {noiseSuppression: false}
, constraints.audio);
+ } else {
+ // Fake device configured, ensure our test freq is correct.
+ TEST_AUDIO_FREQ = 1000;
}
info("Call getUserMedia for " + JSON.stringify(constraints));
return navigator.mediaDevices.getUserMedia(constraints)
.then(stream => (checkMediaStreamTracks(constraints, stream), stream));
}
// These are the promises we use to track that the prerequisites for the test
// are in place before running it.
--- a/dom/media/tests/mochitest/test_getUserMedia_basicAudio_loopback.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicAudio_loopback.html
@@ -11,16 +11,17 @@
title: "getUserMedia Basic Audio Test Loopback",
bug: "1406350",
visible: true
});
/**
* Run a test to verify the use of LoopbackTone as audio input.
*/
scriptsReady.then(() => runTestWhenReady(async () => {
+ let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", "");
if (!audioDevice) {
todo(false, "No loopback device set by framework. Try --use-test-media-devices");
return Promise.resolve();
}
// At this point DefaultLoopbackTone has been instantiated
// automatically on frequency TEST_AUDIO_FREQ (440 Hz). Verify
// that a tone is detected on that frequency.