/extensions/cookie/test/unit_ipc/test_child.js
http://github.com/zpao/v8monkey · JavaScript · 51 lines · 39 code · 11 blank · 1 comment · 3 complexity · dbfe2441f427a042d74d8e95a2bcfcc9 MD5 · raw file
- const Ci = Components.interfaces;
- const Cc = Components.classes;
- const Cr = Components.results;
- var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- function isParentProcess() {
- let appInfo = Cc["@mozilla.org/xre/app-info;1"];
- return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
- }
- function run_test() {
- if (!isParentProcess()) {
- const Ci = Components.interfaces;
- const Cc = Components.classes;
- var mM = Cc["@mozilla.org/childprocessmessagemanager;1"].
- getService(Ci.nsISyncMessageSender);
- var messageListener = {
- receiveMessage: function(aMessage) {
- switch(aMessage.name) {
- case "TESTING:Stage2A":
- // Permissions created after the child is present
- do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.org", null, null), "cookie1"), pm.ALLOW_ACTION);
- do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.com", null, null), "cookie2"), pm.DENY_ACTION);
- do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.net", null, null), "cookie3"), pm.ALLOW_ACTION);
- do_check_eq(pm.testPermission(gIoService.newURI("http://firefox.org", null, null), "cookie1"), pm.ALLOW_ACTION);
- do_check_eq(pm.testPermission(gIoService.newURI("http://firefox.com", null, null), "cookie2"), pm.DENY_ACTION);
- do_check_eq(pm.testPermission(gIoService.newURI("http://firefox.net", null, null), "cookie3"), pm.ALLOW_ACTION);
- mM.sendAsyncMessage("TESTING:Stage3");
- break;
- }
- return true;
- },
- };
- mM.addMessageListener("TESTING:Stage2A", messageListener);
- var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
- do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.org", null, null), "cookie1"), pm.ALLOW_ACTION);
- do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.com", null, null), "cookie2"), pm.DENY_ACTION);
- do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.net", null, null), "cookie3"), pm.ALLOW_ACTION);
- mM.sendAsyncMessage("TESTING:Stage2");
- }
- }