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 <?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"/>
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>
17 <!-- test code goes here -->
18 <script type="application/javascript">
19 <![CDATA[
20 /** Tests for document.domain. **/
22 SimpleTest.waitForExplicitFinish();
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 }
32 function startTest() {
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;
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");
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");
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");
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");
73 // Explicitly collaborate with base.
74 winBase.setDomain('example.org');
75 ok(winBase.tryToAccess(win1A), "base collaborates");
76 ok(win1A.tryToAccess(winBase), "base collaborates");
78 // All done.
79 SimpleTest.finish();
80 }
83 ]]>
84 </script>
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>