test_about_protocol.js (1356B)
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/. */ 4 5 "use strict"; 6 7 var unsafeAboutModule = { 8 QueryInterface: ChromeUtils.generateQI(["nsIAboutModule"]), 9 newChannel(aURI, aLoadInfo) { 10 var uri = Services.io.newURI("about:blank"); 11 let chan = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo); 12 chan.owner = Services.scriptSecurityManager.getSystemPrincipal(); 13 return chan; 14 }, 15 getURIFlags() { 16 return Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT; 17 }, 18 }; 19 20 var factory = { 21 createInstance(aIID) { 22 return unsafeAboutModule.QueryInterface(aIID); 23 }, 24 QueryInterface: ChromeUtils.generateQI(["nsIFactory"]), 25 }; 26 27 function run_test() { 28 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 29 let classID = Services.uuid.generateUUID(); 30 registrar.registerFactory( 31 classID, 32 "", 33 "@mozilla.org/network/protocol/about;1?what=unsafe", 34 factory 35 ); 36 37 let aboutUnsafeChan = NetUtil.newChannel({ 38 uri: "about:unsafe", 39 loadUsingSystemPrincipal: true, 40 }); 41 42 Assert.equal( 43 null, 44 aboutUnsafeChan.owner, 45 "URI_SAFE_FOR_UNTRUSTED_CONTENT channel has no owner" 46 ); 47 48 registrar.unregisterFactory(classID, factory); 49 }