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 Components.classes["@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: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: michael@0: var mM = Cc["@mozilla.org/childprocessmessagemanager;1"]. michael@0: getService(Ci.nsISyncMessageSender); michael@0: michael@0: var messageListener = { michael@0: receiveMessage: function(aMessage) { michael@0: switch(aMessage.name) { michael@0: case "TESTING:Stage2A": michael@0: // Permissions created after the child is present michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1"), pm.ALLOW_ACTION); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2"), pm.DENY_ACTION); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3"), pm.ALLOW_ACTION); michael@0: michael@0: mM.sendAsyncMessage("TESTING:Stage3"); michael@0: break; michael@0: michael@0: } michael@0: return true; michael@0: }, michael@0: }; michael@0: michael@0: mM.addMessageListener("TESTING:Stage2A", messageListener); michael@0: michael@0: var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); michael@0: do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); michael@0: michael@0: mM.sendAsyncMessage("TESTING:Stage2"); michael@0: } michael@0: } michael@0: