зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1371294 - Add a SearchTestUtils.jsm file and stop duplicating promiseNewSearchEngine. r=mikedeboer
MozReview-Commit-ID: IP5iRstshrM --HG-- extra : rebase_source : 11e70ee041a8015486c15b57ababe05e6e567792
This commit is contained in:
Родитель
6b8c87c819
Коммит
1361f77350
|
@ -9,6 +9,11 @@ const TEST_ENGINE_2_BASENAME = "searchSuggestionEngine2.xml";
|
|||
|
||||
const TEST_MSG = "ContentSearchUIControllerTest";
|
||||
|
||||
let {SearchTestUtils} = ChromeUtils.import(
|
||||
"resource://testing-common/SearchTestUtils.jsm", {});
|
||||
|
||||
SearchTestUtils.init(Assert, registerCleanupFunction);
|
||||
|
||||
requestLongerTimeout(2);
|
||||
|
||||
add_task(async function emptyInput() {
|
||||
|
@ -391,6 +396,7 @@ add_task(async function cycleEngines() {
|
|||
if (data != "engine-current") {
|
||||
return;
|
||||
}
|
||||
subj.QueryInterface(Ci.nsISearchEngine);
|
||||
SimpleTest.is(subj.name, newEngineName, "Engine cycled correctly");
|
||||
Services.obs.removeObserver(resolver, "browser-search-engine-modified");
|
||||
resolve();
|
||||
|
@ -739,8 +745,11 @@ function setUpEngines() {
|
|||
let currentEngineName = Services.search.currentEngine.name;
|
||||
let currentEngines = Services.search.getVisibleEngines();
|
||||
info("Adding test search engines");
|
||||
let engine1 = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
await promiseNewSearchEngine(TEST_ENGINE_2_BASENAME);
|
||||
let rootDir = getRootDirectory(gTestPath);
|
||||
let engine1 = await SearchTestUtils.promiseNewSearchEngine(
|
||||
rootDir + TEST_ENGINE_BASENAME);
|
||||
await SearchTestUtils.promiseNewSearchEngine(
|
||||
rootDir + TEST_ENGINE_2_BASENAME);
|
||||
Services.search.currentEngine = engine1;
|
||||
for (let engine of currentEngines) {
|
||||
Services.search.removeEngine(engine);
|
||||
|
|
|
@ -526,24 +526,6 @@ function promiseNotificationShown(notification) {
|
|||
return panelPromise;
|
||||
}
|
||||
|
||||
function promiseNewSearchEngine(basename) {
|
||||
return new Promise((resolve, reject) => {
|
||||
info("Waiting for engine to be added: " + basename);
|
||||
let url = getRootDirectory(gTestPath) + basename;
|
||||
Services.search.addEngine(url, null, "", false, {
|
||||
onSuccess(engine) {
|
||||
info("Search engine added: " + basename);
|
||||
registerCleanupFunction(() => Services.search.removeEngine(engine));
|
||||
resolve(engine);
|
||||
},
|
||||
onError(errCode) {
|
||||
Assert.ok(false, "addEngine failed with error code " + errCode);
|
||||
reject();
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves when a bookmark with the given uri is added.
|
||||
*/
|
||||
|
|
|
@ -19,7 +19,8 @@ add_task(async function switchToTab() {
|
|||
});
|
||||
|
||||
add_task(async function searchSuggestions() {
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
Services.search.currentEngine = engine;
|
||||
Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true);
|
||||
|
|
|
@ -8,7 +8,8 @@ add_task(async function init() {
|
|||
|
||||
// Add a search suggestion engine and move it to the front so that it appears
|
||||
// as the first one-off.
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
Services.search.moveEngine(engine, 0);
|
||||
|
||||
registerCleanupFunction(async function() {
|
||||
|
|
|
@ -6,7 +6,8 @@ add_task(async function init() {
|
|||
set: [["browser.urlbar.oneOffSearches", true],
|
||||
["browser.urlbar.suggest.searches", true]],
|
||||
});
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
Services.search.moveEngine(engine, 0);
|
||||
Services.search.currentEngine = engine;
|
||||
|
|
|
@ -17,7 +17,8 @@ var extraEngine;
|
|||
var tabs = [];
|
||||
|
||||
add_task(async function setup() {
|
||||
extraEngine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let rootDir = getRootDirectory(gTestPath);
|
||||
extraEngine = await SearchTestUtils.promiseNewSearchEngine(rootDir + TEST_ENGINE_BASENAME);
|
||||
|
||||
// Force display of a tab with a URL bar, to clear out any possible placeholder
|
||||
// initialization listeners that happen on startup.
|
||||
|
|
|
@ -5,7 +5,8 @@ const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
|
|||
add_task(async function prepare() {
|
||||
let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF);
|
||||
Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true);
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
Services.search.currentEngine = engine;
|
||||
registerCleanupFunction(async function() {
|
||||
|
|
|
@ -9,7 +9,8 @@ const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
|
|||
const ONEOFF_PREF = "browser.urlbar.oneOffSearches";
|
||||
|
||||
add_task(async function prepare() {
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
Services.search.currentEngine = engine;
|
||||
let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF);
|
||||
|
|
|
@ -9,7 +9,8 @@ const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
|
|||
add_task(async function prepare() {
|
||||
let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF);
|
||||
Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true);
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
Services.search.currentEngine = engine;
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ add_task(async function init() {
|
|||
set: [["browser.urlbar.suggest.searches", true]],
|
||||
});
|
||||
// Add a test search engine that returns suggestions on a delay.
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
Services.search.moveEngine(engine, 0);
|
||||
Services.search.currentEngine = engine;
|
||||
|
|
|
@ -29,7 +29,8 @@ add_task(async function setup() {
|
|||
["network.dns.disableIPv6", true]],
|
||||
});
|
||||
|
||||
let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
|
||||
let engine = await SearchTestUtils.promiseNewSearchEngine(
|
||||
getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
|
||||
let oldCurrentEngine = Services.search.currentEngine;
|
||||
Services.search.currentEngine = engine;
|
||||
|
||||
|
@ -53,4 +54,3 @@ add_task(async function connect_search_engine_tests() {
|
|||
await promiseSpeculativeConnection(gHttpServer);
|
||||
is(gHttpServer.connectionNumber, 1, `${gHttpServer.connectionNumber} speculative connection has been setup.`);
|
||||
});
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@ ChromeUtils.defineModuleGetter(this, "Preferences",
|
|||
"resource://gre/modules/Preferences.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "HttpServer",
|
||||
"resource://testing-common/httpd.js");
|
||||
ChromeUtils.defineModuleGetter(this, "SearchTestUtils",
|
||||
"resource://testing-common/SearchTestUtils.jsm");
|
||||
|
||||
SearchTestUtils.init(Assert, registerCleanupFunction);
|
||||
|
||||
/**
|
||||
* Waits for the next top-level document load in the current browser. The URI
|
||||
|
@ -204,24 +208,6 @@ function promiseAutocompleteResultPopup(inputText,
|
|||
return promiseSearchComplete(win, dontAnimate);
|
||||
}
|
||||
|
||||
function promiseNewSearchEngine(basename) {
|
||||
return new Promise((resolve, reject) => {
|
||||
info("Waiting for engine to be added: " + basename);
|
||||
let url = getRootDirectory(gTestPath) + basename;
|
||||
Services.search.addEngine(url, null, "", false, {
|
||||
onSuccess(engine) {
|
||||
info("Search engine added: " + basename);
|
||||
registerCleanupFunction(() => Services.search.removeEngine(engine));
|
||||
resolve(engine);
|
||||
},
|
||||
onError(errCode) {
|
||||
Assert.ok(false, "addEngine failed with error code " + errCode);
|
||||
reject();
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function promisePageActionPanelOpen() {
|
||||
let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils);
|
||||
|
|
|
@ -10,6 +10,10 @@ BROWSER_CHROME_MANIFESTS += [
|
|||
'test/google_nocodes/browser.ini',
|
||||
]
|
||||
|
||||
TESTING_JS_MODULES += [
|
||||
'test/SearchTestUtils.jsm',
|
||||
]
|
||||
|
||||
JAR_MANIFESTS += ['jar.mn']
|
||||
|
||||
with Files('**'):
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
"use strict";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var EXPORTED_SYMBOLS = [
|
||||
"SearchTestUtils",
|
||||
];
|
||||
|
||||
var gTestGlobals;
|
||||
|
||||
var SearchTestUtils = Object.freeze({
|
||||
init(Assert, registerCleanupFunction) {
|
||||
gTestGlobals = {
|
||||
Assert,
|
||||
registerCleanupFunction
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a search engine to the search service. It will remove the engine
|
||||
* at the end of the test.
|
||||
*
|
||||
* @param {String} url The URL of the engine to add.
|
||||
* @param {Function} registerCleanupFunction Pass the registerCleanupFunction
|
||||
* from the test's scope.
|
||||
* @returns {Promise} Returns a promise that is resolved with the new engine
|
||||
* or rejected if it fails.
|
||||
*/
|
||||
promiseNewSearchEngine(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
Services.search.addEngine(url, null, "", false, {
|
||||
onSuccess(engine) {
|
||||
gTestGlobals.registerCleanupFunction(() => Services.search.removeEngine(engine));
|
||||
resolve(engine);
|
||||
},
|
||||
onError(errCode) {
|
||||
gTestGlobals.Assert.ok(false, `addEngine failed with error code ${errCode}`);
|
||||
reject();
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
Загрузка…
Ссылка в новой задаче