test_bug640387_1.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=640387
  5. -->
  6. <head>
  7. <title>Test for Bug 640387</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=640387">Mozilla Bug 640387</a>
  14. <script type='application/javascript;version=1.7'>
  15. SimpleTest.waitForExplicitFinish();
  16. function test() {
  17. /* Spin the event loop so we get out of the onload handler. */
  18. SimpleTest.executeSoon(function() { gGen.next() });
  19. yield undefined;
  20. popup.history.pushState('', '', '#hash1');
  21. popup.history.pushState('', '', '#hash2');
  22. // Now the history looks like:
  23. // file_bug640387.html
  24. // file_bug640387.html#hash1
  25. // file_bug640387.html#hash2 <-- current
  26. // Going back should trigger a hashchange, which will wake us up from the
  27. // yield.
  28. popup.history.back();
  29. yield undefined;
  30. ok(true, 'Got first hashchange.');
  31. // Going back should wake us up again.
  32. popup.history.back();
  33. yield undefined;
  34. ok(true, 'Got second hashchange.');
  35. // Now the history looks like:
  36. // file_bug640387.html <-- current
  37. // file_bug640387.html#hash1
  38. // file_bug640387.html#hash2
  39. // Going forward should trigger a hashchange.
  40. popup.history.forward();
  41. yield undefined;
  42. ok(true, 'Got third hashchange.');
  43. // Now modify the history so it looks like:
  44. // file_bug640387.html
  45. // file_bug640387.html#hash1
  46. // file_bug640387.html#hash1 <-- current
  47. popup.history.pushState('', '', '#hash1');
  48. // Now when we go back, we should not get a hashchange. Instead, wait for a
  49. // popstate. We need to asynchronously go back because popstate is fired
  50. // sync.
  51. gHashchangeExpected = false;
  52. gCallbackOnPopstate = true;
  53. SimpleTest.executeSoon(function() { popup.history.back() });
  54. yield undefined;
  55. ok(true, 'Got popstate.');
  56. gCallbackOnPopstate = false;
  57. // Spin the event loop so hashchange has a chance to fire, if it's going to.
  58. SimpleTest.executeSoon(function() { gGen.next() });
  59. yield undefined;
  60. popup.close();
  61. SimpleTest.finish();
  62. yield undefined;
  63. }
  64. gGen = null;
  65. function childLoad() {
  66. gGen = test();
  67. gGen.next();
  68. }
  69. gHashchangeExpected = true;
  70. function childHashchange() {
  71. if (gHashchangeExpected) {
  72. gGen.next();
  73. }
  74. else {
  75. ok(false, "Got hashchange when we weren't expecting one.");
  76. }
  77. }
  78. gCallbackOnPopstate = false;
  79. function childPopstate() {
  80. if (gCallbackOnPopstate) {
  81. gGen.next();
  82. }
  83. }
  84. /* We need to run this test in a popup, because navigating an iframe
  85. * back/forwards tends to cause intermittent orange. */
  86. popup = window.open('file_bug640387.html');
  87. /* Control now flows up to childLoad(), called once the popup loads. */
  88. </script>
  89. </body>
  90. </html>