Backed out 3 changesets (bug 1883476, bug 1826375) for causing windows build bustages...
[gecko.git] / browser / components / tests / browser / browser_system_notification_telemetry.js
blob6cc8d12165c61268c3f1f836f5c5ef147a64c2d0
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 async function handleCommandLine(args, state) {
7   let newWinPromise;
8   let target = Services.urlFormatter.formatURLPref(
9     "browser.shell.defaultBrowserAgent.thanksURL"
10   );
12   const EXISTING_FILE = Cc["@mozilla.org/file/local;1"].createInstance(
13     Ci.nsIFile
14   );
15   EXISTING_FILE.initWithPath(getTestFilePath("dummy.pdf"));
17   if (state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) {
18     newWinPromise = BrowserTestUtils.waitForNewWindow({
19       url: target, // N.b.: trailing slashes matter when matching.
20     });
21   }
23   let cmdLineHandler = Cc["@mozilla.org/browser/final-clh;1"].getService(
24     Ci.nsICommandLineHandler
25   );
27   let fakeCmdLine = Cu.createCommandLine(args, EXISTING_FILE.parent, state);
28   cmdLineHandler.handle(fakeCmdLine);
30   if (newWinPromise) {
31     let newWin = await newWinPromise;
32     await BrowserTestUtils.closeWindow(newWin);
33   } else {
34     BrowserTestUtils.removeTab(gBrowser.selectedTab);
35   }
38 // Launching from the WDBA should open the "thanks" page and should send a
39 // telemetry event.
40 add_task(async function test_launched_to_handle_default_browser_agent() {
41   await handleCommandLine(
42     ["-to-handle-default-browser-agent"],
43     Ci.nsICommandLine.STATE_INITIAL_LAUNCH
44   );
46   TelemetryTestUtils.assertEvents(
47     [{ extra: { name: "default-browser-agent" } }],
48     {
49       category: "browser.launched_to_handle",
50       method: "system_notification",
51       object: "toast",
52     }
53   );
54 });