summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/sidebar
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /browser/base/content/test/sidebar
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/sidebar')
-rw-r--r--browser/base/content/test/sidebar/.eslintrc.js5
-rw-r--r--browser/base/content/test/sidebar/browser.ini6
-rw-r--r--browser/base/content/test/sidebar/browser_sidebar_adopt.js67
-rw-r--r--browser/base/content/test/sidebar/browser_sidebar_keys.js24
-rw-r--r--browser/base/content/test/sidebar/browser_sidebar_move.js72
-rw-r--r--browser/base/content/test/sidebar/browser_sidebar_switcher.js64
6 files changed, 238 insertions, 0 deletions
diff --git a/browser/base/content/test/sidebar/.eslintrc.js b/browser/base/content/test/sidebar/.eslintrc.js
new file mode 100644
index 0000000000..1779fd7f1c
--- /dev/null
+++ b/browser/base/content/test/sidebar/.eslintrc.js
@@ -0,0 +1,5 @@
+"use strict";
+
+module.exports = {
+ extends: ["plugin:mozilla/browser-test"],
+};
diff --git a/browser/base/content/test/sidebar/browser.ini b/browser/base/content/test/sidebar/browser.ini
new file mode 100644
index 0000000000..3e076fadd4
--- /dev/null
+++ b/browser/base/content/test/sidebar/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+
+[browser_sidebar_adopt.js]
+[browser_sidebar_keys.js]
+[browser_sidebar_move.js]
+[browser_sidebar_switcher.js]
diff --git a/browser/base/content/test/sidebar/browser_sidebar_adopt.js b/browser/base/content/test/sidebar/browser_sidebar_adopt.js
new file mode 100644
index 0000000000..e61e9a1972
--- /dev/null
+++ b/browser/base/content/test/sidebar/browser_sidebar_adopt.js
@@ -0,0 +1,67 @@
+/* This test checks that the SidebarFocused event doesn't fire in adopted
+ * windows when the sidebar gets opened during window opening, to make sure
+ * that sidebars don't steal focus from the page in this case (Bug 1394207).
+ * There's another case not covered here that has the same expected behavior -
+ * during the initial browser startup - but it would be hard to do with a mochitest. */
+
+registerCleanupFunction(() => {
+ SidebarUI.hide();
+});
+
+function failIfSidebarFocusedFires() {
+ ok(false, "This event shouldn't have fired");
+}
+
+add_task(async function testAdoptedTwoWindows() {
+ // First open a new window, show the sidebar in that window, and close it.
+ // Then, open another new window and confirm that the sidebar is closed since it is
+ // being adopted from the main window which doesn't have a shown sidebar. See Bug 1407737.
+ info("Ensure that sidebar state is adopted only from the opener");
+
+ let win1 = await BrowserTestUtils.openNewBrowserWindow();
+ await win1.SidebarUI.show("viewBookmarksSidebar");
+ await BrowserTestUtils.closeWindow(win1);
+
+ let win2 = await BrowserTestUtils.openNewBrowserWindow();
+ ok(
+ !win2.document.getElementById("sidebar-button").hasAttribute("checked"),
+ "Sidebar button isn't checked"
+ );
+ ok(!win2.SidebarUI.isOpen, "Sidebar is closed");
+ await BrowserTestUtils.closeWindow(win2);
+});
+
+add_task(async function testEventsReceivedInMainWindow() {
+ info(
+ "Opening the sidebar and expecting both SidebarShown and SidebarFocused events"
+ );
+
+ let initialShown = BrowserTestUtils.waitForEvent(window, "SidebarShown");
+ let initialFocus = BrowserTestUtils.waitForEvent(window, "SidebarFocused");
+
+ await SidebarUI.show("viewBookmarksSidebar");
+ await initialShown;
+ await initialFocus;
+
+ ok(true, "SidebarShown and SidebarFocused events fired on a new window");
+});
+
+add_task(async function testEventReceivedInNewWindow() {
+ info(
+ "Opening a new window and expecting the SidebarFocused event to not fire"
+ );
+
+ let promiseNewWindow = BrowserTestUtils.waitForNewWindow();
+ let win = OpenBrowserWindow();
+
+ let adoptedShown = BrowserTestUtils.waitForEvent(win, "SidebarShown");
+ win.addEventListener("SidebarFocused", failIfSidebarFocusedFires);
+ registerCleanupFunction(async function() {
+ win.removeEventListener("SidebarFocused", failIfSidebarFocusedFires);
+ await BrowserTestUtils.closeWindow(win);
+ });
+
+ await promiseNewWindow;
+ await adoptedShown;
+ ok(true, "SidebarShown event fired on an adopted window");
+});
diff --git a/browser/base/content/test/sidebar/browser_sidebar_keys.js b/browser/base/content/test/sidebar/browser_sidebar_keys.js
new file mode 100644
index 0000000000..2c9817d5b0
--- /dev/null
+++ b/browser/base/content/test/sidebar/browser_sidebar_keys.js
@@ -0,0 +1,24 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+async function testSidebarKeyToggle(key, options, expectedSidebarId) {
+ EventUtils.synthesizeMouseAtCenter(gURLBar.textbox, {});
+ let promiseShown = BrowserTestUtils.waitForEvent(window, "SidebarShown");
+ EventUtils.synthesizeKey(key, options);
+ await promiseShown;
+ Assert.equal(
+ document.getElementById("sidebar-box").getAttribute("sidebarcommand"),
+ expectedSidebarId
+ );
+ EventUtils.synthesizeKey(key, options);
+ Assert.ok(!SidebarUI.isOpen);
+}
+
+add_task(async function test_sidebar_keys() {
+ registerCleanupFunction(() => SidebarUI.hide());
+
+ await testSidebarKeyToggle("b", { accelKey: true }, "viewBookmarksSidebar");
+
+ let options = { accelKey: true, shiftKey: AppConstants.platform == "macosx" };
+ await testSidebarKeyToggle("h", options, "viewHistorySidebar");
+});
diff --git a/browser/base/content/test/sidebar/browser_sidebar_move.js b/browser/base/content/test/sidebar/browser_sidebar_move.js
new file mode 100644
index 0000000000..49d705895b
--- /dev/null
+++ b/browser/base/content/test/sidebar/browser_sidebar_move.js
@@ -0,0 +1,72 @@
+registerCleanupFunction(() => {
+ Services.prefs.clearUserPref("sidebar.position_start");
+ SidebarUI.hide();
+});
+
+const EXPECTED_START_ORDINALS = [
+ ["sidebar-box", 1],
+ ["sidebar-splitter", 2],
+ ["appcontent", 3],
+];
+
+const EXPECTED_END_ORDINALS = [
+ ["sidebar-box", 3],
+ ["sidebar-splitter", 2],
+ ["appcontent", 1],
+];
+
+function getBrowserChildrenWithOrdinals() {
+ let browser = document.getElementById("browser");
+ return [...browser.children].map(node => {
+ return [node.id, node.style.MozBoxOrdinalGroup];
+ });
+}
+
+add_task(async function() {
+ await SidebarUI.show("viewBookmarksSidebar");
+ SidebarUI.showSwitcherPanel();
+
+ let reversePositionButton = document.getElementById(
+ "sidebar-reverse-position"
+ );
+ let originalLabel = reversePositionButton.getAttribute("label");
+ let box = document.getElementById("sidebar-box");
+
+ // Default (position: left)
+ Assert.deepEqual(
+ getBrowserChildrenWithOrdinals(),
+ EXPECTED_START_ORDINALS,
+ "Correct ordinal (start)"
+ );
+ ok(!box.hasAttribute("positionend"), "Positioned start");
+
+ // Moved to right
+ SidebarUI.reversePosition();
+ SidebarUI.showSwitcherPanel();
+ Assert.deepEqual(
+ getBrowserChildrenWithOrdinals(),
+ EXPECTED_END_ORDINALS,
+ "Correct ordinal (end)"
+ );
+ isnot(
+ reversePositionButton.getAttribute("label"),
+ originalLabel,
+ "Label changed"
+ );
+ ok(box.hasAttribute("positionend"), "Positioned end");
+
+ // Moved to back to left
+ SidebarUI.reversePosition();
+ SidebarUI.showSwitcherPanel();
+ Assert.deepEqual(
+ getBrowserChildrenWithOrdinals(),
+ EXPECTED_START_ORDINALS,
+ "Correct ordinal (start)"
+ );
+ ok(!box.hasAttribute("positionend"), "Positioned start");
+ is(
+ reversePositionButton.getAttribute("label"),
+ originalLabel,
+ "Label is back to normal"
+ );
+});
diff --git a/browser/base/content/test/sidebar/browser_sidebar_switcher.js b/browser/base/content/test/sidebar/browser_sidebar_switcher.js
new file mode 100644
index 0000000000..dce5821394
--- /dev/null
+++ b/browser/base/content/test/sidebar/browser_sidebar_switcher.js
@@ -0,0 +1,64 @@
+registerCleanupFunction(() => {
+ SidebarUI.hide();
+});
+
+function showSwitcherPanelPromise() {
+ return new Promise(resolve => {
+ SidebarUI._switcherPanel.addEventListener(
+ "popupshown",
+ () => {
+ resolve();
+ },
+ { once: true }
+ );
+ SidebarUI.showSwitcherPanel();
+ });
+}
+
+function clickSwitcherButton(querySelector) {
+ let sidebarPopup = document.querySelector("#sidebarMenu-popup");
+ let switcherPromise = Promise.all([
+ BrowserTestUtils.waitForEvent(window, "SidebarFocused"),
+ BrowserTestUtils.waitForEvent(sidebarPopup, "popuphidden"),
+ ]);
+ document.querySelector(querySelector).click();
+ return switcherPromise;
+}
+
+add_task(async function() {
+ // If a sidebar is already open, close it.
+ if (!document.getElementById("sidebar-box").hidden) {
+ ok(
+ false,
+ "Unexpected sidebar found - a previous test failed to cleanup correctly"
+ );
+ SidebarUI.hide();
+ }
+
+ let sidebar = document.querySelector("#sidebar-box");
+ await SidebarUI.show("viewBookmarksSidebar");
+
+ await showSwitcherPanelPromise();
+ await clickSwitcherButton("#sidebar-switcher-history");
+ is(
+ sidebar.getAttribute("sidebarcommand"),
+ "viewHistorySidebar",
+ "History sidebar loaded"
+ );
+
+ await showSwitcherPanelPromise();
+ await clickSwitcherButton("#sidebar-switcher-tabs");
+ is(
+ sidebar.getAttribute("sidebarcommand"),
+ "viewTabsSidebar",
+ "Tabs sidebar loaded"
+ );
+
+ await showSwitcherPanelPromise();
+ await clickSwitcherButton("#sidebar-switcher-bookmarks");
+ is(
+ sidebar.getAttribute("sidebarcommand"),
+ "viewBookmarksSidebar",
+ "Bookmarks sidebar loaded"
+ );
+});