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 --- .../browser_system_notification_telemetry.js | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 browser/components/tests/browser/browser_system_notification_telemetry.js (limited to 'browser/components/tests/browser/browser_system_notification_telemetry.js') diff --git a/browser/components/tests/browser/browser_system_notification_telemetry.js b/browser/components/tests/browser/browser_system_notification_telemetry.js new file mode 100644 index 0000000000..6cc8d12165 --- /dev/null +++ b/browser/components/tests/browser/browser_system_notification_telemetry.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +async function handleCommandLine(args, state) { + let newWinPromise; + let target = Services.urlFormatter.formatURLPref( + "browser.shell.defaultBrowserAgent.thanksURL" + ); + + const EXISTING_FILE = Cc["@mozilla.org/file/local;1"].createInstance( + Ci.nsIFile + ); + EXISTING_FILE.initWithPath(getTestFilePath("dummy.pdf")); + + if (state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) { + newWinPromise = BrowserTestUtils.waitForNewWindow({ + url: target, // N.b.: trailing slashes matter when matching. + }); + } + + let cmdLineHandler = Cc["@mozilla.org/browser/final-clh;1"].getService( + Ci.nsICommandLineHandler + ); + + let fakeCmdLine = Cu.createCommandLine(args, EXISTING_FILE.parent, state); + cmdLineHandler.handle(fakeCmdLine); + + if (newWinPromise) { + let newWin = await newWinPromise; + await BrowserTestUtils.closeWindow(newWin); + } else { + BrowserTestUtils.removeTab(gBrowser.selectedTab); + } +} + +// Launching from the WDBA should open the "thanks" page and should send a +// telemetry event. +add_task(async function test_launched_to_handle_default_browser_agent() { + await handleCommandLine( + ["-to-handle-default-browser-agent"], + Ci.nsICommandLine.STATE_INITIAL_LAUNCH + ); + + TelemetryTestUtils.assertEvents( + [{ extra: { name: "default-browser-agent" } }], + { + category: "browser.launched_to_handle", + method: "system_notification", + object: "toast", + } + ); +}); -- cgit v1.2.3