tor-browser

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

browser_test_autoscrolling_in_oop_frame.js (3395B)


      1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* vim: set sts=2 sw=2 et tw=80: */
      3 "use strict";
      4 
      5 Services.scriptloader.loadSubScript(
      6  "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js",
      7  this
      8 );
      9 
     10 Services.scriptloader.loadSubScript(
     11  "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js",
     12  this
     13 );
     14 
     15 add_setup(async function () {
     16  await SpecialPowers.pushPrefEnv({
     17    set: [
     18      ["general.autoScroll", true],
     19      ["middlemouse.contentLoadURL", false],
     20      ["test.events.async.enabled", true],
     21    ],
     22  });
     23 });
     24 
     25 async function doTest() {
     26  function httpURL(filename) {
     27    const chromeURL = getRootDirectory(gTestPath) + filename;
     28    return chromeURL.replace(
     29      "chrome://mochitests/content/",
     30      "http://mochi.test:8888/"
     31    );
     32  }
     33 
     34  function getScrollY(context) {
     35    return SpecialPowers.spawn(context, [], () => content.scrollY);
     36  }
     37 
     38  const pageUrl = httpURL("helper_test_autoscrolling_in_oop_frame.html");
     39 
     40  await BrowserTestUtils.withNewTab(pageUrl, async function (browser) {
     41    await promiseApzFlushedRepaintsInPopup(browser);
     42 
     43    const iframeContext = browser.browsingContext.children[0];
     44    await promiseApzFlushedRepaintsInPopup(iframeContext);
     45 
     46    const { screenX, screenY, viewId, presShellId } = await SpecialPowers.spawn(
     47      iframeContext,
     48      [],
     49      () => {
     50        const winUtils = SpecialPowers.getDOMWindowUtils(content);
     51        return {
     52          screenX: content.mozInnerScreenX * content.devicePixelRatio,
     53          screenY: content.mozInnerScreenY * content.devicePixelRatio,
     54          viewId: winUtils.getViewId(content.document.documentElement),
     55          presShellId: winUtils.getPresShellId(),
     56        };
     57      }
     58    );
     59 
     60    ok(
     61      iframeContext.startApzAutoscroll(
     62        screenX + 100,
     63        screenY + 50,
     64        viewId,
     65        presShellId
     66      ),
     67      "Started autscroll"
     68    );
     69 
     70    const scrollEventPromise = SpecialPowers.spawn(
     71      iframeContext,
     72      [],
     73      async () => {
     74        return new Promise(resolve => {
     75          content.addEventListener(
     76            "scroll",
     77            () => {
     78              dump("Got a scroll event in the iframe\n");
     79              resolve();
     80            },
     81            { once: true }
     82          );
     83        });
     84      }
     85    );
     86 
     87    // Send sequential mousemove events to cause autoscrolling.
     88    for (let i = 0; i < 10; i++) {
     89      await promiseNativeMouseEventWithAPZ({
     90        type: "mousemove",
     91        target: browser,
     92        offsetX: 100,
     93        offsetY: 50 + i * 10,
     94      });
     95    }
     96 
     97    // Flush APZ repaints and waits for MozAfterPaint to make sure the scroll has
     98    // been reflected on the main thread.
     99    const apzPromise = promiseApzFlushedRepaintsInPopup(browser);
    100 
    101    await Promise.all([apzPromise, scrollEventPromise]);
    102 
    103    const frameScrollY = await getScrollY(iframeContext);
    104    ok(frameScrollY > 0, "Autoscrolled the iframe");
    105 
    106    const rootScrollY = await getScrollY(browser);
    107    ok(rootScrollY == 0, "Didn't scroll the root document");
    108 
    109    iframeContext.stopApzAutoscroll(viewId, presShellId);
    110  });
    111 }
    112 
    113 add_task(async function test_autoscroll_in_oop_iframe() {
    114  await doTest();
    115 });
    116 
    117 add_task(async function test_autoscroll_in_oop_iframe_with_os_zoom() {
    118  await SpecialPowers.pushPrefEnv({ set: [["ui.textScaleFactor", 200]] });
    119  await doTest();
    120 });