js/xpconnect/tests/chrome/test_documentdomain.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_documentdomain.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=601277
     1.9 +-->
    1.10 +<window title="Mozilla Bug 601277"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +
    1.14 +  <!-- test results are displayed in the html:body -->
    1.15 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.16 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=601277"
    1.17 +     target="_blank">Mozilla Bug 601277</a>
    1.18 +  </body>
    1.19 +
    1.20 +  <!-- test code goes here -->
    1.21 +  <script type="application/javascript">
    1.22 +  <![CDATA[
    1.23 +  /** Tests for document.domain. **/
    1.24 +
    1.25 +  SimpleTest.waitForExplicitFinish();
    1.26 +
    1.27 +  // Wait for the frames to load.
    1.28 +  var gFramesLoaded = 0;
    1.29 +  function frameLoaded() {
    1.30 +    gFramesLoaded++;
    1.31 +    if (gFramesLoaded == document.getElementsByTagName('iframe').length)
    1.32 +      startTest();
    1.33 +  }
    1.34 +
    1.35 +  function startTest() {
    1.36 +
    1.37 +    // Grab all the content windows and waive Xray. Xray waivers only apply to
    1.38 +    // chrome, so we can pass these references directly to content.
    1.39 +    var win1A = document.getElementById('test1A').contentWindow.wrappedJSObject;
    1.40 +    var win1B = document.getElementById('test1B').contentWindow.wrappedJSObject;
    1.41 +    var win2 = document.getElementById('test2').contentWindow.wrappedJSObject;
    1.42 +    var winBase = document.getElementById('base').contentWindow.wrappedJSObject;
    1.43 +
    1.44 +    // Check the basics.
    1.45 +    ok(win1A.tryToAccess(win1B),
    1.46 +       "Same-origin windows should grant access");
    1.47 +    ok(!win1A.tryToAccess(win2),
    1.48 +       "Cross-origin windows should not grant access");
    1.49 +    ok(!win1A.tryToAccess(winBase),
    1.50 +       "Subdomain windows should not receive access");
    1.51 +
    1.52 +    // Store references now, while test1A and test1B are same-origin.
    1.53 +    win1A.storeReference(win1B);
    1.54 +    win1B.storeReference(win1A);
    1.55 +    ok(win1A.tryToAccessStored(), "Stored references work when same-origin");
    1.56 +
    1.57 +    // Set document.domain on test1A. This should grant no access, since nobody
    1.58 +    // else set it.
    1.59 +    win1A.setDomain('example.org');
    1.60 +    ok(!win1A.tryToAccess(winBase), "base must collaborate too");
    1.61 +    ok(!winBase.tryToAccess(win1A), "base must collaborate too");
    1.62 +    ok(!win1A.tryToAccess(win1B), "No longer same-origin");
    1.63 +    ok(!win1A.tryToAccessStored(), "No longer same-origin");
    1.64 +    ok(!win1B.tryToAccess(win1A), "No longer same-origin");
    1.65 +    ok(!win1B.tryToAccessStored(), "No longer same-origin");
    1.66 +
    1.67 +    // Set document.domain on test1B. Now we're cooking with gas.
    1.68 +    win1B.setDomain('example.org');
    1.69 +    ok(!win1B.tryToAccess(winBase), "base must collaborate too");
    1.70 +    ok(!winBase.tryToAccess(win1B), "base must collaborate too");
    1.71 +    ok(win1A.tryToAccess(win1B), "same-origin");
    1.72 +    ok(win1A.tryToAccessStored(), "same-origin");
    1.73 +    ok(win1B.tryToAccess(win1A), "same-origin");
    1.74 +    ok(win1B.tryToAccessStored(), "same-origin");
    1.75 +
    1.76 +    // Explicitly collaborate with base.
    1.77 +    winBase.setDomain('example.org');
    1.78 +    ok(winBase.tryToAccess(win1A), "base collaborates");
    1.79 +    ok(win1A.tryToAccess(winBase), "base collaborates");
    1.80 +
    1.81 +    // All done.
    1.82 +    SimpleTest.finish();
    1.83 +  }
    1.84 +
    1.85 +
    1.86 +  ]]>
    1.87 +  </script>
    1.88 +
    1.89 +  <iframe id="test1A" onload="frameLoaded();" type="content"
    1.90 +          src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
    1.91 +  <iframe id="test1B" onload="frameLoaded();" type="content"
    1.92 +          src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
    1.93 +  <iframe id="test2" onload="frameLoaded();" type="content"
    1.94 +          src="http://test2.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
    1.95 +  <iframe id="base" onload="frameLoaded();" type="content"
    1.96 +          src="http://example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
    1.97 +</window>

mercurial