1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test for engagement telemetry for tips using Glean.
ChromeUtils.defineESModuleGetters(this, {
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
});
add_setup(async function() {
makeProfileResettable();
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.searchEngagementTelemetry.enabled", true],
["browser.urlbar.quickactions.enabled", true],
["browser.urlbar.suggest.quickactions", true],
["browser.urlbar.quickactions.showInZeroPrefix", true],
],
});
registerCleanupFunction(async function() {
await SpecialPowers.popPrefEnv();
});
});
add_task(async function selected_result_tip() {
const testData = [
{
type: "searchTip_onboard",
expected: "tip_onboard",
},
{
type: "searchTip_persist",
expected: "tip_persist",
},
{
type: "searchTip_redirect",
expected: "tip_redirect",
},
{
type: "test",
expected: "tip_unknown",
},
];
for (const { type, expected } of testData) {
const deferred = PromiseUtils.defer();
const provider = new UrlbarTestUtils.TestProvider({
results: [
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.TIP,
UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
{
type,
helpUrl: "https://example.com/",
titleL10n: { id: "urlbar-search-tips-confirm" },
buttons: [
{
url: "https://example.com/",
l10n: { id: "urlbar-search-tips-confirm" },
},
],
}
),
],
priority: 1,
onEngagement: () => {
deferred.resolve();
},
});
UrlbarProvidersManager.registerProvider(provider);
await doTest(async browser => {
await openPopup("example");
await selectRow(type);
EventUtils.synthesizeKey("VK_RETURN");
await deferred.promise;
assertGleanTelemetry([
{
selected_result: expected,
results: expected,
},
]);
});
UrlbarProvidersManager.unregisterProvider(provider);
}
});
add_task(async function selected_result_intervention_clear() {
await doInterventionTest(
SEARCH_STRINGS.CLEAR,
"intervention_clear",
"chrome://browser/content/sanitize.xhtml",
[
{
selected_result: "intervention_clear",
results: "search_engine,intervention_clear",
},
]
);
});
add_task(async function selected_result_intervention_refresh() {
await doInterventionTest(
SEARCH_STRINGS.REFRESH,
"intervention_refresh",
"chrome://global/content/resetProfile.xhtml",
[
{
selected_result: "intervention_refresh",
results: "search_engine,intervention_refresh",
},
]
);
});
add_task(async function selected_result_intervention_update() {
// Updates are disabled for MSIX packages, this test is irrelevant for them.
if (
AppConstants.platform === "win" &&
Services.sysinfo.getProperty("hasWinPackageId")
) {
return;
}
await UpdateUtils.setAppUpdateAutoEnabled(false);
await initUpdate({ queryString: "&noUpdates=1" });
UrlbarProviderInterventions.checkForBrowserUpdate(true);
await processUpdateSteps([
{
panelId: "checkingForUpdates",
checkActiveUpdate: null,
continueFile: CONTINUE_CHECK,
},
{
panelId: "noUpdatesFound",
checkActiveUpdate: null,
continueFile: null,
},
]);
await doInterventionTest(
SEARCH_STRINGS.UPDATE,
"intervention_update_refresh",
"chrome://global/content/resetProfile.xhtml",
[
{
selected_result: "intervention_update",
results: "search_engine,action,intervention_update",
},
]
);
});
function assertGleanTelemetry(expectedExtraList) {
const telemetries = Glean.urlbar.engagement.testGetValue();
Assert.equal(telemetries.length, expectedExtraList.length);
for (let i = 0; i < telemetries.length; i++) {
const telemetry = telemetries[i];
Assert.equal(telemetry.category, "urlbar");
Assert.equal(telemetry.name, "engagement");
const expectedExtra = expectedExtraList[i];
for (const key of Object.keys(expectedExtra)) {
Assert.equal(
telemetry.extra[key],
expectedExtra[key],
`${key} is correct`
);
}
}
}
async function doInterventionTest(keyword, type, dialog, expectedTelemetry) {
await doTest(async browser => {
await openPopup(keyword);
await selectRow(type);
const onDialog = BrowserTestUtils.promiseAlertDialog("cancel", dialog, {
isSubDialog: true,
});
EventUtils.synthesizeKey("VK_RETURN");
await onDialog;
assertGleanTelemetry(expectedTelemetry);
});
}
async function doTest(testFn) {
Services.fog.testResetFOG();
await BrowserTestUtils.withNewTab(gBrowser, testFn);
}
async function openPopup(input) {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: input,
fireInputEvent: true,
});
}
async function selectRow(type) {
for (let i = 0; i < UrlbarTestUtils.getResultCount(window); i++) {
const detail = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
if (detail.result.payload.type === type) {
UrlbarTestUtils.setSelectedRowIndex(window, i);
return;
}
}
}
|