test_bug413310.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=413310
  5. -->
  6. <head>
  7. <title>Test for Bug 413310</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=413310">Mozilla Bug 413310</a>
  13. <p id="display">
  14. <script class="testbody" type="text/javascript">
  15. if (navigator.platform.startsWith("Mac")) {
  16. SimpleTest.expectAssertions(0, 2);
  17. } else {
  18. SimpleTest.expectAssertions(0, 1);
  19. }
  20. /** Test for Bug 413310 **/
  21. // NOTE: If we ever make subframes do bfcache stuff, this test will need to be
  22. // modified accordingly! It assumes that subframes do NOT get bfcached.
  23. var onloadCount = 0;
  24. var step = -1; // One increment will come from the initial subframe onload.
  25. // Note that this script should come before the subframe,
  26. // so that doNextStep is defined when its onload handler fires.
  27. var textContent;
  28. SimpleTest.waitForExplicitFinish();
  29. addLoadEvent(doNextStep);
  30. function doNextStep() {
  31. ++step;
  32. switch (step) {
  33. case 1:
  34. is(onloadCount, 1, "Loaded initial page");
  35. is($("i").contentWindow.location.href,
  36. location.href.replace(/test_bug413310.html/,
  37. "bug413310-subframe.html"),
  38. "Unexpected subframe location after initial load");
  39. $("i").contentDocument.forms[0].submit();
  40. break;
  41. case 2:
  42. is(onloadCount, 2, "Loaded POST result");
  43. is($("i").contentWindow.location.href,
  44. location.href.replace(/test_bug413310.html/,
  45. "bug413310-post.sjs"),
  46. "Unexpected subframe location after POST load");
  47. textContent = $("i").contentDocument.body.textContent;
  48. isDeeply(textContent.match(/^POST /), ["POST "], "Not a POST?");
  49. $("i").contentWindow.location.hash = "foo";
  50. setTimeout(doNextStep, 0);
  51. break;
  52. case 3:
  53. is(onloadCount, 2, "Anchor scroll should not fire onload");
  54. is($("i").contentWindow.location.href,
  55. location.href.replace(/test_bug413310.html/,
  56. "bug413310-post.sjs#foo"),
  57. "Unexpected subframe location after anchor scroll");
  58. is(textContent, $("i").contentDocument.body.textContent,
  59. "Did a load when scrolling?");
  60. $("i").contentWindow.location.href = "bug413310-subframe.html";;
  61. break;
  62. case 4:
  63. is(onloadCount, 3, "Done new load");
  64. is($("i").contentWindow.location.href,
  65. location.href.replace(/test_bug413310.html/,
  66. "bug413310-subframe.html"),
  67. "Unexpected subframe location after new load");
  68. history.back();
  69. break;
  70. case 5:
  71. is(onloadCount, 4,
  72. "History traversal didn't fire onload: bfcache issues!");
  73. is($("i").contentWindow.location.href,
  74. location.href.replace(/test_bug413310.html/,
  75. "bug413310-post.sjs#foo"),
  76. "Unexpected subframe location");
  77. is(textContent, $("i").contentDocument.body.textContent,
  78. "Did a load when going back?");
  79. SimpleTest.finish();
  80. break;
  81. }
  82. }
  83. </script>
  84. <!-- Use a timeout in onload so that we don't do a load immediately inside onload -->
  85. <iframe id="i" src="bug413310-subframe.html" onload="setTimeout(doNextStep, 20)">
  86. </iframe>
  87. </p>
  88. <div id="content" style="display: none">
  89. </div>
  90. <pre id="test">
  91. </pre>
  92. </body>
  93. </html>