summaryrefslogtreecommitdiffstats
path: root/docshell/test/chrome/bug396649_window.xhtml
blob: c378f11dc3587a020a65aa0fcdd5078e54d90c1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<window id="396649Test"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        width="600"
        height="600"
        onload="setTimeout(nextTest, 0);"
        title="bug 396649 test">

  <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
  <script type="application/javascript" src="docshell_helpers.js" />
  <script type="application/javascript"><![CDATA[
    Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false);
  
    // Define the generator-iterator for the tests.
    var tests = testIterator();
    
    // Maximum number of entries in the bfcache for this session history.
    // This number is hardcoded in docshell code.  In the test, we'll
    // navigate through enough pages so that we hit one that's been
    // evicted from the bfcache because it's farther from the current
    // page than this number.
    const MAX_BFCACHE_PAGES = 3;

    ////
    // Execute the next test in the generator function.
    //
    function nextTest() {
      tests.next();
    }

    ////
    // Generator function for test steps for bug 396649:  Content
    // viewers should be evicted from bfcache when going back if more
    // than MAX_BFCACHE_PAGES from the current index.
    //
    function* testIterator()
    {
      // Make sure bfcache is on.
      enableBFCache(true);
      
      // Load enough pages so that the first loaded is eviced from
      // the bfcache, since it is greater the MAX_BFCACHE_PAGES from
      // the current position in the session history. Verify all
      // of the pages are initially stored in the bfcache when
      // they're unloaded.
      for (var i = 0; i <= MAX_BFCACHE_PAGES + 1; i++) {
        let eventsToListenFor = ["pageshow"];
        let expectedEvents = [ { type: "pageshow",
                                 title: "bug396649 page" + i } ];
        if (i > 0) {
          eventsToListenFor.push("pagehide");
          expectedEvents.unshift({ type: "pagehide",
                                   title: "bug396649 page" + (i-1) });
        }
        doPageNavigation( {
           uri: "data:text/html,<!DOCTYPE html><html>" + 
                "<head><title>bug396649 page" + i + 
                "</title></head>" +
                "<body>" + 
                "test page " + i +
                "</body></html>",
           eventsToListenFor,
           expectedEvents,
           onNavComplete: nextTest 
          } );
        yield undefined;
      }

      // Go back to the first page, one page at a time.  The first 
      // MAX_BFCACHE_PAGES pages loaded via back should come from the bfcache, 
      // the last should not, since it should have been evicted during the 
      // previous navigation sequence.  Verify all pages are initially stored
      // in the bfcache when they're unloaded.
      for (i = MAX_BFCACHE_PAGES + 1; i > 0; i--) {
        doPageNavigation( {
          back: true,
          eventsToListenFor: ["pageshow", "pagehide"],
          expectedEvents: [ { type: "pagehide",
                              title: "bug396649 page" + i,
                              persisted: true },
                            { type: "pageshow", 
                              title: "bug396649 page" + (i - 1),
                              persisted: i > 1 } ],
          onNavComplete: nextTest
        } );
        yield undefined;
      }
      
      // Traverse history forward now.  Again, the first MAX_BFCACHE_PAGES
      // pages should come from the bfcache, the last should not,
      // since it should have been evicted during the backwards
      // traversal above.  Verify all pages are initially stored
      // in the bfcache when they're unloaded.
      for (i = 1; i <= MAX_BFCACHE_PAGES + 1; i++) {
        doPageNavigation( {
          forward: true,
          eventsToListenFor: ["pageshow", "pagehide"],
          expectedEvents: [ { type: "pagehide",
                              title: "bug396649 page" + (i-1),
                              persisted: true },
                            { type: "pageshow", 
                              title: "bug396649 page" + i,
                              persisted: i < MAX_BFCACHE_PAGES + 1 } ],
          onNavComplete: nextTest
        } );
        yield undefined;
      }
      
      Services.prefs.clearUserPref("browser.navigation.requireUserInteraction");
      // Tell the framework the test is finished.
      finish();
    }
    
  ]]></script>

  <browser type="content" primary="true" flex="1" id="content" remote="true" maychangeremoteness="true" />
</window>