michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cr = Components.results; michael@0: michael@0: var gIoService = Components.classes["@mozilla.org/network/io-service;1"] michael@0: .getService(Components.interfaces.nsIIOService); michael@0: michael@0: function isParentProcess() { michael@0: let appInfo = Cc["@mozilla.org/xre/app-info;1"]; michael@0: return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT); michael@0: } michael@0: michael@0: function getPrincipalForURI(aURI) { michael@0: var uri = gIoService.newURI(aURI, null, null); michael@0: return Cc["@mozilla.org/scriptsecuritymanager;1"] michael@0: .getService(Ci.nsIScriptSecurityManager) michael@0: .getNoAppCodebasePrincipal(uri); michael@0: } michael@0: michael@0: function run_test() { michael@0: if (isParentProcess()) { michael@0: var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); michael@0: michael@0: // Permissions created before the child is present michael@0: pm.addFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); michael@0: pm.addFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); michael@0: pm.addFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); michael@0: michael@0: var mM = Cc["@mozilla.org/parentprocessmessagemanager;1"]. michael@0: getService(Ci.nsIMessageBroadcaster); michael@0: michael@0: var messageListener = { michael@0: receiveMessage: function(aMessage) { michael@0: switch(aMessage.name) { michael@0: case "TESTING:Stage2": michael@0: // Permissions created after the child is present michael@0: pm.addFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); michael@0: pm.addFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); michael@0: pm.addFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); michael@0: mM.broadcastAsyncMessage("TESTING:Stage2A"); michael@0: break; michael@0: michael@0: case "TESTING:Stage3": michael@0: do_test_finished(); michael@0: break; michael@0: } michael@0: return true; michael@0: }, michael@0: }; michael@0: michael@0: mM.addMessageListener("TESTING:Stage2", messageListener); michael@0: mM.addMessageListener("TESTING:Stage3", messageListener); michael@0: michael@0: do_test_pending(); michael@0: do_load_child_test_harness(); michael@0: run_test_in_child("test_child.js"); michael@0: } michael@0: } michael@0: