Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | const Ci = Components.interfaces; |
michael@0 | 2 | const Cc = Components.classes; |
michael@0 | 3 | const Cr = Components.results; |
michael@0 | 4 | |
michael@0 | 5 | var gIoService = Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 6 | .getService(Components.interfaces.nsIIOService); |
michael@0 | 7 | |
michael@0 | 8 | function isParentProcess() { |
michael@0 | 9 | let appInfo = Cc["@mozilla.org/xre/app-info;1"]; |
michael@0 | 10 | return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | function getPrincipalForURI(aURI) { |
michael@0 | 14 | var uri = gIoService.newURI(aURI, null, null); |
michael@0 | 15 | return Cc["@mozilla.org/scriptsecuritymanager;1"] |
michael@0 | 16 | .getService(Ci.nsIScriptSecurityManager) |
michael@0 | 17 | .getNoAppCodebasePrincipal(uri); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function run_test() { |
michael@0 | 21 | if (isParentProcess()) { |
michael@0 | 22 | var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); |
michael@0 | 23 | |
michael@0 | 24 | // Permissions created before the child is present |
michael@0 | 25 | pm.addFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); |
michael@0 | 26 | pm.addFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); |
michael@0 | 27 | pm.addFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); |
michael@0 | 28 | |
michael@0 | 29 | var mM = Cc["@mozilla.org/parentprocessmessagemanager;1"]. |
michael@0 | 30 | getService(Ci.nsIMessageBroadcaster); |
michael@0 | 31 | |
michael@0 | 32 | var messageListener = { |
michael@0 | 33 | receiveMessage: function(aMessage) { |
michael@0 | 34 | switch(aMessage.name) { |
michael@0 | 35 | case "TESTING:Stage2": |
michael@0 | 36 | // Permissions created after the child is present |
michael@0 | 37 | pm.addFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); |
michael@0 | 38 | pm.addFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); |
michael@0 | 39 | pm.addFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); |
michael@0 | 40 | mM.broadcastAsyncMessage("TESTING:Stage2A"); |
michael@0 | 41 | break; |
michael@0 | 42 | |
michael@0 | 43 | case "TESTING:Stage3": |
michael@0 | 44 | do_test_finished(); |
michael@0 | 45 | break; |
michael@0 | 46 | } |
michael@0 | 47 | return true; |
michael@0 | 48 | }, |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | mM.addMessageListener("TESTING:Stage2", messageListener); |
michael@0 | 52 | mM.addMessageListener("TESTING:Stage3", messageListener); |
michael@0 | 53 | |
michael@0 | 54 | do_test_pending(); |
michael@0 | 55 | do_load_child_test_harness(); |
michael@0 | 56 | run_test_in_child("test_child.js"); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 |