browser_appmenu.js (4608B)
1 "use strict"; 2 /* global PanelUI */ 3 4 const { CustomizableUITestUtils } = ChromeUtils.importESModule( 5 "resource://testing-common/CustomizableUITestUtils.sys.mjs" 6 ); 7 let gCUITestUtils = new CustomizableUITestUtils(window); 8 9 /** 10 * WHOA THERE: We should never be adding new things to 11 * EXPECTED_APPMENU_OPEN_REFLOWS. This list should slowly go 12 * away as we improve the performance of the front-end. Instead of adding more 13 * reflows to the list, you should be modifying your code to avoid the reflow. 14 * 15 * See https://firefox-source-docs.mozilla.org/performance/bestpractices.html 16 * for tips on how to do that. 17 */ 18 const EXPECTED_APPMENU_OPEN_REFLOWS = [ 19 { 20 stack: [ 21 "openPopup/this._openPopupPromise<@moz-src:///browser/components/customizableui/PanelMultiView.sys.mjs", 22 ], 23 }, 24 ]; 25 26 add_task(async function () { 27 await ensureNoPreloadedBrowser(); 28 await ensureAnimationsFinished(); 29 await disableFxaBadge(); 30 31 // Ensure updating Unified Search Button icon by user interaction before 32 // appmenu test. 33 if ( 34 Services.prefs.getBoolPref("browser.urlbar.scotchBonnet.enableOverride") 35 ) { 36 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); 37 BrowserTestUtils.removeTab(tab); 38 await BrowserTestUtils.waitForCondition( 39 () => 40 gURLBar.querySelector(".searchmode-switcher-icon").style.listStyleImage 41 ); 42 } 43 44 let textBoxRect = gURLBar 45 .querySelector("moz-input-box") 46 .getBoundingClientRect(); 47 let menuButtonRect = document 48 .getElementById("PanelUI-menu-button") 49 .getBoundingClientRect(); 50 let firstTabRect = gBrowser.selectedTab.getBoundingClientRect(); 51 let frameExpectations = { 52 filter: rects => { 53 // We expect the menu button to get into the active state. 54 // 55 // XXX For some reason the menu panel isn't in our screenshots, but 56 // that's where we actually expect many changes. 57 return rects.filter(r => !rectInBoundingClientRect(r, menuButtonRect)); 58 }, 59 exceptions: [ 60 { 61 name: "the urlbar placeholder moves up and down by a few pixels", 62 condition: r => rectInBoundingClientRect(r, textBoxRect), 63 }, 64 { 65 name: "bug 1547341 - a first tab gets drawn early", 66 condition: r => rectInBoundingClientRect(r, firstTabRect), 67 }, 68 ], 69 }; 70 71 // First, open the appmenu. 72 await withPerfObserver(() => gCUITestUtils.openMainMenu(), { 73 expectedReflows: EXPECTED_APPMENU_OPEN_REFLOWS, 74 frames: frameExpectations, 75 }); 76 77 // Now open a series of subviews, and then close the appmenu. We 78 // should not reflow during any of this. 79 await withPerfObserver( 80 async function () { 81 // This recursive function will take the current main or subview, 82 // find all of the buttons that navigate to subviews inside it, 83 // and click each one individually. Upon entering the new view, 84 // we recurse. When the subviews within a view have been 85 // exhausted, we go back up a level. 86 async function openSubViewsRecursively(currentView) { 87 let navButtons = Array.from( 88 // Ensure that only enabled buttons are tested 89 currentView.querySelectorAll( 90 ".subviewbutton-nav:not([disabled]):not([hidden])" 91 ) 92 ); 93 if (!navButtons) { 94 return; 95 } 96 97 for (let button of navButtons) { 98 info("Click " + button.id); 99 let promiseViewShown = BrowserTestUtils.waitForEvent( 100 PanelUI.panel, 101 "ViewShown" 102 ); 103 button.click(); 104 let viewShownEvent = await promiseViewShown; 105 106 // Workaround until bug 1363756 is fixed, then this can be removed. 107 let container = PanelUI.multiView.querySelector( 108 ".panel-viewcontainer" 109 ); 110 await TestUtils.waitForCondition(() => { 111 return !container.hasAttribute("width"); 112 }); 113 114 info("Shown " + viewShownEvent.originalTarget.id); 115 await openSubViewsRecursively(viewShownEvent.originalTarget); 116 promiseViewShown = BrowserTestUtils.waitForEvent( 117 currentView, 118 "ViewShown" 119 ); 120 PanelUI.multiView.goBack(); 121 await promiseViewShown; 122 123 // Workaround until bug 1363756 is fixed, then this can be removed. 124 await TestUtils.waitForCondition(() => { 125 return !container.hasAttribute("width"); 126 }); 127 } 128 } 129 130 await openSubViewsRecursively(PanelUI.mainView); 131 132 await gCUITestUtils.hideMainMenu(); 133 }, 134 { expectedReflows: [], frames: frameExpectations } 135 ); 136 });