tor-browser

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

browser_user_input_handling_delay.js (2359B)


      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    `data:text/html,<body></body>`
     15  );
     16 
     17  let canHandleInput = false;
     18  let mouseDownPromise = BrowserTestUtils.waitForContentEvent(
     19    tab.linkedBrowser,
     20    "mousedown"
     21  ).then(function () {
     22    Assert.ok(
     23      canHandleInput,
     24      "This promise should be resolved after the 5 seconds mark has passed"
     25    );
     26  });
     27 
     28  for (let i = 0; i < 10; ++i) {
     29    await BrowserTestUtils.synthesizeMouseAtPoint(
     30      10,
     31      10,
     32      { type: "mousedown" },
     33      tab.linkedBrowser
     34    );
     35  }
     36  // Wait for roughly 5 seconds to give chances for the
     37  // above mousedown event to be handled.
     38  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     39    for (let i = 0; i < 330; ++i) {
     40      await new Promise(r => {
     41        content.requestAnimationFrame(r);
     42      });
     43    }
     44  });
     45 
     46  // If any user input events were handled in the above 5 seconds
     47  // the mouseDownPromise would be resolved with canHandleInput = false,
     48  // so that the test would fail.
     49  canHandleInput = true;
     50 
     51  // Ensure the events can be handled eventually
     52  await BrowserTestUtils.synthesizeMouseAtPoint(
     53    10,
     54    10,
     55    { type: "mousedown" },
     56    tab.linkedBrowser
     57  );
     58 
     59  await mouseDownPromise;
     60 
     61  BrowserTestUtils.removeTab(tab);
     62 }
     63 
     64 add_task(async function test_MinRAF() {
     65  const prefs = [
     66    ["dom.input_events.security.minNumTicks", 100],
     67    ["dom.input_events.security.minTimeElapsedInMS", 0],
     68    ["dom.input_events.security.isUserInputHandlingDelayTest", true],
     69  ];
     70 
     71  await test_user_input_handling_delay_helper(prefs);
     72 });
     73 
     74 add_task(async function test_MinElapsedTime() {
     75  const prefs = [
     76    ["dom.input_events.security.minNumTicks", 0],
     77    ["dom.input_events.security.minTimeElapsedInMS", 5000],
     78    ["dom.input_events.security.isUserInputHandlingDelayTest", true],
     79  ];
     80 
     81  await test_user_input_handling_delay_helper(prefs);
     82 });