tor-browser

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

browser_tabclose_grow.js (2907B)


      1 "use strict";
      2 
      3 /**
      4 * WHOA THERE: We should never be adding new things to EXPECTED_REFLOWS.
      5 * Instead of adding reflows to the list, you should be modifying your code to
      6 * avoid the reflow.
      7 *
      8 * See https://firefox-source-docs.mozilla.org/performance/bestpractices.html
      9 * for tips on how to do that.
     10 */
     11 const EXPECTED_REFLOWS = [
     12  /**
     13   * Nothing here! Please don't add anything new!
     14   */
     15 ];
     16 
     17 /*
     18 * This test ensures that there are no unexpected
     19 * uninterruptible reflows when closing a tab that will
     20 * cause the existing tabs to grow bigger.
     21 */
     22 add_task(async function () {
     23  // Force-enable tab animations
     24  gReduceMotionOverride = false;
     25 
     26  await ensureNoPreloadedBrowser();
     27  await disableFxaBadge();
     28 
     29  // The test starts on about:blank and opens an about:blank
     30  // tab which triggers opening the toolbar since
     31  // ensureNoPreloadedBrowser sets AboutNewTab.newTabURL to about:blank.
     32  await SpecialPowers.pushPrefEnv({
     33    set: [["browser.toolbars.bookmarks.visibility", "never"]],
     34  });
     35 
     36  // At the time of writing, there are no reflows on tab closing with
     37  // tab growth. Mochitest will fail if we have no assertions, so we
     38  // add one here to make sure nobody adds any new ones.
     39  Assert.equal(
     40    EXPECTED_REFLOWS.length,
     41    0,
     42    "We shouldn't have added any new expected reflows."
     43  );
     44 
     45  // Compute the number of tabs we can put into the strip without
     46  // overflowing. If we remove one of the tabs, we know that the
     47  // remaining tabs will grow to fill the remaining space in the
     48  // tabstrip.
     49  const TAB_COUNT_FOR_GROWTH = computeMaxTabCount();
     50  await createTabs(TAB_COUNT_FOR_GROWTH);
     51 
     52  let lastTab = gBrowser.tabs[gBrowser.tabs.length - 1];
     53  await BrowserTestUtils.switchTab(gBrowser, lastTab);
     54 
     55  let tabStripRect =
     56    gBrowser.tabContainer.arrowScrollbox.getBoundingClientRect();
     57 
     58  function isInTabStrip(r) {
     59    return (
     60      r.y1 >= tabStripRect.top &&
     61      r.y2 <= tabStripRect.bottom &&
     62      r.x1 >= tabStripRect.left &&
     63      r.x2 <= tabStripRect.right &&
     64      // It would make sense for each rect to have a width smaller than
     65      // a tab (ie. tabstrip.width / tabcount), but tabs are small enough
     66      // that they sometimes get reported in the same rect.
     67      // So we accept up to the width of n-1 tabs.
     68      r.w <=
     69        (gBrowser.tabs.length - 1) *
     70          Math.ceil(tabStripRect.width / gBrowser.tabs.length)
     71    );
     72  }
     73 
     74  await withPerfObserver(
     75    async function () {
     76      let switchDone = BrowserTestUtils.waitForEvent(window, "TabSwitchDone");
     77      let tab = gBrowser.tabs[gBrowser.tabs.length - 1];
     78      gBrowser.removeTab(tab, { animate: true });
     79      await BrowserTestUtils.waitForEvent(tab, "TabAnimationEnd");
     80      await switchDone;
     81    },
     82    {
     83      expectedReflows: EXPECTED_REFLOWS,
     84      frames: {
     85        filter: rects => rects.filter(r => !isInTabStrip(r)),
     86      },
     87    }
     88  );
     89 
     90  await removeAllButFirstTab();
     91 });