|
1 const Ci = Components.interfaces; |
|
2 const Cc = Components.classes; |
|
3 const Cr = Components.results; |
|
4 |
|
5 var gIoService = Components.classes["@mozilla.org/network/io-service;1"] |
|
6 .getService(Components.interfaces.nsIIOService); |
|
7 |
|
8 function isParentProcess() { |
|
9 let appInfo = Cc["@mozilla.org/xre/app-info;1"]; |
|
10 return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT); |
|
11 } |
|
12 |
|
13 function getPrincipalForURI(aURI) { |
|
14 var uri = gIoService.newURI(aURI, null, null); |
|
15 return Components.classes["@mozilla.org/scriptsecuritymanager;1"] |
|
16 .getService(Ci.nsIScriptSecurityManager) |
|
17 .getNoAppCodebasePrincipal(uri); |
|
18 } |
|
19 |
|
20 function run_test() { |
|
21 if (!isParentProcess()) { |
|
22 const Ci = Components.interfaces; |
|
23 const Cc = Components.classes; |
|
24 |
|
25 var mM = Cc["@mozilla.org/childprocessmessagemanager;1"]. |
|
26 getService(Ci.nsISyncMessageSender); |
|
27 |
|
28 var messageListener = { |
|
29 receiveMessage: function(aMessage) { |
|
30 switch(aMessage.name) { |
|
31 case "TESTING:Stage2A": |
|
32 // Permissions created after the child is present |
|
33 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); |
|
34 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); |
|
35 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); |
|
36 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1"), pm.ALLOW_ACTION); |
|
37 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2"), pm.DENY_ACTION); |
|
38 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3"), pm.ALLOW_ACTION); |
|
39 |
|
40 mM.sendAsyncMessage("TESTING:Stage3"); |
|
41 break; |
|
42 |
|
43 } |
|
44 return true; |
|
45 }, |
|
46 }; |
|
47 |
|
48 mM.addMessageListener("TESTING:Stage2A", messageListener); |
|
49 |
|
50 var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); |
|
51 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); |
|
52 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); |
|
53 do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); |
|
54 |
|
55 mM.sendAsyncMessage("TESTING:Stage2"); |
|
56 } |
|
57 } |
|
58 |