tor-browser

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

test_scrollRestoration.html (7653B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=
      5 -->
      6 <head>
      7  <title>Test for Bug 1155730</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body onload="runTest()">
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1155730">Mozilla Bug 1155730</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15 
     16 </div>
     17 <pre id="test">
     18  <script type="application/javascript">
     19    SimpleTest.waitForExplicitFinish();
     20    SimpleTest.requestFlakyTimeout("untriaged");
     21 
     22    function assertCheck(data) {
     23      if (data.assertIs) {
     24        for (const args of data.assertIs) {
     25          is(args[0], args[1], args[2]);
     26        }
     27      }
     28      if (data.assertOk) {
     29        for (const args of data.assertOk) {
     30          ok(args[0], args[1]);
     31        }
     32      }
     33      if (data.assertIsNot) {
     34        for (const args of data.assertIsNot) {
     35          isnot(args[0], args[1], args[2]);
     36        }
     37      }
     38    }
     39 
     40    var bc1, currentCase = 0;
     41    function test1() {
     42      bc1 = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1155730_part1");
     43      bc1.onmessage = (msgEvent) => {
     44        var msg = msgEvent.data;
     45        var command = msg.command;
     46        if (command == "pageshow") {
     47          currentCase++;
     48          var persisted = msg.persisted;
     49          is(persisted, false, "Shouldn't have persisted session history entry.");
     50          bc1.postMessage({command: "test", currentCase});
     51        } else if (command == "asserts") {
     52          is(msg.currentCase, currentCase, "correct case");
     53          info(`Checking asserts for case ${msg.currentCase}`);
     54          assertCheck(msg);
     55          if (currentCase == 3) {
     56            // move on to the next test
     57            bc1.close();
     58            test2();
     59          }
     60        }
     61      }
     62      window.open("file_scrollRestoration_part1_nobfcache.html", "", "width=360,height=480,noopener");
     63    }
     64 
     65    var bc2, bc2navigate;
     66    function test2() {
     67      currentCase = 0;
     68      bc2 = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1155730_part2");
     69      bc2.onmessage = (msgEvent) => {
     70        var msg = msgEvent.data;
     71        var command = msg.command;
     72        if (command == "pageshow") {
     73          currentCase++;
     74          var persisted = msg.persisted;
     75          switch (currentCase) {
     76            case 1:
     77              is(persisted, false, "Shouldn't have persisted session history entry.");
     78              break;
     79            case 2:
     80              is(persisted, true, "Should have persisted session history entry.");
     81          }
     82          bc2.postMessage({command: "test", currentCase});
     83        } else if (command == "asserts") {
     84          is(msg.currentCase, currentCase, "correct case");
     85          info(`Checking asserts for case ${msg.currentCase}`);
     86          assertCheck(msg);
     87          if (currentCase == 3) {
     88            // move on to the next test
     89            bc2.close();
     90            test3();
     91          }
     92        } else if (command == "nextCase") {
     93          currentCase++;
     94        }
     95      }
     96 
     97      bc2navigate = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("navigate");
     98      bc2navigate.onmessage = (event) => {
     99        if (event.data.command == "loaded") {
    100          bc2navigate.postMessage({command: "back"})
    101          bc2navigate.close();
    102        }
    103      }
    104      window.open("file_scrollRestoration_part2_bfcache.html", "", "width=360,height=480,noopener");
    105    }
    106 
    107    var bc3, bc3navigate;
    108    function test3() {
    109      currentCase = 0;
    110      bc3 = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1155730_part3");
    111      bc3.onmessage = (msgEvent) => {
    112        var msg = msgEvent.data;
    113        var command = msg.command;
    114        if (command == "pageshow") {
    115          currentCase++;
    116          if (currentCase == 3) {
    117            var persisted = msg.persisted;
    118            is(persisted, false, "Shouldn't have persisted session history entry.");
    119          }
    120 
    121          bc3.postMessage({command: "test", currentCase});
    122        } else if (command == "asserts") {
    123          is(msg.currentCase, currentCase, "correct case");
    124          info(`Checking asserts for case ${msg.currentCase}`);
    125          assertCheck(msg);
    126        } else if (command == "nextCase") {
    127          currentCase++;
    128        } else if (command == "finishing") {
    129          bc3.close();
    130          test4();
    131        }
    132      }
    133 
    134      bc3navigate = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("navigate");
    135      bc3navigate.onmessage = (event) => {
    136        if (event.data.command == "loaded") {
    137          is(event.data.scrollRestoration, 'auto', "correct scroll restoration");
    138          bc3navigate.postMessage({command: "back"})
    139          bc3navigate.close();
    140        }
    141      }
    142      window.open("file_scrollRestoration_part3_nobfcache.html", "", "width=360,height=480,noopener");
    143    }
    144 
    145    // test4 opens a new page which can enter bfcache. That page then loads
    146    // another page which can't enter bfcache. That second page then scrolls
    147    // down. History API is then used to navigate back and forward. When the
    148    // second page loads again, it should scroll down automatically.
    149    var bc4a, bc4b;
    150    var scrollYCounter = 0;
    151    function test4() {
    152      currentCase = 0;
    153      bc4a = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bfcached");
    154      bc4a.onmessage = (msgEvent) => {
    155        var msg = msgEvent.data;
    156        var command = msg.command;
    157        if (command == "pageshow") {
    158          ++currentCase;
    159          if (currentCase == 1) {
    160            ok(!msg.persisted, "The first page should not be persisted initially.");
    161            bc4a.postMessage("loadNext");
    162          } else if (currentCase == 3) {
    163            ok(msg.persisted, "The first page should be persisted.");
    164            bc4a.postMessage("forward");
    165            bc4a.close();
    166          }
    167        }
    168      }
    169 
    170      bc4b = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("notbfcached");
    171      bc4b.onmessage = (event) => {
    172        var msg = event.data;
    173        var command = msg.command;
    174        if (command == "pageshow") {
    175          ++currentCase;
    176          if (currentCase == 2) {
    177            ok(!msg.persisted, "The second page should not be persisted.");
    178            bc4b.postMessage("getScrollY");
    179            bc4b.postMessage("scroll");
    180            bc4b.postMessage("getScrollY");
    181            bc4b.postMessage("back");
    182          } else if (currentCase == 4) {
    183            ok(!msg.persisted, "The second page should not be persisted.");
    184            bc4b.postMessage("getScrollY");
    185          }
    186        } else if (msg == "closed") {
    187          bc4b.close();
    188          SimpleTest.finish();
    189        } else if ("scrollY" in msg) {
    190          ++scrollYCounter;
    191          if (scrollYCounter == 1) {
    192            is(msg.scrollY, 0, "The page should be initially scrolled to top.");
    193          } else if (scrollYCounter == 2) {
    194            isnot(msg.scrollY, 0, "The page should be then scrolled down.");
    195          } else if (scrollYCounter == 3) {
    196            isnot(msg.scrollY, 0, "The page should be scrolled down after being restored from the session history.");
    197            bc4b.postMessage("close");
    198          }
    199        }
    200      }
    201      window.open("file_scrollRestoration_bfcache_and_nobfcache.html", "", "width=360,height=480,noopener");
    202    }
    203 
    204    function runTest() {
    205      // If Fission is disabled, the pref is no-op.
    206      SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]}, () => {
    207        test1();
    208      });
    209    }
    210 
    211  </script>
    212 </pre>
    213 </body>
    214 </html>