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.

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

mercurial