summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/whatwg/postMessage_helper.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/tests/mochitest/whatwg/postMessage_helper.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/tests/mochitest/whatwg/postMessage_helper.html')
-rw-r--r--dom/tests/mochitest/whatwg/postMessage_helper.html110
1 files changed, 110 insertions, 0 deletions
diff --git a/dom/tests/mochitest/whatwg/postMessage_helper.html b/dom/tests/mochitest/whatwg/postMessage_helper.html
new file mode 100644
index 000000000..86e34e9d4
--- /dev/null
+++ b/dom/tests/mochitest/whatwg/postMessage_helper.html
@@ -0,0 +1,110 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>postMessage message receiver</title>
+ <script type="application/javascript" src="browserFu.js"></script>
+ <script type="application/javascript">
+ function $(id) { return document.getElementById(id); }
+
+ function setup()
+ {
+ var target = $("domain");
+ target.textContent = location.hostname + ":" + (location.port || 80);
+ }
+
+ function receiveMessage(evt)
+ {
+ var response = evt.data + "-response";
+
+ if (evt.lastEventId !== "")
+ response += " wrong-lastEventId(" + evt.lastEventId + ")";
+
+ if (evt.source !== window.parent)
+ {
+ response += " unexpected-source(" + evt.source + ")";
+ response += " window-parent-is(" + window.parent + ")";
+ response += " location(" + window.location.href + ")";
+ }
+
+ if (isMozilla)
+ {
+ if (evt.isTrusted !== false)
+ response += " unexpected-trusted";
+ }
+
+ if (evt.type != "message")
+ response += " wrong-type(" + evt.type + ")";
+
+ var data = evt.data;
+ if (data == "post-to-other-same-domain")
+ {
+ receiveSame(evt, response);
+ }
+ else if (data == "post-to-other-cross-domain")
+ {
+ receiveCross(evt, response);
+ }
+ else
+ {
+ response += " unexpected-message-to(" + window.location.href + ")";
+ window.parent.postMessage(response, "http://mochi.test:8888");
+ return;
+ }
+ }
+
+ function receiveSame(evt, response)
+ {
+ var source = evt.source;
+ try
+ {
+ if (evt.origin != "http://mochi.test:8888")
+ response += " unexpected-origin(" + evt.origin + ")";
+
+ try
+ {
+ var threw = false;
+ var privateVariable = source.privateVariable;
+ }
+ catch (e)
+ {
+ threw = true;
+ }
+ if (threw || privateVariable !== window.parent.privateVariable)
+ response += " accessed-source!!!";
+
+ }
+ finally
+ {
+ source.postMessage(response, evt.origin);
+ }
+ }
+
+ function receiveCross(evt, response)
+ {
+ var source = evt.source;
+ if (evt.origin != "http://mochi.test:8888")
+ response += " unexpected-origin(" + evt.origin + ")";
+
+ try
+ {
+ var threw = false;
+ var privateVariable = source.privateVariable;
+ }
+ catch (e)
+ {
+ threw = true;
+ }
+ if (!threw || privateVariable !== undefined)
+ response += " accessed-source!!!";
+
+ source.postMessage(response, evt.origin);
+ }
+
+ window.addEventListener("load", setup, false);
+ window.addEventListener("message", receiveMessage, false);
+ </script>
+</head>
+<body>
+<h1 id="domain"></h1>
+</body>
+</html>