tor-browser

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

test_scroll_position_restore_after_stop.html (2497B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1312697
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1312697</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <script src="/tests/SimpleTest/paint_listener.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1312697">Mozilla Bug 1312697</a>
     15 <p id="display"></p>
     16 <script>
     17 SimpleTest.waitForExplicitFinish();
     18 
     19 var loadCount = 0;
     20 var childWin = window.open('file_SlowPage.sjs', '_blank');
     21 var targetPos = 0;
     22 
     23 // Called by the page in the child window when it's halfway loaded.
     24 function partiallyLoaded() {
     25  if (loadCount == 1) {
     26    // Halfway through the first reload, stop loading.
     27    childWin.stop();
     28    
     29    // Force a reflow in the stopped state. This triggers the buggy behaviour. 
     30    var newNode = childWin.document.createElement('p');
     31    newNode.innerHTML = "Added text.";
     32    childWin.document.body.insertBefore(newNode, childWin.document.body.childNodes[0]);
     33    
     34    childWin.waitForAllPaintsFlushed(function() {
     35      // Since we're only partially loaded, we should not have been able to
     36      // reach the target scroll position.
     37      ok(childWin.scrollY < targetPos, "Expected page to not be fully loaded");
     38      
     39      // Now re-load again. Continue reading in fullyLoaded(), the 
     40      // 'loadCount == 2' case.
     41      loadCount++;
     42      childWin.location.reload();
     43    });
     44  }
     45 }
     46 
     47 // Called by the page in the child window when it's fully loaded.
     48 function fullyLoaded() {
     49  if (loadCount == 0) {
     50    // Scroll to a target position near the end of the page (past the
     51    // half-way point.)
     52    targetPos = childWin.scrollMaxY - 100;
     53    childWin.scrollTo(0, targetPos);
     54    childWin.waitForAllPaintsFlushed(function() {
     55      ok(childWin.scrollY == targetPos, "Expected page to have scrolled");
     56      
     57      // Reload the page.
     58      loadCount++;
     59      childWin.location.reload();
     60      
     61      // Next, we'll get into partiallyLoaded(). Read on there.
     62    });
     63  } else if (loadCount == 2) {
     64    // After the second reload is complete, check that the initial target
     65    // position was remembered and scrolled to.
     66    childWin.waitForAllPaintsFlushed(function() {
     67      ok(childWin.scrollY == targetPos, "Expected page to have scrolled to target position");
     68      childWin.close();
     69      SimpleTest.finish();
     70    });
     71  }
     72 }
     73 
     74 </script>
     75 </body>
     76 </html>