summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/menubar
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /browser/base/content/test/menubar
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/menubar')
-rw-r--r--browser/base/content/test/menubar/browser.ini9
-rw-r--r--browser/base/content/test/menubar/browser_file_close_tabs.js60
-rw-r--r--browser/base/content/test/menubar/browser_file_menu_import_wizard.js27
-rw-r--r--browser/base/content/test/menubar/browser_file_share.js136
-rw-r--r--browser/base/content/test/menubar/file_shareurl.html2
5 files changed, 234 insertions, 0 deletions
diff --git a/browser/base/content/test/menubar/browser.ini b/browser/base/content/test/menubar/browser.ini
new file mode 100644
index 0000000000..e32dc6dffc
--- /dev/null
+++ b/browser/base/content/test/menubar/browser.ini
@@ -0,0 +1,9 @@
+[DEFAULT]
+
+[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
+support-files =
+ file_shareurl.html
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..7783d59da7
--- /dev/null
+++ b/browser/base/content/test/menubar/browser_file_menu_import_wizard.js
@@ -0,0 +1,27 @@
+/* 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 if
+ // we're using the new migration wizard, we'll load the about:preferences
+ // page in a new tab rather than overtaking the initial one. This
+ // makes it easier to be consistent with closing and opening
+ // behaviours between the two kinds of migration wizards.
+ let browser = gBrowser.selectedBrowser;
+ BrowserTestUtils.loadURIString(browser, "https://example.com");
+ await BrowserTestUtils.browserLoaded(browser);
+});
+
+add_task(async function file_menu_import_wizard() {
+ // We can't call this code directly or our JS execution will get blocked on Windows/Linux where
+ // the dialog is modal.
+ executeSoon(() =>
+ document.getElementById("menu_importFromAnotherBrowser").doCommand()
+ );
+
+ let wizard = await BrowserTestUtils.waitForMigrationWizard(window);
+ ok(wizard, "Migrator window opened");
+ await BrowserTestUtils.closeMigrationWizard(wizard);
+});
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/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>