Bug 1674160 - Don't show the bookmarks toolbar if there are no visible toolbarbuttons or toolbaritems. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D95539
This commit is contained in:
Jared Wein 2020-11-05 23:00:55 +00:00
Родитель 7465d643ed
Коммит fb60475439
2 изменённых файлов: 35 добавлений и 9 удалений

Просмотреть файл

@ -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)`
);
},

Просмотреть файл

@ -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();
}
});