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 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | const Ci = Components.interfaces; |
michael@0 | 8 | |
michael@0 | 9 | function do_check_true(cond, text) { |
michael@0 | 10 | // we don't have the test harness' utilities in this scope, so we need this |
michael@0 | 11 | // little helper. In the failure case, the exception is propagated to the |
michael@0 | 12 | // caller in the main run_test() function, and the test fails. |
michael@0 | 13 | if (!cond) |
michael@0 | 14 | throw "Failed check: " + text; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function FileComponent() { |
michael@0 | 18 | this.wrappedJSObject = this; |
michael@0 | 19 | } |
michael@0 | 20 | FileComponent.prototype = |
michael@0 | 21 | { |
michael@0 | 22 | doTest: function() { |
michael@0 | 23 | // throw if anything goes wrong |
michael@0 | 24 | |
michael@0 | 25 | // find the current directory path |
michael@0 | 26 | var file = Components.classes["@mozilla.org/file/directory_service;1"] |
michael@0 | 27 | .getService(Ci.nsIProperties) |
michael@0 | 28 | .get("CurWorkD", Ci.nsIFile); |
michael@0 | 29 | file.append("xpcshell.ini"); |
michael@0 | 30 | |
michael@0 | 31 | // should be able to construct a file |
michael@0 | 32 | var f1 = File(file.path); |
michael@0 | 33 | // with either constructor syntax |
michael@0 | 34 | var f2 = new File(file.path); |
michael@0 | 35 | // and with nsIFiles |
michael@0 | 36 | var f3 = File(file); |
michael@0 | 37 | var f4 = new File(file); |
michael@0 | 38 | |
michael@0 | 39 | // do some tests |
michael@0 | 40 | do_check_true(f1 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
michael@0 | 41 | do_check_true(f2 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
michael@0 | 42 | do_check_true(f3 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
michael@0 | 43 | do_check_true(f4 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
michael@0 | 44 | |
michael@0 | 45 | do_check_true(f1.name == "xpcshell.ini", "Should be the right file"); |
michael@0 | 46 | do_check_true(f2.name == "xpcshell.ini", "Should be the right file"); |
michael@0 | 47 | do_check_true(f3.name == "xpcshell.ini", "Should be the right file"); |
michael@0 | 48 | do_check_true(f4.name == "xpcshell.ini", "Should be the right file"); |
michael@0 | 49 | |
michael@0 | 50 | do_check_true(f1.type == "", "Should be the right type"); |
michael@0 | 51 | do_check_true(f2.type == "", "Should be the right type"); |
michael@0 | 52 | do_check_true(f3.type == "", "Should be the right type"); |
michael@0 | 53 | do_check_true(f4.type == "", "Should be the right type"); |
michael@0 | 54 | |
michael@0 | 55 | var threw = false; |
michael@0 | 56 | try { |
michael@0 | 57 | // Needs a ctor argument |
michael@0 | 58 | var f7 = File(); |
michael@0 | 59 | } catch (e) { |
michael@0 | 60 | threw = true; |
michael@0 | 61 | } |
michael@0 | 62 | do_check_true(threw, "No ctor arguments should throw"); |
michael@0 | 63 | |
michael@0 | 64 | var threw = false; |
michael@0 | 65 | try { |
michael@0 | 66 | // Needs a valid ctor argument |
michael@0 | 67 | var f7 = File(Date(132131532)); |
michael@0 | 68 | } catch (e) { |
michael@0 | 69 | threw = true; |
michael@0 | 70 | } |
michael@0 | 71 | do_check_true(threw, "Passing a random object should fail"); |
michael@0 | 72 | |
michael@0 | 73 | var threw = false |
michael@0 | 74 | try { |
michael@0 | 75 | // Directories fail |
michael@0 | 76 | var dir = Components.classes["@mozilla.org/file/directory_service;1"] |
michael@0 | 77 | .getService(Ci.nsIProperties) |
michael@0 | 78 | .get("CurWorkD", Ci.nsIFile); |
michael@0 | 79 | var f7 = File(dir) |
michael@0 | 80 | } catch (e) { |
michael@0 | 81 | threw = true; |
michael@0 | 82 | } |
michael@0 | 83 | do_check_true(threw, "Can't create a File object for a directory"); |
michael@0 | 84 | |
michael@0 | 85 | return true; |
michael@0 | 86 | }, |
michael@0 | 87 | |
michael@0 | 88 | // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm |
michael@0 | 89 | classDescription: "File in components scope code", |
michael@0 | 90 | classID: Components.ID("{da332370-91d4-464f-a730-018e14769cab}"), |
michael@0 | 91 | contractID: "@mozilla.org/tests/component-file;1", |
michael@0 | 92 | |
michael@0 | 93 | // nsIClassInfo |
michael@0 | 94 | implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, |
michael@0 | 95 | flags: 0, |
michael@0 | 96 | |
michael@0 | 97 | getInterfaces: function getInterfaces(aCount) { |
michael@0 | 98 | var interfaces = [Components.interfaces.nsIClassInfo]; |
michael@0 | 99 | aCount.value = interfaces.length; |
michael@0 | 100 | return interfaces; |
michael@0 | 101 | }, |
michael@0 | 102 | |
michael@0 | 103 | getHelperForLanguage: function getHelperForLanguage(aLanguage) { |
michael@0 | 104 | return null; |
michael@0 | 105 | }, |
michael@0 | 106 | |
michael@0 | 107 | // nsISupports |
michael@0 | 108 | QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo]) |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | var gComponentsArray = [FileComponent]; |
michael@0 | 112 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray); |