tor-browser

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

browser_windowclose.js (2738B)


      1 "use strict";
      2 
      3 add_setup(async function () {
      4  await SpecialPowers.pushPrefEnv({
      5    set: [["test.wait300msAfterTabSwitch", true]],
      6  });
      7 });
      8 
      9 /**
     10 * WHOA THERE: We should never be adding new things to EXPECTED_REFLOWS.
     11 * Instead of adding reflows to the list, you should be modifying your code to
     12 * avoid the reflow.
     13 *
     14 * See https://firefox-source-docs.mozilla.org/performance/bestpractices.html
     15 * for tips on how to do that.
     16 */
     17 const EXPECTED_REFLOWS = [
     18  /**
     19   * Nothing here! Please don't add anything new!
     20   */
     21 ];
     22 
     23 /**
     24 * This test ensures that there are no unexpected
     25 * uninterruptible reflows when closing windows. When the
     26 * window is closed, the test waits until the original window
     27 * has activated.
     28 */
     29 add_task(async function () {
     30  // Ensure that this browser window starts focused. This seems to be
     31  // necessary to avoid intermittent failures when running this test
     32  // on repeat.
     33  await new Promise(resolve => {
     34    waitForFocus(resolve, window);
     35  });
     36 
     37  let win = await BrowserTestUtils.openNewBrowserWindow();
     38  await new Promise(resolve => {
     39    waitForFocus(resolve, win);
     40  });
     41 
     42  // At the time of writing, there are no reflows on window closing.
     43  // Mochitest will fail if we have no assertions, so we add one here
     44  // to make sure nobody adds any new ones.
     45  Assert.equal(
     46    EXPECTED_REFLOWS.length,
     47    0,
     48    "We shouldn't have added any new expected reflows for window close."
     49  );
     50 
     51  let inRange = (val, min, max) => min <= val && val <= max;
     52  let tabRect = win.gBrowser.tabContainer
     53    .querySelector("tab[selected=true] .tab-background")
     54    .getBoundingClientRect();
     55  await withPerfObserver(
     56    async function () {
     57      let promiseOrigBrowserFocused = TestUtils.waitForCondition(() => {
     58        return Services.focus.activeWindow == window;
     59      });
     60      await BrowserTestUtils.closeWindow(win);
     61      await promiseOrigBrowserFocused;
     62    },
     63    {
     64      expectedReflows: EXPECTED_REFLOWS,
     65      frames: {
     66        filter(rects, frame) {
     67          // Ignore the focus-out animation.
     68          if (isLikelyFocusChange(rects, frame)) {
     69            return [];
     70          }
     71          return rects;
     72        },
     73        exceptions: [
     74          {
     75            name: "Shadow around active tab should not flicker on macOS (bug 1960967)",
     76            condition(r) {
     77              return (
     78                AppConstants.platform == "macosx" &&
     79                inRange(r.x1, tabRect.x - 2, tabRect.x + 2) &&
     80                inRange(r.y1, tabRect.y - 2, tabRect.y + 2) &&
     81                inRange(r.w, tabRect.width - 4, tabRect.width + 4) &&
     82                inRange(r.h, tabRect.height - 4, tabRect.height + 4)
     83              );
     84            },
     85          },
     86        ],
     87      },
     88    },
     89    win
     90  );
     91 });