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
1 const Ci = Components.interfaces;
2 const Cc = Components.classes;
3 const Cr = Components.results;
5 var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
6 .getService(Components.interfaces.nsIIOService);
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 }
13 function getPrincipalForURI(aURI) {
14 var uri = gIoService.newURI(aURI, null, null);
15 return Cc["@mozilla.org/scriptsecuritymanager;1"]
16 .getService(Ci.nsIScriptSecurityManager)
17 .getNoAppCodebasePrincipal(uri);
18 }
20 function run_test() {
21 if (isParentProcess()) {
22 var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
24 // Permissions created before the child is present
25 pm.addFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0);
26 pm.addFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0);
27 pm.addFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24);
29 var mM = Cc["@mozilla.org/parentprocessmessagemanager;1"].
30 getService(Ci.nsIMessageBroadcaster);
32 var messageListener = {
33 receiveMessage: function(aMessage) {
34 switch(aMessage.name) {
35 case "TESTING:Stage2":
36 // Permissions created after the child is present
37 pm.addFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0);
38 pm.addFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0);
39 pm.addFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24);
40 mM.broadcastAsyncMessage("TESTING:Stage2A");
41 break;
43 case "TESTING:Stage3":
44 do_test_finished();
45 break;
46 }
47 return true;
48 },
49 };
51 mM.addMessageListener("TESTING:Stage2", messageListener);
52 mM.addMessageListener("TESTING:Stage3", messageListener);
54 do_test_pending();
55 do_load_child_test_harness();
56 run_test_in_child("test_child.js");
57 }
58 }