tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_defaultAudioConstraints.html (2861B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
      5 </head>
      6 <body>
      7 <pre id="test">
      8 <script type="application/javascript">
      9 "use strict";
     10 
     11 createHTML({
     12  title: "Test that the audio constraints that observe at the audio constraints we expect.",
     13  bug: "1509842"
     14 });
     15 
     16 runTest(async () => {
     17  // We need a real device to get a MediaEngine supporting constraints
     18  let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", "");
     19  if (!audioDevice) {
     20    todo(false, "No device set by framework. Try --use-test-media-devices");
     21    return;
     22  }
     23 
     24  // Get a gUM track with the default settings, check that they are what we
     25  // expect.
     26  let stream = await navigator.mediaDevices.getUserMedia({ audio: true });
     27  let track = stream.getAudioTracks()[0];
     28  let defaultSettings = track.getSettings();
     29 
     30  is(defaultSettings.echoCancellation, true,
     31      "Echo cancellation should be ON by default.");
     32  is(defaultSettings.noiseSuppression, true,
     33      "Noise suppression should be ON by default.");
     34  is(defaultSettings.autoGainControl, true,
     35      "Automatic gain control should be ON by default.");
     36 
     37  track.stop();
     38 
     39  // This is UA-dependant, and belongs in a Mochitest, not in a WPT.
     40  // When a gUM track has been requested with `echoCancellation` OFF, check that
     41  // `noiseSuppression` and `autoGainControl` are off as well.
     42  stream =
     43    await navigator.mediaDevices.getUserMedia({audio:{echoCancellation: false}});
     44  track = stream.getAudioTracks()[0];
     45  defaultSettings = track.getSettings();
     46 
     47  is(defaultSettings.echoCancellation, false,
     48      "Echo cancellation should be OFF when requested.");
     49  is(defaultSettings.noiseSuppression, false,
     50      `Noise suppression should be OFF when echoCancellation is the only
     51      constraint and is OFF.`);
     52  is(defaultSettings.autoGainControl, false,
     53      `Automatic gain control should be OFF when echoCancellation is the only
     54      constraint and is OFF.`);
     55 
     56  track.stop();
     57 
     58  // When a gUM track has been requested with `echoCancellation` OFF, check that
     59  // `noiseSuppression` and `autoGainControl` are not OFF as well if another
     60  // constraint has been specified.
     61  stream =
     62    await navigator.mediaDevices.getUserMedia({audio:{echoCancellation: false,
     63                                                      autoGainControl: true}});
     64  track = stream.getAudioTracks()[0];
     65  defaultSettings = track.getSettings();
     66 
     67  is(defaultSettings.echoCancellation, false,
     68      "Echo cancellation should be OFF when requested.");
     69  is(defaultSettings.noiseSuppression, false,
     70      `Noise suppression should be OFF when echoCancellation is OFF and another
     71      constraint has been specified.`);
     72  is(defaultSettings.autoGainControl, true,
     73      "Auto gain control should be ON when requested.");
     74 
     75  track.stop();
     76 });
     77 </script>
     78 </pre>
     79 </body>
     80 </html>