summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js')
-rw-r--r--browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js129
1 files changed, 129 insertions, 0 deletions
diff --git a/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js b/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js
new file mode 100644
index 0000000000..66258659fd
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_new_tab_bookmarks_toolbar_height.js
@@ -0,0 +1,129 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// Tests that showing the bookmarks toolbar for new tabs only doesn't affect
+// the view port height in background tabs.
+
+let gHeightChanges = 0;
+async function expectHeightChanges(tab, expectedNewHeightChanges, msg) {
+ let contentObservedHeightChanges = await ContentTask.spawn(
+ tab.linkedBrowser,
+ null,
+ async args => {
+ await new Promise(resolve => content.requestAnimationFrame(resolve));
+ return content.document.body.innerText;
+ }
+ );
+ is(
+ contentObservedHeightChanges - gHeightChanges,
+ expectedNewHeightChanges,
+ msg
+ );
+ gHeightChanges = contentObservedHeightChanges;
+}
+
+async function expectBmToolbarVisibilityChange(triggerFn, visible, msg) {
+ let collapsedState = BrowserTestUtils.waitForMutationCondition(
+ BookmarkingUI.toolbar,
+ { attributes: true, attributeFilter: ["collapsed"] },
+ () => BookmarkingUI.toolbar.collapsed != visible
+ );
+ let toolbarItemsVisibilityUpdated = visible
+ ? BrowserTestUtils.waitForEvent(
+ BookmarkingUI.toolbar,
+ "BookmarksToolbarVisibilityUpdated"
+ )
+ : null;
+ triggerFn();
+ await collapsedState;
+ is(
+ BookmarkingUI.toolbar.getAttribute("collapsed"),
+ (!visible).toString(),
+ `${msg}; collapsed attribute state`
+ );
+ if (visible) {
+ info(`${msg}; waiting for toolbar items to become visible`);
+ await toolbarItemsVisibilityUpdated;
+ isnot(
+ BookmarkingUI.toolbar.getBoundingClientRect().height,
+ 0,
+ `${msg}; should have a height`
+ );
+ } else {
+ is(
+ BookmarkingUI.toolbar.getBoundingClientRect().height,
+ 0,
+ `${msg}; should have zero height`
+ );
+ }
+}
+
+add_task(async function () {
+ registerCleanupFunction(() => {
+ setToolbarVisibility(
+ BookmarkingUI.toolbar,
+ gBookmarksToolbarVisibility,
+ false,
+ false
+ );
+ });
+
+ await expectBmToolbarVisibilityChange(
+ () => setToolbarVisibility(BookmarkingUI.toolbar, false, false, false),
+ false,
+ "bookmarks toolbar is hidden initially"
+ );
+
+ let pageURL = getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ "https://example.com"
+ );
+ pageURL = `${pageURL}file_observe_height_changes.html`;
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageURL);
+
+ await expectBmToolbarVisibilityChange(
+ () => setToolbarVisibility(BookmarkingUI.toolbar, true, false, false),
+ true,
+ "bookmarks toolbar is visible after explicitly showing it for tab with content loaded"
+ );
+ await expectHeightChanges(
+ tab,
+ 1,
+ "content area height changes when showing the toolbar without the animation"
+ );
+
+ await expectBmToolbarVisibilityChange(
+ () => setToolbarVisibility(BookmarkingUI.toolbar, "newtab", false, false),
+ false,
+ "bookmarks toolbar is hidden for non-new tab after setting it to only show for new tabs"
+ );
+ await expectHeightChanges(
+ tab,
+ 1,
+ "content area height changes when hiding the toolbar without the animation"
+ );
+
+ info("Opening a new tab, making the previous tab non-selected");
+ await expectBmToolbarVisibilityChange(
+ () => {
+ BrowserOpenTab();
+ ok(
+ !tab.selected,
+ "non-new tab is in the background (not the selected tab)"
+ );
+ },
+ true,
+ "bookmarks toolbar is visible for new tab after setting it to only show for new tabs"
+ );
+ await expectHeightChanges(
+ tab,
+ 0,
+ "no additional content area height change in background tab when showing the bookmarks toolbar in new tab"
+ );
+
+ gBrowser.removeCurrentTab();
+ gBrowser.removeTab(tab);
+});