Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for Principal in MessageManager</title> |
michael@0 | 5 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | |
michael@0 | 10 | <script type="application/javascript;version=1.7"> |
michael@0 | 11 | "use strict"; |
michael@0 | 12 | |
michael@0 | 13 | const Ci = Components.interfaces; |
michael@0 | 14 | const Cc = Components.classes; |
michael@0 | 15 | const Cu = Components.utils; |
michael@0 | 16 | |
michael@0 | 17 | var permManager = Cc["@mozilla.org/permissionmanager;1"] |
michael@0 | 18 | .getService(Ci.nsIPermissionManager); |
michael@0 | 19 | |
michael@0 | 20 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 21 | |
michael@0 | 22 | const childFrameURL = |
michael@0 | 23 | "data:text/html,<!DOCTYPE HTML><html><body></body></html>"; |
michael@0 | 24 | |
michael@0 | 25 | function childFrameScript() { |
michael@0 | 26 | "use strict"; |
michael@0 | 27 | |
michael@0 | 28 | addMessageListener("test:ipcMessage", function(message) { |
michael@0 | 29 | sendAsyncMessage(message.name, "principal: " + (message.principal ? "OK" : "KO")); |
michael@0 | 30 | |
michael@0 | 31 | sendAsyncMessage(message.name, "principal.appId: " + |
michael@0 | 32 | ("appId" in message.principal ? "OK" : "KO")); |
michael@0 | 33 | |
michael@0 | 34 | sendAsyncMessage(message.name, "principal.origin: " + |
michael@0 | 35 | ("origin" in message.principal ? "OK" : "KO")); |
michael@0 | 36 | |
michael@0 | 37 | sendAsyncMessage(message.name, "principal.isInBrowserElement: " + |
michael@0 | 38 | ("isInBrowserElement" in message.principal ? "OK" : "KO")); |
michael@0 | 39 | |
michael@0 | 40 | sendAsyncMessage(message.name, "DONE"); |
michael@0 | 41 | }); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function runTests() { |
michael@0 | 45 | ok("Browser prefs set."); |
michael@0 | 46 | |
michael@0 | 47 | let iframe = document.createElement("iframe"); |
michael@0 | 48 | SpecialPowers.wrap(iframe).mozbrowser = true; |
michael@0 | 49 | iframe.id = "iframe"; |
michael@0 | 50 | iframe.src = childFrameURL; |
michael@0 | 51 | |
michael@0 | 52 | iframe.addEventListener("mozbrowserloadend", function() { |
michael@0 | 53 | ok(true, "Got iframe load event."); |
michael@0 | 54 | |
michael@0 | 55 | let mm = SpecialPowers.getBrowserFrameMessageManager(iframe); |
michael@0 | 56 | mm.addMessageListener("test:ipcMessage", function(message) { |
michael@0 | 57 | // We need to wrap to access message.json, and unwrap to do the |
michael@0 | 58 | // identity check. |
michael@0 | 59 | var msg = SpecialPowers.unwrap(SpecialPowers.wrap(message).json); |
michael@0 | 60 | if (/OK$/.exec(msg)) { |
michael@0 | 61 | ok(true, msg); |
michael@0 | 62 | } else if(/KO$/.exec(msg)) { |
michael@0 | 63 | ok(true, false); |
michael@0 | 64 | } else if (/DONE/.exec(msg)) { |
michael@0 | 65 | permManager.removeFromPrincipal(window.document.nodePrincipal, "browser", |
michael@0 | 66 | Ci.nsIPermissionManager.ALLOW_ACTION); |
michael@0 | 67 | SimpleTest.finish(); |
michael@0 | 68 | } |
michael@0 | 69 | }); |
michael@0 | 70 | mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();", |
michael@0 | 71 | false); |
michael@0 | 72 | |
michael@0 | 73 | mm.sendAsyncMessage("test:ipcMessage", 42, null, window.document.nodePrincipal); |
michael@0 | 74 | }); |
michael@0 | 75 | |
michael@0 | 76 | document.body.appendChild(iframe); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | addEventListener("load", function() { |
michael@0 | 80 | info("Got load event."); |
michael@0 | 81 | |
michael@0 | 82 | permManager.addFromPrincipal(window.document.nodePrincipal, "browser", |
michael@0 | 83 | Ci.nsIPermissionManager.ALLOW_ACTION); |
michael@0 | 84 | |
michael@0 | 85 | SpecialPowers.pushPrefEnv({ |
michael@0 | 86 | "set": [ |
michael@0 | 87 | ["dom.mozBrowserFramesEnabled", true], |
michael@0 | 88 | ["browser.pagethumbnails.capturing_disabled", true] |
michael@0 | 89 | ] |
michael@0 | 90 | }, runTests); |
michael@0 | 91 | }); |
michael@0 | 92 | </script> |
michael@0 | 93 | </body> |
michael@0 | 94 | </html> |