1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_about_protocol.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +let Ci = Components.interfaces; 1.9 +let Cc = Components.classes; 1.10 + 1.11 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.12 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.13 + 1.14 +let unsafeAboutModule = { 1.15 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), 1.16 + newChannel: function (aURI) { 1.17 + let chan = Services.io.newChannel("about:blank", null, null); 1.18 + chan.owner = Services.scriptSecurityManager.getSystemPrincipal(); 1.19 + return chan; 1.20 + }, 1.21 + getURIFlags: function (aURI) { 1.22 + return Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT; 1.23 + } 1.24 +}; 1.25 + 1.26 +let factory = { 1.27 + createInstance: function(aOuter, aIID) { 1.28 + if (aOuter) 1.29 + throw Components.results.NS_ERROR_NO_AGGREGATION; 1.30 + return unsafeAboutModule.QueryInterface(aIID); 1.31 + }, 1.32 + lockFactory: function(aLock) { 1.33 + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; 1.34 + }, 1.35 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]) 1.36 +}; 1.37 + 1.38 +function run_test() { 1.39 + let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 1.40 + let classID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID(); 1.41 + registrar.registerFactory(classID, "", "@mozilla.org/network/protocol/about;1?what=unsafe", factory); 1.42 + 1.43 + let aboutUnsafeURI = Services.io.newURI("about:unsafe", null, null); 1.44 + let aboutUnsafeChan = Services.io.newChannelFromURI(aboutUnsafeURI); 1.45 + do_check_null(aboutUnsafeChan.owner, "URI_SAFE_FOR_UNTRUSTED_CONTENT channel has no owner"); 1.46 + 1.47 + registrar.unregisterFactory(classID, factory); 1.48 +}