PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1const Ci = Components.interfaces;
 2const Cc = Components.classes;
 3const Cr = Components.results;
 4
 5var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
 6                           .getService(Components.interfaces.nsIIOService);
 7
 8function 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
13function run_test() {
14  if (!isParentProcess()) {
15    const Ci = Components.interfaces;
16    const Cc = Components.classes;
17
18    var mM = Cc["@mozilla.org/childprocessmessagemanager;1"].
19                         getService(Ci.nsISyncMessageSender);
20
21    var messageListener = {
22      receiveMessage: function(aMessage) {
23        switch(aMessage.name) {
24          case "TESTING:Stage2A":
25            // Permissions created after the child is present
26            do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.org", null, null), "cookie1"), pm.ALLOW_ACTION);
27            do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.com", null, null), "cookie2"), pm.DENY_ACTION);
28            do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.net", null, null), "cookie3"), pm.ALLOW_ACTION);
29            do_check_eq(pm.testPermission(gIoService.newURI("http://firefox.org", null, null), "cookie1"), pm.ALLOW_ACTION);
30            do_check_eq(pm.testPermission(gIoService.newURI("http://firefox.com", null, null), "cookie2"), pm.DENY_ACTION);
31            do_check_eq(pm.testPermission(gIoService.newURI("http://firefox.net", null, null), "cookie3"), pm.ALLOW_ACTION);
32
33            mM.sendAsyncMessage("TESTING:Stage3");
34            break;
35
36        }
37        return true;
38      },
39    };
40
41    mM.addMessageListener("TESTING:Stage2A", messageListener);
42
43    var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
44    do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.org", null, null), "cookie1"), pm.ALLOW_ACTION);
45    do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.com", null, null), "cookie2"), pm.DENY_ACTION);
46    do_check_eq(pm.testPermission(gIoService.newURI("http://mozilla.net", null, null), "cookie3"), pm.ALLOW_ACTION);
47
48    mM.sendAsyncMessage("TESTING:Stage2");
49  }
50}
51