Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage
5 -->
6 <head>
7 <title>postMessage chrome tests</title>
8 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
11 </head>
12 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a>
15 <p id="display"></p>
16 <div id="content" style="display: none"></div>
18 <iframe src="http://example.org/tests/dom/tests/mochitest/whatwg/postMessage_chrome_helper.html"
19 name="contentDomain"></iframe>
22 <pre id="test">
23 <script class="testbody" type="application/javascript">
24 /** Test for Bug 387706 **/
26 SimpleTest.waitForExplicitFinish();
28 var finished = false;
29 function finish()
30 {
31 if (!finished)
32 {
33 finished = true;
34 SimpleTest.finish();
35 }
36 }
38 /** Receives MessageEvents to this window. */
39 function messageReceiver(evt)
40 {
41 ok(evt instanceof MessageEvent, "umm, how did we get this?");
42 is(evt.type, "message", "expected events of type 'message'");
43 is(evt.lastEventId, "", "postMessage creates events with empty lastEventId");
45 switch (evt.data)
46 {
47 case "path-is-set":
48 chromePathIsSet(evt);
49 break;
51 case "post-to-self":
52 checkSelf(evt);
53 break;
55 case "post-to-content-response":
56 receiveContent(evt);
57 break;
59 default:
60 ok(false, "unexpected message: " + evt.data);
61 finish();
62 break;
63 }
64 }
67 /******************
68 * SELF-RESPONDER *
69 ******************/
71 function checkSelf(evt)
72 {
73 var prepath = getChromePrePath(window.location.href);
75 is(evt.isTrusted, true, "should have sent a trusted event");
76 is(evt.origin, prepath, "wrong origin for chrome: URL");
77 is(evt.source, null, "chrome posters get a null source, for security");
79 window.frames.contentDomain.postMessage(prepath, "*");
80 }
83 function chromePathIsSet(evt)
84 {
85 window.frames.contentDomain.postMessage("post-to-content",
86 "http://example.org");
87 }
89 /*************
90 * RECEIVERS *
91 *************/
93 function receiveContent(evt)
94 {
95 is(evt.isTrusted, true, "should have sent a trusted event");
96 finish();
97 }
100 /**************
101 * TEST SETUP *
102 **************/
104 function run()
105 {
106 window.addEventListener("message", messageReceiver, false);
107 window.postMessage("post-to-self", "*");
108 }
110 window.addEventListener("load", run, false);
111 </script>
112 </pre>
113 </body>
114 </html>