tor-browser

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

test_getUserMedia_scarySources.html (1796B)


      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 
     10 createHTML({title: "Detect screensharing sources that are firefox", bug: "1311048"});
     11 
     12 const Services = SpecialPowers.Services;
     13 
     14 let observe = topic => new Promise(r => Services.obs.addObserver(function o(...args) {
     15  Services.obs.removeObserver(o, topic);
     16  r(args.map(x => SpecialPowers.wrap(x)));
     17 }, topic));
     18 
     19 let getDevices = async constraints => {
     20  SpecialPowers.wrap(document).notifyUserGestureActivation();
     21  let [{ windowID, innerWindowID, callID, devices }] = await Promise.race([
     22    getUserMedia(constraints),
     23    observe("getUserMedia:request")
     24  ]);
     25  let window = Services.wm.getOuterWindowWithId(windowID);
     26  return devices.map(SpecialPowers.wrapCallback(d => d.QueryInterface(Ci.nsIMediaDevice)));
     27 };
     28 
     29 runTest(async () => {
     30  await pushPrefs(["media.navigator.permission.disabled", true],
     31                  ["media.navigator.permission.force", true]);
     32  let devices = await getDevices({video: { mediaSource: "window" }});
     33  ok(devices.length, "Found one or more windows.");
     34  devices = Array.prototype.filter.call(devices, d => d.scary);
     35  ok(devices.length, "Found one or more scary windows (our own counts).");
     36  devices = devices.filter(d => d.rawName.includes("MochiTest"));
     37  ok(devices.length,
     38     "Our own window is among the scary: "
     39     + devices.map(d => `"${d.rawName}"`));
     40 
     41  devices = await getDevices({video: { mediaSource: "screen" }});
     42  let numScreens = devices.length;
     43  ok(numScreens, "Found one or more screens.");
     44  devices = Array.prototype.filter.call(devices, d => d.scary);
     45  is(devices.length, numScreens, "All screens are scary.");
     46 });
     47 
     48 </script>
     49 </pre>
     50 </body>
     51 </html>