diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/test/sidebar/browser_sidebar_keys.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/sidebar/browser_sidebar_keys.js')
-rw-r--r-- | browser/base/content/test/sidebar/browser_sidebar_keys.js | 108 |
1 files changed, 108 insertions, 0 deletions
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..f12d1cf5f7 --- /dev/null +++ b/browser/base/content/test/sidebar/browser_sidebar_keys.js @@ -0,0 +1,108 @@ +/* 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"); +}); + +add_task(async function test_sidebar_in_customize_mode() { + // Test bug 1756385 - widgets to appear unchecked in customize mode. Test that + // the sidebar button widget doesn't appear checked, and that the sidebar + // button toggle is inert while in customize mode. + let { CustomizableUI } = ChromeUtils.importESModule( + "resource:///modules/CustomizableUI.sys.mjs" + ); + registerCleanupFunction(() => SidebarUI.hide()); + + let placement = CustomizableUI.getPlacementOfWidget("sidebar-button"); + if (!(placement?.area == CustomizableUI.AREA_NAVBAR)) { + CustomizableUI.addWidgetToArea( + "sidebar-button", + CustomizableUI.AREA_NAVBAR, + 0 + ); + CustomizableUI.ensureWidgetPlacedInWindow("sidebar-button", window); + registerCleanupFunction(function () { + CustomizableUI.removeWidgetFromArea("sidebar-button"); + }); + } + + let widgetIcon = CustomizableUI.getWidget("sidebar-button") + .forWindow(window) + .node?.querySelector(".toolbarbutton-icon"); + // Get the alpha value of the sidebar toggle widget's background + let getBGAlpha = () => + InspectorUtils.colorToRGBA( + getComputedStyle(widgetIcon).getPropertyValue("background-color") + ).a; + + let promiseShown = BrowserTestUtils.waitForEvent(window, "SidebarShown"); + SidebarUI.show("viewBookmarksSidebar"); + await promiseShown; + + Assert.greater( + getBGAlpha(), + 0, + "Sidebar widget background should appear checked" + ); + + // Enter customize mode. This should disable the toggle and make the sidebar + // toggle widget appear unchecked. + let customizationReadyPromise = BrowserTestUtils.waitForEvent( + gNavToolbox, + "customizationready" + ); + gCustomizeMode.enter(); + await customizationReadyPromise; + + Assert.equal( + getBGAlpha(), + 0, + "Sidebar widget background should appear unchecked" + ); + + // Attempt toggle - should fail in customize mode. + await SidebarUI.toggle(); + ok(SidebarUI.isOpen, "Sidebar is still open"); + + // Exit customize mode. This should re-enable the toggle and make the sidebar + // toggle widget appear checked again, since toggle() didn't hide the sidebar. + let afterCustomizationPromise = BrowserTestUtils.waitForEvent( + gNavToolbox, + "aftercustomization" + ); + gCustomizeMode.exit(); + await afterCustomizationPromise; + + Assert.greater( + getBGAlpha(), + 0, + "Sidebar widget background should appear checked again" + ); + + await SidebarUI.toggle(); + ok(!SidebarUI.isOpen, "Sidebar is closed"); + Assert.equal( + getBGAlpha(), + 0, + "Sidebar widget background should appear unchecked" + ); +}); |