|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=601277 |
|
6 --> |
|
7 <window title="Mozilla Bug 601277" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
10 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=601277" |
|
14 target="_blank">Mozilla Bug 601277</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 /** Tests for document.domain. **/ |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 // Wait for the frames to load. |
|
25 var gFramesLoaded = 0; |
|
26 function frameLoaded() { |
|
27 gFramesLoaded++; |
|
28 if (gFramesLoaded == document.getElementsByTagName('iframe').length) |
|
29 startTest(); |
|
30 } |
|
31 |
|
32 function startTest() { |
|
33 |
|
34 // Grab all the content windows and waive Xray. Xray waivers only apply to |
|
35 // chrome, so we can pass these references directly to content. |
|
36 var win1A = document.getElementById('test1A').contentWindow.wrappedJSObject; |
|
37 var win1B = document.getElementById('test1B').contentWindow.wrappedJSObject; |
|
38 var win2 = document.getElementById('test2').contentWindow.wrappedJSObject; |
|
39 var winBase = document.getElementById('base').contentWindow.wrappedJSObject; |
|
40 |
|
41 // Check the basics. |
|
42 ok(win1A.tryToAccess(win1B), |
|
43 "Same-origin windows should grant access"); |
|
44 ok(!win1A.tryToAccess(win2), |
|
45 "Cross-origin windows should not grant access"); |
|
46 ok(!win1A.tryToAccess(winBase), |
|
47 "Subdomain windows should not receive access"); |
|
48 |
|
49 // Store references now, while test1A and test1B are same-origin. |
|
50 win1A.storeReference(win1B); |
|
51 win1B.storeReference(win1A); |
|
52 ok(win1A.tryToAccessStored(), "Stored references work when same-origin"); |
|
53 |
|
54 // Set document.domain on test1A. This should grant no access, since nobody |
|
55 // else set it. |
|
56 win1A.setDomain('example.org'); |
|
57 ok(!win1A.tryToAccess(winBase), "base must collaborate too"); |
|
58 ok(!winBase.tryToAccess(win1A), "base must collaborate too"); |
|
59 ok(!win1A.tryToAccess(win1B), "No longer same-origin"); |
|
60 ok(!win1A.tryToAccessStored(), "No longer same-origin"); |
|
61 ok(!win1B.tryToAccess(win1A), "No longer same-origin"); |
|
62 ok(!win1B.tryToAccessStored(), "No longer same-origin"); |
|
63 |
|
64 // Set document.domain on test1B. Now we're cooking with gas. |
|
65 win1B.setDomain('example.org'); |
|
66 ok(!win1B.tryToAccess(winBase), "base must collaborate too"); |
|
67 ok(!winBase.tryToAccess(win1B), "base must collaborate too"); |
|
68 ok(win1A.tryToAccess(win1B), "same-origin"); |
|
69 ok(win1A.tryToAccessStored(), "same-origin"); |
|
70 ok(win1B.tryToAccess(win1A), "same-origin"); |
|
71 ok(win1B.tryToAccessStored(), "same-origin"); |
|
72 |
|
73 // Explicitly collaborate with base. |
|
74 winBase.setDomain('example.org'); |
|
75 ok(winBase.tryToAccess(win1A), "base collaborates"); |
|
76 ok(win1A.tryToAccess(winBase), "base collaborates"); |
|
77 |
|
78 // All done. |
|
79 SimpleTest.finish(); |
|
80 } |
|
81 |
|
82 |
|
83 ]]> |
|
84 </script> |
|
85 |
|
86 <iframe id="test1A" onload="frameLoaded();" type="content" |
|
87 src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" /> |
|
88 <iframe id="test1B" onload="frameLoaded();" type="content" |
|
89 src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" /> |
|
90 <iframe id="test2" onload="frameLoaded();" type="content" |
|
91 src="http://test2.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" /> |
|
92 <iframe id="base" onload="frameLoaded();" type="content" |
|
93 src="http://example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" /> |
|
94 </window> |