tor-browser

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

browser_test_content_response_timeout.js (2542B)


      1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* vim: set sts=2 sw=2 et tw=80: */
      3 
      4 "use strict";
      5 
      6 Services.scriptloader.loadSubScript(
      7  "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js",
      8  this
      9 );
     10 
     11 Services.scriptloader.loadSubScript(
     12  "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js",
     13  this
     14 );
     15 
     16 add_task(async () => {
     17  // Use pan gesture events for Mac.
     18  await SpecialPowers.pushPrefEnv({
     19    set: [
     20      // Set a relatively shorter timeout value.
     21      ["apz.content_response_timeout", 100],
     22    ],
     23  });
     24 
     25  const URL_ROOT = getRootDirectory(gTestPath).replace(
     26    "chrome://mochitests/content/",
     27    "http://mochi.test:8888/"
     28  );
     29  // Load a content having an APZ-aware listener causing 500ms busy state and
     30  // a scroll event listener changing the background color of an element.
     31  // The reason why we change the background color in a scroll listener rather
     32  // than setting up a Promise resolved in a scroll event handler and waiting
     33  // for the Promise is SpecialPowers.spawn doesn't allow it (bug 1743857).
     34  const tab = await BrowserTestUtils.openNewForegroundTab(
     35    gBrowser,
     36    URL_ROOT + "helper_content_response_timeout.html"
     37  );
     38 
     39  let scrollPromise = BrowserTestUtils.waitForContentEvent(
     40    tab.linkedBrowser,
     41    "scroll"
     42  );
     43 
     44  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     45    await content.wrappedJSObject.promiseApzFlushedRepaints();
     46    await content.wrappedJSObject.waitUntilApzStable();
     47  });
     48 
     49  // Note that below function uses `WaitForObserver` version of sending a
     50  // pan-start event function so that the notification can be sent in the parent
     51  // process, thus we can get the notification even if the content process is
     52  // busy.
     53  await NativePanHandler.promiseNativePanEvent(
     54    tab.linkedBrowser,
     55    100,
     56    100,
     57    0,
     58    NativePanHandler.delta,
     59    NativePanHandler.beginPhase
     60  );
     61 
     62  await new Promise(resolve => {
     63    // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     64    setTimeout(resolve, 200);
     65  });
     66 
     67  await NativePanHandler.promiseNativePanEvent(
     68    tab.linkedBrowser,
     69    100,
     70    100,
     71    0,
     72    NativePanHandler.delta,
     73    NativePanHandler.updatePhase
     74  );
     75  await NativePanHandler.promiseNativePanEvent(
     76    tab.linkedBrowser,
     77    100,
     78    100,
     79    0,
     80    0,
     81    NativePanHandler.endPhase
     82  );
     83 
     84  await scrollPromise;
     85  ok(true, "We got at least one scroll event");
     86 
     87  BrowserTestUtils.removeTab(tab);
     88  await SpecialPowers.popPrefEnv();
     89 });