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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /*
     5  * test_serialize_file: Add test engines
     6  *
     7  * Ensure that :
     8  * - File is created.
     9  * - File size is bigger than 0.
    10  * - lazySerializeTask updates the file.
    11  */
    13 const Ci = Components.interfaces;
    14 const Cu = Components.utils;
    16 Cu.import("resource://testing-common/httpd.js");
    17 Cu.import("resource://gre/modules/NetUtil.jsm");
    19 add_test(function test_batchTask() {
    20   let observer = function(aSubject, aTopic, aData) {
    21     if (aTopic == "browser-search-engine-modified" && aData == "engine-loaded") {
    22       let engine1 = Services.search.getEngineByName("Test search engine");
    23       let engine2 = Services.search.getEngineByName("Sherlock test search engine");
    24       if (engine1 && engine2) {
    25         Services.obs.removeObserver(observer, aTopic);
    26         // Test that files are written correctly.
    27         let engineFile1 = engine1.wrappedJSObject._file;
    28         let engineFile2 = engine2.wrappedJSObject._file;
    29         do_check_true(engineFile1.exists());
    30         do_check_true(engineFile2.exists());
    31         do_check_neq(engineFile1.fileSize, 0);
    32         do_check_neq(engineFile2.fileSize, 0);
    33         run_next_test();
    34       }
    35     }
    36   }
    38   Services.obs.addObserver(observer, "browser-search-engine-modified", false);
    39   Services.search.addEngine("http://localhost:4444/data/engine.xml",
    40                             Ci.nsISearchEngine.DATA_XML, null, false);
    41   Services.search.addEngine("http://localhost:4444/data/engine.src",
    42                             Ci.nsISearchEngine.DATA_TEXT,
    43                             "http://localhost:4444/data/ico-size-16x16-png.ico",
    44                             false);
    45 });
    47 add_test(function test_addParam() {
    48   let engine = Services.search.getEngineByName("Test search engine");
    49   engine.addParam("param-name", "param-value", null);
    51   function readAsyncFile(aFile, aCallback) {
    52     NetUtil.asyncFetch(aFile, function(inputStream, status) {
    53       do_check_true(Components.isSuccessCode(status));
    55       let data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
    56       aCallback(data);
    57     });
    58   }
    60   let observer = function(aSubject, aTopic, aData) {
    61     // The sherlock engine file may still be updated because the icon takes
    62     // time be loaded, therefore, the engine name is checked here.
    63     aSubject.QueryInterface(Ci.nsIFile);
    64     if (aTopic == "browser-search-service" &&
    65         aData == "write-engine-to-disk-complete" &&
    66         aSubject.leafName == "test-search-engine.xml") {
    67       Services.obs.removeObserver(observer, aTopic);
    69       let engineFile = engine.wrappedJSObject._file;
    71       readAsyncFile(engineFile, function(engineData) {
    72         do_check_true(engineData.indexOf("param-name") > 0);
    73         run_next_test();
    74       });
    75     }
    76   }
    77   Services.obs.addObserver(observer, "browser-search-service", false);
    78 });
    80 function run_test() {
    81   updateAppInfo();
    83   let httpServer = new HttpServer();
    84   httpServer.start(4444);
    85   httpServer.registerDirectory("/", do_get_cwd());
    87   do_register_cleanup(function cleanup() {
    88     httpServer.stop(function() {});
    89   });
    91   run_next_test();
    92 }

mercurial