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