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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TEST_CONFIG = [
{
webExtension: {
id: "get@search.mozilla.org",
name: "Get Engine",
search_url: "https://example.com",
search_url_get_params: "webExtension=1&search={searchTerms}",
suggest_url: "https://example.com",
suggest_url_get_params: "webExtension=1&suggest={searchTerms}",
},
appliesTo: [{ included: { everywhere: true } }],
suggestExtraParams: [
{
name: "custom_param",
pref: "test_pref_param",
condition: "pref",
},
],
},
];
const TEST_CONFIG_V2 = [
{
recordType: "engine",
identifier: "get",
base: {
name: "Get Engine",
urls: {
search: {
base: "https://example.com",
params: [
{
name: "webExtension",
value: "1",
},
],
searchTermParamName: "search",
},
suggestions: {
base: "https://example.com",
params: [
{
name: "custom_param",
experimentConfig: "test_pref_param",
},
{
name: "webExtension",
value: "1",
},
],
searchTermParamName: "suggest",
},
},
},
variants: [
{
environment: { allRegionsAndLocales: true },
},
],
},
{
recordType: "defaultEngines",
globalDefault: "get",
specificDefaults: [],
},
{
recordType: "engineOrders",
orders: [],
},
];
add_setup(async function () {
await SearchTestUtils.useTestEngines(
"method-extensions",
null,
SearchUtils.newSearchConfigEnabled ? TEST_CONFIG_V2 : TEST_CONFIG
);
await AddonTestUtils.promiseStartupManager();
await Services.search.init();
});
add_task(async function test_custom_suggest_param() {
let engine = Services.search.getEngineByName("Get Engine");
Assert.notEqual(engine, null, "Should have found an engine");
let submissionSuggest = engine.getSubmission(
"bar",
SearchUtils.URL_TYPE.SUGGEST_JSON
);
Assert.equal(
submissionSuggest.uri.spec,
"https://example.com/?webExtension=1&suggest=bar",
"Suggest URLs should match"
);
let defaultBranch = Services.prefs.getDefaultBranch("browser.search.");
defaultBranch.setCharPref("param.test_pref_param", "good");
let nextSubmissionSuggest = engine.getSubmission(
"bar",
SearchUtils.URL_TYPE.SUGGEST_JSON
);
Assert.equal(
nextSubmissionSuggest.uri.spec,
"https://example.com/?custom_param=good&webExtension=1&suggest=bar",
"Suggest URLs should include custom param"
);
});
|