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 --- .../test/browser/browser_multistage_spotlight.js | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 browser/components/newtab/test/browser/browser_multistage_spotlight.js (limited to 'browser/components/newtab/test/browser/browser_multistage_spotlight.js') diff --git a/browser/components/newtab/test/browser/browser_multistage_spotlight.js b/browser/components/newtab/test/browser/browser_multistage_spotlight.js new file mode 100644 index 0000000000..bbaf64a9e3 --- /dev/null +++ b/browser/components/newtab/test/browser/browser_multistage_spotlight.js @@ -0,0 +1,58 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { Spotlight } = ChromeUtils.import( + "resource://activity-stream/lib/Spotlight.jsm" +); +const { PanelTestProvider } = ChromeUtils.importESModule( + "resource://activity-stream/lib/PanelTestProvider.sys.mjs" +); +const { BrowserWindowTracker } = ChromeUtils.import( + "resource:///modules/BrowserWindowTracker.jsm" +); +const { SpecialMessageActions } = ChromeUtils.importESModule( + "resource://messaging-system/lib/SpecialMessageActions.sys.mjs" +); + +async function waitForClick(selector, win) { + await TestUtils.waitForCondition(() => win.document.querySelector(selector)); + win.document.querySelector(selector).click(); +} + +async function showDialog(dialogOptions) { + Spotlight.showSpotlightDialog( + dialogOptions.browser, + dialogOptions.message, + dialogOptions.dispatchStub + ); + const [win] = await TestUtils.topicObserved("subdialog-loaded"); + return win; +} + +add_task(async function test_specialAction() { + let message = (await PanelTestProvider.getMessages()).find( + m => m.id === "MULTISTAGE_SPOTLIGHT_MESSAGE" + ); + let dispatchStub = sinon.stub(); + let browser = BrowserWindowTracker.getTopWindow().gBrowser.selectedBrowser; + let specialActionStub = sinon.stub(SpecialMessageActions, "handleAction"); + + let win = await showDialog({ message, browser, dispatchStub }); + await waitForClick("button.primary", win); + win.close(); + + Assert.equal( + specialActionStub.callCount, + 1, + "Should be called by primary action" + ); + Assert.deepEqual( + specialActionStub.firstCall.args[0], + message.content.screens[0].content.primary_button.action, + "Should be called with button action" + ); + + specialActionStub.restore(); +}); -- cgit v1.2.3