docshell/test/chrome/bug396649_window.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     4 <window id="396649Test"
     5         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     6         width="600"
     7         height="600"
     8         onload="setTimeout(nextTest,0);"
     9         title="bug 396649 test">
    11   <script type="text/javascript"
    12           src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/>
    13   <script type="text/javascript"
    14           src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/>
    15   <script type="text/javascript"
    16           src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/>
    17   <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
    18   <script type="application/javascript" src="docshell_helpers.js" />
    19   <script type="application/javascript"><![CDATA[
    21     // Define the generator-iterator for the tests.
    22     var tests = testIterator();
    24     // Maximum number of entries in the bfcache for this session history.
    25     // This number is hardcoded in docshell code.  In the test, we'll
    26     // navigate through enough pages so that we hit one that's been
    27     // evicted from the bfcache because it's farther from the current
    28     // page than this number.
    29     const MAX_BFCACHE_PAGES = 3;
    31     ////
    32     // Execute the next test in the generator function.
    33     //
    34     function nextTest() {
    35       tests.next();
    36     }
    38     ////
    39     // Generator function for test steps for bug 396649:  Content
    40     // viewers should be evicted from bfcache when going back if more
    41     // than MAX_BFCACHE_PAGES from the current index.
    42     //
    43     function testIterator()
    44     {
    45       // Make sure bfcache is on.
    46       enableBFCache(true);
    48       // Load enough pages so that the first loaded is eviced from
    49       // the bfcache, since it is greater the MAX_BFCACHE_PAGES from
    50       // the current position in the session history. Verify all
    51       // of the pages are initially stored in the bfcache when
    52       // they're unloaded.
    53       for (var i = 0; i <= MAX_BFCACHE_PAGES + 1; i++) {
    54         doPageNavigation( {
    55            uri: "data:text/html,<!DOCTYPE html><html>" + 
    56                 "<head><title>bug396649 page" + i + 
    57                 "</title></head>" +
    58                 "<body>" + 
    59                 "test page " + i +
    60                 "</body></html>",
    61            eventsToListenFor: ["pageshow", "pagehide"],
    62            expectedEvents: [ { type: "pagehide",
    63                                title: i == 0 ? 
    64                                  undefined : "bug396649 page" + (i-1),
    65                                persisted: true },
    66                              { type: "pageshow", 
    67                                title: "bug396649 page" + i } ],
    68            onNavComplete: nextTest 
    69           } );
    70         yield undefined;
    71       }
    73       // Go back to the first page, one page at a time.  The first 
    74       // MAX_BFCACHE_PAGES pages loaded via back should come from the bfcache, 
    75       // the last should not, since it should have been evicted during the 
    76       // previous navigation sequence.  Verify all pages are initially stored
    77       // in the bfcache when they're unloaded.
    78       for (i = MAX_BFCACHE_PAGES + 1; i > 0; i--) {
    79         doPageNavigation( {
    80           back: true,
    81           eventsToListenFor: ["pageshow", "pagehide"],
    82           expectedEvents: [ { type: "pagehide",
    83                               title: "bug396649 page" + i,
    84                               persisted: true },
    85                             { type: "pageshow", 
    86                               title: "bug396649 page" + (i - 1),
    87                               persisted: i > 1 } ],
    88           onNavComplete: nextTest
    89         } );
    90         yield undefined;
    91       }
    93       // Traverse history forward now.  Again, the first MAX_BFCACHE_PAGES
    94       // pages should come from the bfcache, the last should not,
    95       // since it should have been evicted during the backwards
    96       // traversal above.  Verify all pages are initially stored
    97       // in the bfcache when they're unloaded.
    98       for (i = 1; i <= MAX_BFCACHE_PAGES + 1; i++) {
    99         doPageNavigation( {
   100           forward: true,
   101           eventsToListenFor: ["pageshow", "pagehide"],
   102           expectedEvents: [ { type: "pagehide",
   103                               title: "bug396649 page" + (i-1),
   104                               persisted: true },
   105                             { type: "pageshow", 
   106                               title: "bug396649 page" + i,
   107                               persisted: i < MAX_BFCACHE_PAGES + 1 } ],
   108           onNavComplete: nextTest
   109         } );
   110         yield undefined;
   111       }
   113       // Tell the framework the test is finished.  Include the final 'yield' 
   114       // statement to prevent a StopIteration exception from being thrown.
   115       finish();
   116       yield undefined;
   117     }
   119   ]]></script>
   121   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   122 </window>

mercurial