dom/media/tests/mochitest/test_getUserMedia_scarySources.html
author Sebastian Hengst <archaeopteryx@coole-files.de>
Fri, 14 Apr 2017 23:39:22 +0200
changeset 401420 d523c49136775a7187486dbc96858a2cb0383bfb
parent 401401 322fde2d53bf49266dbc293321e6b36a4c789c12
child 401430 56bf52d4ddeb1dc7019c4f9e23961670d0a31414
permissions -rw-r--r--
Backed out changeset 322fde2d53bf (bug 1356569) so bug 1355161 can be backed out. r=backout

<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="head.js"></script>
  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">

createHTML({title: "Detect screensharing sources that are firefox", bug: "1311048"});

const { Services } = SpecialPowers.Cu.import('resource://gre/modules/Services.jsm');

let observe = topic => new Promise(r => Services.obs.addObserver(function o(...args) {
  Services.obs.removeObserver(o, topic);
  r(args);
}, topic, false));

let getDevices = async constraints => {
  let [{ windowID, innerWindowID, callID }] = await Promise.race([
    getUserMedia(constraints),
    observe("getUserMedia:request")
  ]);
  let window = Services.wm.getOuterWindowWithId(windowID);
  let devices = await new Promise((resolve, reject) =>
      window.navigator.mozGetUserMediaDevices({}, resolve, reject,
                                              innerWindowID, callID));
  return devices.map(SpecialPowers.wrapCallback(d => d.QueryInterface(Ci.nsIMediaDevice)));
};

runTest(async () => {
  const isWinXP = navigator.userAgent.indexOf("Windows NT 5.1") != -1;
  if (IsMacOSX10_6orOlder() || isWinXP) {
    ok(true, "Screensharing disabled for OSX10.6 and WinXP");
    return;
  }

  await pushPrefs(["media.navigator.permission.disabled", true],
                  ["media.navigator.permission.fake", true],
                  ["media.navigator.permission.force", true]);
  let devices = await getDevices({video: { mediaSource: "window" }});
  ok(devices.length, "Found one or more windows.");
  devices = devices.filter(d => d.scary);
  ok(devices.length, "Found one or more scary windows (our own counts).");
  devices.filter(d => d.name.includes("MochiTest"));
  ok(devices.length,
     "Our own window is among the scary: " + devices.map(d => `"${d.name}"`));

  devices = await getDevices({video: { mediaSource: "screen" }});
  let numScreens = devices.length;
  ok(numScreens, "Found one or more screens.");
  devices = devices.filter(d => d.scary);
  is(devices.length, numScreens, "All screens are scary.");
});

</script>
</pre>
</body>
</html>