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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/search/tests/xpcshell/test_nodb_pluschanges.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +
     1.8 +/*
     1.9 + * test_nodb: Start search engine
    1.10 + * - without search-metadata.json
    1.11 + * - without search.sqlite
    1.12 + *
    1.13 + * Ensure that :
    1.14 + * - nothing explodes;
    1.15 + * - if we change the order, search-metadata.json is created;
    1.16 + * - this search-medata.json can be parsed;
    1.17 + * - the order stored in search-metadata.json is consistent.
    1.18 + *
    1.19 + * Notes:
    1.20 + * - we install the search engines of test "test_downloadAndAddEngines.js"
    1.21 + * to ensure that this test is independent from locale, commercial agreements
    1.22 + * and configuration of Firefox.
    1.23 + */
    1.24 +
    1.25 +const Cc = Components.classes;
    1.26 +const Ci = Components.interfaces;
    1.27 +const Cu = Components.utils;
    1.28 +const Cr = Components.results;
    1.29 +
    1.30 +Cu.import("resource://testing-common/httpd.js");
    1.31 +
    1.32 +
    1.33 +function run_test()
    1.34 +{
    1.35 +  do_print("Preparing test");
    1.36 +  removeMetadata();
    1.37 +  updateAppInfo();
    1.38 +  do_load_manifest("data/chrome.manifest");
    1.39 +
    1.40 +  let httpServer = new HttpServer();
    1.41 +  httpServer.start(-1);
    1.42 +  httpServer.registerDirectory("/", do_get_cwd());
    1.43 +  let baseUrl = "http://localhost:" + httpServer.identity.primaryPort;
    1.44 +
    1.45 +  let search = Services.search;
    1.46 +
    1.47 +  do_print("Setting up observer");
    1.48 +  function observer(aSubject, aTopic, aData) {
    1.49 +    do_print("Observing topic " + aTopic);
    1.50 +    if ("engine-added" == aData) {
    1.51 +      let engine1 = search.getEngineByName("Test search engine");
    1.52 +      let engine2 = search.getEngineByName("Sherlock test search engine");
    1.53 +      do_print("Currently, engine1 is " + engine1);
    1.54 +      do_print("Currently, engine2 is " + engine2);
    1.55 +      if(engine1 && engine2)
    1.56 +      {
    1.57 +        search.moveEngine(engine1, 0);
    1.58 +        search.moveEngine(engine2, 1);
    1.59 +        do_print("Next step is forcing flush");
    1.60 +        do_timeout(0,
    1.61 +                   function() {
    1.62 +                     do_print("Forcing flush");
    1.63 +                     // Force flush
    1.64 +                     // Note: the timeout is needed, to avoid some reentrency
    1.65 +                     // issues in nsSearchService.
    1.66 +                     search.QueryInterface(Ci.nsIObserver).
    1.67 +                       observe(observer, "quit-application", "<no verb>");
    1.68 +                   });
    1.69 +        afterCommit(
    1.70 +          function()
    1.71 +          {
    1.72 +            do_print("Commit complete");
    1.73 +            // Check that search-metadata.json has been created
    1.74 +            let metadata = gProfD.clone();
    1.75 +            metadata.append("search-metadata.json");
    1.76 +            do_check_true(metadata.exists());
    1.77 +
    1.78 +            // Check that the entries are placed as specified correctly
    1.79 +            let stream = NetUtil.newChannel(metadata).open();
    1.80 +            do_print("Parsing metadata");
    1.81 +            let json = parseJsonFromStream(stream);
    1.82 +            do_check_eq(json["[app]/test-search-engine.xml"].order, 1);
    1.83 +            do_check_eq(json["[profile]/sherlock-test-search-engine.xml"].order, 2);
    1.84 +
    1.85 +            do_print("Cleaning up");
    1.86 +            httpServer.stop(function() {});
    1.87 +            stream.close(); // Stream must be closed under Windows
    1.88 +            removeMetadata();
    1.89 +            do_test_finished();
    1.90 +          }
    1.91 +        );
    1.92 +      }
    1.93 +    }
    1.94 +  };
    1.95 +  Services.obs.addObserver(observer, "browser-search-engine-modified",
    1.96 +                           false);
    1.97 +
    1.98 +  do_test_pending();
    1.99 +
   1.100 +  search.addEngine(baseUrl + "/data/engine.xml",
   1.101 +                   Ci.nsISearchEngine.DATA_XML,
   1.102 +                   null, false);
   1.103 +  search.addEngine(baseUrl + "/data/engine.src",
   1.104 +                   Ci.nsISearchEngine.DATA_TEXT,
   1.105 +                   baseUrl + "/data/ico-size-16x16-png.ico",
   1.106 +                   false);
   1.107 +
   1.108 +  do_timeout(120000, function() {
   1.109 +    do_throw("Timeout");
   1.110 +  });
   1.111 +}

mercurial