summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_messagemanager_send_principal.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/base/test/test_messagemanager_send_principal.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/base/test/test_messagemanager_send_principal.html')
-rw-r--r--dom/base/test/test_messagemanager_send_principal.html131
1 files changed, 131 insertions, 0 deletions
diff --git a/dom/base/test/test_messagemanager_send_principal.html b/dom/base/test/test_messagemanager_send_principal.html
new file mode 100644
index 000000000..c50cdfeb3
--- /dev/null
+++ b/dom/base/test/test_messagemanager_send_principal.html
@@ -0,0 +1,131 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Principal in MessageManager</title>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+</head>
+<body>
+
+ <script type="application/javascript;version=1.7">
+ "use strict";
+
+ const Ci = Components.interfaces;
+ const Cc = Components.classes;
+ const Cu = Components.utils;
+
+ var permManager = Cc["@mozilla.org/permissionmanager;1"]
+ .getService(Ci.nsIPermissionManager);
+
+ SimpleTest.waitForExplicitFinish();
+
+ const childFrameURL =
+ "data:text/html,<!DOCTYPE HTML><html><body></body></html>";
+
+ function childFrameScript() {
+ "use strict";
+
+ const secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].
+ getService(Ci.nsIScriptSecurityManager);
+
+ addMessageListener("test:content", function(message) {
+ sendAsyncMessage("test:result", "is nsIPrincipal: " +
+ (message.data instanceof Ci.nsIPrincipal ? "OK" : "KO"));
+
+ sendAsyncMessage("test:result", "principal.appId: " +
+ ("appId" in message.data ? "OK" : "KO"));
+
+ sendAsyncMessage("test:result", "principal.origin: " +
+ ("origin" in message.data ? "OK" : "KO"));
+
+ sendAsyncMessage("test:result", "principal.isInIsolatedMozBrowserElement: " +
+ ("isInIsolatedMozBrowserElement" in message.data ? "OK" : "KO"));
+ });
+
+ addMessageListener("test:system", function(message) {
+ sendAsyncMessage("test:result", "isSystemPrincipal: " +
+ (secMan.isSystemPrincipal(message.data) ? "OK" : "KO"));
+ });
+
+ addMessageListener("test:ep", function(message) {
+ sendAsyncMessage("test:result", "expanded principal: " +
+ (message.data.isExpandedPrincipal ? "OK" : "KO"));
+ sendAsyncMessage("test:result", "correct origin: " +
+ (message.data.origin == "[Expanded Principal [http://bar.example.com, http://foo.example.com]]" ? "OK" : "KO"));
+ });
+
+ addMessageListener("test:null", function(message) {
+ sendAsyncMessage("test:result", "is nsIPrincipal: " +
+ (message.data instanceof Ci.nsIPrincipal ? "OK" : "KO"));
+
+ sendAsyncMessage("test:result", "isNullPrincipal: " +
+ (message.data.isNullPrincipal ? "OK" : "KO"));
+ sendAsyncMessage("test:result", "DONE");
+ });
+ }
+
+ function runTests() {
+ ok("Browser prefs set.");
+
+ let iframe = document.createElement("iframe");
+ SpecialPowers.wrap(iframe).mozbrowser = true;
+ iframe.id = "iframe";
+ iframe.src = childFrameURL;
+
+ let sb = new Cu.Sandbox(['http://foo.example.com', 'http://bar.example.com']);
+ let ep = Components.utils.getObjectPrincipal(sb);
+
+ iframe.addEventListener("mozbrowserloadend", function() {
+ ok(true, "Got iframe load event.");
+
+ let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
+ mm.addMessageListener("test:result", function(message) {
+ // We need to wrap to access message.json, and unwrap to do the
+ // identity check.
+ var msg = SpecialPowers.unwrap(SpecialPowers.wrap(message).data);
+ if (/OK$/.exec(msg)) {
+ ok(true, msg);
+ } else if(/KO$/.exec(msg)) {
+ ok(true, false);
+ } else if (/DONE/.exec(msg)) {
+ permManager.removeFromPrincipal(window.document.nodePrincipal, "browser",
+ Ci.nsIPermissionManager.ALLOW_ACTION);
+ SimpleTest.finish();
+ }
+ });
+ mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();",
+ false);
+
+ mm.sendAsyncMessage("test:content", window.document.nodePrincipal);
+
+ let system = Cc["@mozilla.org/systemprincipal;1"].
+ createInstance(Ci.nsIPrincipal);
+ mm.sendAsyncMessage("test:system", system);
+
+ mm.sendAsyncMessage("test:ep", ep);
+
+ let nullP = Cc["@mozilla.org/nullprincipal;1"].
+ createInstance(Ci.nsIPrincipal);
+ mm.sendAsyncMessage("test:null", nullP);
+ });
+
+ document.body.appendChild(iframe);
+ }
+
+ addEventListener("load", function() {
+ info("Got load event.");
+
+ permManager.addFromPrincipal(window.document.nodePrincipal, "browser",
+ Ci.nsIPermissionManager.ALLOW_ACTION);
+
+ SpecialPowers.pushPrefEnv({
+ "set": [
+ ["dom.mozBrowserFramesEnabled", true],
+ ["network.disable.ipc.security", true],
+ ["browser.pagethumbnails.capturing_disabled", true]
+ ]
+ }, runTests);
+ });
+ </script>
+</body>
+</html>