From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser_default_bookmark_toolbar_visibility.js | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 browser/components/tests/browser/browser_default_bookmark_toolbar_visibility.js (limited to 'browser/components/tests/browser/browser_default_bookmark_toolbar_visibility.js') diff --git a/browser/components/tests/browser/browser_default_bookmark_toolbar_visibility.js b/browser/components/tests/browser/browser_default_bookmark_toolbar_visibility.js new file mode 100644 index 0000000000..90dde882cc --- /dev/null +++ b/browser/components/tests/browser/browser_default_bookmark_toolbar_visibility.js @@ -0,0 +1,89 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Test PlacesUIUtils.maybeToggleBookmarkToolbarVisibility() code running for new profiles. + * Ensure that the bookmarks toolbar is hidden in a default configuration. + * If new default bookmarks are added to the toolbar then the threshold of > 3 + * in NUM_TOOLBAR_BOOKMARKS_TO_UNHIDE may need to be adjusted there. + */ + +add_setup(async function () { + registerCleanupFunction(() => { + Services.prefs.clearUserPref("browser.toolbars.bookmarks.visibility"); + }); +}); + +add_task(async function test_default_bookmark_toolbar_visibility() { + // The Bookmarks Toolbar visibility state should be set only after + // Places has notified that it's done initializing. + const browserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService( + Ci.nsIObserver + ); + + let placesInitCompleteObserved = TestUtils.topicObserved( + "places-browser-init-complete" + ); + + // If places-browser-init-complete has already notified, this will cause it + // to notify again. Otherwise, we wait until the notify is done. + browserGlue.observe( + null, + "browser-glue-test", + "places-browser-init-complete" + ); + + await placesInitCompleteObserved; + + const BROWSER_DOCURL = AppConstants.BROWSER_CHROME_URL; + let xulStore = Services.xulStore; + + is( + xulStore.getValue(BROWSER_DOCURL, "PersonalToolbar", "collapsed"), + "", + "Check that @collapsed isn't persisted" + ); + ok( + document.getElementById("PersonalToolbar").collapsed, + "The bookmarks toolbar should be collapsed by default" + ); +}); + +/** + * Ensure that the bookmarks toolbar is visible in a new profile + * if the toolbar has > 3 (NUM_TOOLBAR_BOOKMARKS_TO_UNHIDE) bookmarks. + */ +add_task(async function test_bookmark_toolbar_visible_when_populated() { + const { Bookmarks } = ChromeUtils.importESModule( + "resource://gre/modules/Bookmarks.sys.mjs" + ); + const { PlacesUIUtils } = ChromeUtils.importESModule( + "resource:///modules/PlacesUIUtils.sys.mjs" + ); + + let bookmark = { + type: Bookmarks.TYPE_BOOKMARK, + parentGuid: Bookmarks.toolbarGuid, + }; + let bookmarksInserted = await Promise.all([ + Bookmarks.insert(Object.assign({ url: "https://example.com/1" }, bookmark)), + Bookmarks.insert(Object.assign({ url: "https://example.com/2" }, bookmark)), + Bookmarks.insert(Object.assign({ url: "https://example.com/3" }, bookmark)), + Bookmarks.insert(Object.assign({ url: "https://example.com/4" }, bookmark)), + Bookmarks.insert(Object.assign({ url: "https://example.com/5" }, bookmark)), + Bookmarks.insert(Object.assign({ url: "https://example.com/6" }, bookmark)), + ]); + + await PlacesUIUtils.maybeToggleBookmarkToolbarVisibility(); + + const personalToolbar = document.getElementById("PersonalToolbar"); + ok( + !personalToolbar.collapsed, + "The bookmarks toolbar should be visible since it has many bookmarks" + ); + + for (let insertedBookmark of bookmarksInserted) { + await Bookmarks.remove(insertedBookmark.guid); + } + personalToolbar.collapsed = true; +}); -- cgit v1.2.3