toolkit/components/search/tests/xpcshell/test_nodb_pluschanges.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4
michael@0 5 /*
michael@0 6 * test_nodb: Start search engine
michael@0 7 * - without search-metadata.json
michael@0 8 * - without search.sqlite
michael@0 9 *
michael@0 10 * Ensure that :
michael@0 11 * - nothing explodes;
michael@0 12 * - if we change the order, search-metadata.json is created;
michael@0 13 * - this search-medata.json can be parsed;
michael@0 14 * - the order stored in search-metadata.json is consistent.
michael@0 15 *
michael@0 16 * Notes:
michael@0 17 * - we install the search engines of test "test_downloadAndAddEngines.js"
michael@0 18 * to ensure that this test is independent from locale, commercial agreements
michael@0 19 * and configuration of Firefox.
michael@0 20 */
michael@0 21
michael@0 22 const Cc = Components.classes;
michael@0 23 const Ci = Components.interfaces;
michael@0 24 const Cu = Components.utils;
michael@0 25 const Cr = Components.results;
michael@0 26
michael@0 27 Cu.import("resource://testing-common/httpd.js");
michael@0 28
michael@0 29
michael@0 30 function run_test()
michael@0 31 {
michael@0 32 do_print("Preparing test");
michael@0 33 removeMetadata();
michael@0 34 updateAppInfo();
michael@0 35 do_load_manifest("data/chrome.manifest");
michael@0 36
michael@0 37 let httpServer = new HttpServer();
michael@0 38 httpServer.start(-1);
michael@0 39 httpServer.registerDirectory("/", do_get_cwd());
michael@0 40 let baseUrl = "http://localhost:" + httpServer.identity.primaryPort;
michael@0 41
michael@0 42 let search = Services.search;
michael@0 43
michael@0 44 do_print("Setting up observer");
michael@0 45 function observer(aSubject, aTopic, aData) {
michael@0 46 do_print("Observing topic " + aTopic);
michael@0 47 if ("engine-added" == aData) {
michael@0 48 let engine1 = search.getEngineByName("Test search engine");
michael@0 49 let engine2 = search.getEngineByName("Sherlock test search engine");
michael@0 50 do_print("Currently, engine1 is " + engine1);
michael@0 51 do_print("Currently, engine2 is " + engine2);
michael@0 52 if(engine1 && engine2)
michael@0 53 {
michael@0 54 search.moveEngine(engine1, 0);
michael@0 55 search.moveEngine(engine2, 1);
michael@0 56 do_print("Next step is forcing flush");
michael@0 57 do_timeout(0,
michael@0 58 function() {
michael@0 59 do_print("Forcing flush");
michael@0 60 // Force flush
michael@0 61 // Note: the timeout is needed, to avoid some reentrency
michael@0 62 // issues in nsSearchService.
michael@0 63 search.QueryInterface(Ci.nsIObserver).
michael@0 64 observe(observer, "quit-application", "<no verb>");
michael@0 65 });
michael@0 66 afterCommit(
michael@0 67 function()
michael@0 68 {
michael@0 69 do_print("Commit complete");
michael@0 70 // Check that search-metadata.json has been created
michael@0 71 let metadata = gProfD.clone();
michael@0 72 metadata.append("search-metadata.json");
michael@0 73 do_check_true(metadata.exists());
michael@0 74
michael@0 75 // Check that the entries are placed as specified correctly
michael@0 76 let stream = NetUtil.newChannel(metadata).open();
michael@0 77 do_print("Parsing metadata");
michael@0 78 let json = parseJsonFromStream(stream);
michael@0 79 do_check_eq(json["[app]/test-search-engine.xml"].order, 1);
michael@0 80 do_check_eq(json["[profile]/sherlock-test-search-engine.xml"].order, 2);
michael@0 81
michael@0 82 do_print("Cleaning up");
michael@0 83 httpServer.stop(function() {});
michael@0 84 stream.close(); // Stream must be closed under Windows
michael@0 85 removeMetadata();
michael@0 86 do_test_finished();
michael@0 87 }
michael@0 88 );
michael@0 89 }
michael@0 90 }
michael@0 91 };
michael@0 92 Services.obs.addObserver(observer, "browser-search-engine-modified",
michael@0 93 false);
michael@0 94
michael@0 95 do_test_pending();
michael@0 96
michael@0 97 search.addEngine(baseUrl + "/data/engine.xml",
michael@0 98 Ci.nsISearchEngine.DATA_XML,
michael@0 99 null, false);
michael@0 100 search.addEngine(baseUrl + "/data/engine.src",
michael@0 101 Ci.nsISearchEngine.DATA_TEXT,
michael@0 102 baseUrl + "/data/ico-size-16x16-png.ico",
michael@0 103 false);
michael@0 104
michael@0 105 do_timeout(120000, function() {
michael@0 106 do_throw("Timeout");
michael@0 107 });
michael@0 108 }

mercurial