From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- extensions/cookie/test/unit_ipc/test_child.js | 59 ++++++++++++++++++++++++++ extensions/cookie/test/unit_ipc/test_parent.js | 59 ++++++++++++++++++++++++++ extensions/cookie/test/unit_ipc/xpcshell.ini | 7 +++ 3 files changed, 125 insertions(+) create mode 100644 extensions/cookie/test/unit_ipc/test_child.js create mode 100644 extensions/cookie/test/unit_ipc/test_parent.js create mode 100644 extensions/cookie/test/unit_ipc/xpcshell.ini (limited to 'extensions/cookie/test/unit_ipc') diff --git a/extensions/cookie/test/unit_ipc/test_child.js b/extensions/cookie/test/unit_ipc/test_child.js new file mode 100644 index 000000000..40a48d8b8 --- /dev/null +++ b/extensions/cookie/test/unit_ipc/test_child.js @@ -0,0 +1,59 @@ +var Ci = Components.interfaces; +var Cc = Components.classes; +var 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 getPrincipalForURI(aURI) { + var uri = gIoService.newURI(aURI, null, null); + var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] + .getService(Ci.nsIScriptSecurityManager); + return ssm.createCodebasePrincipal(uri, {}); +} + +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.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1"), pm.ALLOW_ACTION); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2"), pm.DENY_ACTION); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3"), pm.ALLOW_ACTION); + + mM.sendAsyncMessage("TESTING:Stage3"); + break; + + } + return true; + }, + }; + + mM.addMessageListener("TESTING:Stage2A", messageListener); + + // Permissions created before the child is present + var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION); + do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION); + + mM.sendAsyncMessage("TESTING:Stage2"); + } +} + diff --git a/extensions/cookie/test/unit_ipc/test_parent.js b/extensions/cookie/test/unit_ipc/test_parent.js new file mode 100644 index 000000000..5423dd594 --- /dev/null +++ b/extensions/cookie/test/unit_ipc/test_parent.js @@ -0,0 +1,59 @@ +var Ci = Components.interfaces; +var Cc = Components.classes; +var 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 getPrincipalForURI(aURI) { + var uri = gIoService.newURI(aURI, null, null); + var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] + .getService(Ci.nsIScriptSecurityManager); + return ssm.createCodebasePrincipal(uri, {}); +} + +function run_test() { + if (isParentProcess()) { + var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); + + // Permissions created before the child is present + pm.addFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); + pm.addFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); + pm.addFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); + + var mM = Cc["@mozilla.org/parentprocessmessagemanager;1"]. + getService(Ci.nsIMessageBroadcaster); + + var messageListener = { + receiveMessage: function(aMessage) { + switch(aMessage.name) { + case "TESTING:Stage2": + // Permissions created after the child is present + pm.addFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); + pm.addFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0); + pm.addFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24); + mM.broadcastAsyncMessage("TESTING:Stage2A"); + break; + + case "TESTING:Stage3": + do_test_finished(); + break; + } + return true; + }, + }; + + mM.addMessageListener("TESTING:Stage2", messageListener); + mM.addMessageListener("TESTING:Stage3", messageListener); + + do_test_pending(); + do_load_child_test_harness(); + run_test_in_child("test_child.js"); + } +} + diff --git a/extensions/cookie/test/unit_ipc/xpcshell.ini b/extensions/cookie/test/unit_ipc/xpcshell.ini new file mode 100644 index 000000000..5640ea0e3 --- /dev/null +++ b/extensions/cookie/test/unit_ipc/xpcshell.ini @@ -0,0 +1,7 @@ +[DEFAULT] +head = +tail = +skip-if = toolkit == 'android' + +[test_child.js] +[test_parent.js] -- cgit v1.2.3