diff --git a/docshell/test/unit/data/engine.xml b/docshell/test/unit/data/engine.xml
new file mode 100644
index 000000000000..3a2bd85c1b09
--- /dev/null
+++ b/docshell/test/unit/data/engine.xml
@@ -0,0 +1,10 @@
+
+
+test_urifixup_search_engine
+test_urifixup_search_engine
+UTF-8
+
+
+
+https://www.example.org/
+
diff --git a/docshell/test/unit/data/enginePost.xml b/docshell/test/unit/data/enginePost.xml
new file mode 100644
index 000000000000..14775b6f0a0c
--- /dev/null
+++ b/docshell/test/unit/data/enginePost.xml
@@ -0,0 +1,10 @@
+
+
+test_urifixup_search_engine_post
+test_urifixup_search_engine_post
+UTF-8
+
+
+
+https://www.example.org/
+
diff --git a/docshell/test/unit/data/enginePrivate.xml b/docshell/test/unit/data/enginePrivate.xml
new file mode 100644
index 000000000000..7d87de98fa52
--- /dev/null
+++ b/docshell/test/unit/data/enginePrivate.xml
@@ -0,0 +1,10 @@
+
+
+test_urifixup_search_engine_private
+test_urifixup_search_engine_private
+UTF-8
+
+
+
+https://www.example.org/
+
diff --git a/docshell/test/unit/head_docshell.js b/docshell/test/unit/head_docshell.js
index c4603ae63e5a..6702a50b003c 100644
--- a/docshell/test/unit/head_docshell.js
+++ b/docshell/test/unit/head_docshell.js
@@ -13,6 +13,7 @@ ChromeUtils.defineESModuleGetters(this, {
XPCOMUtils.defineLazyModuleGetters(this, {
AddonTestUtils: "resource://testing-common/AddonTestUtils.jsm",
+ HttpServer: "resource://testing-common/httpd.js",
NetUtil: "resource://gre/modules/NetUtil.jsm",
TestUtils: "resource://testing-common/TestUtils.jsm",
});
@@ -47,7 +48,6 @@ const SEARCH_CONFIG = [
async function setupSearchService() {
SearchTestUtils.init(this);
- Services.prefs.setBoolPref("browser.search.modernConfig", true);
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.createAppInfo(
@@ -62,24 +62,39 @@ async function setupSearchService() {
await Services.search.init();
}
+/**
+ * After useHttpServer() is called, this string contains the URL of the "data"
+ * directory, including the final slash.
+ */
+var gDataUrl;
+
+/**
+ * Initializes the HTTP server and ensures that it is terminated when tests end.
+ *
+ * @param {string} dir
+ * The test sub-directory to use for the engines.
+ * @returns {HttpServer}
+ * The HttpServer object in case further customization is needed.
+ */
+function useHttpServer(dir = "data") {
+ let httpServer = new HttpServer();
+ httpServer.start(-1);
+ httpServer.registerDirectory("/", do_get_cwd());
+ gDataUrl = `http://localhost:${httpServer.identity.primaryPort}/${dir}/`;
+ registerCleanupFunction(async function cleanup_httpServer() {
+ await new Promise(resolve => {
+ httpServer.stop(resolve);
+ });
+ });
+ return httpServer;
+}
+
async function addTestEngines() {
+ useHttpServer();
// This is a hack, ideally we should be setting up a configuration with
// built-in engines, but the `chrome_settings_overrides` section that
// WebExtensions need is only defined for browser/
- await Services.search.addPolicyEngine({
- description: "urifixup search engine",
- name: kSearchEngineID,
- search_url: kSearchEngineURL,
- });
- await Services.search.addPolicyEngine({
- description: "urifixup private search engine",
- name: kPrivateSearchEngineID,
- search_url: kPrivateSearchEngineURL,
- });
- await Services.search.addPolicyEngine({
- description: "urifixup POST search engine",
- name: kPostSearchEngineID,
- search_url: kPostSearchEngineURL,
- search_url_post_params: kPostSearchEngineData,
- });
+ await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/engine.xml`);
+ await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/enginePrivate.xml`);
+ await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/enginePost.xml`);
}
diff --git a/docshell/test/unit/xpcshell.ini b/docshell/test/unit/xpcshell.ini
index 3a9b51f986e2..8bd7ef4f289e 100644
--- a/docshell/test/unit/xpcshell.ini
+++ b/docshell/test/unit/xpcshell.ini
@@ -1,5 +1,9 @@
[DEFAULT]
head = head_docshell.js
+support-files =
+ data/engine.xml
+ data/enginePost.xml
+ data/enginePrivate.xml
[test_allowJavascript.js]
skip-if = os == 'android'
diff --git a/toolkit/components/search/tests/xpcshell/head_search.js b/toolkit/components/search/tests/xpcshell/head_search.js
index 2c379e838412..9deb48c85106 100644
--- a/toolkit/components/search/tests/xpcshell/head_search.js
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -45,8 +45,6 @@ var XULRuntime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
Services.prefs.setBoolPref("browser.search.log", true);
Services.prefs.setBoolPref("browser.region.log", true);
-Services.prefs.setBoolPref("browser.search.modernConfig", true);
-
AddonTestUtils.init(this, false);
AddonTestUtils.createAppInfo(
"xpcshell@tests.mozilla.org",