toolkit/components/search/tests/xpcshell/test_notifications.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 "use strict";
     6 const Ci = Components.interfaces;
     8 Components.utils.import("resource://testing-common/httpd.js");
    10 let gTestLog = [];
    12 /**
    13  * The order of notifications expected for this test is:
    14  *  - engine-changed (while we're installing the engine, we modify it, which notifies - bug 606886)
    15  *  - engine-added (engine was added to the store by the search service)
    16  *   -> our search observer is called, which sets:
    17  *    - .defaultEngine, triggering engine-default
    18  *    - .currentEngine, triggering engine-current (after bug 493051 - for now the search service sets this after engine-added)
    19  *   ...and then schedules a removal
    20  *  - engine-loaded (the search service's observer is garanteed to fire first, which is what causes engine-added to fire)
    21  *  - engine-removed (due to the removal schedule above)
    22  */
    23 let expectedLog = [
    24   "engine-changed", // XXX bug 606886
    25   "engine-added",
    26   "engine-default",
    27   "engine-current",
    28   "engine-loaded",
    29   "engine-removed"
    30 ];
    32 function search_observer(subject, topic, data) {
    33   let engine = subject.QueryInterface(Ci.nsISearchEngine);
    34   gTestLog.push(data + " for " + engine.name);
    36   do_print("Observer: " + data + " for " + engine.name);
    38   switch (data) {
    39     case "engine-added":
    40       let retrievedEngine = Services.search.getEngineByName("Test search engine");
    41       do_check_eq(engine, retrievedEngine);
    42       Services.search.defaultEngine = engine;
    43       Services.search.currentEngine = engine;
    44       do_execute_soon(function () {
    45         Services.search.removeEngine(engine);
    46       });
    47       break;
    48     case "engine-removed":
    49       let engineNameOutput = " for Test search engine";
    50       expectedLog = expectedLog.map(logLine => logLine + engineNameOutput);
    51       do_print("expectedLog:\n" + expectedLog.join("\n"))
    52       do_print("gTestLog:\n" + gTestLog.join("\n"))
    53       for (let i = 0; i < expectedLog.length; i++) {
    54         do_check_eq(gTestLog[i], expectedLog[i]);
    55       }
    56       do_check_eq(gTestLog.length, expectedLog.length);
    57       do_test_finished();
    58       break;
    59   }
    60 }
    62 function run_test() {
    63   removeMetadata();
    64   updateAppInfo();
    66   let httpServer = new HttpServer();
    67   httpServer.start(-1);
    68   httpServer.registerDirectory("/", do_get_cwd());
    70   do_register_cleanup(function cleanup() {
    71     httpServer.stop(function() {});
    72     Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
    73   });
    75   do_test_pending();
    77   Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
    79   Services.search.addEngine("http://localhost:" +
    80                             httpServer.identity.primaryPort +
    81                             "/data/engine.xml",
    82                             Ci.nsISearchEngine.DATA_XML,
    83                             null, false);
    84 }

mercurial