tor-browser

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

bug321671_window.xhtml (5506B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 
      4 <window id="321671Test"
      5        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      6        width="600"
      7        height="600"
      8        onload="setTimeout(runTest, 0);"
      9        title="bug 321671 test">
     10 
     11  <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js" />
     12  <script type="application/javascript" src="docshell_helpers.js" />
     13  <script type="application/javascript"><![CDATA[
     14    Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false);
     15  
     16    // Maximum number of entries in the bfcache for this session history.
     17    // This number is hardcoded in docshell code.  In the test, we'll
     18    // navigate through enough pages so that we hit one that's been
     19    // evicted from the bfcache because it's farther from the current
     20    // page than this number.
     21    const MAX_BFCACHE_PAGES = 3;
     22 
     23    ////
     24    // Bug 321671:  Scroll position should be retained when moving backwards and
     25    // forwards through pages when bfcache is enabled.
     26    //
     27    async function runTest()
     28    {
     29      // Variable to hold the scroll positions of the test pages.
     30      var scrollPositions = [];
     31      
     32      // Make sure bfcache is on.
     33      enableBFCache(true);
     34      
     35      // Load enough test pages that so the first one is evicted from the
     36      // bfcache, scroll down on each page, and save the
     37      // current scroll position before continuing.  Verify that each
     38      // page we're navigating away from is initially put into the bfcache.
     39      for (var i = 0; i <= MAX_BFCACHE_PAGES + 1; i++) {
     40        let eventsToListenFor = ["pageshow"];
     41        let expectedEvents = [ { type: "pageshow",
     42                                 title: "bug321671 page" + (i + 1) } ];
     43        if (i > 0) {
     44          eventsToListenFor.push("pagehide");
     45          expectedEvents.unshift({ type: "pagehide",
     46                                   persisted: true,
     47                                   title: "bug321671 page" + i });
     48        }
     49        await promisePageNavigation( {
     50           uri: "data:text/html,<html><head><title>bug321671 page" + (i + 1) +
     51                "</title></head>" +
     52                "<body><table border='1' width='300' height='1000'>" +
     53                "<tbody><tr><td>" +
     54                " page " + (i + 1) + ": foobar foobar foobar foobar " +
     55                "</td></tr></tbody></table> " +
     56                "</body></html>",
     57           eventsToListenFor,
     58           expectedEvents,
     59          } );
     60 
     61        let { initialScrollY, scrollY } = await SpecialPowers.spawn(TestWindow.getBrowser(), [i], (i) => {
     62          let initialScrollY = content.scrollY;
     63          content.scrollByLines(10 + (2 * i));
     64          return { initialScrollY, scrollY: content.scrollY };
     65        });
     66        is(initialScrollY, 0,
     67          "Page initially has non-zero scrollY position");
     68        ok(scrollY > 0,
     69          "Page has zero scrollY position after scrolling");
     70        scrollPositions[i] = scrollY;
     71      }
     72      
     73      // Go back to the first page, one page at a time.  For each 'back' 
     74      // action, verify that its vertical scroll position is restored 
     75      // correctly.  Verify that the last page in the sequence
     76      // does not come from the bfcache.  Again verify that all pages 
     77      // that we navigate away from are initially
     78      // stored in the bfcache.
     79      for (i = MAX_BFCACHE_PAGES + 1; i > 0; i--) {
     80        await promisePageNavigation( {
     81          back: true,
     82          eventsToListenFor: ["pageshow", "pagehide"],
     83          expectedEvents: [ { type: "pagehide",
     84                              title: "bug321671 page" + (i+1),
     85                              persisted: true }, 
     86                            { type: "pageshow", 
     87                              title: "bug321671 page" + i,
     88                              persisted: i > 1 } ],
     89        } );
     90 
     91        is(await SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
     92             return content.scrollY;
     93           }), scrollPositions[i-1],
     94           "Scroll position not restored while going back!");
     95      }
     96      
     97      // Traverse history forward now, and verify scroll position is still 
     98      // restored.  Similar to the backward traversal, verify that all
     99      // but the last page in the sequence comes from the bfcache.  Also 
    100      // verify that all of the pages get stored in the bfcache when we 
    101      // navigate away from them.
    102      for (i = 1; i <= MAX_BFCACHE_PAGES + 1; i++) {
    103        await promisePageNavigation( {
    104          forward: true,
    105          eventsToListenFor: ["pageshow", "pagehide"],
    106          expectedEvents: [ { type: "pagehide", 
    107                              persisted: true,
    108                              title: "bug321671 page" + i },
    109                            { type: "pageshow", 
    110                              persisted: i < MAX_BFCACHE_PAGES + 1,
    111                              title: "bug321671 page" + (i + 1) } ],
    112        } );
    113 
    114        is(await SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
    115             return content.scrollY;
    116           }), scrollPositions[i],
    117           "Scroll position not restored while going forward!");
    118      }
    119 
    120      Services.prefs.clearUserPref("browser.navigation.requireUserInteraction");
    121      // Tell the framework the test is finished.
    122      finish();
    123    }
    124 
    125  ]]></script>
    126 
    127  <browser type="content" primary="true" flex="1" id="content" remote="true" maychangeremoteness="true" />
    128 </window>