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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function() {
// Our search would be handled by the urlbar normally and not by the docshell,
// thus we must force going through dns first, so that the urlbar thinks
// the value may be a url, and asks the docshell to visit it.
// On NS_ERROR_UNKNOWN_HOST the docshell will fix it up.
await SpecialPowers.pushPrefEnv({
set: [["browser.fixup.dns_first_for_single_words", true]],
});
const kSearchEngineID = "test_urifixup_search_engine";
const kSearchEngineURL = "http://localhost/?search={searchTerms}";
await Services.search.addEngineWithDetails(kSearchEngineID, {
method: "get",
template: kSearchEngineURL,
});
let oldDefaultEngine = await Services.search.getDefault();
await Services.search.setDefault(
Services.search.getEngineByName(kSearchEngineID)
);
let selectedName = (await Services.search.getDefault()).name;
Assert.equal(
selectedName,
kSearchEngineID,
"Check fake search engine is selected"
);
registerCleanupFunction(async function() {
if (oldDefaultEngine) {
await Services.search.setDefault(oldDefaultEngine);
}
let engine = Services.search.getEngineByName(kSearchEngineID);
if (engine) {
await Services.search.removeEngine(engine);
}
});
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
gBrowser.selectedTab = tab;
gURLBar.value = "firefox";
gURLBar.handleCommand();
let [subject, data] = await TestUtils.topicObserved("keyword-search");
let engine = Services.search.defaultEngine;
Assert.ok(engine, "Have default search engine.");
Assert.equal(engine, subject, "Notification subject is engine.");
Assert.equal(data, "firefox", "Notification data is search term.");
gBrowser.removeTab(tab);
});
|