Bug 1250934: Make tests use the correct audio frequency when fake devices are used r?drno draft
authorRandell Jesup <rjesup@jesup.org>
Fri, 26 Feb 2016 00:36:25 -0500
changeset 334846 cf7fab6e6b517c26b92d6a57a5afecf18a494635
parent 334845 a3f13339de51f9c6d669fed7c2395cff5b3d9f70
child 334847 51b064c728459e0b22eadc8da73c87b362608a54
child 334850 6cb2edec5523c7851dd89c855353e63cf784dc9b
push id11645
push userrjesup@wgate.com
push dateFri, 26 Feb 2016 05:38:04 +0000
reviewersdrno
bugs1250934
milestone47.0a1
Bug 1250934: Make tests use the correct audio frequency when fake devices are used r?drno MozReview-Commit-ID: 6kKu0KCnyXp
dom/media/tests/mochitest/head.js
dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
dom/media/tests/mochitest/test_peerConnection_verifyAudioAfterRenegotiation.html
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -4,22 +4,24 @@
 
 "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;
+  TEST_AUDIO_FREQ = 440;
 } catch (e) {
   dump('TEST DEVICES: No test devices found (in media.{audio,video}_loopback_dev, using fake streams.\n');
   FAKE_ENABLED = true;
 }
 
 /**
  * This class provides helpers around analysing the audio content in a stream
  * using WebAudio AnalyserNodes.
--- a/dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
+++ b/dom/media/tests/mochitest/test_peerConnection_trackDisabling.html
@@ -12,17 +12,17 @@ createHTML({
   title: "Disabling locally should be reflected remotely",
   visible: true
 });
 
 runNetworkTest(() => {
   var test = new PeerConnectionTest();
 
   // Always use fake tracks since we depend on video to be somewhat green and
-  // audio to have a large 1000Hz component.
+  // audio to have a large 1000Hz component (or 440Hz if using fake devices).
   test.setMediaConstraints([{audio: true, video: true, fake: true}], []);
   test.chain.append([
     function CHECK_ASSUMPTIONS() {
       is(test.pcLocal.mediaElements.length, 1,
          "pcLocal should only have one media element");
       is(test.pcRemote.mediaElements.length, 1,
          "pcRemote should only have one media element");
       is(test.pcLocal.streams.length, 1,
--- a/dom/media/tests/mochitest/test_peerConnection_verifyAudioAfterRenegotiation.html
+++ b/dom/media/tests/mochitest/test_peerConnection_verifyAudioAfterRenegotiation.html
@@ -39,30 +39,30 @@
            "pcLocal should only have one stream (the local one)");
         is(test.pcRemote.streams.length, 1,
            "pcRemote should only have one stream (the remote one)");
       },
       function CHECK_AUDIO() {
         local1Analyser = new AudioStreamAnalyser(ac, test.pcLocal.streams[0]);
         remote1Analyser = new AudioStreamAnalyser(ac, test.pcRemote.streams[0]);
 
-        freq1k = local1Analyser.binIndexForFrequency(1000);
+        freq = local1Analyser.binIndexForFrequency(TEST_AUDIO_FREQ);
 
         return Promise.resolve()
           .then(() => info("Checking local audio enabled"))
-          .then(() => checkAudioEnabled(local1Analyser, freq1k))
+          .then(() => checkAudioEnabled(local1Analyser, freq))
           .then(() => info("Checking remote audio enabled"))
-          .then(() => checkAudioEnabled(remote1Analyser, freq1k))
+          .then(() => checkAudioEnabled(remote1Analyser, freq))
 
           .then(() => test.pcLocal.streams[0].getAudioTracks()[0].enabled = false)
 
           .then(() => info("Checking local audio disabled"))
-          .then(() => checkAudioDisabled(local1Analyser, freq1k))
+          .then(() => checkAudioDisabled(local1Analyser, freq))
           .then(() => info("Checking remote audio disabled"))
-          .then(() => checkAudioDisabled(remote1Analyser, freq1k))
+          .then(() => checkAudioDisabled(remote1Analyser, freq))
       }
     ]);
 
     addRenegotiation(test.chain,
       [
         function PC_LOCAL_ADD_SECOND_STREAM(test) {
           test.setMediaConstraints([{audio: true}],
                                    []);
@@ -81,41 +81,41 @@
            "pcLocal should have two streams");
         is(test.pcRemote.streams.length, 2,
            "pcRemote should have two streams");
       },
       function RE_CHECK_AUDIO() {
         local2Analyser = new AudioStreamAnalyser(ac, test.pcLocal.streams[1]);
         remote2Analyser = new AudioStreamAnalyser(ac, test.pcRemote.streams[1]);
 
-        freq1k = local2Analyser.binIndexForFrequency(1000);
+        freq = local2Analyser.binIndexForFrequency(TEST_AUDIO_FREQ);
 
         return Promise.resolve()
           .then(() => info("Checking local audio disabled"))
-          .then(() => checkAudioDisabled(local1Analyser, freq1k))
+          .then(() => checkAudioDisabled(local1Analyser, freq))
           .then(() => info("Checking remote audio disabled"))
-          .then(() => checkAudioDisabled(remote1Analyser, freq1k))
+          .then(() => checkAudioDisabled(remote1Analyser, freq))
 
           .then(() => info("Checking local2 audio enabled"))
-          .then(() => checkAudioEnabled(local2Analyser, freq1k))
+          .then(() => checkAudioEnabled(local2Analyser, freq))
           .then(() => info("Checking remote2 audio enabled"))
-          .then(() => checkAudioEnabled(remote2Analyser, freq1k))
+          .then(() => checkAudioEnabled(remote2Analyser, freq))
 
           .then(() => test.pcLocal.streams[1].getAudioTracks()[0].enabled = false)
           .then(() => test.pcLocal.streams[0].getAudioTracks()[0].enabled = true)
 
           .then(() => info("Checking local2 audio disabled"))
-          .then(() => checkAudioDisabled(local2Analyser, freq1k))
+          .then(() => checkAudioDisabled(local2Analyser, freq))
           .then(() => info("Checking remote2 audio disabled"))
-          .then(() => checkAudioDisabled(remote2Analyser, freq1k))
+          .then(() => checkAudioDisabled(remote2Analyser, freq))
 
           .then(() => info("Checking local audio enabled"))
-          .then(() => checkAudioEnabled(local1Analyser, freq1k))
+          .then(() => checkAudioEnabled(local1Analyser, freq))
           .then(() => info("Checking remote audio enabled"))
-          .then(() => checkAudioEnabled(remote1Analyser, freq1k))
+          .then(() => checkAudioEnabled(remote1Analyser, freq))
       }
     ]);
 
     test.setMediaConstraints([{audio: true}], []);
     test.run();
   });
 </script>
 </pre>