forked from mirrors/gecko-dev
Bug 1445134 - Migrate docshell xpcshell-tests away from using enterprise policies. r=mcheang
Differential Revision: https://phabricator.services.mozilla.com/D159056
This commit is contained in:
parent
80e16caaee
commit
3a86c6fa41
6 changed files with 66 additions and 19 deletions
10
docshell/test/unit/data/engine.xml
Normal file
10
docshell/test/unit/data/engine.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
|
||||||
|
<ShortName>test_urifixup_search_engine</ShortName>
|
||||||
|
<Description>test_urifixup_search_engine</Description>
|
||||||
|
<InputEncoding>UTF-8</InputEncoding>
|
||||||
|
<Url type="text/html" method="GET" template="https://www.example.org/">
|
||||||
|
<Param name="search" value="{searchTerms}"/>
|
||||||
|
</Url>
|
||||||
|
<SearchForm>https://www.example.org/</SearchForm>
|
||||||
|
</SearchPlugin>
|
||||||
10
docshell/test/unit/data/enginePost.xml
Normal file
10
docshell/test/unit/data/enginePost.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
|
||||||
|
<ShortName>test_urifixup_search_engine_post</ShortName>
|
||||||
|
<Description>test_urifixup_search_engine_post</Description>
|
||||||
|
<InputEncoding>UTF-8</InputEncoding>
|
||||||
|
<Url type="text/html" method="POST" template="https://www.example.org/">
|
||||||
|
<Param name="q" value="{searchTerms}"/>
|
||||||
|
</Url>
|
||||||
|
<SearchForm>https://www.example.org/</SearchForm>
|
||||||
|
</SearchPlugin>
|
||||||
10
docshell/test/unit/data/enginePrivate.xml
Normal file
10
docshell/test/unit/data/enginePrivate.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
|
||||||
|
<ShortName>test_urifixup_search_engine_private</ShortName>
|
||||||
|
<Description>test_urifixup_search_engine_private</Description>
|
||||||
|
<InputEncoding>UTF-8</InputEncoding>
|
||||||
|
<Url type="text/html" method="GET" template="https://www.example.org/">
|
||||||
|
<Param name="private" value="{searchTerms}"/>
|
||||||
|
</Url>
|
||||||
|
<SearchForm>https://www.example.org/</SearchForm>
|
||||||
|
</SearchPlugin>
|
||||||
|
|
@ -13,6 +13,7 @@ ChromeUtils.defineESModuleGetters(this, {
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||||
AddonTestUtils: "resource://testing-common/AddonTestUtils.jsm",
|
AddonTestUtils: "resource://testing-common/AddonTestUtils.jsm",
|
||||||
|
HttpServer: "resource://testing-common/httpd.js",
|
||||||
NetUtil: "resource://gre/modules/NetUtil.jsm",
|
NetUtil: "resource://gre/modules/NetUtil.jsm",
|
||||||
TestUtils: "resource://testing-common/TestUtils.jsm",
|
TestUtils: "resource://testing-common/TestUtils.jsm",
|
||||||
});
|
});
|
||||||
|
|
@ -47,7 +48,6 @@ const SEARCH_CONFIG = [
|
||||||
async function setupSearchService() {
|
async function setupSearchService() {
|
||||||
SearchTestUtils.init(this);
|
SearchTestUtils.init(this);
|
||||||
|
|
||||||
Services.prefs.setBoolPref("browser.search.modernConfig", true);
|
|
||||||
AddonTestUtils.init(this);
|
AddonTestUtils.init(this);
|
||||||
AddonTestUtils.overrideCertDB();
|
AddonTestUtils.overrideCertDB();
|
||||||
AddonTestUtils.createAppInfo(
|
AddonTestUtils.createAppInfo(
|
||||||
|
|
@ -62,24 +62,39 @@ async function setupSearchService() {
|
||||||
await Services.search.init();
|
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() {
|
async function addTestEngines() {
|
||||||
|
useHttpServer();
|
||||||
// This is a hack, ideally we should be setting up a configuration with
|
// This is a hack, ideally we should be setting up a configuration with
|
||||||
// built-in engines, but the `chrome_settings_overrides` section that
|
// built-in engines, but the `chrome_settings_overrides` section that
|
||||||
// WebExtensions need is only defined for browser/
|
// WebExtensions need is only defined for browser/
|
||||||
await Services.search.addPolicyEngine({
|
await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/engine.xml`);
|
||||||
description: "urifixup search engine",
|
await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/enginePrivate.xml`);
|
||||||
name: kSearchEngineID,
|
await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/enginePost.xml`);
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
head = head_docshell.js
|
head = head_docshell.js
|
||||||
|
support-files =
|
||||||
|
data/engine.xml
|
||||||
|
data/enginePost.xml
|
||||||
|
data/enginePrivate.xml
|
||||||
|
|
||||||
[test_allowJavascript.js]
|
[test_allowJavascript.js]
|
||||||
skip-if = os == 'android'
|
skip-if = os == 'android'
|
||||||
|
|
|
||||||
|
|
@ -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.search.log", true);
|
||||||
Services.prefs.setBoolPref("browser.region.log", true);
|
Services.prefs.setBoolPref("browser.region.log", true);
|
||||||
|
|
||||||
Services.prefs.setBoolPref("browser.search.modernConfig", true);
|
|
||||||
|
|
||||||
AddonTestUtils.init(this, false);
|
AddonTestUtils.init(this, false);
|
||||||
AddonTestUtils.createAppInfo(
|
AddonTestUtils.createAppInfo(
|
||||||
"xpcshell@tests.mozilla.org",
|
"xpcshell@tests.mozilla.org",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue