dom/tests/mochitest/whatwg/postMessage_joined_helper2.html

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:41ea44a4f18d
1 <!DOCTYPE html>
2 <html>
3 <!--
4 http://example.org/tests/dom/tests/mochitest/whatwg/postMessage_joined_helper2.html
5 -->
6 <head>
7 <title>postMessage joined domains, innermost frame</title>
8 <script type="application/javascript" src="browserFu.js"></script>
9 <script type="application/javascript">
10 function receiveMessage(evt)
11 {
12 var response = "subframe-test-finished";
13
14 if (evt.origin !== "http://sub1.test1.example.org")
15 {
16 response += " wrong-origin(" + evt.origin + ")";
17 response += " location(" + window.location.href + ")";
18 }
19
20 if (evt.data !== "start-test")
21 response += " incorrect-subframe-data(" + evt.data + ")";
22 if (evt.type !== "message")
23 response += " wrong-type(" + evt.type + ")";
24 if (evt.target !== window)
25 {
26 response += " wrong-target(" + evt.target + ")";
27 response += " location(" + window.location.href + ")";
28 }
29
30 if (isMozilla)
31 {
32 if (evt.isTrusted !== false)
33 response += " unexpected-trusted-event";
34 }
35
36 if (evt.source !== window.parent)
37 {
38 response += " unexpected-source(" + evt.source + ")";
39 response += " window-parent-is(" + window.parent + ")";
40 response += " location(" + window.location.href + ")";
41 }
42
43 // verify that document.domain was actually joined with this domain
44 try
45 {
46 var passed = evt.source.document.domain === document.domain;
47 }
48 catch (e)
49 {
50 }
51
52 if (!passed)
53 response += " expected-joined-domains";
54
55 window.parent.postMessage(response, "http://sub1.test1.example.org");
56 }
57
58 function setup()
59 {
60 var oldDomain = document.domain;
61 var newDomain = "example.org"; // join with parent
62
63 document.domain = newDomain;
64
65 var target = document.getElementById("location");
66 target.textContent = "Location: " + oldDomain +
67 ", effective domain: " + newDomain;
68
69 window.addEventListener("message", receiveMessage, false);
70 }
71
72 window.addEventListener("load", setup, false);
73 </script>
74 </head>
75 <body>
76 <p id="location">No location!</p>
77 </body>
78 </html>

mercurial