test_bug351633-3.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=351633
  5. -->
  6. <head>
  7. <title>Test for Bug 351633</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=351633">Mozilla Bug 351633</a>
  13. <pre id="test">
  14. <script class="testbody" type="text/javascript">
  15. var passJSUrl;
  16. var passJSUrl2;
  17. var finishTest;
  18. /** Test for Bug 351633 **/
  19. function runTests() {
  20. $("testframe1").onload = test1;
  21. // test2 will be called as finishTest
  22. $("testframe3").onload = test3;
  23. $("testframe4").onload = test4;
  24. $("testframe5").onload = test5;
  25. passJSUrl = false;
  26. window.testframe1.location.href =
  27. 'javascript:"<script>parent.passJSUrl = true</' + 'script>"'
  28. }
  29. function test1() {
  30. is(passJSUrl, true, "Script should have run in child");
  31. passJSUrl = false;
  32. passJSUrl2 = true;
  33. finishTest = test2;
  34. window.testframe2.location.href =
  35. 'javascript: location = "pass.html"; ' +
  36. '"<script>parent.passJSUrl2 = false</' + 'script>"'
  37. }
  38. function test2() {
  39. is(passJSUrl, true, "pass.html should have loaded");
  40. is(passJSUrl2, true, "<script> should not have run");
  41. passJSUrl = true;
  42. passJSUrl2 = false;
  43. finishTest = function() { };
  44. window.testframe3.location.href = 'fail.html';
  45. window.testframe3.location.href =
  46. 'javascript: "<script>parent.passJSUrl2 = true</' + 'script>"'
  47. }
  48. function test3() {
  49. if (window.testframe3.location.href == 'fail.html') {
  50. // Ignore this call; we expect the javascript: URI to still load. Note
  51. // that whether onload fires for the fail.html load before the event for
  52. // the javascript: URI execution runs is a timing issue, so we can't depend
  53. // on the ordering.
  54. return;
  55. }
  56. // Since fail.html could have loaded, the value of passJSUrl here is random
  57. // Something is bogus here. Maybe we're ending up with the href being the
  58. // javascript: URI even though it hasn't run yet? Or something? In any
  59. // case, this test fails on some tinderboxen but not others.... Need to
  60. // sort it out.
  61. // is(passJSUrl2, true, "<script> should have run");
  62. passJSUrl = false;
  63. passJSUrl2 = true;
  64. finishTest = function() { };
  65. window.testframe4.location.href = 'pass.html';
  66. window.testframe4.location.href =
  67. 'javascript:void("<script>parent.passJSUrl2 = false</' + 'script>")';
  68. }
  69. function test4() {
  70. is(passJSUrl, true, "pass.html should have loaded again");
  71. is(passJSUrl2, true, "<script> should not have run in void");
  72. passJSUrl = false;
  73. passJSUrl2 = true;
  74. finishTest = function() { };
  75. window.testframe5.location.href =
  76. 'javascript:"<script>parent.passJSUrl2 = false</' + 'script>"';
  77. window.testframe5.location.href = 'pass.html';
  78. }
  79. function test5() {
  80. is(passJSUrl, true, "pass.html should have loaded yet again");
  81. is(passJSUrl2, true, "javascript: load should have been canceled");
  82. SimpleTest.finish();
  83. }
  84. SimpleTest.waitForExplicitFinish();
  85. addLoadEvent(runTests);
  86. </script>
  87. </pre>
  88. <p id="display">
  89. <iframe name="testframe1" id="testframe1"></iframe>
  90. <iframe name="testframe2" id="testframe2"></iframe>
  91. <iframe name="testframe3" id="testframe3"></iframe>
  92. <iframe name="testframe4" id="testframe4"></iframe>
  93. <iframe name="testframe5" id="testframe5"></iframe>
  94. </p>
  95. <div id="content" style="display: none">
  96. </div>
  97. </body>
  98. </html>