|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 |
|
4 <window id="360511Test" |
|
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 360511 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 |
|
15 // Define the generator-iterator for the tests. |
|
16 var tests = testIterator(); |
|
17 |
|
18 //// |
|
19 // Execute the next test in the generator function. |
|
20 // |
|
21 function nextTest() { |
|
22 tests.next(); |
|
23 } |
|
24 |
|
25 //// |
|
26 // Generator function for test steps for bug 360511: |
|
27 // Fragment uri's in session history should be restored correctly |
|
28 // upon back navigation. |
|
29 // |
|
30 function testIterator() |
|
31 { |
|
32 // Case 1: load a page containing a fragment link; the page should be |
|
33 // stored in the bfcache. |
|
34 // Case 2: load a page containing a fragment link; the page should NOT |
|
35 // be stored in the bfcache. |
|
36 for (var i = 1; i < 3; i++) |
|
37 { |
|
38 var url = "bug360511_case" + i + ".html"; |
|
39 doPageNavigation( { |
|
40 uri: getHttpUrl(url), |
|
41 onNavComplete: nextTest, |
|
42 preventBFCache: i != 1 |
|
43 } ); |
|
44 yield undefined; |
|
45 |
|
46 // Store the original url for later comparison. |
|
47 var originalUrl = TestWindow.getBrowser().currentURI.spec; |
|
48 var originalDocLocation = TestWindow.getDocument().location.href; |
|
49 |
|
50 // Verify we're at the top of the page. |
|
51 is(TestWindow.getWindow().scrollY, 0, |
|
52 "Page initially has a non-zero scrollY property"); |
|
53 |
|
54 // Click the on the fragment link in the browser, and use setTimeout |
|
55 // to give the event a chance to be processed. |
|
56 var event = TestWindow.getDocument().createEvent('MouseEvent'); |
|
57 event.initMouseEvent("click", true, true, TestWindow.getWindow(), 0, |
|
58 0, 0, 0, 0, |
|
59 false, false, false, false, 0, null); |
|
60 TestWindow.getDocument().getElementById("link1").dispatchEvent(event); |
|
61 setTimeout(nextTest, 0); |
|
62 yield undefined; |
|
63 |
|
64 // Store the fragment url for later comparison. |
|
65 var fragmentUrl = TestWindow.getBrowser().currentURI.spec; |
|
66 var fragDocLocation = TestWindow.getDocument().location.href; |
|
67 |
|
68 // Verify we're no longer at the top of the page. |
|
69 ok(TestWindow.getWindow().scrollY > 0, |
|
70 "We're at the top of the page but we should be at the bottom"); |
|
71 |
|
72 // Now navigate to any other page |
|
73 var expectedPageTitle = "bug360511 case " + i; |
|
74 doPageNavigation( { |
|
75 uri: getHttpUrl("generic.html"), |
|
76 eventsToListenFor: ["pagehide", "pageshow"], |
|
77 expectedEvents: [ {type: "pagehide", title: expectedPageTitle, |
|
78 persisted: i == 1}, |
|
79 {type: "pageshow"} ], |
|
80 onNavComplete: nextTest |
|
81 } ); |
|
82 yield undefined; |
|
83 |
|
84 // Go back |
|
85 doPageNavigation( { |
|
86 back: true, |
|
87 eventsToListenFor: ["pageshow"], |
|
88 expectedEvents: [ {type: "pageshow", title: expectedPageTitle, |
|
89 persisted: i == 1} ], |
|
90 onNavComplete: nextTest |
|
91 } ); |
|
92 yield undefined; |
|
93 |
|
94 // Verify the current url is the fragment url |
|
95 is(TestWindow.getBrowser().currentURI.spec, fragmentUrl, |
|
96 "current url is not the previous fragment url"); |
|
97 is(TestWindow.getDocument().location.href, fragDocLocation, |
|
98 "document.location is not the previous fragment url"); |
|
99 |
|
100 // Go back again. Since we're just going from a fragment url to |
|
101 // parent url, no pageshow event is fired, so don't wait for any |
|
102 // events. Rather, just wait for the page's scrollY property to |
|
103 // change. |
|
104 var originalScrollY = TestWindow.getWindow().scrollY; |
|
105 doPageNavigation( { |
|
106 back: true, |
|
107 eventsToListenFor: [] |
|
108 } ); |
|
109 waitForTrue( |
|
110 function() { |
|
111 return (TestWindow.getWindow().scrollY != originalScrollY); |
|
112 }, |
|
113 function() { |
|
114 setTimeout(nextTest, 0); |
|
115 }, 20); |
|
116 yield undefined; |
|
117 |
|
118 // Verify the current url is the original url without fragment |
|
119 is(TestWindow.getBrowser().currentURI.spec, originalUrl, |
|
120 "current url is not the original url"); |
|
121 is(TestWindow.getDocument().location.href, originalDocLocation, |
|
122 "document.location is not the original url"); |
|
123 } |
|
124 |
|
125 // Tell the framework the test is finished. Include the final 'yield' |
|
126 // statement to prevent a StopIteration exception from being thrown. |
|
127 finish(); |
|
128 yield undefined; |
|
129 } |
|
130 |
|
131 ]]></script> |
|
132 |
|
133 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
134 </window> |