|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 |
|
4 <window id="298622Test" |
|
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 298622 test"> |
|
10 |
|
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[ |
|
20 // Global variable that holds a reference to the find bar. |
|
21 var gFindBar; |
|
22 |
|
23 // Define the generator-iterator for the tests. |
|
24 var tests = testIterator(); |
|
25 |
|
26 //// |
|
27 // Execute the next test in the generator function. |
|
28 // |
|
29 function nextTest() { |
|
30 tests.next(); |
|
31 } |
|
32 |
|
33 //// |
|
34 // Generator function for test steps for bug 298622: |
|
35 // Find should work correctly on a page loaded from the |
|
36 // bfcache. |
|
37 // |
|
38 function testIterator() |
|
39 { |
|
40 // Make sure bfcache is on. |
|
41 enableBFCache(true); |
|
42 |
|
43 // Load a test page which contains some text to be found. |
|
44 doPageNavigation({ |
|
45 uri: "data:text/html,<html><head><title>test1</title></head>" + |
|
46 "<body>find this!</body></html>", |
|
47 onNavComplete: nextTest |
|
48 }); |
|
49 yield undefined; |
|
50 |
|
51 // Load a second, dummy page, verifying that the original |
|
52 // page gets stored in the bfcache. |
|
53 doPageNavigation({ |
|
54 uri: getHttpUrl("generic.html"), |
|
55 eventsToListenFor: ["pageshow", "pagehide"], |
|
56 expectedEvents: [ { type: "pagehide", |
|
57 title: "test1", |
|
58 persisted: true }, |
|
59 { type: "pageshow", |
|
60 title: "generic page" } ], |
|
61 onNavComplete: nextTest |
|
62 }); |
|
63 yield undefined; |
|
64 |
|
65 // Make sure we unsuppress painting before continuing |
|
66 SimpleTest.executeSoon(nextTest); |
|
67 yield undefined; |
|
68 |
|
69 // Search for some text that's on the second page (but not on |
|
70 // the first page), and verify that it can be found. |
|
71 gFindBar = document.getElementById("FindToolbar"); |
|
72 document.getElementById("cmd_find").doCommand(); |
|
73 ok(!gFindBar.hidden, "failed to open findbar"); |
|
74 gFindBar._findField.value = "A generic page"; |
|
75 gFindBar._find(); |
|
76 SimpleTest.executeSoon(nextTest); |
|
77 yield undefined; |
|
78 |
|
79 // Make sure Find bar's internal status is not 'notfound' |
|
80 isnot(gFindBar._findField.getAttribute("status"), "notfound", |
|
81 "Findfield status attribute should not have been 'notfound'" + |
|
82 " after Find"); |
|
83 |
|
84 // Make sure the key events above have time to be processed |
|
85 // before continuing |
|
86 waitForTrue(function() { |
|
87 return ( |
|
88 TestWindow.getWindow().getSelection().toString().toLowerCase() == |
|
89 "a generic page"); |
|
90 }, nextTest, 20); |
|
91 yield undefined; |
|
92 |
|
93 is(gFindBar._findField.inputField.value, "A generic page", |
|
94 "expected text not present in find input field"); |
|
95 is(TestWindow.getWindow().getSelection().toString().toLowerCase(), |
|
96 "a generic page", |
|
97 "find failed on second page loaded"); |
|
98 |
|
99 // Go back to the original page and verify it's loaded from the |
|
100 // bfcache. |
|
101 doPageNavigation({ |
|
102 back: true, |
|
103 eventsToListenFor: ["pageshow"], |
|
104 expectedEvents: [ { type: "pageshow", |
|
105 title: "test1", |
|
106 persisted: true } ], |
|
107 onNavComplete: nextTest |
|
108 }); |
|
109 yield undefined; |
|
110 |
|
111 // Search for some text that's on the original page (but not |
|
112 // the dummy page loaded above), and verify that it can |
|
113 // be found. |
|
114 gFindBar = document.getElementById("FindToolbar"); |
|
115 document.getElementById("cmd_find").doCommand(); |
|
116 ok(!gFindBar.hidden, "failed to open findbar"); |
|
117 gFindBar._findField.value = "find this"; |
|
118 gFindBar._find(); |
|
119 SimpleTest.executeSoon(nextTest); |
|
120 yield undefined; |
|
121 |
|
122 // Make sure Find bar's internal status is not 'notfound' |
|
123 isnot(gFindBar._findField.getAttribute("status"), "notfound", |
|
124 "Findfield status attribute should not have been 'notfound'" + |
|
125 " after Find"); |
|
126 |
|
127 // Make sure the key events above have time to be processed |
|
128 // before continuing |
|
129 waitForTrue(function() { |
|
130 return ( |
|
131 TestWindow.getWindow().getSelection().toString().toLowerCase() == |
|
132 "find this"); |
|
133 }, nextTest, 20); |
|
134 yield undefined; |
|
135 |
|
136 is(TestWindow.getWindow().getSelection().toString().toLowerCase(), |
|
137 "find this", |
|
138 "find failed on page loaded from bfcache"); |
|
139 |
|
140 // Tell the framework the test is finished. Include the final 'yield' |
|
141 // statement to prevent a StopIteration exception from being thrown. |
|
142 finish(); |
|
143 yield undefined; |
|
144 } |
|
145 |
|
146 ]]></script> |
|
147 |
|
148 <commandset> |
|
149 <command id="cmd_find" |
|
150 oncommand="document.getElementById('FindToolbar').onFindCommand();"/> |
|
151 </commandset> |
|
152 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
153 <findbar id="FindToolbar" browserid="content"/> |
|
154 </window> |