mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1255605 - search.json.mozlz4 should always contain search engines. r=adw, a=sledru
This commit is contained in:
parent
300f5b9f94
commit
02cc0f075d
@ -2856,6 +2856,9 @@ SearchService.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!cache.engines.length)
|
||||||
|
throw "cannot write without any engine.";
|
||||||
|
|
||||||
LOG("_buildCache: Writing to cache file.");
|
LOG("_buildCache: Writing to cache file.");
|
||||||
let path = OS.Path.join(OS.Constants.Path.profileDir, CACHE_FILENAME);
|
let path = OS.Path.join(OS.Constants.Path.profileDir, CACHE_FILENAME);
|
||||||
let data = gEncoder.encode(JSON.stringify(cache));
|
let data = gEncoder.encode(JSON.stringify(cache));
|
||||||
@ -3174,7 +3177,10 @@ SearchService.prototype = {
|
|||||||
bis.readArrayBuffer(count, array.buffer);
|
bis.readArrayBuffer(count, array.buffer);
|
||||||
|
|
||||||
let bytes = Lz4.decompressFileContent(array);
|
let bytes = Lz4.decompressFileContent(array);
|
||||||
return JSON.parse(new TextDecoder().decode(bytes));
|
let json = JSON.parse(new TextDecoder().decode(bytes));
|
||||||
|
if (!json.engines || !json.engines.length)
|
||||||
|
throw "no engine in the file";
|
||||||
|
return json;
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
LOG("_readCacheFile: Error reading cache file: " + ex);
|
LOG("_readCacheFile: Error reading cache file: " + ex);
|
||||||
} finally {
|
} finally {
|
||||||
@ -3227,6 +3233,8 @@ SearchService.prototype = {
|
|||||||
let cacheFilePath = OS.Path.join(OS.Constants.Path.profileDir, CACHE_FILENAME);
|
let cacheFilePath = OS.Path.join(OS.Constants.Path.profileDir, CACHE_FILENAME);
|
||||||
let bytes = yield OS.File.read(cacheFilePath, {compression: "lz4"});
|
let bytes = yield OS.File.read(cacheFilePath, {compression: "lz4"});
|
||||||
json = JSON.parse(new TextDecoder().decode(bytes));
|
json = JSON.parse(new TextDecoder().decode(bytes));
|
||||||
|
if (!json.engines || !json.engines.length)
|
||||||
|
throw "no engine in the file";
|
||||||
this._cacheFileJSON = json;
|
this._cacheFileJSON = json;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
LOG("_asyncReadCacheFile: Error reading cache file: " + ex);
|
LOG("_asyncReadCacheFile: Error reading cache file: " + ex);
|
||||||
|
@ -215,6 +215,12 @@ function promiseCacheData() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function promiseSaveCacheData(data) {
|
||||||
|
return OS.File.writeAtomic(OS.Path.join(OS.Constants.Path.profileDir, CACHE_FILENAME),
|
||||||
|
new TextEncoder().encode(JSON.stringify(data)),
|
||||||
|
{compression: "lz4"});
|
||||||
|
}
|
||||||
|
|
||||||
function promiseEngineMetadata() {
|
function promiseEngineMetadata() {
|
||||||
return new Promise(resolve => Task.spawn(function* () {
|
return new Promise(resolve => Task.spawn(function* () {
|
||||||
let cache = yield promiseCacheData();
|
let cache = yield promiseCacheData();
|
||||||
@ -237,9 +243,7 @@ function promiseSaveGlobalMetadata(globalData) {
|
|||||||
return new Promise(resolve => Task.spawn(function* () {
|
return new Promise(resolve => Task.spawn(function* () {
|
||||||
let data = yield promiseCacheData();
|
let data = yield promiseCacheData();
|
||||||
data.metaData = globalData;
|
data.metaData = globalData;
|
||||||
yield OS.File.writeAtomic(OS.Path.join(OS.Constants.Path.profileDir, CACHE_FILENAME),
|
yield promiseSaveCacheData(data);
|
||||||
new TextEncoder().encode(JSON.stringify(data)),
|
|
||||||
{compression: "lz4"});
|
|
||||||
resolve();
|
resolve();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -254,6 +258,7 @@ var forceExpiration = Task.async(function* () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean the profile of any cache file left from a previous run.
|
* Clean the profile of any cache file left from a previous run.
|
||||||
|
* Returns a boolean indicating if the cache file existed.
|
||||||
*/
|
*/
|
||||||
function removeCacheFile()
|
function removeCacheFile()
|
||||||
{
|
{
|
||||||
@ -261,7 +266,9 @@ function removeCacheFile()
|
|||||||
file.append(CACHE_FILENAME);
|
file.append(CACHE_FILENAME);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.remove(false);
|
file.remove(false);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,9 +45,12 @@ add_task(function* async_init() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* sync_init() {
|
add_task(function* sync_init() {
|
||||||
|
let unInitPromise = waitForSearchNotification("uninit-complete");
|
||||||
let reInitPromise = asyncReInit();
|
let reInitPromise = asyncReInit();
|
||||||
// Synchronously check the current default engine, to force a sync init.
|
yield unInitPromise;
|
||||||
do_check_false(Services.search.isInitialized);
|
do_check_false(Services.search.isInitialized);
|
||||||
|
|
||||||
|
// Synchronously check the current default engine, to force a sync init.
|
||||||
do_check_eq(Services.search.currentEngine.name, "hidden");
|
do_check_eq(Services.search.currentEngine.name, "hidden");
|
||||||
do_check_true(Services.search.isInitialized);
|
do_check_true(Services.search.isInitialized);
|
||||||
|
|
||||||
@ -63,7 +66,6 @@ add_task(function* sync_init() {
|
|||||||
do_check_neq(engine, null);
|
do_check_neq(engine, null);
|
||||||
|
|
||||||
yield reInitPromise;
|
yield reInitPromise;
|
||||||
yield promiseAfterCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* invalid_engine() {
|
add_task(function* invalid_engine() {
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
removeMetadata();
|
||||||
|
removeCacheFile();
|
||||||
|
|
||||||
|
do_load_manifest("data/chrome.manifest");
|
||||||
|
|
||||||
|
configureToLoadJarEngines();
|
||||||
|
do_check_false(Services.search.isInitialized);
|
||||||
|
|
||||||
|
run_next_test();
|
||||||
|
}
|
||||||
|
|
||||||
|
add_task(function* ignore_cache_files_without_engines() {
|
||||||
|
let commitPromise = promiseAfterCache()
|
||||||
|
yield asyncInit();
|
||||||
|
|
||||||
|
let engineCount = Services.search.getEngines().length;
|
||||||
|
do_check_eq(engineCount, 1);
|
||||||
|
|
||||||
|
// Wait for the file to be saved to disk, so that we can mess with it.
|
||||||
|
yield commitPromise;
|
||||||
|
|
||||||
|
// Remove all engines from the cache file.
|
||||||
|
let cache = yield promiseCacheData();
|
||||||
|
cache.engines = [];
|
||||||
|
yield promiseSaveCacheData(cache);
|
||||||
|
|
||||||
|
// Check that after an async re-initialization, we still have the same engine count.
|
||||||
|
commitPromise = promiseAfterCache()
|
||||||
|
yield asyncReInit();
|
||||||
|
do_check_eq(engineCount, Services.search.getEngines().length);
|
||||||
|
yield commitPromise;
|
||||||
|
|
||||||
|
// Check that after a sync re-initialization, we still have the same engine count.
|
||||||
|
yield promiseSaveCacheData(cache);
|
||||||
|
let unInitPromise = waitForSearchNotification("uninit-complete");
|
||||||
|
let reInitPromise = asyncReInit();
|
||||||
|
yield unInitPromise;
|
||||||
|
do_check_false(Services.search.isInitialized);
|
||||||
|
// Synchronously check the engine count; will force a sync init.
|
||||||
|
do_check_eq(engineCount, Services.search.getEngines().length);
|
||||||
|
do_check_true(Services.search.isInitialized);
|
||||||
|
yield reInitPromise;
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* skip_writing_cache_without_engines() {
|
||||||
|
let unInitPromise = waitForSearchNotification("uninit-complete");
|
||||||
|
let reInitPromise = asyncReInit();
|
||||||
|
yield unInitPromise;
|
||||||
|
|
||||||
|
// Configure so that no engines will be found.
|
||||||
|
do_check_true(removeCacheFile());
|
||||||
|
let resProt = Services.io.getProtocolHandler("resource")
|
||||||
|
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||||
|
resProt.setSubstitution("search-plugins",
|
||||||
|
Services.io.newURI("about:blank", null, null));
|
||||||
|
|
||||||
|
// Let the async-reInit happen.
|
||||||
|
yield reInitPromise;
|
||||||
|
do_check_eq(0, Services.search.getEngines().length);
|
||||||
|
|
||||||
|
// Trigger yet another re-init, to flush of any pending cache writing task.
|
||||||
|
unInitPromise = waitForSearchNotification("uninit-complete");
|
||||||
|
reInitPromise = asyncReInit();
|
||||||
|
yield unInitPromise;
|
||||||
|
|
||||||
|
// Now check that a cache file doesn't exist.
|
||||||
|
do_check_false(removeCacheFile());
|
||||||
|
|
||||||
|
yield reInitPromise;
|
||||||
|
});
|
@ -88,3 +88,4 @@ tags = addons
|
|||||||
[test_geodefaults.js]
|
[test_geodefaults.js]
|
||||||
[test_hidden.js]
|
[test_hidden.js]
|
||||||
[test_currentEngine_fallback.js]
|
[test_currentEngine_fallback.js]
|
||||||
|
[test_require_engines_in_cache.js]
|
||||||
|
Loading…
Reference in New Issue
Block a user