1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/extensions/cookie/test/unit_ipc/test_parent.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +const Ci = Components.interfaces; 1.5 +const Cc = Components.classes; 1.6 +const Cr = Components.results; 1.7 + 1.8 +var gIoService = Components.classes["@mozilla.org/network/io-service;1"] 1.9 + .getService(Components.interfaces.nsIIOService); 1.10 + 1.11 +function isParentProcess() { 1.12 + let appInfo = Cc["@mozilla.org/xre/app-info;1"]; 1.13 + return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT); 1.14 +} 1.15 + 1.16 +function getPrincipalForURI(aURI) { 1.17 + var uri = gIoService.newURI(aURI, null, null); 1.18 + return Cc["@mozilla.org/scriptsecuritymanager;1"] 1.19 + .getService(Ci.nsIScriptSecurityManager) 1.20 + .getNoAppCodebasePrincipal(uri); 1.21 +} 1.22 + 1.23 +function run_test() { 1.24 + if (isParentProcess()) { 1.25 + var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); 1.26 + 1.27 + // Permissions created before the child is present 1.28 + pm.addFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); 1.29 + pm.addFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); 1.30 + pm.addFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); 1.31 + 1.32 + var mM = Cc["@mozilla.org/parentprocessmessagemanager;1"]. 1.33 + getService(Ci.nsIMessageBroadcaster); 1.34 + 1.35 + var messageListener = { 1.36 + receiveMessage: function(aMessage) { 1.37 + switch(aMessage.name) { 1.38 + case "TESTING:Stage2": 1.39 + // Permissions created after the child is present 1.40 + pm.addFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); 1.41 + pm.addFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); 1.42 + pm.addFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); 1.43 + mM.broadcastAsyncMessage("TESTING:Stage2A"); 1.44 + break; 1.45 + 1.46 + case "TESTING:Stage3": 1.47 + do_test_finished(); 1.48 + break; 1.49 + } 1.50 + return true; 1.51 + }, 1.52 + }; 1.53 + 1.54 + mM.addMessageListener("TESTING:Stage2", messageListener); 1.55 + mM.addMessageListener("TESTING:Stage3", messageListener); 1.56 + 1.57 + do_test_pending(); 1.58 + do_load_child_test_harness(); 1.59 + run_test_in_child("test_child.js"); 1.60 + } 1.61 +} 1.62 +