tor-browser

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

browser_bug1757410.js (1550B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const PAGECONTENT =
      7  "<!DOCTYPE html>" +
      8  "<html>" +
      9  "<style>" +
     10  "html { " +
     11  "  height: 120vh;" +
     12  "  overflow-y: scroll;" +
     13  "}" +
     14  "</style>" +
     15  "</html>";
     16 
     17 const pageUrl = "data:text/html," + encodeURIComponent(PAGECONTENT);
     18 
     19 add_task(async function test() {
     20  if (window.devicePixelRatio == 1) {
     21    ok(
     22      true,
     23      "Skip this test since this test is supposed to run on HiDPI mode, " +
     24        "the devixePixelRato on this machine is " +
     25        window.devicePixelRatio
     26    );
     27    return;
     28  }
     29 
     30  const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
     31 
     32  // Scroll the content a bit.
     33  const originalScrollPosition = await SpecialPowers.spawn(
     34    tab.linkedBrowser,
     35    [],
     36    async () => {
     37      content.document.scrollingElement.scrollTop = 100;
     38      return content.document.scrollingElement.scrollTop;
     39    }
     40  );
     41 
     42  // Disabling HiDPI mode and check the scroll position.
     43  SpecialPowers.DOMWindowUtils.setHiDPIMode(false);
     44  // Make sure we restore even if this test failed.
     45  registerCleanupFunction(() => {
     46    SpecialPowers.DOMWindowUtils.restoreHiDPIMode();
     47  });
     48 
     49  const scrollPosition = await SpecialPowers.spawn(
     50    tab.linkedBrowser,
     51    [],
     52    async () => {
     53      return content.document.scrollingElement.scrollTop;
     54    }
     55  );
     56  is(
     57    originalScrollPosition,
     58    scrollPosition,
     59    "The scroll position should be kept"
     60  );
     61  BrowserTestUtils.removeTab(tab);
     62 });