diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/menubar | |
parent | Initial commit. (diff) | |
download | firefox-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/menubar')
8 files changed, 756 insertions, 0 deletions
diff --git a/browser/base/content/test/menubar/browser.toml b/browser/base/content/test/menubar/browser.toml new file mode 100644 index 0000000000..4ba2101891 --- /dev/null +++ b/browser/base/content/test/menubar/browser.toml @@ -0,0 +1,22 @@ +[DEFAULT] +prefs = [ + "browser.sessionstore.closedTabsFromAllWindows=true", + "browser.sessionstore.closedTabsFromClosedWindows=true", +] + +["browser_file_close_tabs.js"] + +["browser_file_menu_import_wizard.js"] + +["browser_file_share.js"] +https_first_disabled = true +run-if = ["os == 'mac'"] # Mac only feature + +["browser_history_recently_closed_tabs.js"] +skip-if = ["os == 'mac'"] # No menubar on macOS. + +support-files = ["file_shareurl.html"] + +["browser_search_bookmarks.js"] + +["browser_search_history.js"] diff --git a/browser/base/content/test/menubar/browser_file_close_tabs.js b/browser/base/content/test/menubar/browser_file_close_tabs.js new file mode 100644 index 0000000000..15abd92bba --- /dev/null +++ b/browser/base/content/test/menubar/browser_file_close_tabs.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +/** + * This test verifies behavior from bug 1732375: + * https://bugzilla.mozilla.org/show_bug.cgi?id=1732375 + * + * If there are multiple tabs selected, the 'Close' entry + * under the File menu should correctly reflect the number of + * selected tabs + */ +add_task(async function test_menu_close_tab_count() { + // Window should have one tab open already, so we + // just need to add one more to have a total of two + info("Adding new tabs"); + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com"); + + info("Selecting all tabs"); + await gBrowser.selectAllTabs(); + is(gBrowser.multiSelectedTabsCount, 2, "Two (2) tabs are selected"); + + let fileMenu = document.getElementById("menu_FilePopup"); + await simulateMenuOpen(fileMenu); + + let closeMenuEntry = document.getElementById("menu_close"); + let closeMenuL10nArgsObject = document.l10n.getAttributes(closeMenuEntry); + + is( + closeMenuL10nArgsObject.args.tabCount, + 2, + "Menu bar reflects multi-tab selection number (Close 2 Tabs)" + ); + + let onClose = BrowserTestUtils.waitForEvent( + gBrowser.tabContainer, + "TabClose" + ); + + BrowserTestUtils.removeTab(gBrowser.selectedTab); + + await onClose; + + info("Tabs closed"); +}); + +async function simulateMenuOpen(menu) { + return new Promise(resolve => { + menu.addEventListener("popupshown", resolve, { once: true }); + menu.dispatchEvent(new MouseEvent("popupshowing")); + menu.dispatchEvent(new MouseEvent("popupshown")); + }); +} + +async function simulateMenuClosed(menu) { + return new Promise(resolve => { + menu.addEventListener("popuphidden", resolve, { once: true }); + menu.dispatchEvent(new MouseEvent("popuphiding")); + menu.dispatchEvent(new MouseEvent("popuphidden")); + }); +} diff --git a/browser/base/content/test/menubar/browser_file_menu_import_wizard.js b/browser/base/content/test/menubar/browser_file_menu_import_wizard.js new file mode 100644 index 0000000000..9fb969b777 --- /dev/null +++ b/browser/base/content/test/menubar/browser_file_menu_import_wizard.js @@ -0,0 +1,23 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_setup(async () => { + // Load the initial tab at example.com. This makes it so that when the + // about:preferences hosting the migration wizard opens, we'll load + // the about:preferences page in a new tab rather than overtaking the + // initial one. This makes it easier to be more explicit when cleaning + // up because we can just remove the opened tab. + let browser = gBrowser.selectedBrowser; + BrowserTestUtils.startLoadingURIString(browser, "https://example.com"); + await BrowserTestUtils.browserLoaded(browser); +}); + +add_task(async function file_menu_import_wizard() { + let wizardTabPromise = BrowserTestUtils.waitForMigrationWizard(window); + document.getElementById("menu_importFromAnotherBrowser").doCommand(); + let wizardTab = await wizardTabPromise; + ok(wizardTab, "Migration wizard tab opened"); + BrowserTestUtils.removeTab(wizardTab); +}); diff --git a/browser/base/content/test/menubar/browser_file_share.js b/browser/base/content/test/menubar/browser_file_share.js new file mode 100644 index 0000000000..bd6a4c3f60 --- /dev/null +++ b/browser/base/content/test/menubar/browser_file_share.js @@ -0,0 +1,136 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { sinon } = ChromeUtils.importESModule( + "resource://testing-common/Sinon.sys.mjs" +); +const BASE = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://example.com" +); +const TEST_URL = BASE + "file_shareurl.html"; + +let mockShareData = [ + { + name: "Test", + menuItemTitle: "Sharing Service Test", + image: + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAKE" + + "lEQVR42u3NQQ0AAAgEoNP+nTWFDzcoQE1udQQCgUAgEAgEAsGTYAGjxAE/G/Q2tQAAAABJRU5ErkJggg==", + }, +]; + +// Setup spies for observing function calls from MacSharingService +let shareUrlSpy = sinon.spy(); +let openSharingPreferencesSpy = sinon.spy(); +let getSharingProvidersSpy = sinon.spy(); + +let stub = sinon.stub(gBrowser, "MacSharingService").get(() => { + return { + getSharingProviders(url) { + getSharingProvidersSpy(url); + return mockShareData; + }, + shareUrl(name, url, title) { + shareUrlSpy(name, url, title); + }, + openSharingPreferences() { + openSharingPreferencesSpy(); + }, + }; +}); + +registerCleanupFunction(async function () { + stub.restore(); +}); + +/** + * Test the "Share" item menus in the tab contextmenu on MacOSX. + */ +add_task(async function test_file_menu_share() { + await BrowserTestUtils.withNewTab(TEST_URL, async () => { + // We can't toggle menubar items on OSX, so mocking instead. + let menu = document.getElementById("menu_FilePopup"); + await simulateMenuOpen(menu); + + await BrowserTestUtils.waitForMutationCondition( + menu, + { childList: true }, + () => menu.querySelector(".share-tab-url-item") + ); + ok(true, "Got Share item"); + + let popup = menu.querySelector(".share-tab-url-item").menupopup; + await simulateMenuOpen(popup); + ok(getSharingProvidersSpy.calledOnce, "getSharingProviders called"); + + info( + "Check we have a service and one extra menu item for the More... button" + ); + let items = popup.querySelectorAll("menuitem"); + is(items.length, 2, "There should be 2 sharing services."); + + info("Click on the sharing service"); + let shareButton = items[0]; + is( + shareButton.label, + mockShareData[0].menuItemTitle, + "Share button's label should match the service's menu item title. " + ); + is( + shareButton.getAttribute("share-name"), + mockShareData[0].name, + "Share button's share-name value should match the service's name. " + ); + + shareButton.doCommand(); + + ok(shareUrlSpy.calledOnce, "shareUrl called"); + + info("Check the correct data was shared."); + let [name, url, title] = shareUrlSpy.getCall(0).args; + is(name, mockShareData[0].name, "Shared correct service name"); + is(url, TEST_URL, "Shared correct URL"); + is(title, "Sharing URL", "Shared the correct title."); + await simulateMenuClosed(popup); + await simulateMenuClosed(menu); + + info("Test the More... button"); + + await simulateMenuOpen(menu); + popup = menu.querySelector(".share-tab-url-item").menupopup; + await simulateMenuOpen(popup); + // Since the menu was collapsed previously, the popup needs to get the + // providers again. + ok(getSharingProvidersSpy.calledTwice, "getSharingProviders called again"); + items = popup.querySelectorAll("menuitem"); + is(items.length, 2, "There should be 2 sharing services."); + + info("Click on the More Button"); + let moreButton = items[1]; + moreButton.doCommand(); + ok(openSharingPreferencesSpy.calledOnce, "openSharingPreferences called"); + // Tidy up: + await simulateMenuClosed(popup); + await simulateMenuClosed(menu); + }); +}); + +async function simulateMenuOpen(menu) { + return new Promise(resolve => { + menu.addEventListener("popupshown", resolve, { once: true }); + menu.dispatchEvent(new MouseEvent("popupshowing")); + menu.dispatchEvent(new MouseEvent("popupshown")); + }); +} + +async function simulateMenuClosed(menu) { + return new Promise(resolve => { + menu.addEventListener("popuphidden", resolve, { once: true }); + menu.dispatchEvent(new MouseEvent("popuphiding")); + menu.dispatchEvent(new MouseEvent("popuphidden")); + }); +} diff --git a/browser/base/content/test/menubar/browser_history_recently_closed_tabs.js b/browser/base/content/test/menubar/browser_history_recently_closed_tabs.js new file mode 100644 index 0000000000..246dce4db0 --- /dev/null +++ b/browser/base/content/test/menubar/browser_history_recently_closed_tabs.js @@ -0,0 +1,397 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +/** + * This test verifies behavior from bug 1819675: + * https://bugzilla.mozilla.org/show_bug.cgi?id=1819675 + * + * The recently closed tabs menu item should be enabled when there are tabs + * closed from any window that is in the same private/non-private bucket as + * the current window. + */ + +const { SessionStoreTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/SessionStoreTestUtils.sys.mjs" +); +const triggeringPrincipal_base64 = E10SUtils.SERIALIZED_SYSTEMPRINCIPAL; +SessionStoreTestUtils.init(this, window); + +async function checkMenu(window, expected) { + await SimpleTest.promiseFocus(window); + const historyMenubarItem = window.document.getElementById("history-menu"); + const historyMenu = window.document.getElementById("historyMenuPopup"); + const recentlyClosedTabsItem = historyMenu.querySelector("#historyUndoMenu"); + + const menuShown = BrowserTestUtils.waitForEvent(historyMenu, "popupshown"); + historyMenubarItem.openMenu(true); + info("checkMenu:, waiting for menuShown"); + await menuShown; + + Assert.equal( + recentlyClosedTabsItem.disabled, + expected.menuItemDisabled, + `Recently closed tabs menu item is ${ + expected.menuItemDisabled ? "disabled" : "not disabled" + }` + ); + const menuHidden = BrowserTestUtils.waitForEvent(historyMenu, "popuphidden"); + historyMenu.hidePopup(); + info("checkMenu:, waiting for menuHidden"); + await menuHidden; + info("checkMenu:, menuHidden, returning"); +} + +function resetClosedTabsAndWindows() { + // Clear the lists of closed windows and tabs. + Services.obs.notifyObservers(null, "browser:purge-session-history"); + is(SessionStore.getClosedWindowCount(), 0, "Expect 0 closed windows"); + for (const win of BrowserWindowTracker.orderedWindows) { + is( + SessionStore.getClosedTabCountForWindow(win), + 0, + "Expect 0 closed tabs for this window" + ); + } +} + +add_task(async function test_recently_closed_tabs_nonprivate() { + await resetClosedTabsAndWindows(); + + const win1 = window; + const win2 = await BrowserTestUtils.openNewBrowserWindow(); + await BrowserTestUtils.openNewForegroundTab( + win1.gBrowser, + "https://example.com" + ); + // we're going to close a tab and don't want to accidentally close the window when it has 0 tabs + await BrowserTestUtils.openNewForegroundTab(win2.gBrowser, "about:about"); + await BrowserTestUtils.openNewForegroundTab( + win2.gBrowser, + "https://example.org" + ); + + info("Checking the menuitem is initially disabled in both windows"); + for (let win of [win1, win2]) { + await checkMenu(win, { + menuItemDisabled: true, + }); + } + + await SessionStoreTestUtils.closeTab(win2.gBrowser.selectedTab); + is( + SessionStore.getClosedTabCount(), + 1, + "Expect closed tab count of 1 after closing a tab" + ); + + for (let win of [win1, win2]) { + await checkMenu(win, { + menuItemDisabled: false, + }); + } + + // clean up + info("clean up opened window"); + const sessionStoreChanged = TestUtils.topicObserved( + "sessionstore-closed-objects-changed" + ); + await BrowserTestUtils.closeWindow(win2); + await sessionStoreChanged; + + info("starting tab cleanup"); + while (gBrowser.tabs.length > 1) { + await SessionStoreTestUtils.closeTab( + gBrowser.tabs[gBrowser.tabs.length - 1] + ); + } + info("finished tab cleanup"); +}); + +add_task(async function test_recently_closed_tabs_nonprivate_pref_off() { + await SpecialPowers.pushPrefEnv({ + set: [["browser.sessionstore.closedTabsFromAllWindows", false]], + }); + await resetClosedTabsAndWindows(); + + const win1 = window; + const win2 = await BrowserTestUtils.openNewBrowserWindow(); + await BrowserTestUtils.openNewForegroundTab( + win1.gBrowser, + "https://example.com" + ); + // we're going to close a tab and don't want to accidentally close the window when it has 0 tabs + await BrowserTestUtils.openNewForegroundTab(win2.gBrowser, "about:about"); + await BrowserTestUtils.openNewForegroundTab( + win2.gBrowser, + "https://example.org" + ); + + info("Checking the menuitem is initially disabled in both windows"); + for (let win of [win1, win2]) { + await checkMenu(win, { + menuItemDisabled: true, + }); + } + await SimpleTest.promiseFocus(win2); + await SessionStoreTestUtils.closeTab(win2.gBrowser.selectedTab); + is( + SessionStore.getClosedTabCount(), + 1, + "Expect closed tab count of 1 after closing a tab" + ); + + await checkMenu(win1, { + menuItemDisabled: true, + }); + await checkMenu(win2, { + menuItemDisabled: false, + }); + + // clean up + info("clean up opened window"); + const sessionStoreChanged = TestUtils.topicObserved( + "sessionstore-closed-objects-changed" + ); + await BrowserTestUtils.closeWindow(win2); + await sessionStoreChanged; + + info("starting tab cleanup"); + while (gBrowser.tabs.length > 1) { + await SessionStoreTestUtils.closeTab( + gBrowser.tabs[gBrowser.tabs.length - 1] + ); + } + info("finished tab cleanup"); + SpecialPowers.popPrefEnv(); +}); + +add_task(async function test_recently_closed_tabs_mixed_private() { + await resetClosedTabsAndWindows(); + is( + SessionStore.getClosedTabCount(), + 0, + "Expect closed tab count of 0 after reset" + ); + + await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "about:robots"); + await BrowserTestUtils.openNewForegroundTab( + window.gBrowser, + "https://example.com" + ); + + const privateWin = await BrowserTestUtils.openNewBrowserWindow({ + private: true, + }); + await BrowserTestUtils.openNewForegroundTab( + privateWin.gBrowser, + "about:about" + ); + await BrowserTestUtils.openNewForegroundTab( + privateWin.gBrowser, + "https://example.org" + ); + + for (let win of [window, privateWin]) { + await checkMenu(win, { + menuItemDisabled: true, + }); + } + + await SessionStoreTestUtils.closeTab(privateWin.gBrowser.selectedTab); + is( + SessionStore.getClosedTabCount(privateWin), + 1, + "Expect closed tab count of 1 for private windows" + ); + is( + SessionStore.getClosedTabCount(window), + 0, + "Expect closed tab count of 0 for non-private windows" + ); + + // the menu should be enabled only for the private window + await checkMenu(window, { + menuItemDisabled: true, + }); + await checkMenu(privateWin, { + menuItemDisabled: false, + }); + + await resetClosedTabsAndWindows(); + await SimpleTest.promiseFocus(window); + + info("closing tab in non-private window"); + await SessionStoreTestUtils.closeTab(window.gBrowser.selectedTab); + is( + SessionStore.getClosedTabCount(window), + 1, + "Expect 1 closed tab count after closing the a tab in the non-private window" + ); + + // the menu should be enabled only for the non-private window + await checkMenu(window, { + menuItemDisabled: false, + }); + await checkMenu(privateWin, { + menuItemDisabled: true, + }); + + // clean up + info("closing private window"); + await BrowserTestUtils.closeWindow(privateWin); + await TestUtils.waitForTick(); + + info("starting tab cleanup"); + while (gBrowser.tabs.length > 1) { + await SessionStoreTestUtils.closeTab( + gBrowser.tabs[gBrowser.tabs.length - 1] + ); + } + info("finished tab cleanup"); +}); + +add_task(async function test_recently_closed_tabs_mixed_private_pref_off() { + await SpecialPowers.pushPrefEnv({ + set: [["browser.sessionstore.closedTabsFromAllWindows", false]], + }); + await resetClosedTabsAndWindows(); + + await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "about:robots"); + await BrowserTestUtils.openNewForegroundTab( + window.gBrowser, + "https://example.com" + ); + + const privateWin = await BrowserTestUtils.openNewBrowserWindow({ + private: true, + }); + await BrowserTestUtils.openNewForegroundTab( + privateWin.gBrowser, + "about:about" + ); + await BrowserTestUtils.openNewForegroundTab( + privateWin.gBrowser, + "https://example.org" + ); + + for (let win of [window, privateWin]) { + await checkMenu(win, { + menuItemDisabled: true, + }); + } + + await SimpleTest.promiseFocus(privateWin); + await SessionStoreTestUtils.closeTab(privateWin.gBrowser.selectedTab); + is( + SessionStore.getClosedTabCount(privateWin), + 1, + "Expect closed tab count of 1 for private windows" + ); + is( + SessionStore.getClosedTabCount(window), + 0, + "Expect closed tab count of 0 for non-private windows" + ); + + // the menu should be enabled only for the private window + await checkMenu(window, { + menuItemDisabled: true, + }); + await checkMenu(privateWin, { + menuItemDisabled: false, + }); + + await resetClosedTabsAndWindows(); + is( + SessionStore.getClosedTabCount(privateWin), + 0, + "Expect 0 closed tab count after reset" + ); + is( + SessionStore.getClosedTabCount(window), + 0, + "Expect 0 closed tab count after reset" + ); + + info("closing tab in non-private window"); + await SimpleTest.promiseFocus(window); + await SessionStoreTestUtils.closeTab(window.gBrowser.selectedTab); + + // the menu should be enabled only for the non-private window + await checkMenu(window, { + menuItemDisabled: false, + }); + await checkMenu(privateWin, { + menuItemDisabled: true, + }); + + // clean up + info("closing private window"); + await BrowserTestUtils.closeWindow(privateWin); + await TestUtils.waitForTick(); + + info("starting tab cleanup"); + while (gBrowser.tabs.length > 1) { + await SessionStoreTestUtils.closeTab( + gBrowser.tabs[gBrowser.tabs.length - 1] + ); + } + info("finished tab cleanup"); + SpecialPowers.popPrefEnv(); +}); + +add_task(async function test_recently_closed_tabs_closed_windows() { + // prepare window state with closed tabs from closed windows + await SpecialPowers.pushPrefEnv({ + set: [["sessionstore.closedTabsFromClosedWindows", true]], + }); + const closedTabUrls = ["about:robots"]; + const closedWindowState = { + tabs: [ + { + entries: [{ url: "about:mozilla", triggeringPrincipal_base64 }], + }, + ], + _closedTabs: closedTabUrls.map(url => { + return { + state: { + entries: [ + { + url, + triggeringPrincipal_base64, + }, + ], + }, + }; + }), + }; + await SessionStoreTestUtils.promiseBrowserState({ + windows: [ + { + tabs: [ + { + entries: [{ url: "about:mozilla", triggeringPrincipal_base64 }], + }, + ], + }, + ], + _closedWindows: [closedWindowState], + }); + + // verify the recently-closed-tabs menu item is enabled + await checkMenu(window, { + menuItemDisabled: false, + }); + + // flip the pref + await SpecialPowers.popPrefEnv(); + await SpecialPowers.pushPrefEnv({ + set: [["browser.sessionstore.closedTabsFromClosedWindows", false]], + }); + + // verify the recently-closed-tabs menu item is disabled + await checkMenu(window, { + menuItemDisabled: true, + }); + + SpecialPowers.popPrefEnv(); +}); diff --git a/browser/base/content/test/menubar/browser_search_bookmarks.js b/browser/base/content/test/menubar/browser_search_bookmarks.js new file mode 100644 index 0000000000..1c0da6071e --- /dev/null +++ b/browser/base/content/test/menubar/browser_search_bookmarks.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests the Search Bookmarks option from the menubar starts Address Bar search + * mode for bookmarks. + */ +ChromeUtils.defineLazyGetter(this, "UrlbarTestUtils", () => { + const { UrlbarTestUtils: module } = ChromeUtils.importESModule( + "resource://testing-common/UrlbarTestUtils.sys.mjs" + ); + module.init(this); + return module; +}); + +add_task(async function test_menu_search_bookmarks_with_window_open() { + info("Opening bookmarks menu"); + let searchBookmarksMenuEntry = document.getElementById( + "menu_searchBookmarks" + ); + + searchBookmarksMenuEntry.doCommand(); + + await isUrlbarInBookmarksSearchMode(window); +}); + +add_task(async function test_menu_search_bookmarks_opens_new_window() { + let newWindowPromise = TestUtils.topicObserved( + "browser-delayed-startup-finished" + ); + + info( + "Executing command in untracked browser window (simulating non-browser window)." + ); + BrowserWindowTracker.untrackForTestsOnly(window); + let searchBookmarksMenuEntry = document.getElementById( + "menu_searchBookmarks" + ); + searchBookmarksMenuEntry.doCommand(); + BrowserWindowTracker.track(window); + + info("Waiting for new window to open."); + let [newWindow] = await newWindowPromise; + await isUrlbarInBookmarksSearchMode(newWindow); + await BrowserTestUtils.closeWindow(newWindow); +}); + +async function isUrlbarInBookmarksSearchMode(targetWin) { + is( + targetWin, + BrowserWindowTracker.getTopWindow(), + "Target window is top window." + ); + await UrlbarTestUtils.promisePopupOpen(targetWin, () => {}); + + // Verify URLBar is in search mode with correct restriction + let searchMode = UrlbarUtils.searchModeForToken("*"); + searchMode.entry = "bookmarkmenu"; + await UrlbarTestUtils.assertSearchMode(targetWin, searchMode); +} diff --git a/browser/base/content/test/menubar/browser_search_history.js b/browser/base/content/test/menubar/browser_search_history.js new file mode 100644 index 0000000000..06c1402362 --- /dev/null +++ b/browser/base/content/test/menubar/browser_search_history.js @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests the Search History option from the menubar starts Address Bar search + * mode for history. + */ +ChromeUtils.defineLazyGetter(this, "UrlbarTestUtils", () => { + const { UrlbarTestUtils: module } = ChromeUtils.importESModule( + "resource://testing-common/UrlbarTestUtils.sys.mjs" + ); + module.init(this); + return module; +}); + +add_task(async function test_menu_search_history_with_window_open() { + info("Opening history menu"); + let searchHistoryMenuEntry = document.getElementById("menu_searchHistory"); + + searchHistoryMenuEntry.doCommand(); + + await isUrlbarInHistorySearchMode(window); +}); + +add_task(async function test_menu_search_history_opens_new_window() { + let newWindowPromise = TestUtils.topicObserved( + "browser-delayed-startup-finished" + ); + + info( + "Executing command in untracked browser window (simulating non-browser window)." + ); + BrowserWindowTracker.untrackForTestsOnly(window); + let searchHistoryMenuEntry = document.getElementById("menu_searchHistory"); + searchHistoryMenuEntry.doCommand(); + BrowserWindowTracker.track(window); + + info("Waiting for new window to open."); + let [newWindow] = await newWindowPromise; + await isUrlbarInHistorySearchMode(newWindow); + await BrowserTestUtils.closeWindow(newWindow); +}); + +async function isUrlbarInHistorySearchMode(targetWin) { + is( + targetWin, + BrowserWindowTracker.getTopWindow(), + "Target window is top window." + ); + await UrlbarTestUtils.promisePopupOpen(targetWin, () => {}); + + // Verify URLBar is in search mode with correct restriction + let searchMode = UrlbarUtils.searchModeForToken("^"); + searchMode.entry = "historymenu"; + await UrlbarTestUtils.assertSearchMode(targetWin, searchMode); +} diff --git a/browser/base/content/test/menubar/file_shareurl.html b/browser/base/content/test/menubar/file_shareurl.html new file mode 100644 index 0000000000..c7fb193972 --- /dev/null +++ b/browser/base/content/test/menubar/file_shareurl.html @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<title>Sharing URL</title> |