browser_tabopen_squeeze.js (3195B)
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 opening a new tab that will 20 * cause the existing tabs to squeeze smaller. 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 // Compute the number of tabs we can put into the strip without 37 // overflowing, and remove one, so that we can create 38 // TAB_COUNT_FOR_SQUEEE tabs, and then one more, which should 39 // cause the tab to squeeze to a smaller size rather than overflow. 40 const TAB_COUNT_FOR_SQUEEZE = computeMaxTabCount() - 1; 41 42 await createTabs(TAB_COUNT_FOR_SQUEEZE); 43 44 gURLBar.focus(); 45 46 let tabStripRect = 47 gBrowser.tabContainer.arrowScrollbox.getBoundingClientRect(); 48 let textBoxRect = gURLBar 49 .querySelector("moz-input-box") 50 .getBoundingClientRect(); 51 52 await withPerfObserver( 53 async function () { 54 let switchDone = BrowserTestUtils.waitForEvent(window, "TabSwitchDone"); 55 BrowserCommands.openTab(); 56 await BrowserTestUtils.waitForEvent( 57 gBrowser.selectedTab, 58 "TabAnimationEnd" 59 ); 60 await switchDone; 61 }, 62 { 63 expectedReflows: EXPECTED_REFLOWS, 64 frames: { 65 filter: rects => 66 rects.filter( 67 r => 68 !( 69 // We expect plenty of changed rects within the tab strip. 70 ( 71 r.y1 >= tabStripRect.top && 72 r.y2 <= tabStripRect.bottom && 73 r.x1 >= tabStripRect.left && 74 r.x2 <= tabStripRect.right && 75 // It would make sense for each rect to have a width smaller than 76 // a tab (ie. tabstrip.width / tabcount), but tabs are small enough 77 // that they sometimes get reported in the same rect. 78 // So we accept up to the width of n-1 tabs. 79 r.w <= 80 (gBrowser.tabs.length - 1) * 81 Math.ceil(tabStripRect.width / gBrowser.tabs.length) 82 ) 83 ) 84 ), 85 exceptions: [ 86 { 87 name: "the urlbar placeolder moves up and down by a few pixels", 88 condition: r => 89 r.x1 >= textBoxRect.left && 90 r.x2 <= textBoxRect.right && 91 r.y1 >= textBoxRect.top && 92 r.y2 <= textBoxRect.bottom, 93 }, 94 ], 95 }, 96 } 97 ); 98 99 await removeAllButFirstTab(); 100 });