1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/whatwg/postMessage_chrome_helper.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<head> 1.7 + <title>postMessage chrome message receiver</title> 1.8 + <script type="application/javascript"> 1.9 + var gPrePath = ""; 1.10 + 1.11 + function receiveMessage(evt) 1.12 + { 1.13 + if (evt.data.substring(0,9) == "chrome://") { 1.14 + gPrePath = evt.data; 1.15 + respond("path-is-set"); 1.16 + } else { 1.17 + // Content cannot post to chrome without privileges 1.18 + try { 1.19 + window.parent.postMessage("SHOULD NOT GET THIS!", "*"); 1.20 + } 1.21 + catch (ex) { 1.22 + } 1.23 + 1.24 + var msg = "post-to-content-response"; 1.25 + 1.26 + if (evt.source !== null) 1.27 + msg += " wrong-source(" + evt.source + ")"; 1.28 + if (!evt.isTrusted) 1.29 + msg += " unexpected-untrusted-event"; 1.30 + if (evt.type !== "message") 1.31 + msg += " wrong-type(" + evt.type + ")"; 1.32 + if (evt.origin !== gPrePath) 1.33 + msg += " wrong-origin(" + evt.origin + ")"; 1.34 + if (evt.data !== "post-to-content") 1.35 + msg += " wrong-message(" + evt.data + ")"; 1.36 + 1.37 + respond(msg); 1.38 + } 1.39 + } 1.40 + 1.41 + function respond(msg) 1.42 + { 1.43 + SpecialPowers.wrap(window).parent.postMessage(msg, "*"); 1.44 + } 1.45 + 1.46 + window.addEventListener("message", receiveMessage, false); 1.47 + </script> 1.48 +</head> 1.49 +<body> 1.50 +<h1 id="domain">example.org</h1> 1.51 +</body> 1.52 +</html>