1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
6 const { UrlbarTestUtils } = ChromeUtils.importESModule(
7 "resource://testing-common/UrlbarTestUtils.sys.mjs"
9 const { SearchTestUtils } = ChromeUtils.importESModule(
10 "resource://testing-common/SearchTestUtils.sys.mjs"
13 SearchTestUtils.init(this);
15 const kSearchEngineID = "browser_urifixup_search_engine";
16 const kSearchEngineURL = "https://example.com/?search={searchTerms}";
17 const kPrivateSearchEngineID = "browser_urifixup_search_engine_private";
18 const kPrivateSearchEngineURL = "https://example.com/?private={searchTerms}";
20 add_setup(async function () {
21 await SpecialPowers.pushPrefEnv({
23 ["browser.search.separatePrivateDefault.ui.enabled", true],
24 ["browser.search.separatePrivateDefault", true],
28 // Add new fake search engines.
29 await SearchTestUtils.installSearchExtension(
31 name: kSearchEngineID,
32 search_url: "https://example.com/",
33 search_url_get_params: "search={searchTerms}",
35 { setAsDefault: true }
38 await SearchTestUtils.installSearchExtension(
40 name: kPrivateSearchEngineID,
41 search_url: "https://example.com/",
42 search_url_get_params: "private={searchTerms}",
44 { setAsDefaultPrivate: true }
48 add_task(async function test() {
49 // Test both directly setting a value and pressing enter, or setting the
50 // value through input events, like the user would do.
53 win.gURLBar.value = value;
56 return UrlbarTestUtils.promiseAutocompleteResultPopup({
58 waitForFocus: SimpleTest.waitForFocus,
64 for (let value of ["foo bar", "brokenprotocol:somethingelse"]) {
65 for (let setValueFn of setValueFns) {
66 for (let inPrivateWindow of [false, true]) {
67 await do_test(value, setValueFn, inPrivateWindow);
73 async function do_test(value, setValueFn, inPrivateWindow) {
74 info(`Search ${value} in a ${inPrivateWindow ? "private" : "normal"} window`);
75 let win = await BrowserTestUtils.openNewBrowserWindow({
76 private: inPrivateWindow,
78 // Enter search terms and start a search.
80 await setValueFn(value, win);
82 EventUtils.synthesizeKey("KEY_Enter", {}, win);
84 // Check that we load the correct URL.
85 let escapedValue = encodeURIComponent(value).replace("%20", "+");
86 let searchEngineUrl = inPrivateWindow
87 ? kPrivateSearchEngineURL
89 let expectedURL = searchEngineUrl.replace("{searchTerms}", escapedValue);
90 await BrowserTestUtils.browserLoaded(
91 win.gBrowser.selectedBrowser,
95 // There should be at least one test.
97 win.gBrowser.selectedBrowser.currentURI.spec,
99 "New tab should have loaded with expected url."
103 await BrowserTestUtils.closeWindow(win);