DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1e1617c67238)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
</head>
<body>
<script type="application/javascript">
"use strict";

createHTML({
  title: "ondevicechange tests",
  bug: "1152383"
});

const RESPONSE_WAIT_TIME_MS = 3000;

function OnDeviceChangeEvent() {
  return new Promise(resolve => navigator.mediaDevices.ondevicechange = resolve);
}

function OnDeviceChangeEventReceived() {
  return Promise.race([
    OnDeviceChangeEvent(),
    wait(RESPONSE_WAIT_TIME_MS).then(() =>
      Promise.reject(new Error("Timed out waiting for devicechange"))),
  ]);
}

function OnDeviceChangeEventNotReceived() {
  return Promise.race([
    OnDeviceChangeEvent().then(() =>
      Promise.reject(new Error("devicechange fired unexpectedly"))),
    wait(RESPONSE_WAIT_TIME_MS),
  ]);
}

runTest(async () => {
  SimpleTest.requestCompleteLog();

  await pushPrefs(
    // Ensure there are continuous fake devicechange events throughout this test
    ["media.ondevicechange.fakeDeviceChangeEvent.enabled", true],
    // Enforce gUM permission prompts initially
    ["media.navigator.permission.disabled", false],
    // Make fake devices count as real, permission-wise, or devicechange events
    // won't be exposed
    ["media.navigator.permission.fake", true],
  );

  info("assure devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted");
  await OnDeviceChangeEventNotReceived();
  ok(true, "devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted");

  await pushPrefs(['media.navigator.permission.disabled', true]);

  info("assure devicechange event is fired when gUM is NOT in use and permanent permission is granted");
  await OnDeviceChangeEventReceived();
  ok(true, "devicechange event is fired when gUM is NOT in use and permanent permission is granted");

  info("assure devicechange event is fired when gUM is in use");
  const st = await getUserMedia({video: true});
  const videoTracks = st.getVideoTracks();
  await pushPrefs(['media.navigator.permission.disabled', false]);
  await OnDeviceChangeEventReceived();
  ok(true, "devicechange event is fired when gUM is in use");
  videoTracks.forEach(track => track.stop());
});

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