browser_window_resize.js (3676B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * WHOA THERE: We should never be adding new things to EXPECTED_REFLOWS. 8 * Instead of adding reflows to the list, you should be modifying your code to 9 * avoid the reflow. 10 * 11 * See https://firefox-source-docs.mozilla.org/performance/bestpractices.html 12 * for tips on how to do that. 13 */ 14 const EXPECTED_REFLOWS = [ 15 /** 16 * Nothing here! Please don't add anything new! 17 */ 18 ]; 19 20 const gToolbar = document.getElementById("PersonalToolbar"); 21 22 /** 23 * Sets the visibility state on the Bookmarks Toolbar, and 24 * waits for it to transition to fully visible. 25 * 26 * @param visible (bool) 27 * Whether or not the bookmarks toolbar should be made visible. 28 * @returns Promise 29 */ 30 async function toggleBookmarksToolbar(visible) { 31 let transitionPromise = BrowserTestUtils.waitForEvent( 32 gToolbar, 33 "transitionend", 34 e => e.propertyName == "max-height" 35 ); 36 37 setToolbarVisibility(gToolbar, visible); 38 await transitionPromise; 39 } 40 41 /** 42 * Resizes a browser window to a particular width and height, and 43 * waits for it to reach a "steady state" with respect to its overflowing 44 * toolbars. 45 * 46 * @param win (browser window) 47 * The window to resize. 48 * @param width (int) 49 * The width to resize the window to. 50 * @param height (int) 51 * The height to resize the window to. 52 * @returns Promise 53 */ 54 async function resizeWindow(win, width, height) { 55 let toolbarEvent = BrowserTestUtils.waitForEvent( 56 win, 57 "BookmarksToolbarVisibilityUpdated" 58 ); 59 let resizeEvent = BrowserTestUtils.waitForEvent(win, "resize"); 60 win.windowUtils.ensureDirtyRootFrame(); 61 win.resizeTo(width, height); 62 await resizeEvent; 63 await toolbarEvent; 64 } 65 66 /* 67 * This test ensures that there are no unexpected 68 * uninterruptible reflows when resizing windows. 69 */ 70 add_task(async function () { 71 const BOOKMARKS_COUNT = 150; 72 const STARTING_WIDTH = 600; 73 const STARTING_HEIGHT = 400; 74 const SMALL_WIDTH = 150; 75 const SMALL_HEIGHT = 150; 76 77 await PlacesUtils.bookmarks.eraseEverything(); 78 79 // Add a bunch of bookmarks to display in the Bookmarks toolbar 80 await PlacesUtils.bookmarks.insertTree({ 81 guid: PlacesUtils.bookmarks.toolbarGuid, 82 children: Array(BOOKMARKS_COUNT) 83 .fill("") 84 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 85 .map((_, i) => ({ url: `http://test.places.${i}.x/` })), 86 }); 87 88 let wasCollapsed = gToolbar.collapsed; 89 Assert.ok(wasCollapsed, "The toolbar is collapsed by default"); 90 if (wasCollapsed) { 91 let promiseReady = BrowserTestUtils.waitForEvent( 92 gToolbar, 93 "BookmarksToolbarVisibilityUpdated" 94 ); 95 await toggleBookmarksToolbar(true); 96 await promiseReady; 97 } 98 99 registerCleanupFunction(async () => { 100 if (wasCollapsed) { 101 await toggleBookmarksToolbar(false); 102 } 103 await PlacesUtils.bookmarks.eraseEverything(); 104 await PlacesUtils.history.clear(); 105 }); 106 107 let win = await prepareSettledWindow(); 108 109 if ( 110 win.screen.availWidth < STARTING_WIDTH || 111 win.screen.availHeight < STARTING_HEIGHT 112 ) { 113 Assert.ok( 114 false, 115 "This test is running on too small a display - " + 116 `(${STARTING_WIDTH}x${STARTING_HEIGHT} min)` 117 ); 118 return; 119 } 120 121 await resizeWindow(win, STARTING_WIDTH, STARTING_HEIGHT); 122 123 await withPerfObserver( 124 async function () { 125 await resizeWindow(win, SMALL_WIDTH, SMALL_HEIGHT); 126 await resizeWindow(win, STARTING_WIDTH, STARTING_HEIGHT); 127 }, 128 { expectedReflows: EXPECTED_REFLOWS, frames: { filter: () => [] } }, 129 win 130 ); 131 132 await BrowserTestUtils.closeWindow(win); 133 });