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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const CONFIG_DEFAULT = [
{
webExtension: { id: "basic@search.mozilla.org" },
urls: {
trending: {
fullPath:
"https://example.com/browser/browser/components/search/test/browser/trendingSuggestionEngine.sjs?richsuggestions=true",
query: "",
},
},
appliesTo: [{ included: { everywhere: true } }],
default: "yes",
},
];
SearchTestUtils.init(this);
add_setup(async () => {
// Use engines in test directory
let searchExtensions = getChromeDir(getResolvedURI(gTestPath));
searchExtensions.append("search-engines");
await SearchTestUtils.useMochitestEngines(searchExtensions);
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.suggest.searches", true],
["browser.urlbar.trending.featureGate", true],
["browser.urlbar.trending.requireSearchMode", false],
["browser.urlbar.eventTelemetry.enabled", true],
// Bug 1775917: Disable the persisted-search-terms search tip because if
// not dismissed, it can cause issues with other search tests.
["browser.urlbar.tipShownCount.searchTip_persist", 999],
],
});
SearchTestUtils.useMockIdleService();
await SearchTestUtils.updateRemoteSettingsConfig(CONFIG_DEFAULT);
registerCleanupFunction(async () => {
let settingsWritten = SearchTestUtils.promiseSearchNotification(
"write-settings-to-disk-complete"
);
await SearchTestUtils.updateRemoteSettingsConfig();
await settingsWritten;
});
});
add_task(async function test_trending_results() {
await check_results({ featureEnabled: true });
await check_results({ featureEnabled: false });
});
async function check_results({ featureEnabled = false }) {
Services.telemetry.clearEvents();
Services.telemetry.clearScalars();
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.richSuggestions.featureGate", featureEnabled]],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "",
waitForFocus: SimpleTest.waitForFocus,
});
let numResults = UrlbarTestUtils.getResultCount(window);
for (let i = 0; i < numResults; i++) {
let { result } = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH);
Assert.equal(result.providerName, "SearchSuggestions");
Assert.equal(result.payload.engine, "basic");
Assert.equal(result.payload.isRichSuggestion, featureEnabled);
if (featureEnabled) {
Assert.equal(typeof result.payload.description, "string");
Assert.ok(result.payload.icon.startsWith("data:"));
}
}
info("Select first remote search suggestion & hit Enter.");
EventUtils.synthesizeKey("KEY_ArrowDown", {}, window);
EventUtils.synthesizeKey("VK_RETURN", {}, window);
let event = {
category: "urlbar",
method: "engagement",
object: "enter",
value: "typed",
extra: {
elapsed: val => parseInt(val) > 0,
numChars: "0",
numWords: "0",
selIndex: "0",
selType: featureEnabled ? "trending_rich" : "trending",
provider: "SearchSuggestions",
},
};
TelemetryTestUtils.assertEvents([event], {
category: "urlbar",
});
let scalars = TelemetryTestUtils.getProcessScalars("parent", false, true);
TelemetryTestUtils.assertScalar(scalars, "urlbar.engagement", 1);
await SpecialPowers.popPrefEnv();
}
|