netwerk/test/unit/test_about_protocol.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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 let Ci = Components.interfaces;
michael@0 6 let Cc = Components.classes;
michael@0 7
michael@0 8 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 9 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 10
michael@0 11 let unsafeAboutModule = {
michael@0 12 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
michael@0 13 newChannel: function (aURI) {
michael@0 14 let chan = Services.io.newChannel("about:blank", null, null);
michael@0 15 chan.owner = Services.scriptSecurityManager.getSystemPrincipal();
michael@0 16 return chan;
michael@0 17 },
michael@0 18 getURIFlags: function (aURI) {
michael@0 19 return Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT;
michael@0 20 }
michael@0 21 };
michael@0 22
michael@0 23 let factory = {
michael@0 24 createInstance: function(aOuter, aIID) {
michael@0 25 if (aOuter)
michael@0 26 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 27 return unsafeAboutModule.QueryInterface(aIID);
michael@0 28 },
michael@0 29 lockFactory: function(aLock) {
michael@0 30 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
michael@0 31 },
michael@0 32 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
michael@0 33 };
michael@0 34
michael@0 35 function run_test() {
michael@0 36 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
michael@0 37 let classID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
michael@0 38 registrar.registerFactory(classID, "", "@mozilla.org/network/protocol/about;1?what=unsafe", factory);
michael@0 39
michael@0 40 let aboutUnsafeURI = Services.io.newURI("about:unsafe", null, null);
michael@0 41 let aboutUnsafeChan = Services.io.newChannelFromURI(aboutUnsafeURI);
michael@0 42 do_check_null(aboutUnsafeChan.owner, "URI_SAFE_FOR_UNTRUSTED_CONTENT channel has no owner");
michael@0 43
michael@0 44 registrar.unregisterFactory(classID, factory);
michael@0 45 }

mercurial