test_bug853571.xul 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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=853571
  6. -->
  7. <window title="Mozilla Bug 853571"
  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=853571"
  13. target="_blank">Mozilla Bug 853571</a>
  14. </body>
  15. <!-- test code goes here -->
  16. <script type="application/javascript">
  17. <![CDATA[
  18. /** Test for Bug 853571 **/
  19. SimpleTest.waitForExplicitFinish();
  20. const Cu = Components.utils;
  21. function mainTest() {
  22. var iwin = $('ifr').contentWindow;
  23. // Test with a simple sandbox with no prototype.
  24. checkSource(iwin, new Cu.Sandbox(iwin), null, "should get null source with no sandboxPrototype");
  25. yield;
  26. // Test with a sandboxPrototype.
  27. checkSource(iwin, new Cu.Sandbox(iwin, { sandboxPrototype: iwin }), iwin, "should be able to impersonate the prototype");
  28. yield;
  29. SimpleTest.finish();
  30. yield; // Prevent StopIteration from being thrown.
  31. }
  32. var gen;
  33. function runTest() {
  34. gen = mainTest();
  35. gen.next();
  36. }
  37. function checkSource(target, sb, expectedSource, message) {
  38. target.addEventListener("message", function listener(event) {
  39. target.removeEventListener("message", listener);
  40. is(event.source, expectedSource, message);
  41. try {
  42. gen.next();
  43. } catch (e if e instanceof StopIteration) {
  44. // We're done.
  45. }
  46. });
  47. sb.target = target;
  48. Cu.evalInSandbox("target.postMessage('foo', '*');", sb);
  49. }
  50. ]]>
  51. </script>
  52. <iframe id="ifr" type="content" onload="runTest()" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
  53. </window>