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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/*
* Test that defaultEngine property can be set and yields the proper events and\
* behavior (search results)
*/
"use strict";
let engine1;
let engine2;
add_setup(async () => {
do_get_profile();
Services.fog.initializeFOG();
useHttpServer();
await AddonTestUtils.promiseStartupManager();
await Services.search.init();
engine1 = await SearchTestUtils.promiseNewSearchEngine({
url: `${gDataUrl}engine.xml`,
});
engine2 = await SearchTestUtils.promiseNewSearchEngine({
url: `${gDataUrl}engine2.xml`,
});
});
function promiseDefaultNotification() {
return SearchTestUtils.promiseSearchNotification(
SearchUtils.MODIFIED_TYPE.DEFAULT,
SearchUtils.TOPIC_ENGINE_MODIFIED
);
}
add_task(async function test_defaultEngine() {
let promise = promiseDefaultNotification();
Services.search.defaultEngine = engine1;
Assert.equal((await promise).wrappedJSObject, engine1);
Assert.equal(Services.search.defaultEngine.wrappedJSObject, engine1);
await assertGleanDefaultEngine({
normal: {
engineId: "other-Test search engine",
displayName: "Test search engine",
loadPath: "[http]localhost/test-search-engine.xml",
submissionUrl: "https://www.google.com/search?q=",
verified: "verified",
},
});
promise = promiseDefaultNotification();
Services.search.defaultEngine = engine2;
Assert.equal((await promise).wrappedJSObject, engine2);
Assert.equal(Services.search.defaultEngine.wrappedJSObject, engine2);
await assertGleanDefaultEngine({
normal: {
engineId: "other-A second test engine",
displayName: "A second test engine",
loadPath: "[http]localhost/a-second-test-engine.xml",
submissionUrl: "https://duckduckgo.com/?q=",
verified: "verified",
},
});
promise = promiseDefaultNotification();
Services.search.defaultEngine = engine1;
Assert.equal((await promise).wrappedJSObject, engine1);
Assert.equal(Services.search.defaultEngine.wrappedJSObject, engine1);
await assertGleanDefaultEngine({
normal: {
engineId: "other-Test search engine",
displayName: "Test search engine",
loadPath: "[http]localhost/test-search-engine.xml",
submissionUrl: "https://www.google.com/search?q=",
verified: "verified",
},
});
});
add_task(async function test_telemetry_empty_submission_url() {
let engine = await Services.search.addOpenSearchEngine(
gDataUrl + "../opensearch/simple.xml",
null
);
Services.search.defaultPrivateEngine = engine;
await assertGleanDefaultEngine({
normal: {
engineId: "other-simple",
displayName: "simple",
loadPath: "[http]localhost/simple.xml",
submissionUrl: "blank:",
verified: "verified",
},
private: {
engineId: "",
displayName: "",
loadPath: "",
submissionUrl: "blank:",
verified: "",
},
});
});
add_task(async function test_switch_with_invalid_overriddenBy() {
engine1.wrappedJSObject.setAttr("overriddenBy", "random@id");
consoleAllowList.push(
"Test search engine had overriddenBy set, but no _overriddenData"
);
let promise = promiseDefaultNotification();
Services.search.defaultEngine = engine2;
Assert.equal((await promise).wrappedJSObject, engine2);
Assert.equal(Services.search.defaultEngine.wrappedJSObject, engine2);
});
|