js/xpconnect/tests/unit/test_import.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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

mercurial