test_bug792280.xul 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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=792280
  6. -->
  7. <window title="Mozilla Bug 792280"
  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=792280"
  13. target="_blank">Mozilla Bug 792280</a>
  14. </body>
  15. <!-- test code goes here -->
  16. <script type="application/javascript">
  17. <![CDATA[
  18. /** Test for Bug 792280 **/
  19. const Cu = Components.utils;
  20. function checkSb(sb, expect) {
  21. var target = new Cu.Sandbox('http://www.example.com');
  22. Cu.evalInSandbox('function fun() { return arguments.callee.caller; };', target);
  23. sb.fun = target.fun;
  24. let allowed = false;
  25. try {
  26. allowed = Cu.evalInSandbox('function doTest() { return fun() == doTest; }; doTest()', sb);
  27. isnot(expect, "throw", "Should have thrown");
  28. } catch (e) {
  29. is(expect, "throw", "Should expect exception");
  30. ok(/denied|insecure/.test(e), "Should be a security exception: " + e);
  31. }
  32. is(allowed, expect == "allow", "should censor appropriately");
  33. }
  34. // Note that COWs are callable, but XOWs are not.
  35. checkSb(new Cu.Sandbox('http://www.example.com'), "allow");
  36. checkSb(new Cu.Sandbox('http://www.example.org'), "throw");
  37. checkSb(new Cu.Sandbox(window), "censor");
  38. ]]>
  39. </script>
  40. </window>