tor-browser

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

browser_bug1787079.js (2375B)


      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 { height: 100vh; }" +
     11  "</style>" +
     12  "</html>";
     13 
     14 const pageUrl = "data:text/html," + encodeURIComponent(PAGECONTENT);
     15 
     16 add_task(async function test() {
     17  SpecialPowers.DOMWindowUtils.setHiDPIMode(true);
     18  registerCleanupFunction(() => {
     19    SpecialPowers.DOMWindowUtils.restoreHiDPIMode();
     20  });
     21 
     22  const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
     23 
     24  // Enter fullscreen.
     25  let fullscreenChangePromise = BrowserTestUtils.waitForContentEvent(
     26    tab.linkedBrowser,
     27    "fullscreenchange"
     28  );
     29  await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     30    content.document.documentElement.requestFullscreen();
     31  });
     32  await fullscreenChangePromise;
     33 
     34  let [originalInnerWidth, originalInnerHeight] = await SpecialPowers.spawn(
     35    tab.linkedBrowser,
     36    [],
     37    () => {
     38      return [content.window.innerWidth, content.window.innerHeight];
     39    }
     40  );
     41 
     42  // Then change the DPI.
     43  let originalPixelRatio = await SpecialPowers.spawn(
     44    tab.linkedBrowser,
     45    [],
     46    () => {
     47      return content.window.devicePixelRatio;
     48    }
     49  );
     50  let dpiChangedPromise = TestUtils.waitForCondition(async () => {
     51    let pixelRatio = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     52      return content.window.devicePixelRatio;
     53    });
     54    return pixelRatio != originalPixelRatio;
     55  }, "Make sure the DPI changed");
     56  SpecialPowers.DOMWindowUtils.setHiDPIMode(false);
     57  await dpiChangedPromise;
     58 
     59  let [innerWidth, innerHeight] = await SpecialPowers.spawn(
     60    tab.linkedBrowser,
     61    [],
     62    () => {
     63      return [content.window.innerWidth, content.window.innerHeight];
     64    }
     65  );
     66 
     67  Assert.less(
     68    originalInnerWidth,
     69    innerWidth,
     70    "window.innerWidth on a lower DPI should be greater than the original"
     71  );
     72  Assert.less(
     73    originalInnerHeight,
     74    innerHeight,
     75    "window.innerHeight on a lower DPI should be greater than the original"
     76  );
     77 
     78  fullscreenChangePromise = BrowserTestUtils.waitForContentEvent(
     79    tab.linkedBrowser,
     80    "fullscreenchange"
     81  );
     82  await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     83    content.document.exitFullscreen();
     84  });
     85  await fullscreenChangePromise;
     86 
     87  BrowserTestUtils.removeTab(tab);
     88 });