dom/tests/mochitest/whatwg/postMessage_joined_helper.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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 <!--
michael@0 4 http://sub1.test1.example.org/tests/dom/tests/mochitest/whatwg/postMessage_joined_helper.html
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>postMessage joined domains, inner frame</title>
michael@0 8 <script type="application/javascript" src="browserFu.js"></script>
michael@0 9 <script type="application/javascript">
michael@0 10 function receiveMessage(evt)
michael@0 11 {
michael@0 12 var response, target, providedOrigin;
michael@0 13 var data = evt.data;
michael@0 14 if (data === "subframe-test-finished")
michael@0 15 {
michael@0 16 target = window.parent;
michael@0 17 providedOrigin = "http://mochi.test:8888";
michael@0 18 response = "test-passed";
michael@0 19 }
michael@0 20 else if (data === "start-test")
michael@0 21 {
michael@0 22 target = window.frames.innermost;
michael@0 23 providedOrigin = "http://example.org";
michael@0 24 response = "start-test";
michael@0 25 }
michael@0 26 else
michael@0 27 {
michael@0 28 target = window.parent;
michael@0 29 providedOrigin = "http://mochi.test:8888";
michael@0 30 response = "not reached";
michael@0 31 }
michael@0 32
michael@0 33 if (evt.lastEventId !== "")
michael@0 34 response += " wrong-lastEventId(" + evt.lastEventId + ")";
michael@0 35
michael@0 36 if (evt.type !== "message")
michael@0 37 response += " wrong-type(" + evt.type + ")";
michael@0 38
michael@0 39 if (evt.target !== window)
michael@0 40 {
michael@0 41 response += " wrong-target(" + evt.target + ")";
michael@0 42 response += " location(" + window.location.href + ")";
michael@0 43 }
michael@0 44
michael@0 45 if (isMozilla && evt.isTrusted === true)
michael@0 46 {
michael@0 47 response += " unexpected-trusted-event";
michael@0 48 }
michael@0 49
michael@0 50 var origin;
michael@0 51 if (data == "subframe-test-finished")
michael@0 52 origin = "http://example.org";
michael@0 53 else if (data === "start-test")
michael@0 54 origin = "http://mochi.test:8888";
michael@0 55 else
michael@0 56 origin = "unreached";
michael@0 57
michael@0 58 if (evt.origin !== origin)
michael@0 59 {
michael@0 60 response += " wrong-origin(" + evt.origin + ")";
michael@0 61 response += " location(" + window.location.href + ")";
michael@0 62 }
michael@0 63
michael@0 64 target.postMessage(response, providedOrigin);
michael@0 65 }
michael@0 66
michael@0 67 function setup()
michael@0 68 {
michael@0 69 var oldDomain = document.domain;
michael@0 70 var newDomain = "example.org";
michael@0 71
michael@0 72 document.domain = newDomain;
michael@0 73
michael@0 74 var target = document.getElementById("location");
michael@0 75 target.textContent = "Location: " + oldDomain +
michael@0 76 ", effective domain: " + newDomain;
michael@0 77
michael@0 78 window.addEventListener("message", receiveMessage, false);
michael@0 79 }
michael@0 80
michael@0 81 window.addEventListener("load", setup, false);
michael@0 82 </script>
michael@0 83 </head>
michael@0 84 <body>
michael@0 85 <p id="location">No location!</p>
michael@0 86
michael@0 87 <iframe src="http://example.org/tests/dom/tests/mochitest/whatwg/postMessage_joined_helper2.html"
michael@0 88 name="innermost"></iframe>
michael@0 89
michael@0 90 </body>
michael@0 91 </html>

mercurial