js/xpconnect/tests/chrome/test_documentdomain.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial