tor-browser

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

007.html (2502B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <title>Firing popstate after onload with pushed state</title>
      5                <meta name=timeout content=long>
      6    <script type="text/javascript" src="/resources/testharness.js"></script>
      7    <script type="text/javascript" src="/resources/testharnessreport.js"></script>
      8  </head>
      9  <body>
     10 
     11    <noscript><p>Enable JavaScript and reload</p></noscript>
     12    <div id="log">It looks like the browser stopped loading the page when encountering a .go(-1) command pointing to a pushed state. This will break the tests.</div>
     13    <script type="text/javascript">
     14 
     15 //spec (25 March 2011 draft) states that popstate must fire before onload if there is a pushed/replaced state that is navigated
     16 var popfired = false;
     17 setup({explicit_done:true});
     18 test(function () {
     19  assert_equals( history.state, null );
     20 }, 'history.state should initially be null');
     21 window.addEventListener('popstate',function (e) { popfired = e.state; },false);
     22 test(function () {
     23  history.pushState('state1','');
     24  history.pushState('state2','');
     25 }, 'history.pushState support is needed for this testcase');
     26 test(function () {
     27  assert_equals( history.state, 'state2' );
     28 }, 'history.state should reflect pushed state');
     29 if( history.pushState ) { history.go(-1); }
     30 window.onload = function () {
     31  test(function () {
     32    assert_true( !!popfired );
     33  }, 'popstate event should fire before onload fires');
     34  test(function () {
     35    assert_equals( popfired, 'state1' );
     36  }, 'the correct state should be restored when navigating during initial load');
     37  test(function () {
     38    assert_equals( history.state, 'state1' );
     39  }, 'history.state should reflect the navigated state onload');
     40  popfired = false;
     41  setTimeout(function () {
     42    test(function () {
     43      assert_false( !!popfired );
     44    }, 'popstate event should not fire after onload fires');
     45    test(function () {
     46      assert_equals( history.state, 'state1' );
     47    }, 'history.state should reflect the navigated state after onload');
     48    done();
     49    if( history.pushState ) { history.go(-1); } //go back to the start to avoid state recovery when reloading
     50  },100);
     51 };
     52 
     53    </script>
     54 
     55  <!--
     56    Reuse an existing server side script to slow down page load so that
     57    history.go(-1); above gets run before load event fires.
     58  -->
     59  <script>
     60    // define TEST_DELAY so that executing delay.py doesn't warn about use
     61    // of undefined variable.
     62    var TEST_DELAY;
     63  </script>
     64  <script src="/xhr/resources/delay.py?ms=2500"></script>
     65  </body>
     66 </html>