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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /* |
michael@0 | 5 | * Test that currentEngine and defaultEngine properties can be set and yield the |
michael@0 | 6 | * proper events and behavior (search results) |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | "use strict"; |
michael@0 | 10 | |
michael@0 | 11 | const Ci = Components.interfaces; |
michael@0 | 12 | |
michael@0 | 13 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 14 | |
michael@0 | 15 | let waitForEngines = { |
michael@0 | 16 | "Test search engine": 1, |
michael@0 | 17 | "A second test engine": 1 |
michael@0 | 18 | }; |
michael@0 | 19 | |
michael@0 | 20 | function search_observer(aSubject, aTopic, aData) { |
michael@0 | 21 | let engine = aSubject.QueryInterface(Ci.nsISearchEngine); |
michael@0 | 22 | do_print("Observer: " + aData + " for " + engine.name); |
michael@0 | 23 | |
michael@0 | 24 | if (aData != "engine-added") { |
michael@0 | 25 | return; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | // If the engine is defined in `waitForEngines`, remove it from the list |
michael@0 | 29 | if (waitForEngines[engine.name]) { |
michael@0 | 30 | delete waitForEngines[engine.name]; |
michael@0 | 31 | } else { |
michael@0 | 32 | // This engine is not one we're waiting for, so bail out early. |
michael@0 | 33 | return; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // Only continue when both engines have been loaded. |
michael@0 | 37 | if (Object.keys(waitForEngines).length) |
michael@0 | 38 | return; |
michael@0 | 39 | |
michael@0 | 40 | let search = Services.search; |
michael@0 | 41 | |
michael@0 | 42 | let engine1 = search.getEngineByName("Test search engine"); |
michael@0 | 43 | let engine2 = search.getEngineByName("A second test engine"); |
michael@0 | 44 | |
michael@0 | 45 | search.defaultEngine = engine1; |
michael@0 | 46 | do_check_eq(search.defaultEngine, engine1); |
michael@0 | 47 | search.defaultEngine = engine2 |
michael@0 | 48 | do_check_eq(search.defaultEngine, engine2); |
michael@0 | 49 | search.defaultEngine = engine1; |
michael@0 | 50 | do_check_eq(search.defaultEngine, engine1); |
michael@0 | 51 | |
michael@0 | 52 | // Test that hiding the currently-default engine affects the defaultEngine getter |
michael@0 | 53 | // (when the default is hidden, we fall back to the first in the list, so move |
michael@0 | 54 | // our second engine to that position) |
michael@0 | 55 | search.moveEngine(engine2, 0); |
michael@0 | 56 | engine1.hidden = true; |
michael@0 | 57 | do_check_eq(search.defaultEngine, engine2); |
michael@0 | 58 | |
michael@0 | 59 | // Test that the default engine is restored when it is unhidden |
michael@0 | 60 | engine1.hidden = false; |
michael@0 | 61 | do_check_eq(search.defaultEngine, engine1); |
michael@0 | 62 | |
michael@0 | 63 | // Test that setting defaultEngine to an already-hidden engine works, but |
michael@0 | 64 | // doesn't change the return value of the getter |
michael@0 | 65 | engine2.hidden = true; |
michael@0 | 66 | search.moveEngine(engine1, 0) |
michael@0 | 67 | search.defaultEngine = engine2; |
michael@0 | 68 | do_check_eq(search.defaultEngine, engine1); |
michael@0 | 69 | engine2.hidden = false; |
michael@0 | 70 | do_check_eq(search.defaultEngine, engine2); |
michael@0 | 71 | |
michael@0 | 72 | do_test_finished(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function run_test() { |
michael@0 | 76 | removeMetadata(); |
michael@0 | 77 | updateAppInfo(); |
michael@0 | 78 | |
michael@0 | 79 | let httpServer = new HttpServer(); |
michael@0 | 80 | httpServer.start(-1); |
michael@0 | 81 | httpServer.registerDirectory("/", do_get_cwd()); |
michael@0 | 82 | let baseUrl = "http://localhost:" + httpServer.identity.primaryPort; |
michael@0 | 83 | |
michael@0 | 84 | do_register_cleanup(function cleanup() { |
michael@0 | 85 | httpServer.stop(function() {}); |
michael@0 | 86 | Services.obs.removeObserver(search_observer, "browser-search-engine-modified"); |
michael@0 | 87 | }); |
michael@0 | 88 | |
michael@0 | 89 | do_test_pending(); |
michael@0 | 90 | |
michael@0 | 91 | Services.obs.addObserver(search_observer, "browser-search-engine-modified", false); |
michael@0 | 92 | |
michael@0 | 93 | Services.search.addEngine(baseUrl + "/data/engine.xml", |
michael@0 | 94 | Ci.nsISearchEngine.DATA_XML, |
michael@0 | 95 | null, false); |
michael@0 | 96 | Services.search.addEngine(baseUrl + "/data/engine2.xml", |
michael@0 | 97 | Ci.nsISearchEngine.DATA_XML, |
michael@0 | 98 | null, false); |
michael@0 | 99 | } |