Sat, 03 Jan 2015 20:18:00 +0100
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 let Cu = Components.utils;
5 let Ci = Components.interfaces;
7 Cu.import("resource://gre/modules/osfile.jsm");
8 Cu.import("resource://gre/modules/Task.jsm");
9 Cu.import("resource://testing-common/httpd.js");
11 /*
12 * test_nocache: Start search engine
13 * - without search.json
14 *
15 * Ensure that :
16 * - nothing explodes;
17 * - search.json is created.
18 */
21 function run_test()
22 {
23 removeCache();
24 updateAppInfo();
25 do_load_manifest("data/chrome.manifest");
27 let httpServer = new HttpServer();
28 httpServer.start(-1);
29 httpServer.registerDirectory("/", do_get_cwd());
31 let search = Services.search;
33 do_test_pending();
35 // Check that cache is created at startup
36 afterCache(function cacheCreated() {
37 // Check that search.json has been created.
38 let cache = gProfD.clone();
39 cache.append("search.json");
40 do_check_true(cache.exists());
41 });
43 // Perform initialization
44 search.init(function ss_initialized(rv) {
45 do_check_true(Components.isSuccessCode(rv));
47 do_print("Setting up observer");
48 function observer(aSubject, aTopic, aData) {
49 do_print("Observing topic " + aTopic);
50 if ("engine-added" == aData) {
51 let engine = search.getEngineByName("Test search engine");
52 if (!engine) {
53 return;
54 }
55 Services.obs.removeObserver(observer, "browser-search-engine-modified");
56 do_print("Engine has been added, let's wait for the cache to be built");
57 afterCache(function() {
58 do_print("Success");
60 Task.spawn(function task() {
61 do_print("Searching test engine in cache");
62 try {
63 let path = OS.Path.join(OS.Constants.Path.profileDir, "search.json");
64 let data = yield OS.File.read(path);
65 let text = new TextDecoder().decode(data);
66 let cache = JSON.parse(text);
67 let found = false;
68 for (let dirName in cache.directories) {
69 for (let engine of cache.directories[dirName].engines) {
70 if (engine._id == "[app]/test-search-engine.xml") {
71 found = true;
72 break;
73 }
74 }
75 if (found) {
76 break;
77 }
78 }
79 do_check_true(found);
80 } catch (ex) {
81 do_throw(ex);
82 } finally {
83 removeCache();
84 httpServer.stop(function() {
85 // httpServer doesn't seem to stop cleanly if there is no callback
86 });
87 do_test_finished();
88 }
89 });
90 });
91 }
92 };
93 Services.obs.addObserver(observer, "browser-search-engine-modified", false);
95 // Add an engine, check if it appears in the cache
96 search.addEngine("http://localhost:" + httpServer.identity.primaryPort +
97 "/data/engine.xml",
98 Ci.nsISearchEngine.DATA_XML,
99 null, false);
100 });
101 }