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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const Cc = Components.classes; |
michael@0 | 6 | const Ci = Components.interfaces; |
michael@0 | 7 | const Cu = Components.utils; |
michael@0 | 8 | const Cr = Components.results; |
michael@0 | 9 | |
michael@0 | 10 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 11 | |
michael@0 | 12 | const nsIBLS = Ci.nsIBlocklistService; |
michael@0 | 13 | const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; |
michael@0 | 14 | |
michael@0 | 15 | var gBlocklist = null; |
michael@0 | 16 | var gPrefs = null; |
michael@0 | 17 | var gTestserver = null; |
michael@0 | 18 | |
michael@0 | 19 | var gNextTestPart = null; |
michael@0 | 20 | |
michael@0 | 21 | |
michael@0 | 22 | var PLUGINS = [{ |
michael@0 | 23 | // Tests a plugin whose state goes from not-blocked, to outdated |
michael@0 | 24 | name: "test_bug514327_outdated", |
michael@0 | 25 | version: "5", |
michael@0 | 26 | disabled: false, |
michael@0 | 27 | blocklisted: false |
michael@0 | 28 | }, { |
michael@0 | 29 | // Used to trigger the blocklist dialog, which indicates the blocklist has updated |
michael@0 | 30 | name: "test_bug514327_1", |
michael@0 | 31 | version: "5", |
michael@0 | 32 | disabled: false, |
michael@0 | 33 | blocklisted: false |
michael@0 | 34 | }, { |
michael@0 | 35 | // Used to trigger the blocklist dialog, which indicates the blocklist has updated |
michael@0 | 36 | name: "test_bug514327_2", |
michael@0 | 37 | version: "5", |
michael@0 | 38 | disabled: false, |
michael@0 | 39 | blocklisted: false |
michael@0 | 40 | } ]; |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | // A fake plugin host for the blocklist service to use |
michael@0 | 44 | var PluginHost = { |
michael@0 | 45 | getPluginTags: function(countRef) { |
michael@0 | 46 | countRef.value = PLUGINS.length; |
michael@0 | 47 | return PLUGINS; |
michael@0 | 48 | }, |
michael@0 | 49 | |
michael@0 | 50 | QueryInterface: function(iid) { |
michael@0 | 51 | if (iid.equals(Ci.nsIPluginHost) |
michael@0 | 52 | || iid.equals(Ci.nsISupports)) |
michael@0 | 53 | return this; |
michael@0 | 54 | |
michael@0 | 55 | throw Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | var PluginHostFactory = { |
michael@0 | 60 | createInstance: function (outer, iid) { |
michael@0 | 61 | if (outer != null) |
michael@0 | 62 | throw Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 63 | return PluginHost.QueryInterface(iid); |
michael@0 | 64 | } |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | // Don't need the full interface, attempts to call other methods will just |
michael@0 | 68 | // throw which is just fine |
michael@0 | 69 | var WindowWatcher = { |
michael@0 | 70 | openWindow: function(parent, url, name, features, arguments) { |
michael@0 | 71 | // Should be called to list the newly blocklisted items |
michael@0 | 72 | do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); |
michael@0 | 73 | // Should only include one item |
michael@0 | 74 | do_check_eq(arguments.wrappedJSObject.list.length, 1); |
michael@0 | 75 | // And that item should be the blocked plugin, not the outdated one |
michael@0 | 76 | var item = arguments.wrappedJSObject.list[0]; |
michael@0 | 77 | do_check_true(item.item instanceof Ci.nsIPluginTag); |
michael@0 | 78 | do_check_neq(item.name, "test_bug514327_outdated"); |
michael@0 | 79 | |
michael@0 | 80 | // Call the next test after the blocklist has finished up |
michael@0 | 81 | do_timeout(0, gNextTestPart); |
michael@0 | 82 | }, |
michael@0 | 83 | |
michael@0 | 84 | QueryInterface: function(iid) { |
michael@0 | 85 | if (iid.equals(Ci.nsIWindowWatcher) |
michael@0 | 86 | || iid.equals(Ci.nsISupports)) |
michael@0 | 87 | return this; |
michael@0 | 88 | |
michael@0 | 89 | throw Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | var WindowWatcherFactory = { |
michael@0 | 94 | createInstance: function createInstance(outer, iid) { |
michael@0 | 95 | if (outer != null) |
michael@0 | 96 | throw Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 97 | return WindowWatcher.QueryInterface(iid); |
michael@0 | 98 | } |
michael@0 | 99 | }; |
michael@0 | 100 | |
michael@0 | 101 | var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
michael@0 | 102 | registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), |
michael@0 | 103 | "Fake Plugin Host", |
michael@0 | 104 | "@mozilla.org/plugin/host;1", PluginHostFactory); |
michael@0 | 105 | registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), |
michael@0 | 106 | "Fake Window Watcher", |
michael@0 | 107 | "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); |
michael@0 | 108 | |
michael@0 | 109 | |
michael@0 | 110 | function do_update_blocklist(aDatafile, aNextPart) { |
michael@0 | 111 | gNextTestPart = aNextPart; |
michael@0 | 112 | |
michael@0 | 113 | gPrefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/" + aDatafile); |
michael@0 | 114 | gBlocklist.QueryInterface(Ci.nsITimerCallback).notify(null); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function run_test() { |
michael@0 | 118 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
michael@0 | 119 | |
michael@0 | 120 | gTestserver = new HttpServer(); |
michael@0 | 121 | gTestserver.registerDirectory("/data/", do_get_file("data")); |
michael@0 | 122 | gTestserver.start(-1); |
michael@0 | 123 | gPort = gTestserver.identity.primaryPort; |
michael@0 | 124 | |
michael@0 | 125 | startupManager(); |
michael@0 | 126 | |
michael@0 | 127 | // initialize the blocklist with no entries |
michael@0 | 128 | copyBlocklistToProfile(do_get_file("data/test_bug514327_3_empty.xml")); |
michael@0 | 129 | |
michael@0 | 130 | gPrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); |
michael@0 | 131 | gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS); |
michael@0 | 132 | |
michael@0 | 133 | // should NOT be marked as outdated by the blocklist |
michael@0 | 134 | do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_NOT_BLOCKED); |
michael@0 | 135 | |
michael@0 | 136 | do_test_pending(); |
michael@0 | 137 | |
michael@0 | 138 | // update blocklist with data that marks the plugin as outdated |
michael@0 | 139 | do_update_blocklist("test_bug514327_3_outdated_1.xml", test_part_1); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | function test_part_1() { |
michael@0 | 143 | // plugin should now be marked as outdated |
michael@0 | 144 | do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED); |
michael@0 | 145 | // and the notifyUser pref should be set to true |
michael@0 | 146 | do_check_true(gPrefs.getBoolPref("plugins.update.notifyUser")); |
michael@0 | 147 | |
michael@0 | 148 | // preternd the user has been notified, reset the pref |
michael@0 | 149 | gPrefs.setBoolPref("plugins.update.notifyUser", false); |
michael@0 | 150 | |
michael@0 | 151 | // update blocklist with data that marks the plugin as outdated |
michael@0 | 152 | do_update_blocklist("test_bug514327_3_outdated_2.xml", test_part_2); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | function test_part_2() { |
michael@0 | 156 | // plugin should still be marked as outdated |
michael@0 | 157 | do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED); |
michael@0 | 158 | // and the notifyUser pref should NOT be set to true, as the plugin was already outdated |
michael@0 | 159 | do_check_false(gPrefs.getBoolPref("plugins.update.notifyUser")); |
michael@0 | 160 | |
michael@0 | 161 | finish(); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | function finish() { |
michael@0 | 165 | gTestserver.stop(do_test_finished); |
michael@0 | 166 | } |