tor-browser

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

browser_user_input_handling_delay_invisible_iframe.js (2356B)


      1 /* -*- Mode: JavaScript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 async function test_user_input_handling_delay_helper(prefs) {
      8  await SpecialPowers.pushPrefEnv({
      9    set: prefs,
     10  });
     11 
     12  const tab = await BrowserTestUtils.openNewForegroundTab(
     13    gBrowser,
     14    `
     15    data:text/html,
     16    <body>
     17      <iframe width="1" height="1" style="position:absolute; top:-9999px; left: -9999px; border-style: none" src="https://example.org/dom/base/test/empty.html"></iframe>
     18      <input />
     19    </body>`
     20  );
     21 
     22  await BrowserTestUtils.reloadTab(tab);
     23 
     24  let iframeFocused = SpecialPowers.spawn(
     25    tab.linkedBrowser,
     26    [],
     27    async function () {
     28      let iframe = content.document.querySelector("iframe");
     29      await ContentTaskUtils.waitForCondition(function () {
     30        return content.document.activeElement == iframe;
     31      });
     32    }
     33  );
     34 
     35  // Now the focus moves to the cross origin iframe
     36  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
     37    content.document.querySelector("iframe").focus();
     38  });
     39 
     40  await iframeFocused;
     41 
     42  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     43  await new Promise(r => setTimeout(r, 1000));
     44 
     45  const inputGetFocused = SpecialPowers.spawn(
     46    tab.linkedBrowser,
     47    [],
     48    async function () {
     49      await ContentTaskUtils.waitForEvent(
     50        content.document.querySelector("input"),
     51        "focus"
     52      );
     53    }
     54  ).then(function () {
     55    Assert.ok(
     56      true,
     57      "Invisible OOP iframe shouldn't prevent user input event handling"
     58    );
     59  });
     60 
     61  let iframeBC = tab.linkedBrowser.browsingContext.children[0];
     62  // Next tab key should move the focus from the iframe to link
     63  await BrowserTestUtils.synthesizeKey("KEY_Tab", {}, iframeBC);
     64 
     65  await inputGetFocused;
     66 
     67  BrowserTestUtils.removeTab(tab);
     68 }
     69 
     70 add_task(async function test_InvisibleIframe() {
     71  const prefs = [
     72    ["dom.input_events.security.minNumTicks", 3],
     73    ["dom.input_events.security.minTimeElapsedInMS", 0],
     74    ["dom.input_events.security.isUserInputHandlingDelayTest", true],
     75  ];
     76 
     77  await test_user_input_handling_delay_helper(prefs);
     78 });