/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

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