tor-browser

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

test_unfocused_pref.html (1576B)


      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  // This pref exists only for a partner testing framework without WebDriver
     13  // switch-to-window nor SpecialPowers to set the active window.
     14  // Prefer "focusmanager.testmode".
     15  title: "Test media.devices.unfocused.enabled",
     16  bug: "1740824"
     17 });
     18 
     19 const blank_url = "/tests/docshell/test/navigation/blank.html";
     20 
     21 async function resolveOnEvent(target, name) {
     22  return new Promise(r => target.addEventListener(name, r, {once: true}));
     23 }
     24 
     25 runTest(async () => {
     26  ok(document.hasFocus(), "This test expects initial focus on the document.");
     27  // 'resizable' is requested for a separate OS window on relevant platforms
     28  // so that this test tests OS focus changes rather than document visibility.
     29  const other = window.open(blank_url, "", "resizable");
     30  SimpleTest.registerCleanupFunction(() => {
     31    other.close();
     32    return SimpleTest.promiseFocus(window);
     33  });
     34  await Promise.all([
     35    resolveOnEvent(window, 'blur'),
     36    SimpleTest.promiseFocus(other),
     37    pushPrefs(["media.devices.unfocused.enabled", true]),
     38  ]);
     39  ok(!document.hasFocus(), "!document.hasFocus()");
     40  await navigator.mediaDevices.enumerateDevices();
     41  ok(true, "enumerateDevices() completes without focus.");
     42  // The focus requirement with media.devices.unfocused.enabled false
     43  // (default) is tested in
     44  // testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-without-focus.https.html
     45 });
     46 
     47 </script>
     48 </body>
     49 </html>