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 Components.classes["@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 | const Ci = Components.interfaces; |
michael@0 | 23 | const Cc = Components.classes; |
michael@0 | 24 | |
michael@0 | 25 | var mM = Cc["@mozilla.org/childprocessmessagemanager;1"]. |
michael@0 | 26 | getService(Ci.nsISyncMessageSender); |
michael@0 | 27 | |
michael@0 | 28 | var messageListener = { |
michael@0 | 29 | receiveMessage: function(aMessage) { |
michael@0 | 30 | switch(aMessage.name) { |
michael@0 | 31 | case "TESTING:Stage2A": |
michael@0 | 32 | // Permissions created after the child is present |
michael@0 | 33 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); |
michael@0 | 34 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); |
michael@0 | 35 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); |
michael@0 | 36 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1"), pm.ALLOW_ACTION); |
michael@0 | 37 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2"), pm.DENY_ACTION); |
michael@0 | 38 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3"), pm.ALLOW_ACTION); |
michael@0 | 39 | |
michael@0 | 40 | mM.sendAsyncMessage("TESTING:Stage3"); |
michael@0 | 41 | break; |
michael@0 | 42 | |
michael@0 | 43 | } |
michael@0 | 44 | return true; |
michael@0 | 45 | }, |
michael@0 | 46 | }; |
michael@0 | 47 | |
michael@0 | 48 | mM.addMessageListener("TESTING:Stage2A", messageListener); |
michael@0 | 49 | |
michael@0 | 50 | var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); |
michael@0 | 51 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); |
michael@0 | 52 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); |
michael@0 | 53 | do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); |
michael@0 | 54 | |
michael@0 | 55 | mM.sendAsyncMessage("TESTING:Stage2"); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 |