From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../contextMenu/browser_contextmenu_share_win.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 browser/base/content/test/contextMenu/browser_contextmenu_share_win.js (limited to 'browser/base/content/test/contextMenu/browser_contextmenu_share_win.js') diff --git a/browser/base/content/test/contextMenu/browser_contextmenu_share_win.js b/browser/base/content/test/contextMenu/browser_contextmenu_share_win.js new file mode 100644 index 0000000000..716da584c5 --- /dev/null +++ b/browser/base/content/test/contextMenu/browser_contextmenu_share_win.js @@ -0,0 +1,77 @@ +/* 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 + "browser_contextmenu_shareurl.html"; + +// Setup spies for observing function calls from MacSharingService +let shareUrlSpy = sinon.spy(); + +let stub = sinon.stub(gBrowser.ownerGlobal, "WindowsUIUtils").get(() => { + return { + shareUrl(url, title) { + shareUrlSpy(url, title); + }, + }; +}); + +registerCleanupFunction(async function () { + stub.restore(); +}); + +/** + * Test the "Share" item in the tab contextmenu on Windows. + */ +add_task(async function test_contextmenu_share_win() { + await BrowserTestUtils.withNewTab(TEST_URL, async () => { + await openTabContextMenu(gBrowser.selectedTab); + + let contextMenu = document.getElementById("tabContextMenu"); + let contextMenuClosedPromise = BrowserTestUtils.waitForPopupEvent( + contextMenu, + "hidden" + ); + let itemCreated = contextMenu.querySelector(".share-tab-url-item"); + if (!AppConstants.isPlatformAndVersionAtLeast("win", "6.4")) { + Assert.ok(!itemCreated, "We only expose share on windows 10 and above"); + contextMenu.hidePopup(); + await contextMenuClosedPromise; + return; + } + + ok(itemCreated, "Got Share item on Windows 10"); + + info("Test the correct URL is shared when Share is selected."); + EventUtils.synthesizeMouseAtCenter(itemCreated, {}); + await contextMenuClosedPromise; + + ok(shareUrlSpy.calledOnce, "shareUrl called"); + let [url, title] = shareUrlSpy.getCall(0).args; + is(url, TEST_URL, "Shared correct URL"); + is(title, "Sharing URL", "Shared correct URL"); + }); +}); + +/** + * Helper for opening the toolbar context menu. + */ +async function openTabContextMenu(tab) { + info("Opening tab context menu"); + let contextMenu = document.getElementById("tabContextMenu"); + let openTabContextMenuPromise = BrowserTestUtils.waitForPopupEvent( + contextMenu, + "shown" + ); + + EventUtils.synthesizeMouseAtCenter(tab, { type: "contextmenu" }); + await openTabContextMenuPromise; +} -- cgit v1.2.3