tor-browser

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

test_enumerateDevices_getUserMediaFake.html (2211B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <script src="mediaStreamPlayback.js"></script>
      6 </head>
      7 <body>
      8  <script>
      9 "use strict";
     10 
     11 createHTML({
     12  title: "Test labeled devices or speakers aren't exposed in enumerateDevices() after fake getUserMedia()",
     13  bug: "1743524"
     14 });
     15 
     16 runTest(async () => {
     17  await pushPrefs(
     18    ["media.setsinkid.enabled", true],
     19    // This test uses real devices because fake devices are not grouped with
     20    // audiooutput devices.
     21    ["media.navigator.streams.fake", false]);
     22  const devices = navigator.mediaDevices;
     23  {
     24    // `fake:true` means that getUserMedia() resolves without any permission
     25    // check, and so this should not be sufficient to expose real device info.
     26    const stream = await devices.getUserMedia({ audio: true, fake: true });
     27    stream.getTracks()[0].stop();
     28    const list = await devices.enumerateDevices();
     29    const labeledDevices = list.filter(({label}) => label != "");
     30    is(labeledDevices.length, 0, "must be zero labeled devices after fake gUM");
     31    const outputDevices = list.filter(({kind}) => kind == "audiooutput");
     32    is(outputDevices.length, 0, "must be zero output devices after fake gUM");
     33  }
     34  {
     35    // Check without `fake:true` to verify assumptions about existing devices.
     36    let stream;
     37    try {
     38      stream = await devices.getUserMedia({ audio: true });
     39      stream.getTracks()[0].stop();
     40    } catch (e) {
     41      if (e.name == "NotFoundError" &&
     42          navigator.userAgent.includes("Mac OS X")) {
     43        todo(false, "Expecting no real audioinput device on Mac test machines");
     44        return;
     45      }
     46      throw e;
     47    }
     48    {
     49      const list = await devices.enumerateDevices();
     50      const audioDevices = list.filter(({kind}) => kind.includes("audio"));
     51      ok(audioDevices.length, "have audio devices after real gUM");
     52      const unlabeledAudioDevices = audioDevices.filter(({label}) => !label);
     53      is(unlabeledAudioDevices.length, 0,
     54         "must be zero unlabeled audio devices after real gUM");
     55 
     56      const outputDevices = list.filter(({kind}) => kind == "audiooutput");
     57      isnot(outputDevices.length, 0, "have output devices after real gUM");
     58    }
     59  }
     60 });
     61  </script>
     62 </body>
     63 </html>