test_bug860494.xul 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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=860494
  6. -->
  7. <window title="Mozilla Bug 860494"
  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. <!-- test results are displayed in the html:body -->
  11. <body xmlns="http://www.w3.org/1999/xhtml">
  12. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=860494"
  13. target="_blank">Mozilla Bug 860494</a>
  14. </body>
  15. <!-- test code goes here -->
  16. <script type="application/javascript">
  17. <![CDATA[
  18. /** Test for Bug 860494 **/
  19. SimpleTest.waitForExplicitFinish();
  20. const Cu = Components.utils;
  21. function go() {
  22. var iwin = $('ifr').contentWindow;
  23. // NB: mochitest-chrome actually runs the test as a content docshell.
  24. is(iwin.top, window.top, "iframe names shouldn't shadow |top| via Xray");
  25. is(iwin.parent, window, "iframe names shouldn't shadow |parent| via Xray");
  26. ok(!!/http/.exec(iwin.location), "iframe names shouldn't shadow |location| via Xray");
  27. is(iwin.length, 7, "iframe names shouldn't shadow |length| via Xray");
  28. is(iwin.window, iwin, "iframe names shouldn't shadow |window| via Xray");
  29. is(iwin.navigator, XPCNativeWrapper(iwin.wrappedJSObject.navigator),
  30. "iframe names shouldn't shadow |navigator| via Xray");
  31. ok(iwin.alert instanceof Function,
  32. "iframe names shouldn't shadow |alert| via Xray");
  33. // Now test XOWs.
  34. var sb = new Cu.Sandbox('http://www.example.com');
  35. sb.win = iwin;
  36. sb.topWin = top;
  37. sb.parentWin = window;
  38. sb.is = is;
  39. sb.ok = ok;
  40. Cu.evalInSandbox('ok(win.top === topWin, "iframe names shouldnt shadow |top| via cross-origin Xray");', sb);
  41. Cu.evalInSandbox('ok(win.parent === parentWin, "iframe names shouldnt shadow |parent| via cross-origin Xray");', sb);
  42. Cu.evalInSandbox('is(win.length, 7, "iframe names shouldnt shadow |length| via cross-origin Xray");', sb);
  43. Cu.evalInSandbox('ok(win.window === win, "iframe names shouldnt shadow |window| via cross-origin Xray");', sb);
  44. 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);
  45. 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);
  46. SimpleTest.finish();
  47. }
  48. ]]>
  49. </script>
  50. <iframe id="ifr" type="content" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_bug860494.html" />
  51. </window>