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 | const Cc = Components.classes; |
michael@0 | 5 | const Ci = Components.interfaces; |
michael@0 | 6 | const Cu = Components.utils; |
michael@0 | 7 | const Cr = Components.results; |
michael@0 | 8 | const CC = Components.Constructor; |
michael@0 | 9 | |
michael@0 | 10 | Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 14 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 15 | Cu.import("resource://gre/modules/FileUtils.jsm"); |
michael@0 | 16 | |
michael@0 | 17 | let gClient, gActor; |
michael@0 | 18 | |
michael@0 | 19 | function connect(onDone) { |
michael@0 | 20 | // Initialize a loopback remote protocol connection |
michael@0 | 21 | DebuggerServer.init(function () { return true; }); |
michael@0 | 22 | // We need to register browser actors to have `listTabs` working |
michael@0 | 23 | // and also have a root actor |
michael@0 | 24 | DebuggerServer.addBrowserActors(); |
michael@0 | 25 | |
michael@0 | 26 | // Setup client and actor used in all tests |
michael@0 | 27 | gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
michael@0 | 28 | gClient.connect(function onConnect() { |
michael@0 | 29 | gClient.listTabs(function onListTabs(aResponse) { |
michael@0 | 30 | gActor = aResponse.webappsActor; |
michael@0 | 31 | onDone(); |
michael@0 | 32 | }); |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function webappActorRequest(request, onResponse) { |
michael@0 | 37 | if (!gActor) { |
michael@0 | 38 | connect(webappActorRequest.bind(null, request, onResponse)); |
michael@0 | 39 | return; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | request.to = gActor; |
michael@0 | 43 | gClient.request(request, onResponse); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | // Install a test packaged webapp from data folder |
michael@0 | 47 | function installTestApp(zipName, appId, onDone) { |
michael@0 | 48 | // Copy our package to tmp folder, where the actor retrieves it |
michael@0 | 49 | let zip = do_get_file("data/" + zipName); |
michael@0 | 50 | let appDir = FileUtils.getDir("TmpD", ["b2g", appId], true, true); |
michael@0 | 51 | zip.copyTo(appDir, "application.zip"); |
michael@0 | 52 | |
michael@0 | 53 | let request = {type: "install", appId: appId}; |
michael@0 | 54 | webappActorRequest(request, function (aResponse) { |
michael@0 | 55 | do_check_eq(aResponse.appId, appId); |
michael@0 | 56 | if ("error" in aResponse) { |
michael@0 | 57 | do_throw("Error: " + aResponse.error); |
michael@0 | 58 | } |
michael@0 | 59 | if ("message" in aResponse) { |
michael@0 | 60 | do_throw("Error message: " + aResponse.message); |
michael@0 | 61 | } |
michael@0 | 62 | do_check_false("error" in aResponse); |
michael@0 | 63 | |
michael@0 | 64 | onDone(); |
michael@0 | 65 | }); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | function setup() { |
michael@0 | 69 | // We have to setup a profile, otherwise indexed db used by webapps |
michael@0 | 70 | // will throw random exception when trying to get profile folder |
michael@0 | 71 | do_get_profile(); |
michael@0 | 72 | |
michael@0 | 73 | // The webapps dir isn't registered on b2g xpcshell tests, |
michael@0 | 74 | // we have to manually set it to the directory service. |
michael@0 | 75 | do_get_webappsdir(); |
michael@0 | 76 | |
michael@0 | 77 | // We also need a valid nsIXulAppInfo service as Webapps.jsm is querying it |
michael@0 | 78 | Components.utils.import("resource://testing-common/AppInfo.jsm"); |
michael@0 | 79 | updateAppInfo(); |
michael@0 | 80 | |
michael@0 | 81 | // We have to toggle this flag in order to have apps being listed in getAll |
michael@0 | 82 | // as only launchable apps are returned |
michael@0 | 83 | Components.utils.import('resource://gre/modules/Webapps.jsm'); |
michael@0 | 84 | DOMApplicationRegistry.allAppsLaunchable = true; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function do_get_webappsdir() { |
michael@0 | 88 | var webappsDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile); |
michael@0 | 89 | webappsDir.append("test_webapps"); |
michael@0 | 90 | if (!webappsDir.exists()) |
michael@0 | 91 | webappsDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8)); |
michael@0 | 92 | |
michael@0 | 93 | var coreAppsDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile); |
michael@0 | 94 | coreAppsDir.append("test_coreapps"); |
michael@0 | 95 | if (!coreAppsDir.exists()) |
michael@0 | 96 | coreAppsDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8)); |
michael@0 | 97 | |
michael@0 | 98 | // Register our own provider for the profile directory. |
michael@0 | 99 | // It will return our special docshell profile directory. |
michael@0 | 100 | var provider = { |
michael@0 | 101 | getFile: function(prop, persistent) { |
michael@0 | 102 | persistent.value = true; |
michael@0 | 103 | if (prop == "webappsDir") { |
michael@0 | 104 | return webappsDir.clone(); |
michael@0 | 105 | } |
michael@0 | 106 | else if (prop == "coreAppsDir") { |
michael@0 | 107 | return coreAppsDir.clone(); |
michael@0 | 108 | } |
michael@0 | 109 | throw Cr.NS_ERROR_FAILURE; |
michael@0 | 110 | }, |
michael@0 | 111 | QueryInterface: function(iid) { |
michael@0 | 112 | if (iid.equals(Ci.nsIDirectoryServiceProvider) || |
michael@0 | 113 | iid.equals(Ci.nsISupports)) { |
michael@0 | 114 | return this; |
michael@0 | 115 | } |
michael@0 | 116 | throw Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 117 | } |
michael@0 | 118 | }; |
michael@0 | 119 | Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 |