tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug640387_1.html (2891B)


      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 src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script 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 
     15 <script type='application/javascript'>
     16 SimpleTest.waitForExplicitFinish();
     17 
     18 function* test() {
     19  /* Spin the event loop so we get out of the onload handler. */
     20  SimpleTest.executeSoon(function() { gGen.next(); });
     21  yield undefined;
     22 
     23  popup.history.pushState("", "", "#hash1");
     24  popup.history.pushState("", "", "#hash2");
     25 
     26  // Now the history looks like:
     27  //   file_bug640387.html
     28  //   file_bug640387.html#hash1
     29  //   file_bug640387.html#hash2  <-- current
     30 
     31  // Going back should trigger a hashchange, which will wake us up from the
     32  // yield.
     33  popup.history.back();
     34  yield undefined;
     35  ok(true, "Got first hashchange.");
     36 
     37  // Going back should wake us up again.
     38  popup.history.back();
     39  yield undefined;
     40  ok(true, "Got second hashchange.");
     41 
     42  // Now the history looks like:
     43  //   file_bug640387.html        <-- current
     44  //   file_bug640387.html#hash1
     45  //   file_bug640387.html#hash2
     46 
     47  // Going forward should trigger a hashchange.
     48  popup.history.forward();
     49  yield undefined;
     50  ok(true, "Got third hashchange.");
     51 
     52  // Now modify the history so it looks like:
     53  //   file_bug640387.html
     54  //   file_bug640387.html#hash1
     55  //   file_bug640387.html#hash1  <-- current
     56  popup.history.pushState("", "", "#hash1");
     57 
     58  // Now when we go back, we should not get a hashchange.  Instead, wait for a
     59  // popstate.  We need to asynchronously go back because popstate is fired
     60  // sync.
     61  gHashchangeExpected = false;
     62  gCallbackOnPopstate = true;
     63  SimpleTest.executeSoon(function() { popup.history.back(); });
     64  yield undefined;
     65  ok(true, "Got popstate.");
     66  gCallbackOnPopstate = false;
     67 
     68  // Spin the event loop so hashchange has a chance to fire, if it's going to.
     69  SimpleTest.executeSoon(function() { gGen.next(); });
     70  yield undefined;
     71 
     72  popup.close();
     73  SimpleTest.finish();
     74 }
     75 
     76 var gGen = null;
     77 function childLoad() {
     78  gGen = test();
     79  gGen.next();
     80 }
     81 
     82 var gHashchangeExpected = true;
     83 function childHashchange() {
     84  if (gHashchangeExpected) {
     85    gGen.next();
     86  } else {
     87    ok(false, "Got hashchange when we weren't expecting one.");
     88  }
     89 }
     90 
     91 var gCallbackOnPopstate = false;
     92 function childPopstate() {
     93  if (gCallbackOnPopstate) {
     94    gGen.next();
     95  }
     96 }
     97 
     98 /* We need to run this test in a popup, because navigating an iframe
     99 * back/forwards tends to cause intermittent orange. */
    100 var popup = window.open("file_bug640387.html");
    101 
    102 /* Control now flows up to childLoad(), called once the popup loads. */
    103 
    104 </script>
    105 
    106 </body>
    107 </html>