summaryrefslogtreecommitdiff
path: root/system/docshell/test/chrome/bug360511_window.xul
blob: 9d0cde7f1fcad44bd8a49dfe98f7ca5c8289a19c (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<window id="360511Test"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        width="600"
        height="600"
        onload="setTimeout(nextTest,0);"
        title="bug 360511 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[
  
    // Define the generator-iterator for the tests.
    var tests = testIterator();

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

    ////
    // Generator function for test steps for bug 360511:  
    // Fragment uri's in session history should be restored correctly
    // upon back navigation.
    //
    function testIterator()
    {
      // Case 1: load a page containing a fragment link; the page should be 
      // stored in the bfcache.
      // Case 2: load a page containing a fragment link; the page should NOT 
      // be stored in the bfcache.
      for (var i = 1; i < 3; i++)
      {
        var url = "bug360511_case" + i + ".html";
        doPageNavigation( {
          uri: getHttpUrl(url),
          onNavComplete: nextTest,
          preventBFCache: i != 1
        } );
        yield undefined;
      
        // Store the original url for later comparison.
        var originalUrl = TestWindow.getBrowser().currentURI.spec;
        var originalDocLocation = TestWindow.getDocument().location.href;
        
        // Verify we're at the top of the page.
        is(TestWindow.getWindow().scrollY, 0, 
          "Page initially has a non-zero scrollY property");
      
        // Click the on the fragment link in the browser, and use setTimeout 
        // to give the event a chance to be processed.
        var event = TestWindow.getDocument().createEvent('MouseEvent');
        event.initMouseEvent("click", true, true, TestWindow.getWindow(), 0,
          0, 0, 0, 0,
          false, false, false, false, 0, null);
        TestWindow.getDocument().getElementById("link1").dispatchEvent(event);
        setTimeout(nextTest, 0);
        yield undefined;

        // Store the fragment url for later comparison.
        var fragmentUrl = TestWindow.getBrowser().currentURI.spec;
        var fragDocLocation = TestWindow.getDocument().location.href;
        
        // Verify we're no longer at the top of the page.
        ok(TestWindow.getWindow().scrollY > 0,
          "We're at the top of the page but we should be at the bottom");
      
        // Now navigate to any other page
        var expectedPageTitle = "bug360511 case " + i;
        doPageNavigation( {
          uri: getHttpUrl("generic.html"),
          eventsToListenFor: ["pagehide", "pageshow"],
          expectedEvents: [ {type: "pagehide", title: expectedPageTitle,
                             persisted: i == 1},
                            {type: "pageshow"} ],
          onNavComplete: nextTest
        } );
        yield undefined;
      
        // Go back
        doPageNavigation( {
          back: true,
          eventsToListenFor: ["pageshow"],
          expectedEvents: [ {type: "pageshow", title: expectedPageTitle, 
                             persisted: i == 1} ],
          onNavComplete: nextTest
        } );
        yield undefined;
      
        // Verify the current url is the fragment url
        is(TestWindow.getBrowser().currentURI.spec, fragmentUrl, 
          "current url is not the previous fragment url");
        is(TestWindow.getDocument().location.href, fragDocLocation,
          "document.location is not the previous fragment url");
        
        // Go back again.  Since we're just going from a fragment url to 
        // parent url, no pageshow event is fired, so don't wait for any 
        // events.  Rather, just wait for the page's scrollY property to 
        // change.
        var originalScrollY = TestWindow.getWindow().scrollY;
        doPageNavigation( {
          back: true,
          eventsToListenFor: []
        } );
        waitForTrue( 
          function() {
            return (TestWindow.getWindow().scrollY != originalScrollY);
          }, 
          function() {
            setTimeout(nextTest, 0);
          }, 20);      
        yield undefined;
      
        // Verify the current url is the original url without fragment
        is(TestWindow.getBrowser().currentURI.spec, originalUrl, 
          "current url is not the original url");
        is(TestWindow.getDocument().location.href, originalDocLocation,
          "document.location is not the original url");
      }
                      
      // Tell the framework the test is finished.  Include the final 'yield' 
      // statement to prevent a StopIteration exception from being thrown.
      finish();
      yield undefined;
    }
    
  ]]></script>

  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
</window>