tor-browser

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

browser_opaque_region.js (2102B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const lazy = {};
      7 ChromeUtils.defineESModuleGetters(lazy, {
      8  AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
      9 });
     10 
     11 async function assert_opaque_region() {
     12  // Ensure we've painted.
     13  await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
     14 
     15  let contentRect = document
     16    .getElementById("tabbrowser-tabbox")
     17    .getBoundingClientRect();
     18  let opaqueRegion = window.windowUtils.getWidgetOpaqueRegion();
     19 
     20  info(`Got opaque region: ${JSON.stringify(opaqueRegion)}`);
     21  isnot(opaqueRegion.length, 0, "Should have some part of the window opaque");
     22 
     23  let anyContainsContentRect = false;
     24  let containsContentRect = opaqueRect => {
     25    return (
     26      opaqueRect.x <= contentRect.x &&
     27      opaqueRect.y <= contentRect.y &&
     28      opaqueRect.width >= contentRect.width &&
     29      opaqueRect.height >= contentRect.height
     30    );
     31  };
     32 
     33  for (let opaqueRect of opaqueRegion) {
     34    anyContainsContentRect |= containsContentRect(opaqueRect);
     35  }
     36 
     37  ok(
     38    anyContainsContentRect,
     39    "The browser area should be considered opaque by widget"
     40  );
     41 }
     42 
     43 registerCleanupFunction(async function () {
     44  let defaultTheme = await lazy.AddonManager.getAddonByID(
     45    "default-theme@mozilla.org"
     46  );
     47  await defaultTheme.enable();
     48 });
     49 
     50 add_task(async function assert_opaque_region_system_theme() {
     51  return assert_opaque_region();
     52 });
     53 
     54 add_task(async function assert_opaque_region_mica() {
     55  await SpecialPowers.pushPrefEnv({ set: [["widget.windows.mica", true]] });
     56  return assert_opaque_region();
     57 });
     58 
     59 add_task(async function assert_opaque_region_light_theme() {
     60  let lightTheme = await lazy.AddonManager.getAddonByID(
     61    "firefox-compact-light@mozilla.org"
     62  );
     63  await lightTheme.enable();
     64  return assert_opaque_region();
     65 });
     66 
     67 add_task(async function assert_opaque_region_dark_theme() {
     68  let lightTheme = await lazy.AddonManager.getAddonByID(
     69    "firefox-compact-dark@mozilla.org"
     70  );
     71  await lightTheme.enable();
     72  return assert_opaque_region();
     73 });