tor-browser

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

test_bug590573.html (5039B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=590573
      5 -->
      6 <head>
      7  <title>Test for Bug 590573</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=590573">Mozilla Bug 590573</a>
     14 
     15 <script type='application/javascript'>
     16 SimpleTest.waitForExplicitFinish();
     17 
     18 // Listen to the first callback, since this indicates that the page loaded.
     19 var page1LoadCallbackEnabled = true;
     20 function page1Load() {
     21  if (page1LoadCallbackEnabled) {
     22    page1LoadCallbackEnabled = false;
     23    dump("Got page1 load.\n");
     24    pageLoad();
     25  } else {
     26    dump("Ignoring page1 load.\n");
     27  }
     28 }
     29 
     30 var page1PageShowCallbackEnabled = false;
     31 function page1PageShow() {
     32  if (page1PageShowCallbackEnabled) {
     33    page1PageShowCallbackEnabled = false;
     34    dump("Got page1 pageshow.\n");
     35    pageLoad();
     36  } else {
     37    dump("Ignoring page1 pageshow.\n");
     38  }
     39 }
     40 
     41 var page2LoadCallbackEnabled = false;
     42 function page2Load() {
     43  if (page2LoadCallbackEnabled) {
     44    page2LoadCallbackEnabled = false;
     45    dump("Got page2 popstate.\n");
     46    pageLoad();
     47  } else {
     48    dump("Ignoring page2 popstate.\n");
     49  }
     50 }
     51 
     52 var page2PopstateCallbackEnabled = false;
     53 function page2Popstate() {
     54  if (page2PopstateCallbackEnabled) {
     55    page2PopstateCallbackEnabled = false;
     56    dump("Got page2 popstate.\n");
     57    pageLoad();
     58  } else {
     59    dump("Ignoring page2 popstate.\n");
     60  }
     61 }
     62 
     63 var page2PageShowCallbackEnabled = false;
     64 function page2PageShow() {
     65  if (page2PageShowCallbackEnabled) {
     66    page2PageShowCallbackEnabled = false;
     67    dump("Got page2 pageshow.\n");
     68    pageLoad();
     69  } else {
     70    dump("Ignoring page2 pageshow.\n");
     71  }
     72 }
     73 
     74 var popup = window.open("file_bug590573_1.html");
     75 
     76 var gTestContinuation = null;
     77 var loads = 0;
     78 function pageLoad() {
     79  loads++;
     80  dump("pageLoad(loads=" + loads + ", page location=" + popup.location + ")\n");
     81 
     82  if (!gTestContinuation) {
     83    gTestContinuation = testBody();
     84  }
     85  var ret = gTestContinuation.next();
     86  if (ret.done) {
     87    SimpleTest.finish();
     88  }
     89 }
     90 
     91 function continueAsync() {
     92  popup.addEventListener("popstate", function() {
     93      popup.requestAnimationFrame(function() { gTestContinuation.next(); });
     94    },
     95    {once: true});
     96 }
     97 
     98 function* testBody() {
     99  is(popup.scrollY, 0, "test 1");
    100  popup.scroll(0, 100);
    101 
    102  popup.history.pushState("", "", "?pushed");
    103  is(Math.round(popup.scrollY), 100, "test 2");
    104  popup.scroll(0, 200); // set state-2's position to 200
    105 
    106  popup.history.back();
    107  continueAsync();
    108  yield;
    109  is(Math.round(popup.scrollY), 100, "test 3");
    110  popup.scroll(0, 150); // set original page's position to 150
    111 
    112  popup.history.forward();
    113  continueAsync();
    114  yield;
    115  is(Math.round(popup.scrollY), 200, "test 4");
    116 
    117  popup.history.back();
    118  continueAsync();
    119  yield;
    120  is(Math.round(popup.scrollY), 150, "test 5");
    121 
    122  popup.history.forward();
    123  continueAsync();
    124  yield;
    125  is(Math.round(popup.scrollY), 200, "test 6");
    126 
    127  // At this point, the history looks like:
    128  //   PATH                         POSITION
    129  //   file_bug590573_1.html        150       <-- oldest
    130  //   file_bug590573_1.html?pushed 200       <-- newest, current
    131 
    132  // Now test that the scroll position is persisted when we have real
    133  // navigations involved.  First, we need to spin the event loop so that the
    134  // navigation doesn't replace our current history entry.
    135 
    136  setTimeout(pageLoad, 0);
    137  yield;
    138 
    139  page2LoadCallbackEnabled = true;
    140  popup.location = "file_bug590573_2.html";
    141  yield;
    142 
    143  ok(popup.location.href.match("file_bug590573_2.html$"),
    144     "Location was " + popup.location +
    145     " but should end with file_bug590573_2.html");
    146 
    147  is(popup.scrollY, 0, "test 7");
    148  popup.scroll(0, 300);
    149 
    150  // We need to spin the event loop again before we go back, otherwise the
    151  // scroll positions don't get updated properly.
    152  setTimeout(pageLoad, 0);
    153  yield;
    154 
    155  page1PageShowCallbackEnabled = true;
    156  popup.history.back();
    157  yield;
    158 
    159  // Spin the event loop again so that we get the right scroll positions.
    160  setTimeout(pageLoad, 0);
    161  yield;
    162 
    163  is(popup.location.search, "?pushed");
    164  ok(popup.document.getElementById("div1"), "page should have div1.");
    165 
    166  is(Math.round(popup.scrollY), 200, "test 8");
    167 
    168  popup.history.back();
    169  continueAsync();
    170  yield;
    171  is(Math.round(popup.scrollY), 150, "test 9");
    172  popup.history.forward();
    173  continueAsync();
    174  yield;
    175 
    176  is(Math.round(popup.scrollY), 200, "test 10");
    177 
    178  // Spin one last time...
    179  setTimeout(pageLoad, 0);
    180  yield;
    181 
    182  page2PageShowCallbackEnabled = true;
    183  popup.history.forward();
    184  yield;
    185 
    186  // Bug 821821, on Android tegras we get 299 instead of 300 sometimes
    187  const scrollY = Math.floor(popup.scrollY);
    188  if (scrollY >= 299 && scrollY <= 300) {
    189    is(1, 1, "test 11");
    190  } else {
    191    is(1, 0, "test 11, got " + popup.scrollY + " for popup.scrollY instead of 299|300");
    192  }
    193  popup.close();
    194 }
    195 </script>
    196 
    197 </body>
    198 </html>