Bug 1781880 - Wait for toolbar item to be visible in browser_984455_bookmarks_items_reparenting.js. r=Gijs

Ensuring the element is visible before trying to open the context menu seems
to solve the frequent intermittent failure here.
Also use getIsEmpty() async helper instead of the internal state of the toolbar.

Differential Revision: https://phabricator.services.mozilla.com/D188724
This commit is contained in:
Marco Bonardo
2023-09-22 07:50:27 +00:00
parent 44a600d1e3
commit 1cf5e35b60

View File

@@ -151,8 +151,13 @@ function checkBookmarksItemsChevronContextMenu() {
*/
function overflowEverything() {
info("Waiting for overflow");
let waitOverflowing = BrowserTestUtils.waitForMutationCondition(
gNavBar,
{ attributes: true, attributeFilter: ["overflowing"] },
() => gNavBar.hasAttribute("overflowing")
);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
return TestUtils.waitForCondition(() => gNavBar.hasAttribute("overflowing"));
return waitOverflowing;
}
/**
@@ -162,8 +167,32 @@ function overflowEverything() {
*/
function stopOverflowing() {
info("Waiting until we stop overflowing");
let waitOverflowing = BrowserTestUtils.waitForMutationCondition(
gNavBar,
{ attributes: true, attributeFilter: ["overflowing"] },
() => !gNavBar.hasAttribute("overflowing")
);
window.resizeTo(kOriginalWindowWidth, window.outerHeight);
return TestUtils.waitForCondition(() => !gNavBar.hasAttribute("overflowing"));
return waitOverflowing;
}
/**
* Ensure bookmarks are visible on the toolbar.
* @param {DOMWindow} win the browser window
*/
async function waitBookmarksToolbarIsUpdated(win = window) {
await TestUtils.waitForCondition(
async () => (await win.PlacesToolbarHelper.getIsEmpty()) === false,
"Waiting for the Bookmarks toolbar to have been rebuilt and not be empty"
);
if (
win.PlacesToolbarHelper._viewElt._placesView._updateNodesVisibilityTimer
) {
await BrowserTestUtils.waitForEvent(
win,
"BookmarksToolbarVisibilityUpdated"
);
}
}
/**
@@ -245,9 +274,7 @@ add_task(async function testOverflowingBookmarksItemsContextMenu() {
let bookmarksToolbarItems = document.getElementById(kBookmarksItems);
await gCustomizeMode.addToToolbar(bookmarksToolbarItems);
await TestUtils.waitForCondition(
() => document.getElementById("PlacesToolbar")._placesView
);
await waitBookmarksToolbarIsUpdated();
await checkPlacesContextMenu(bookmarksToolbarItems);
await overflowEverything();
@@ -258,9 +285,7 @@ add_task(async function testOverflowingBookmarksItemsContextMenu() {
await stopOverflowing();
await gCustomizeMode.addToToolbar(bookmarksToolbarItems);
await TestUtils.waitForCondition(
() => document.getElementById("PlacesToolbar")._placesView
);
await waitBookmarksToolbarIsUpdated();
await checkPlacesContextMenu(bookmarksToolbarItems);
});
@@ -291,6 +316,7 @@ add_task(async function testOverflowingBookmarksItemsChevronContextMenu() {
await stopOverflowing();
checkNotOverflowing(kBookmarksItems);
await waitBookmarksToolbarIsUpdated();
await checkBookmarksItemsChevronContextMenu();
placesToolbarItems.style.removeProperty("max-width");