Bug 1132772 - afterCache() and afterCommit() should return Promise. r=ttaubert

--HG--
extra : rebase_source : ff86c3437adcafe9447c2bad2974f353143b6281
This commit is contained in:
Hiroyuki Ikezoe 2015-03-15 16:06:00 -04:00
Родитель f27948958f
Коммит 8e744492bd
4 изменённых файлов: 23 добавлений и 37 удалений

Просмотреть файл

@ -143,36 +143,19 @@ function isUSTimezone() {
}
/**
* Run some callback once metadata has been committed to disk.
* Waits for metadata being committed.
* @return {Promise} Resolved when the metadata is committed to disk.
*/
function afterCommit(callback)
{
let obs = function(result, topic, verb) {
if (verb == "write-metadata-to-disk-complete") {
Services.obs.removeObserver(obs, topic);
callback(result);
} else {
dump("TOPIC: " + topic+ "\n");
}
}
Services.obs.addObserver(obs, "browser-search-service", false);
function promiseAfterCommit() {
return waitForSearchNotification("write-metadata-to-disk-complete");
}
/**
* Run some callback once cache has been built.
* Waits for the cache file to be saved.
* @return {Promise} Resolved when the cache file is saved.
*/
function afterCache(callback)
{
let obs = function(result, topic, verb) {
do_print("afterCache: " + verb);
if (verb == "write-cache-to-disk-complete") {
Services.obs.removeObserver(obs, topic);
callback(result);
} else {
dump("TOPIC: " + topic+ "\n");
}
}
Services.obs.addObserver(obs, "browser-search-service", false);
function promiseAfterCache() {
return waitForSearchNotification("write-cache-to-disk-complete");
}
function parseJsonFromStream(aInputStream) {

Просмотреть файл

@ -23,24 +23,27 @@ function run_test()
add_task(function* test_nocache() {
let search = Services.search;
// Check that cache is created at startup
afterCache(function cacheCreated() {
// Check that search.json has been created.
let cache = gProfD.clone();
cache.append("search.json");
do_check_true(cache.exists());
});
let afterCachePromise = promiseAfterCache();
yield new Promise((resolve, reject) => search.init(rv => {
Components.isSuccessCode(rv) ? resolve() : reject();
}));
// Check that the cache is created at startup
yield afterCachePromise;
// Check that search.json has been created.
let cacheFile = gProfD.clone();
cacheFile.append("search.json");
do_check_true(cacheFile.exists());
// Add engine and wait for cache update
yield addTestEngines([
{ name: "Test search engine", xmlFileName: "engine.xml" },
]);
do_print("Engine has been added, let's wait for the cache to be built");
yield new Promise(resolve => afterCache(resolve));
yield promiseAfterCache();
do_print("Searching test engine in cache");
let path = OS.Path.join(OS.Constants.Path.profileDir, "search.json");

Просмотреть файл

@ -45,7 +45,7 @@ add_task(function* test_nodb_pluschanges() {
yield new Promise(resolve => do_execute_soon(resolve));
do_print("Forcing flush");
let promiseCommit = new Promise(resolve => afterCommit(resolve));
let promiseCommit = promiseAfterCommit();
search.QueryInterface(Ci.nsIObserver)
.observe(null, "quit-application", "");
yield promiseCommit;

Просмотреть файл

@ -39,7 +39,7 @@ add_task(function* test_save_sorted_engines() {
search.moveEngine(engine2, 1);
// Changes should be commited immediately
yield new Promise(resolve => afterCommit(resolve));
yield promiseAfterCommit();
do_print("Commit complete after moveEngine");
// Check that the entries are placed as specified correctly
@ -49,7 +49,7 @@ add_task(function* test_save_sorted_engines() {
// Test removing an engine
search.removeEngine(engine1);
yield new Promise(resolve => afterCommit(resolve));
yield promiseAfterCommit();
do_print("Commit complete after removeEngine");
// Check that the order of the remaining engine was updated correctly
@ -59,7 +59,7 @@ add_task(function* test_save_sorted_engines() {
// Test adding a new engine
search.addEngineWithDetails("foo", "", "foo", "", "GET",
"http://searchget/?search={searchTerms}");
yield new Promise(resolve => afterCommit(resolve));
yield promiseAfterCommit();
do_print("Commit complete after addEngineWithDetails");
json = getSearchMetadata();