diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 89f425f7f11d..26303d7367fc 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -1625,22 +1625,21 @@ var BookmarkingUI = { }, bookmarksToolbarHasVisibleChildren() { - let bookmarksToolbarWidgets = CustomizableUI.getWidgetsInArea( - CustomizableUI.AREA_BOOKMARKS + let bookmarksToolbarItemsPlacement = CustomizableUI.getPlacementOfWidget( + "personal-bookmarks" ); - const BOOKMARKS_TOOLBAR_ITEMS_ID = "personal-bookmarks"; if ( - bookmarksToolbarWidgets.find(w => w.id == BOOKMARKS_TOOLBAR_ITEMS_ID) && + bookmarksToolbarItemsPlacement.area == CustomizableUI.AREA_BOOKMARKS && PlacesUtils.getChildCountForFolder(PlacesUtils.bookmarks.toolbarGuid) ) { return true; } - // The bookmarks items may not have any children, but if there are - // other widgets present then treat them as visible. - return bookmarksToolbarWidgets.some( - w => w.id != BOOKMARKS_TOOLBAR_ITEMS_ID + let bookmarksToolbar = document.getElementById("PersonalToolbar"); + return !!bookmarksToolbar.querySelector( + `#PersonalToolbar > toolbarbutton:not([hidden]), + #PersonalToolbar > toolbaritem:not([hidden]):not(#personal-bookmarks)` ); }, diff --git a/browser/base/content/test/about/browser_aboutNewTab_bookmarksToolbarEmpty.js b/browser/base/content/test/about/browser_aboutNewTab_bookmarksToolbarEmpty.js index 657cdbb3e7c0..09201f68a4c1 100644 --- a/browser/base/content/test/about/browser_aboutNewTab_bookmarksToolbarEmpty.js +++ b/browser/base/content/test/about/browser_aboutNewTab_bookmarksToolbarEmpty.js @@ -51,7 +51,7 @@ add_task(async function setup() { }); }); -add_task(async function bookmarks_toolbar_shown_on_newtab() { +add_task(async function bookmarks_toolbar_not_shown_when_empty() { for (let featureEnabled of [true, false]) { info( "Testing with the feature " + (featureEnabled ? "enabled" : "disabled") @@ -128,7 +128,34 @@ add_task(async function bookmarks_toolbar_shown_on_newtab() { "Toolbar is not visible when there are no items or nested bookmarks in the toolbar area", }); + // 6: Add a toolbarbutton and make sure that the toolbar appears when the button is visible + let button = document.createElementNS( + "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", + "toolbarbutton" + ); + let toolbar = document.getElementById("PersonalToolbar"); + button = toolbar.appendChild(button); + await BrowserTestUtils.switchTab(gBrowser, example); + await BrowserTestUtils.switchTab(gBrowser, newtab); + if (featureEnabled) { + await waitForBookmarksToolbarVisibility({ + visible: true, + message: + "Toolbar is visible when there is a visible button in the toolbar", + }); + } + button.hidden = true; + await BrowserTestUtils.switchTab(gBrowser, example); + await BrowserTestUtils.switchTab(gBrowser, newtab); + await waitForBookmarksToolbarVisibility({ + visible: false, + message: + "Toolbar is hidden when there are no visible buttons in the toolbar", + }); + button.remove(); + await BrowserTestUtils.removeTab(newtab); await BrowserTestUtils.removeTab(example); + CustomizableUI.reset(); } });