gecko/toolkit/components/search/tests/xpcshell/test_nodb_pluschanges.js
David Rajchenbach-Teller 156803bb8c Bug 699856 - Refactor nsSearchService.js to not use a database engine. r=gavin
--HG--
extra : rebase_source : 80f5830b5d6efcc2e6ec21495709f847d53aac7b
2012-03-13 23:32:53 +01:00

88 lines
2.9 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/*
* test_nodb: Start search engine
* - without search-metadata.json
* - without search.sqlite
*
* Ensure that :
* - nothing explodes;
* - if we change the order, search-metadata.json is created;
* - this search-medata.json can be parsed;
* - the order stored in search-metadata.json is consistent.
*
* Notes:
* - we install the search engines of test "test_downloadAndAddEngines.js"
* to ensure that this test is independent from locale, commercial agreements
* and configuration of Firefox.
*/
do_load_httpd_js();
function run_test()
{
removeMetadata();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2");
do_load_manifest("data/chrome.manifest");
let httpServer = new nsHttpServer();
httpServer.start(4444);
httpServer.registerDirectory("/", do_get_cwd());
let search = Services.search;
function observer(aSubject, aTopic, aData) {
if ("engine-added" == aData) {
let engine1 = search.getEngineByName("Test search engine");
let engine2 = search.getEngineByName("Sherlock test search engine");
dumpn("Got engine 2: "+engine2);
if(engine1 && engine2)
{
search.moveEngine(engine1, 0);
search.moveEngine(engine2, 1);
do_timeout(0,
function() {
// Force flush
// Note: the timeout is needed, to avoid some reentrency
// issues in nsSearchService.
search.QueryInterface(Ci.nsIObserver).
observe(observer, "quit-application", "<no verb>");
});
afterCommit(
function()
{
// Check that search-metadata.json has been created
let metadata = gProfD.clone();
metadata.append("search-metadata.json");
do_check_true(metadata.exists());
// Check that the entries are placed as specified correctly
let stream = NetUtil.newChannel(metadata).open();
let json = parseJsonFromStream(stream);
do_check_eq(json["[app]/test-search-engine.xml"].order, 1);
do_check_eq(json["[profile]/sherlock-test-search-engine.xml"].order, 2);
httpServer.stop(function() {});
stream.close(); // Stream must be closed under Windows
removeMetadata();
do_test_finished();
}
);
}
}
};
Services.obs.addObserver(observer, "browser-search-engine-modified",
false);
do_test_pending();
search.addEngine("http://localhost:4444/data/engine.xml",
Ci.nsISearchEngine.DATA_XML,
null, false);
search.addEngine("http://localhost:4444/data/engine.src",
Ci.nsISearchEngine.DATA_TEXT,
"http://localhost:4444/data/ico-size-16x16-png.ico",
false);
}