test_bug940783.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=940783
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 940783</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. <script type="application/javascript">
  12. /** Test for Bug 940783 **/
  13. SimpleTest.waitForExplicitFinish();
  14. function checkHistoryThrows(hist) {
  15. checkThrows(function() { hist.length; });
  16. checkThrows(function() { hist.state; });
  17. checkThrows(function() { hist.go(); });
  18. checkThrows(function() { hist.back(); });
  19. checkThrows(function() { hist.forward(); });
  20. checkThrows(function() { hist.pushState({}, "foo"); });
  21. checkThrows(function() { hist.replaceState({}, "foo"); });
  22. }
  23. window.gLoads = 0;
  24. function load() {
  25. var iwin = $('ifr').contentWindow;
  26. ++gLoads;
  27. if (gLoads == 1) {
  28. window.gHist = iwin.history;
  29. iwin.location = "file_empty.html";
  30. } else if (gLoads == 2) {
  31. checkHistoryThrows(gHist);
  32. window.gHist = iwin.history;
  33. iwin.location = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
  34. } else {
  35. checkHistoryThrows(gHist);
  36. $('ifr').setAttribute('onload', null);
  37. SimpleTest.finish();
  38. }
  39. }
  40. function checkThrows(fn) {
  41. try { fn(); ok(false, "Should have thrown: " + fn.toSource()); }
  42. catch (e) { ok(!!/denied|insecure/.exec(e), "Threw correctly: " + e); }
  43. }
  44. </script>
  45. </head>
  46. <body>
  47. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940783">Mozilla Bug 940783</a>
  48. <p id="display"></p>
  49. <div id="content" style="display: none">
  50. <iframe id="ifr" onload="load();" src="file_empty.html"></iframe>
  51. </div>
  52. <pre id="test">
  53. </pre>
  54. </body>
  55. </html>