1 const TELEMETRY_BASE = "notificationbar.";
3 ChromeUtils.defineESModuleGetters(this, {
4 TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.sys.mjs",
7 add_task(async function showNotification() {
8 Services.telemetry.clearScalars();
10 let tab1 = await BrowserTestUtils.openNewForegroundTab(
12 "https://example.com/"
15 ok(!gBrowser.readNotificationBox(), "no notificationbox created yet");
17 let box1 = gBrowser.getNotificationBox();
19 ok(gBrowser.readNotificationBox(), "notificationbox was created");
21 let tab2 = await BrowserTestUtils.openNewForegroundTab(
23 "https://example.org/"
26 let tab3 = await BrowserTestUtils.openNewForegroundTab(
28 "data:text/html,<body>Hello</body>"
30 let box3 = gBrowser.getNotificationBox();
32 verifyTelemetry("initial", 0, 0, 0, 0, 0, 0);
34 let notif3 = box3.appendNotification("infobar-testtwo-value", {
35 label: "Message for tab 3",
36 priority: box3.PRIORITY_INFO_HIGH,
37 telemetry: TELEMETRY_BASE + "testtwo",
40 verifyTelemetry("first notification", 0, 0, 0, 0, 0, 1);
42 let notif1 = box1.appendNotification(
43 "infobar-testone-value",
45 label: "Message for tab 1",
46 priority: box1.PRIORITY_INFO_HIGH,
47 telemetry: TELEMETRY_BASE + "testone",
52 telemetry: "button1-pressed",
56 telemetry: "button2-pressed",
63 verifyTelemetry("second notification", 0, 0, 0, 0, 0, 1);
65 await BrowserTestUtils.switchTab(gBrowser, tab1);
66 verifyTelemetry("switch to first tab", 1, 0, 0, 0, 0, 1);
68 await BrowserTestUtils.switchTab(gBrowser, tab2);
69 verifyTelemetry("switch to second tab", 1, 0, 0, 0, 0, 1);
71 await BrowserTestUtils.switchTab(gBrowser, tab3);
72 verifyTelemetry("switch to third tab", 1, 0, 0, 0, 0, 1);
74 await BrowserTestUtils.switchTab(gBrowser, tab1);
75 verifyTelemetry("switch to first tab again", 1, 0, 0, 0, 0, 1);
77 notif1.buttonContainer.lastElementChild.click();
78 verifyTelemetry("press third button", 1, 1, 0, 0, 0, 1);
80 notif1.buttonContainer.lastElementChild.previousElementSibling.click();
81 verifyTelemetry("press second button", 1, 1, 0, 1, 0, 1);
83 notif1.buttonContainer.lastElementChild.previousElementSibling.previousElementSibling.click();
84 verifyTelemetry("press first button", 1, 1, 1, 1, 0, 1);
87 verifyTelemetry("dismiss notification for box 1", 1, 1, 1, 1, 1, 1);
90 verifyTelemetry("dismiss notification for box 3", 1, 1, 1, 1, 1, 1, 1);
92 let notif4 = box1.appendNotification(
93 "infobar-testtwo-value",
95 label: "Additional message for tab 1",
96 priority: box1.PRIORITY_INFO_HIGH,
97 telemetry: TELEMETRY_BASE + "testone",
98 telemetryFilter: ["shown"],
106 verifyTelemetry("show first filtered notification", 2, 1, 1, 1, 1, 1, 1);
108 notif4.buttonContainer.lastElementChild.click();
110 verifyTelemetry("dismiss first filtered notification", 2, 1, 1, 1, 1, 1, 1);
112 let notif5 = box1.appendNotification(
113 "infobar-testtwo-value",
115 label: "Dimissed additional message for tab 1",
116 priority: box1.PRIORITY_INFO_HIGH,
117 telemetry: TELEMETRY_BASE + "testone",
118 telemetryFilter: ["dismissed"],
126 verifyTelemetry("show second filtered notification", 2, 1, 1, 1, 1, 1, 1);
128 notif5.buttonContainer.lastElementChild.click();
130 verifyTelemetry("dismiss second filtered notification", 2, 1, 1, 1, 2, 1, 1);
132 let notif6 = box1.appendNotification(
133 "infobar-testtwo-value",
135 label: "Dimissed additional message for tab 1",
136 priority: box1.PRIORITY_INFO_HIGH,
137 telemetry: TELEMETRY_BASE + "testone",
138 telemetryFilter: ["button1-pressed", "dismissed"],
143 telemetry: "button1-pressed",
147 verifyTelemetry("show third filtered notification", 2, 1, 1, 1, 2, 1, 1);
149 notif6.buttonContainer.lastElementChild.click();
151 "click button in third filtered notification",
161 verifyTelemetry("dismiss third filtered notification", 2, 1, 2, 1, 3, 1, 1);
163 BrowserTestUtils.removeTab(tab1);
164 BrowserTestUtils.removeTab(tab2);
165 BrowserTestUtils.removeTab(tab3);
168 function verify(scalars, scalar, key, expected, exists) {
169 scalar = TELEMETRY_BASE + scalar;
172 TelemetryTestUtils.assertKeyedScalar(scalars, scalar, key, expected);
179 `expected ${scalar} to be ${exists ? "present" : "unset"}`
184 !(key in scalars[scalar]),
185 "expected key " + key + " to be unset"
190 function verifyTelemetry(
200 let scalars = TelemetryTestUtils.getProcessScalars("parent", true, false);
204 box1shown || box1action || box1button1 || box1button2 || box1dismissed;
206 verify(scalars, "testone", "shown", box1shown, n1exists);
207 verify(scalars, "testone", "action", box1action, n1exists);
208 verify(scalars, "testone", "button1-pressed", box1button1, n1exists);
209 verify(scalars, "testone", "button2-pressed", box1button2, n1exists);
210 verify(scalars, "testone", "dismissed", box1dismissed, n1exists);
211 verify(scalars, "testtwo", "shown", box3shown, box3shown || box3dismissed);
217 box3shown || box3dismissed