summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_unfocused_pref.html
blob: 22df020f7c796b2603a8db841fd61e65dbc53d83 (plain)
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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <script src="mediaStreamPlayback.js"></script>
</head>
<body>
<script>
"use strict";

createHTML({
  // This pref exists only for a partner testing framework without WebDriver
  // switch-to-window nor SpecialPowers to set the active window.
  // Prefer "focusmanager.testmode".
  title: "Test media.devices.unfocused.enabled",
  bug: "1740824"
});

const blank_url = "/tests/docshell/test/navigation/blank.html";

async function resolveOnEvent(target, name) {
  return new Promise(r => target.addEventListener(name, r, {once: true}));
}

runTest(async () => {
  ok(document.hasFocus(), "This test expects initial focus on the document.");
  // 'resizable' is requested for a separate OS window on relevant platforms
  // so that this test tests OS focus changes rather than document visibility.
  const other = window.open(blank_url, "", "resizable");
  SimpleTest.registerCleanupFunction(() => {
    other.close();
    return SimpleTest.promiseFocus(window);
  });
  await Promise.all([
    resolveOnEvent(window, 'blur'),
    SimpleTest.promiseFocus(other),
    pushPrefs(["media.devices.unfocused.enabled", true]),
  ]);
  ok(!document.hasFocus(), "!document.hasFocus()");
  await navigator.mediaDevices.enumerateDevices();
  ok(true, "enumerateDevices() completes without focus.");
  // The focus requirement with media.devices.unfocused.enabled false
  // (default) is tested in
  // testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-without-focus.https.html
});

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