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 function run_test() {
6 var scope = {};
7 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", scope);
8 do_check_eq(typeof(scope.XPCOMUtils), "object");
9 do_check_eq(typeof(scope.XPCOMUtils.generateNSGetFactory), "function");
11 // access module's global object directly without importing any
12 // symbols
13 var module = Components.utils.import("resource://gre/modules/XPCOMUtils.jsm",
14 null);
15 do_check_eq(typeof(XPCOMUtils), "undefined");
16 do_check_eq(typeof(module), "object");
17 do_check_eq(typeof(module.XPCOMUtils), "object");
18 do_check_eq(typeof(module.XPCOMUtils.generateNSGetFactory), "function");
19 do_check_true(scope.XPCOMUtils == module.XPCOMUtils);
21 // import symbols to our global object
22 do_check_eq(typeof(Components.utils.import), "function");
23 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
24 do_check_eq(typeof(XPCOMUtils), "object");
25 do_check_eq(typeof(XPCOMUtils.generateNSGetFactory), "function");
27 // try on a new object
28 var scope2 = {};
29 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", scope2);
30 do_check_eq(typeof(scope2.XPCOMUtils), "object");
31 do_check_eq(typeof(scope2.XPCOMUtils.generateNSGetFactory), "function");
33 do_check_true(scope2.XPCOMUtils == scope.XPCOMUtils);
35 // try on a new object using the resolved URL
36 var res = Components.classes["@mozilla.org/network/protocol;1?name=resource"]
37 .getService(Components.interfaces.nsIResProtocolHandler);
38 var resURI = res.newURI("resource://gre/modules/XPCOMUtils.jsm", null, null);
39 dump("resURI: " + resURI + "\n");
40 var filePath = res.resolveURI(resURI);
41 var scope3 = {};
42 Components.utils.import(filePath, scope3);
43 do_check_eq(typeof(scope3.XPCOMUtils), "object");
44 do_check_eq(typeof(scope3.XPCOMUtils.generateNSGetFactory), "function");
46 do_check_true(scope3.XPCOMUtils == scope.XPCOMUtils);
48 // make sure we throw when the second arg is bogus
49 var didThrow = false;
50 try {
51 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", "wrong");
52 } catch (ex) {
53 print("exception (expected): " + ex);
54 didThrow = true;
55 }
56 do_check_true(didThrow);
58 // try to create a component
59 do_load_manifest("component_import.manifest");
60 const contractID = "@mozilla.org/tests/module-importer;";
61 do_check_true((contractID + "1") in Components.classes);
62 var foo = Components.classes[contractID + "1"]
63 .createInstance(Components.interfaces.nsIClassInfo);
64 do_check_true(Boolean(foo));
65 do_check_true(foo.contractID == contractID + "1");
66 // XXX the following check succeeds only if the test component wasn't
67 // already registered. Need to figure out a way to force registration
68 // (to manually force it, delete compreg.dat before running the test)
69 // do_check_true(foo.wrappedJSObject.postRegisterCalled);
71 // Call getInterfaces to test line numbers in JS components. But as long as
72 // we're doing that, why not test what it returns too?
73 // Kind of odd that this is not returning an array containing the
74 // number... Or for that matter not returning an array containing an object?
75 var interfaces = foo.getInterfaces({});
76 do_check_eq(interfaces, Components.interfaces.nsIClassInfo.number);
78 // try to create a component by CID
79 const cid = "{6b933fe6-6eba-4622-ac86-e4f654f1b474}";
80 do_check_true(cid in Components.classesByID);
81 foo = Components.classesByID[cid]
82 .createInstance(Components.interfaces.nsIClassInfo);
83 do_check_true(foo.contractID == contractID + "1");
85 // try to create another component which doesn't directly implement QI
86 do_check_true((contractID + "2") in Components.classes);
87 var bar = Components.classes[contractID + "2"]
88 .createInstance(Components.interfaces.nsIClassInfo);
89 do_check_true(Boolean(bar));
90 do_check_true(bar.contractID == contractID + "2");
91 }