js/xpconnect/tests/chrome/test_bug860494.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_bug860494.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     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=860494
     1.9 +-->
    1.10 +<window title="Mozilla Bug 860494"
    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=860494"
    1.17 +     target="_blank">Mozilla Bug 860494</a>
    1.18 +  </body>
    1.19 +
    1.20 +  <!-- test code goes here -->
    1.21 +  <script type="application/javascript">
    1.22 +  <![CDATA[
    1.23 +  /** Test for Bug 860494 **/
    1.24 +  SimpleTest.waitForExplicitFinish();
    1.25 +  const Cu = Components.utils;
    1.26 +
    1.27 +  function go() {
    1.28 +    var iwin = $('ifr').contentWindow;
    1.29 +    // NB: mochitest-chrome actually runs the test as a content docshell.
    1.30 +    is(iwin.top, window.top, "iframe names shouldn't shadow |top| via Xray");
    1.31 +    is(iwin.parent, window, "iframe names shouldn't shadow |parent| via Xray");
    1.32 +    ok(!!/http/.exec(iwin.location), "iframe names shouldn't shadow |location| via Xray");
    1.33 +    is(iwin.length, 7, "iframe names shouldn't shadow |length| via Xray");
    1.34 +    is(iwin.window, iwin, "iframe names shouldn't shadow |window| via Xray");
    1.35 +    is(iwin.navigator, XPCNativeWrapper(iwin.wrappedJSObject.navigator),
    1.36 +       "iframe names shouldn't shadow |navigator| via Xray");
    1.37 +    ok(iwin.alert instanceof Function,
    1.38 +       "iframe names shouldn't shadow |alert| via Xray");
    1.39 +
    1.40 +    // Now test XOWs.
    1.41 +    var sb = new Cu.Sandbox('http://www.example.com');
    1.42 +    sb.win = iwin;
    1.43 +    sb.topWin = top;
    1.44 +    sb.parentWin = window;
    1.45 +    sb.is = is;
    1.46 +    sb.ok = ok;
    1.47 +    Cu.evalInSandbox('is(win.top, topWin, "iframe names shouldnt shadow |top| via cross-origin Xray");', sb);
    1.48 +    Cu.evalInSandbox('is(win.parent, parentWin, "iframe names shouldnt shadow |parent| via cross-origin Xray");', sb);
    1.49 +    Cu.evalInSandbox('is(win.length, 7, "iframe names shouldnt shadow |length| via cross-origin Xray");', sb);
    1.50 +    Cu.evalInSandbox('is(win.window, win, "iframe names shouldnt shadow |window| via cross-origin Xray");', sb);
    1.51 +    Cu.evalInSandbox('var exn = "nothrow"; try { win.navigator; } catch (e) { exn = e; } ok(!!/denied/.exec(exn), "cross-origin Xray blocks subframes that shadow: navigator: " + exn);', sb);
    1.52 +    Cu.evalInSandbox('var exn = "nothrow"; try { win.alert; } catch (e) { exn = e; } ok(!!/denied/.exec(exn), "cross-origin Xray blocks subframes that shadow: alert: " + exn);', sb);
    1.53 +
    1.54 +    SimpleTest.finish();
    1.55 +  }
    1.56 +
    1.57 +  ]]>
    1.58 +  </script>
    1.59 +  <iframe id="ifr" type="content" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_bug860494.html" />
    1.60 +</window>

mercurial