From 570cccef2501c36d2ad34aa7e107d7489aa2dc69 Mon Sep 17 00:00:00 2001 From: Mark Striemer Date: Thu, 11 Mar 2021 15:09:21 +0000 Subject: [PATCH] Bug 1694817 - Fix tests that fail with browser.proton.toolbar.enabled r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D107294 --- .../content/test/general/browser_bug462289.js | 12 +++ .../content/test/general/browser_homeDrop.js | 15 ++++ .../test/general/browser_newTabDrop.js | 4 +- .../test/general/browser_newWindowDrop.js | 7 ++ .../keyboard/browser_toolbarButtonKeyPress.js | 12 +++ .../test/keyboard/browser_toolbarKeyNav.js | 86 +++++++++++++++++-- .../test/sidebar/browser_sidebar_adopt.js | 9 ++ .../browser_identityBlock_focus.js | 11 +++ .../base/content/test/sync/browser_sync.js | 8 +- ...rowser_navigate_home_focuses_addressbar.js | 7 ++ .../browser/browser_downloads_autohide.js | 2 +- .../browser_ext_browserAction_contextMenu.js | 6 ++ .../browser/browser_enable_toolbar_sidebar.js | 9 +- .../browser/browser_searchbar_openpopup.js | 6 ++ .../components/uitour/test/browser_UITour.js | 2 +- .../test/browser_UITour_availableTargets.js | 2 +- .../tests/browser/browser_aboutHomeLoading.js | 9 ++ .../tests/browser/browser_dragdropURL.js | 7 ++ .../tests/browser/browser_tabKeyBehavior.js | 13 ++- .../browser/browser_urlbar_event_telemetry.js | 2 +- .../browser_UsageTelemetry_usagePrefs.js | 23 ++++- .../browser/browser_ext_themes_separators.js | 24 ++++-- ...browser_ext_themes_toolbarbutton_colors.js | 9 ++ .../browser_ext_themes_toolbarbutton_icons.js | 9 ++ 24 files changed, 265 insertions(+), 29 deletions(-) diff --git a/browser/base/content/test/general/browser_bug462289.js b/browser/base/content/test/general/browser_bug462289.js index 8c2c70e1ae06..dfb669e4c525 100644 --- a/browser/base/content/test/general/browser_bug462289.js +++ b/browser/base/content/test/general/browser_bug462289.js @@ -10,6 +10,18 @@ function focus_in_navbar() { } function test() { + if (CustomizableUI.protonToolbarEnabled) { + // Put the home button in the pre-proton placement to test focus states. + CustomizableUI.addWidgetToArea( + "home-button", + "nav-bar", + CustomizableUI.getPlacementOfWidget("stop-reload-button").position + 1 + ); + registerCleanupFunction(async function resetToolbar() { + await CustomizableUI.reset(); + }); + } + waitForExplicitFinish(); tab1 = BrowserTestUtils.addTab(gBrowser, "about:blank", { diff --git a/browser/base/content/test/general/browser_homeDrop.js b/browser/base/content/test/general/browser_homeDrop.js index 0189ad52bd70..3d5c8ef61bf7 100644 --- a/browser/base/content/test/general/browser_homeDrop.js +++ b/browser/base/content/test/general/browser_homeDrop.js @@ -1,6 +1,21 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ +add_task(async function setupHomeButton() { + if (CustomizableUI.protonToolbarEnabled) { + // Put the home button in the pre-proton placement to test focus states. + CustomizableUI.addWidgetToArea( + "home-button", + "nav-bar", + CustomizableUI.getPlacementOfWidget("stop-reload-button").position + 1 + ); + CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar"); + } + registerCleanupFunction(async function resetToolbar() { + await CustomizableUI.reset(); + }); +}); + add_task(async function() { let HOMEPAGE_PREF = "browser.startup.homepage"; diff --git a/browser/base/content/test/general/browser_newTabDrop.js b/browser/base/content/test/general/browser_newTabDrop.js index 309997630cbb..2740a1fe226e 100644 --- a/browser/base/content/test/general/browser_newTabDrop.js +++ b/browser/base/content/test/general/browser_newTabDrop.js @@ -193,8 +193,8 @@ async function drop(dragData, expectedURLs) { // Since synthesizeDrop triggers the srcElement, need to use another button // that should be visible. - let dragSrcElement = document.getElementById("sidebar-button"); - ok(dragSrcElement, "Sidebar button exists"); + let dragSrcElement = document.getElementById("back-button"); + ok(dragSrcElement, "Back button exists"); let newTabButton = document.getElementById( gBrowser.tabContainer.hasAttribute("overflow") ? "new-tab-button" diff --git a/browser/base/content/test/general/browser_newWindowDrop.js b/browser/base/content/test/general/browser_newWindowDrop.js index 5e87b1964d95..fe44e9003c87 100644 --- a/browser/base/content/test/general/browser_newWindowDrop.js +++ b/browser/base/content/test/general/browser_newWindowDrop.js @@ -39,6 +39,13 @@ add_task(async function test_setup() { CustomizableUI.removeWidgetFromArea("new-window-button"); }); } + + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("sidebar-button") + ); + } }); // New Window Button opens any link. diff --git a/browser/base/content/test/keyboard/browser_toolbarButtonKeyPress.js b/browser/base/content/test/keyboard/browser_toolbarButtonKeyPress.js index 95431b43dcfa..119b06a54bb2 100644 --- a/browser/base/content/test/keyboard/browser_toolbarButtonKeyPress.js +++ b/browser/base/content/test/keyboard/browser_toolbarButtonKeyPress.js @@ -60,6 +60,9 @@ add_task(async function testAppMenuButtonWrongKey() { // Test activation of the Library button from the keyboard. // The Library menu should appear and focus should move inside it. add_task(async function testLibraryButtonPress() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("library-button", "nav-bar"); + } let button = document.getElementById("library-button"); forceFocus(button); EventUtils.synthesizeKey(" "); @@ -70,6 +73,9 @@ add_task(async function testLibraryButtonPress() { let hidden = BrowserTestUtils.waitForEvent(document, "popuphidden", true); view.closest("panel").hidePopup(); await hidden; + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.removeWidgetFromArea("library-button"); + } }); // Test activation of the Developer button from the keyboard. @@ -196,6 +202,9 @@ add_task(async function testReloadButtonPress() { // Test activation of the Sidebars button from the keyboard. // This is a toolbarbutton with a command handler. add_task(async function testSidebarsButtonPress() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar"); + } let button = document.getElementById("sidebar-button"); ok(!button.checked, "Sidebars button not checked at start of test"); let sidebarBox = document.getElementById("sidebar-box"); @@ -216,6 +225,9 @@ add_task(async function testSidebarsButtonPress() { await TestUtils.waitForCondition(() => !button.checked); ok(true, "Sidebars button not checked after press"); ok(sidebarBox.hidden, "Sidebar hidden after press"); + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.removeWidgetFromArea("sidebar-button"); + } }); // Test activation of the Bookmark this page button from the keyboard. diff --git a/browser/base/content/test/keyboard/browser_toolbarKeyNav.js b/browser/base/content/test/keyboard/browser_toolbarKeyNav.js index 4622597b7fb0..fda4fe4a2f62 100644 --- a/browser/base/content/test/keyboard/browser_toolbarKeyNav.js +++ b/browser/base/content/test/keyboard/browser_toolbarKeyNav.js @@ -11,6 +11,9 @@ const PERMISSIONS_PAGE = "https://example.com/browser/browser/base/content/test/permissions/permissions.html"; +const afterUrlBarButton = CustomizableUI.protonToolbarEnabled + ? "PanelUI-menu-button" + : "library-button"; // The DevEdition has the DevTools button in the toolbar by default. Remove it // to prevent branch-specific rules what button should be focused. @@ -19,6 +22,57 @@ function resetToolbarWithoutDevEditionButtons() { CustomizableUI.removeWidgetFromArea("developer-button"); } +function maybeAddHomeBesideReload() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea( + "home-button", + "nav-bar", + CustomizableUI.getPlacementOfWidget("stop-reload-button").position + 1 + ); + } +} + +function maybeRemoveHomeButton() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.removeWidgetFromArea("home-button"); + } +} + +function maybeAddOldMenuSideButtons() { + if (CustomizableUI.protonToolbarEnabled) { + // Make the FxA button visible even though we're signed out. + // We'll use oldfxastatus to restore the old state. + document.documentElement.setAttribute( + "oldfxastatus", + document.documentElement.getAttribute("fxastatus") + ); + document.documentElement.setAttribute("fxastatus", "signed_in"); + // The FxA button is supposed to be last, add these buttons before it. + CustomizableUI.addWidgetToArea( + "library-button", + "nav-bar", + CustomizableUI.getWidgetIdsInArea("nav-bar").length - 1 + ); + CustomizableUI.addWidgetToArea( + "sidebar-button", + "nav-bar", + CustomizableUI.getWidgetIdsInArea("nav-bar").length - 1 + ); + } +} + +function maybeRemoveOldMenuSideButtons() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.removeWidgetFromArea("library-button"); + CustomizableUI.removeWidgetFromArea("sidebar-button"); + document.documentElement.setAttribute( + "fxastatus", + document.documentElement.getAttribute("oldfxastatus") + ); + document.documentElement.removeAttribute("oldfxastatus"); + } +} + function startFromUrlBar(aWindow = window) { aWindow.gURLBar.focus(); is( @@ -72,16 +126,18 @@ add_task(async function setup() { }); // Test tab stops with no page loaded. -add_task(async function testTabStopsNoPage() { +add_task(async function testTabStopsNoPageWithHomeButton() { + maybeAddHomeBesideReload(); await withNewBlankTab(async function() { startFromUrlBar(); await expectFocusAfterKey("Shift+Tab", "home-button"); await expectFocusAfterKey("Shift+Tab", "tabbrowser-tabs", true); await expectFocusAfterKey("Tab", "home-button"); await expectFocusAfterKey("Tab", gURLBar.inputField); - await expectFocusAfterKey("Tab", "library-button"); + await expectFocusAfterKey("Tab", afterUrlBarButton); await expectFocusAfterKey("Tab", gBrowser.selectedBrowser); }); + maybeRemoveHomeButton(); }); // Test tab stops with a page loaded. @@ -99,7 +155,7 @@ add_task(async function testTabStopsPageLoaded() { await expectFocusAfterKey("Tab", "tracking-protection-icon-container"); await expectFocusAfterKey("Tab", gURLBar.inputField); await expectFocusAfterKey("Tab", "pageActionButton"); - await expectFocusAfterKey("Tab", "library-button"); + await expectFocusAfterKey("Tab", afterUrlBarButton); await expectFocusAfterKey("Tab", gBrowser.selectedBrowser); }); }); @@ -130,14 +186,14 @@ add_task(async function testTabStopsWithBookmarksToolbar() { await BrowserTestUtils.withNewTab("about:blank", async function() { CustomizableUI.setToolbarVisibility("PersonalToolbar", true); startFromUrlBar(); - await expectFocusAfterKey("Tab", "library-button"); + await expectFocusAfterKey("Tab", afterUrlBarButton); await expectFocusAfterKey("Tab", "PersonalToolbar", true); await expectFocusAfterKey("Tab", gBrowser.selectedBrowser); // Make sure the Bookmarks toolbar is no longer tabbable once hidden. CustomizableUI.setToolbarVisibility("PersonalToolbar", false); startFromUrlBar(); - await expectFocusAfterKey("Tab", "library-button"); + await expectFocusAfterKey("Tab", afterUrlBarButton); await expectFocusAfterKey("Tab", gBrowser.selectedBrowser); }); }); @@ -152,8 +208,10 @@ add_task(async function testTabStopNoButtons() { await expectFocusAfterKey("Shift+Tab", "tabbrowser-tabs", true); await expectFocusAfterKey("Tab", gURLBar.inputField); resetToolbarWithoutDevEditionButtons(); + maybeAddHomeBesideReload(); // Make sure the button is reachable now that it has been re-added. await expectFocusAfterKey("Shift+Tab", "home-button", true); + maybeRemoveHomeButton(); }); }); @@ -163,6 +221,7 @@ add_task(async function testTabStopNoButtons() { // 2. The overflow menu button can't be reached by right arrow when it isn't // visible. add_task(async function testArrowsToolbarbuttons() { + maybeAddOldMenuSideButtons(); await BrowserTestUtils.withNewTab("about:blank", async function() { startFromUrlBar(); await expectFocusAfterKey("Tab", "library-button"); @@ -187,6 +246,7 @@ add_task(async function testArrowsToolbarbuttons() { await expectFocusAfterKey("ArrowLeft", "sidebar-button"); await expectFocusAfterKey("ArrowLeft", "library-button"); }); + maybeRemoveOldMenuSideButtons(); }); // Test that right/left arrows move through buttons wihch aren't toolbarbuttons @@ -238,6 +298,7 @@ add_task(async function testArrowsDisabledButtons() { // Test that right arrow reaches the overflow menu button when it is visible. add_task(async function testArrowsOverflowButton() { + maybeAddOldMenuSideButtons(); await BrowserTestUtils.withNewTab("about:blank", async function() { // Move something to the overflow menu to make the button appear. CustomizableUI.addWidgetToArea( @@ -256,6 +317,7 @@ add_task(async function testArrowsOverflowButton() { document.getElementById("nav-bar-overflow-button").clientWidth; await expectFocusAfterKey("ArrowLeft", "fxa-toolbar-menu-button"); }); + maybeRemoveOldMenuSideButtons(); }); // Test that toolbar keyboard navigation doesn't interfere with PanelMultiView @@ -263,6 +325,7 @@ add_task(async function testArrowsOverflowButton() { // We do this by opening the Library menu and ensuring that pressing left arrow // does nothing. add_task(async function testArrowsInPanelMultiView() { + maybeAddOldMenuSideButtons(); let button = document.getElementById("library-button"); forceFocus(button); EventUtils.synthesizeKey(" "); @@ -279,10 +342,12 @@ add_task(async function testArrowsInPanelMultiView() { let hidden = BrowserTestUtils.waitForEvent(document, "popuphidden", true); view.closest("panel").hidePopup(); await hidden; + maybeRemoveOldMenuSideButtons(); }); // Test that right/left arrows move in the expected direction for RTL locales. add_task(async function testArrowsRtl() { + maybeAddOldMenuSideButtons(); await SpecialPowers.pushPrefEnv({ set: [["intl.l10n.pseudo", "bidi"]] }); // window.RTL_UI doesn't update in existing windows when this pref is changed, // so we need to test in a new window. @@ -298,6 +363,7 @@ add_task(async function testArrowsRtl() { await expectFocusAfterKey("ArrowLeft", "sidebar-button", false, win); await BrowserTestUtils.closeWindow(win); await SpecialPowers.popPrefEnv(); + maybeRemoveOldMenuSideButtons(); }); // Test that right arrow reaches the overflow menu button on the Bookmarks @@ -330,6 +396,7 @@ registerCleanupFunction(async function() { // Test that when a toolbar button opens a panel, closing the panel restores // focus to the button which opened it. add_task(async function testPanelCloseRestoresFocus() { + maybeAddOldMenuSideButtons(); await withNewBlankTab(async function() { // We can't use forceFocus because that removes focusability immediately. // Instead, we must let ToolbarKeyboardNavigator handle this properly. @@ -348,6 +415,7 @@ add_task(async function testPanelCloseRestoresFocus() { "Focus restored to Library button after panel closed" ); }); + maybeRemoveOldMenuSideButtons(); }); // Test that the arrow key works in the group of the @@ -377,6 +445,8 @@ add_task(async function testArrowKeyForTPIconContainerandIdentityBox() { // Test navigation by typed characters. add_task(async function testCharacterNavigation() { + maybeAddHomeBesideReload(); + maybeAddOldMenuSideButtons(); await BrowserTestUtils.withNewTab("https://example.com", async function() { await waitUntilReloadEnabled(); startFromUrlBar(); @@ -401,6 +471,8 @@ add_task(async function testCharacterNavigation() { // Pressing s again should find the next button starting with s: Sidebars. await expectFocusAfterKey("s", "sidebar-button"); }); + maybeRemoveHomeButton(); + maybeRemoveOldMenuSideButtons(); }); // Test that toolbar character navigation doesn't trigger in PanelMultiView for @@ -410,6 +482,7 @@ add_task(async function testCharacterNavigation() { // This test should be removed if PanelMultiView implements character // navigation. add_task(async function testCharacterInPanelMultiView() { + maybeAddOldMenuSideButtons(); let button = document.getElementById("library-button"); forceFocus(button); let view = document.getElementById("appMenu-libraryView"); @@ -422,10 +495,12 @@ add_task(async function testCharacterInPanelMultiView() { let hidden = BrowserTestUtils.waitForEvent(document, "popuphidden", true); view.closest("panel").hidePopup(); await hidden; + maybeRemoveOldMenuSideButtons(); }); // Test tab stops after the search bar is added. add_task(async function testTabStopsAfterSearchBarAdded() { + maybeAddOldMenuSideButtons(); await SpecialPowers.pushPrefEnv({ set: [["browser.search.widget.inNavBar", 1]], }); @@ -435,4 +510,5 @@ add_task(async function testTabStopsAfterSearchBarAdded() { await expectFocusAfterKey("Tab", "library-button"); }); await SpecialPowers.popPrefEnv(); + maybeRemoveOldMenuSideButtons(); }); diff --git a/browser/base/content/test/sidebar/browser_sidebar_adopt.js b/browser/base/content/test/sidebar/browser_sidebar_adopt.js index e61e9a1972e0..b69818fdabe1 100644 --- a/browser/base/content/test/sidebar/browser_sidebar_adopt.js +++ b/browser/base/content/test/sidebar/browser_sidebar_adopt.js @@ -12,6 +12,15 @@ function failIfSidebarFocusedFires() { ok(false, "This event shouldn't have fired"); } +add_task(function setup() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("sidebar-button") + ); + } +}); + 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 diff --git a/browser/base/content/test/siteIdentity/browser_identityBlock_focus.js b/browser/base/content/test/siteIdentity/browser_identityBlock_focus.js index dba2ea775335..c27ec470305c 100644 --- a/browser/base/content/test/siteIdentity/browser_identityBlock_focus.js +++ b/browser/base/content/test/siteIdentity/browser_identityBlock_focus.js @@ -16,6 +16,17 @@ registerCleanupFunction(async function resetToolbar() { await CustomizableUI.reset(); }); +add_task(async function setupHomeButton() { + if (CustomizableUI.protonToolbarEnabled) { + // Put the home button in the pre-proton placement to test focus states. + CustomizableUI.addWidgetToArea( + "home-button", + "nav-bar", + CustomizableUI.getPlacementOfWidget("stop-reload-button").position + 1 + ); + } +}); + function synthesizeKeyAndWaitForFocus(element, keyCode, options) { let focused = BrowserTestUtils.waitForEvent(element, "focus"); EventUtils.synthesizeKey(keyCode, options); diff --git a/browser/base/content/test/sync/browser_sync.js b/browser/base/content/test/sync/browser_sync.js index e8ea273e78c2..985316905d0c 100644 --- a/browser/base/content/test/sync/browser_sync.js +++ b/browser/base/content/test/sync/browser_sync.js @@ -39,11 +39,7 @@ add_task(async function test_ui_state_notification_calls_updateAllUI() { add_task(async function test_navBar_button_visibility() { const button = document.getElementById("fxa-toolbar-menu-button"); - const protonEnabled = Services.prefs.getBoolPref( - "browser.proton.toolbar.enabled", - false - ); - info("pref browser.proton.toolbar.enabled: " + protonEnabled); + info("proton enabled: " + CustomizableUI.protonToolbarEnabled); ok(button.closest("#nav-bar"), "button is in the #nav-bar"); @@ -54,7 +50,7 @@ add_task(async function test_navBar_button_visibility() { gSync.updateAllUI(state); is( BrowserTestUtils.is_visible(button), - !protonEnabled, + !CustomizableUI.protonToolbarEnabled, "Check button visibility with STATUS_NOT_CONFIGURED" ); diff --git a/browser/base/content/test/tabs/browser_navigate_home_focuses_addressbar.js b/browser/base/content/test/tabs/browser_navigate_home_focuses_addressbar.js index a34608df47e4..38d7000b3feb 100644 --- a/browser/base/content/test/tabs/browser_navigate_home_focuses_addressbar.js +++ b/browser/base/content/test/tabs/browser_navigate_home_focuses_addressbar.js @@ -8,6 +8,13 @@ add_task(async function() { await BrowserTestUtils.withNewTab(TEST_HTTP, async function(browser) { info("Tab ready"); + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("home-button") + ); + } + document.getElementById("home-button").click(); await BrowserTestUtils.browserLoaded(browser, false, HomePage.get()); is(gURLBar.value, "", "URL bar should be empty"); diff --git a/browser/components/downloads/test/browser/browser_downloads_autohide.js b/browser/components/downloads/test/browser/browser_downloads_autohide.js index f56957d7aafd..b54d14022a4b 100644 --- a/browser/components/downloads/test/browser/browser_downloads_autohide.js +++ b/browser/components/downloads/test/browser/browser_downloads_autohide.js @@ -469,7 +469,7 @@ add_task(async function checkContextMenu() { ); info("Check context menu in another button"); - await openContextMenu(document.getElementById("home-button")); + await openContextMenu(document.getElementById("reload-button")); is(checkbox.hidden, true, "Auto-hide checkbox is hidden"); contextMenu.hidePopup(); diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js b/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js index fa988272f4c4..68eac9010340 100644 --- a/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js +++ b/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js @@ -75,6 +75,12 @@ function assertTelemetryMatches(events) { add_task(async function test_setup() { // Clear any previosuly collected telemetry event. Services.telemetry.clearEvents(); + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("home-button") + ); + } }); add_task(async function browseraction_popup_contextmenu() { diff --git a/browser/components/places/tests/browser/browser_enable_toolbar_sidebar.js b/browser/components/places/tests/browser/browser_enable_toolbar_sidebar.js index 1136a5b6d588..88faae9c5019 100644 --- a/browser/components/places/tests/browser/browser_enable_toolbar_sidebar.js +++ b/browser/components/places/tests/browser/browser_enable_toolbar_sidebar.js @@ -10,6 +10,9 @@ // Cleanup. registerCleanupFunction(async () => { CustomizableUI.setToolbarVisibility("PersonalToolbar", false); + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.removeWidgetFromArea("library-button"); + } SidebarUI.hide(); }); @@ -18,7 +21,7 @@ async function selectAppMenuView(buttonId, viewId) { await BrowserTestUtils.waitForCondition(() => { btn = document.getElementById(buttonId); return btn; - }, "Should have the " + buttonId + "button"); + }, "Should have the " + buttonId + " button"); btn.click(); let view = document.getElementById(viewId); let viewPromise = BrowserTestUtils.waitForEvent(view, "ViewShown"); @@ -34,6 +37,10 @@ async function openBookmarkingPanelInLibraryToolbarButton() { } add_task(async function test_enable_toolbar() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("library-button", "nav-bar"); + } + await openBookmarkingPanelInLibraryToolbarButton(); let toolbar = document.getElementById("PersonalToolbar"); Assert.ok(toolbar.collapsed, "Bookmarks Toolbar is hidden"); diff --git a/browser/components/search/test/browser/browser_searchbar_openpopup.js b/browser/components/search/test/browser/browser_searchbar_openpopup.js index 20674b57bece..a9642b0da51c 100644 --- a/browser/components/search/test/browser/browser_searchbar_openpopup.js +++ b/browser/components/search/test/browser/browser_searchbar_openpopup.js @@ -593,6 +593,9 @@ add_task(async function dont_consume_clicks() { // Dropping text to the searchbar should open the popup add_task(async function drop_opens_popup() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + } // The previous task leaves focus in the URL bar. However, in that case drags // can be interpreted as being selection drags by the drag manager, which // breaks the drag synthesis from EventUtils.js below. To avoid this, focus @@ -632,6 +635,9 @@ add_task(async function drop_opens_popup() { await promise; textbox.value = ""; + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.removeWidgetFromArea("home-button"); + } }); // Moving the caret using the cursor keys should not close the popup. diff --git a/browser/components/uitour/test/browser_UITour.js b/browser/components/uitour/test/browser_UITour.js index aff691ede2ca..8a1b7604099b 100644 --- a/browser/components/uitour/test/browser_UITour.js +++ b/browser/components/uitour/test/browser_UITour.js @@ -196,7 +196,7 @@ var tests = [ let highlight = document.getElementById("UITourHighlight"); is_element_hidden(highlight, "Highlight should initially be hidden"); - gContentAPI.showHighlight("home"); + gContentAPI.showHighlight("backForward"); waitForElementToBeVisible( highlight, check_highlight_size, diff --git a/browser/components/uitour/test/browser_UITour_availableTargets.js b/browser/components/uitour/test/browser_UITour_availableTargets.js index 9d063ce454ec..238eb9017217 100644 --- a/browser/components/uitour/test/browser_UITour_availableTargets.js +++ b/browser/components/uitour/test/browser_UITour_availableTargets.js @@ -17,7 +17,7 @@ function getExpectedTargets() { "backForward", "devtools", "help", - "home", + ...(CustomizableUI.protonToolbarEnabled ? [] : ["home"]), "library", "logins", "pageAction-bookmark", diff --git a/browser/components/urlbar/tests/browser/browser_aboutHomeLoading.js b/browser/components/urlbar/tests/browser/browser_aboutHomeLoading.js index 7ba9ed328c48..386fba50de08 100644 --- a/browser/components/urlbar/tests/browser/browser_aboutHomeLoading.js +++ b/browser/components/urlbar/tests/browser/browser_aboutHomeLoading.js @@ -14,6 +14,15 @@ const { TabStateFlusher } = ChromeUtils.import( "resource:///modules/sessionstore/TabStateFlusher.jsm" ); +add_task(function addHomeButton() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("home-button") + ); + } +}); + /** * Test what happens if loading a URL that should clear the * location bar after a parent process URL. diff --git a/browser/components/urlbar/tests/browser/browser_dragdropURL.js b/browser/components/urlbar/tests/browser/browser_dragdropURL.js index d2e4971d5464..a46578f42f30 100644 --- a/browser/components/urlbar/tests/browser/browser_dragdropURL.js +++ b/browser/components/urlbar/tests/browser/browser_dragdropURL.js @@ -22,6 +22,13 @@ add_task(async function test_setup() { } await Services.search.setDefault(originalEngine); }); + + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("home-button") + ); + } }); /** diff --git a/browser/components/urlbar/tests/browser/browser_tabKeyBehavior.js b/browser/components/urlbar/tests/browser/browser_tabKeyBehavior.js index a443ad6b1cea..7ccc66d545b0 100644 --- a/browser/components/urlbar/tests/browser/browser_tabKeyBehavior.js +++ b/browser/components/urlbar/tests/browser/browser_tabKeyBehavior.js @@ -14,6 +14,15 @@ add_task(async function init() { } registerCleanupFunction(PlacesUtils.history.clear); + + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar", 0); + CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar"); + registerCleanupFunction(() => { + CustomizableUI.removeWidgetFromArea("home-button"); + CustomizableUI.removeWidgetFromArea("sidebar-button"); + }); + } }); add_task(async function tabWithSearchString() { @@ -335,7 +344,9 @@ async function waitForFocusOnNextFocusableElement(reverse = false) { while ( nextFocusableElement && (!nextFocusableElement.classList.contains("toolbarbutton-1") || - nextFocusableElement.hasAttribute("hidden")) + nextFocusableElement.hasAttribute("hidden") || + nextFocusableElement.hasAttribute("disabled") || + BrowserTestUtils.is_hidden(nextFocusableElement)) ) { nextFocusableElement = reverse ? nextFocusableElement.previousElementSibling diff --git a/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js b/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js index 5934df372579..55873723e0b2 100644 --- a/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js +++ b/browser/components/urlbar/tests/browser/browser_urlbar_event_telemetry.js @@ -578,7 +578,7 @@ const tests = [ info("Drop something."); let promise = BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser); EventUtils.synthesizeDrop( - win.document.getElementById("home-button"), + win.document.getElementById("back-button"), win.gURLBar.inputField, [[{ type: "text/plain", data: "www.example.com" }]], "copy", diff --git a/browser/modules/test/browser/browser_UsageTelemetry_usagePrefs.js b/browser/modules/test/browser/browser_UsageTelemetry_usagePrefs.js index 316270cd10a3..2dcaace0d18e 100644 --- a/browser/modules/test/browser/browser_UsageTelemetry_usagePrefs.js +++ b/browser/modules/test/browser/browser_UsageTelemetry_usagePrefs.js @@ -20,11 +20,19 @@ add_task(async function test_usage_button_prefs_set() { await SpecialPowers.pushPrefEnv({ set: [["browser.download.autohideButton", false]], }); + if (CustomizableUI.protonToolbarEnabled) { + // Move the FxA button to the toolbar so it doesn't get auto-hidden. + CustomizableUI.addWidgetToArea("fxa-toolbar-menu-button", "TabsToolbar"); + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar"); + CustomizableUI.addWidgetToArea("library-button", "nav-bar"); + } - registerCleanupFunction(() => { + registerCleanupFunction(async () => { // Clicking on the sidebar button will show the sidebar, so we'll // make sure it's hidden when the test ends. SidebarUI.hide(); + await CustomizableUI.reset(); }); const PREFS_TO_FALSE = Object.values(BUTTONS_TO_TEST).map(prefName => { @@ -36,7 +44,7 @@ add_task(async function test_usage_button_prefs_set() { }); // We open a new tab to ensure the test passes verify on Windows - await BrowserTestUtils.withNewTab("about:blank", () => { + await BrowserTestUtils.withNewTab("about:blank", async () => { for (let buttonID in BUTTONS_TO_TEST) { let pref = BUTTONS_TO_TEST[buttonID]; Assert.ok( @@ -46,7 +54,16 @@ add_task(async function test_usage_button_prefs_set() { info(`Clicking on ${buttonID}`); let element = document.getElementById(buttonID); - EventUtils.synthesizeMouseAtCenter(element, {}, window); + if (buttonID != "home-button" && buttonID != "sidebar-button") { + let popupShown = BrowserTestUtils.waitForPopupEvent(window, "shown"); + let popupHidden = BrowserTestUtils.waitForPopupEvent(window, "hidden"); + EventUtils.synthesizeMouse(element, 5, 5, {}, window); + let shownEvent = await popupShown; + shownEvent.target.hidePopup(); + await popupHidden; + } else { + EventUtils.synthesizeMouse(element, 5, 5, {}, window); + } Assert.ok( Services.prefs.getBoolPref(pref), diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js b/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js index 4266a982d8af..c41e27b6142f 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js @@ -50,13 +50,23 @@ add_task(async function test_support_separator_properties() { ); let panelUIButton = document.querySelector("#PanelUI-button"); - Assert.ok( - window - .getComputedStyle(panelUIButton) - .getPropertyValue("border-image-source") - .includes(`rgb(${hexToRGB(SEPARATOR_VERTICAL_COLOR).join(", ")})`), - "Vertical separator color properly set" - ); + if (CustomizableUI.protonToolbarEnabled) { + Assert.equal( + window + .getComputedStyle(panelUIButton) + .getPropertyValue("border-image-source"), + "none", + "No vertical separator on app menu" + ); + } else { + Assert.ok( + window + .getComputedStyle(panelUIButton) + .getPropertyValue("border-image-source") + .includes(`rgb(${hexToRGB(SEPARATOR_VERTICAL_COLOR).join(", ")})`), + "Vertical separator color properly set" + ); + } let toolbox = document.querySelector("#navigator-toolbox"); Assert.equal( diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_colors.js b/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_colors.js index f31e0fce8a84..457f2b33dd58 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_colors.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_colors.js @@ -5,6 +5,15 @@ // This test checks whether applied WebExtension themes that attempt to change // the button background color properties are applied correctly. +add_task(async function setup_home_button() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("home-button") + ); + } +}); + add_task(async function test_button_background_properties() { const BUTTON_BACKGROUND_ACTIVE = "#FFFFFF"; const BUTTON_BACKGROUND_HOVER = "#59CBE8"; diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_icons.js b/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_icons.js index 11643412dd28..559b0d8f0d4c 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_icons.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_icons.js @@ -3,6 +3,15 @@ // This test checks applied WebExtension themes that attempt to change // icon color properties +add_task(async function setup_home_button() { + if (CustomizableUI.protonToolbarEnabled) { + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("home-button") + ); + } +}); + add_task(async function test_icons_properties() { const ICONS_COLOR = "#001b47"; const ICONS_ATTENTION_COLOR = "#44ba77";