OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "chrome/common/url_constants.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/test/automation/automation_proxy.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/test/automation/browser_proxy.h" | 8 #include "chrome/test/base/in_process_browser_test.h" |
9 #include "chrome/test/automation/tab_proxy.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
10 #include "chrome/test/ui/ui_test.h" | 10 #include "content/public/browser/notification_service.h" |
11 #include "grit/generated_resources.h" | 11 #include "content/public/browser/notification_types.h" |
12 #include "net/base/net_util.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/common/url_constants.h" |
13 #include "net/test/test_server.h" | 14 #include "net/test/test_server.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 namespace { | 17 class SessionHistoryTest : public InProcessBrowserTest { |
16 | |
17 class SessionHistoryTest : public UITest { | |
18 protected: | 18 protected: |
19 SessionHistoryTest() | 19 SessionHistoryTest() { |
20 : test_server_(net::TestServer::TYPE_HTTP, | 20 EnableDOMAutomation(); |
21 net::TestServer::kLocalhost, | |
22 FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { | |
23 dom_automation_enabled_ = true; | |
24 } | 21 } |
25 | 22 |
26 virtual void SetUp() { | 23 virtual void SetUpOnMainThread() { |
27 UITest::SetUp(); | 24 ASSERT_TRUE(test_server()->Start()); |
28 | |
29 window_ = automation()->GetBrowserWindow(0); | |
30 ASSERT_TRUE(window_.get()); | |
31 | |
32 tab_ = window_->GetActiveTab(); | |
33 ASSERT_TRUE(tab_.get()); | |
34 } | 25 } |
35 | 26 |
36 // Simulate clicking a link. Only works on the frames.html testserver page. | 27 // Simulate clicking a link. Only works on the frames.html testserver page. |
37 void ClickLink(std::string node_id) { | 28 void ClickLink(std::string node_id) { |
38 GURL url("javascript:clickLink('" + node_id + "')"); | 29 GURL url("javascript:clickLink('" + node_id + "')"); |
39 ASSERT_TRUE(tab_->NavigateToURL(url)); | 30 ui_test_utils::NavigateToURL(browser(), url); |
40 } | 31 } |
41 | 32 |
42 // Simulate filling in form data. Only works on the frames.html page with | 33 // Simulate filling in form data. Only works on the frames.html page with |
43 // subframe = form.html, and on form.html itself. | 34 // subframe = form.html, and on form.html itself. |
44 void FillForm(std::string node_id, std::string value) { | 35 void FillForm(std::string node_id, std::string value) { |
45 GURL url("javascript:fillForm('" + node_id + "', '" + value + "')"); | 36 GURL url("javascript:fillForm('" + node_id + "', '" + value + "')"); |
46 // This will return immediately, but since the JS executes synchronously | 37 // This will return immediately, but since the JS executes synchronously |
47 // on the renderer, it will complete before the next navigate message is | 38 // on the renderer, it will complete before the next navigate message is |
48 // processed. | 39 // processed. |
49 ASSERT_TRUE(tab_->NavigateToURLAsync(url)); | 40 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, 0); |
50 } | 41 } |
51 | 42 |
52 // Simulate submitting a form. Only works on the frames.html page with | 43 // Simulate submitting a form. Only works on the frames.html page with |
53 // subframe = form.html, and on form.html itself. | 44 // subframe = form.html, and on form.html itself. |
54 void SubmitForm(std::string node_id) { | 45 void SubmitForm(std::string node_id) { |
55 GURL url("javascript:submitForm('" + node_id + "')"); | 46 GURL url("javascript:submitForm('" + node_id + "')"); |
56 ASSERT_TRUE(tab_->NavigateToURL(url)); | 47 ui_test_utils::NavigateToURL(browser(), url); |
57 } | 48 } |
58 | 49 |
59 // Navigate session history using history.go(distance). | 50 // Navigate session history using history.go(distance). |
60 void JavascriptGo(std::string distance) { | 51 void JavascriptGo(std::string distance) { |
61 GURL url("javascript:history.go('" + distance + "')"); | 52 GURL url("javascript:history.go('" + distance + "')"); |
62 ASSERT_TRUE(tab_->NavigateToURL(url)); | 53 ui_test_utils::NavigateToURL(browser(), url); |
63 } | 54 } |
64 | 55 |
65 std::wstring GetTabTitle() { | 56 std::string GetTabTitle() { |
66 std::wstring title; | 57 return UTF16ToASCII(browser()->GetSelectedWebContents()->GetTitle()); |
67 EXPECT_TRUE(tab_->GetTabTitle(&title)); | |
68 return title; | |
69 } | 58 } |
70 | 59 |
71 GURL GetTabURL() { | 60 GURL GetTabURL() { |
72 GURL url; | 61 return browser()->GetSelectedWebContents()->GetURL(); |
73 EXPECT_TRUE(tab_->GetCurrentURL(&url)); | 62 } |
74 return url; | 63 |
75 } | 64 GURL GetURL(const std::string file) { |
76 | 65 return test_server()->GetURL(std::string("files/session_history/") + file); |
77 protected: | 66 } |
78 scoped_refptr<BrowserProxy> window_; | 67 |
79 scoped_refptr<TabProxy> tab_; | 68 void NavigateAndCheckTitle(const char* filename, |
80 | 69 const std::string& expected_title) { |
81 net::TestServer test_server_; | 70 string16 expected_title16(ASCIIToUTF16(expected_title)); |
| 71 ui_test_utils::TitleWatcher title_watcher( |
| 72 browser()->GetSelectedWebContents(), expected_title16); |
| 73 ui_test_utils::NavigateToURL(browser(), GetURL(filename)); |
| 74 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
| 75 } |
| 76 |
| 77 void GoBack() { |
| 78 ui_test_utils::WindowedNotificationObserver load_stop_observer( |
| 79 content::NOTIFICATION_LOAD_STOP, |
| 80 content::NotificationService::AllSources()); |
| 81 browser()->GoBack(CURRENT_TAB); |
| 82 load_stop_observer.Wait(); |
| 83 } |
| 84 |
| 85 void GoForward() { |
| 86 ui_test_utils::WindowedNotificationObserver load_stop_observer( |
| 87 content::NOTIFICATION_LOAD_STOP, |
| 88 content::NotificationService::AllSources()); |
| 89 browser()->GoForward(CURRENT_TAB); |
| 90 load_stop_observer.Wait(); |
| 91 } |
82 }; | 92 }; |
83 | 93 |
84 #if defined(OS_WIN) || defined(OS_MACOSX) | 94 // If this flakes, use http://crbug.com/61619 on windows and |
85 // See http://crbug.com/61619 on windows. | 95 // http://crbug.com/102094 on mac. |
86 // See http://crbug.com/102094 on mac. | 96 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) { |
87 #define MAYBE_BasicBackForward DISABLED_BasicBackForward | |
88 #else | |
89 #define MAYBE_BasicBackForward BasicBackForward | |
90 #endif | |
91 | |
92 TEST_F(SessionHistoryTest, MAYBE_BasicBackForward) { | |
93 ASSERT_TRUE(test_server_.Start()); | |
94 | |
95 // about:blank should be loaded first. | 97 // about:blank should be loaded first. |
96 ASSERT_FALSE(tab_->GoBack()); | 98 ASSERT_FALSE(browser()->CanGoBack()); |
97 EXPECT_EQ(L"about:blank", GetTabTitle()); | 99 EXPECT_EQ("about:blank", GetTabTitle()); |
98 | 100 |
99 ASSERT_TRUE(tab_->NavigateToURL( | 101 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1")); |
100 test_server_.GetURL("files/session_history/bot1.html"))); | 102 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2")); |
101 EXPECT_EQ(L"bot1", GetTabTitle()); | 103 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); |
102 | |
103 ASSERT_TRUE(tab_->NavigateToURL( | |
104 test_server_.GetURL("files/session_history/bot2.html"))); | |
105 EXPECT_EQ(L"bot2", GetTabTitle()); | |
106 | |
107 ASSERT_TRUE(tab_->NavigateToURL( | |
108 test_server_.GetURL("files/session_history/bot3.html"))); | |
109 EXPECT_EQ(L"bot3", GetTabTitle()); | |
110 | 104 |
111 // history is [blank, bot1, bot2, *bot3] | 105 // history is [blank, bot1, bot2, *bot3] |
112 | 106 |
113 ASSERT_TRUE(tab_->GoBack()); | 107 GoBack(); |
114 EXPECT_EQ(L"bot2", GetTabTitle()); | 108 EXPECT_EQ("bot2", GetTabTitle()); |
115 | 109 |
116 ASSERT_TRUE(tab_->GoBack()); | 110 GoBack(); |
117 EXPECT_EQ(L"bot1", GetTabTitle()); | 111 EXPECT_EQ("bot1", GetTabTitle()); |
118 | 112 |
119 ASSERT_TRUE(tab_->GoForward()); | 113 GoForward(); |
120 EXPECT_EQ(L"bot2", GetTabTitle()); | 114 EXPECT_EQ("bot2", GetTabTitle()); |
121 | 115 |
122 ASSERT_TRUE(tab_->GoBack()); | 116 GoBack(); |
123 EXPECT_EQ(L"bot1", GetTabTitle()); | 117 EXPECT_EQ("bot1", GetTabTitle()); |
124 | 118 |
125 ASSERT_TRUE(tab_->NavigateToURL( | 119 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); |
126 test_server_.GetURL("files/session_history/bot3.html"))); | |
127 EXPECT_EQ(L"bot3", GetTabTitle()); | |
128 | 120 |
129 // history is [blank, bot1, *bot3] | 121 // history is [blank, bot1, *bot3] |
130 | 122 |
131 ASSERT_FALSE(tab_->GoForward()); | 123 ASSERT_FALSE(browser()->CanGoForward()); |
132 EXPECT_EQ(L"bot3", GetTabTitle()); | 124 EXPECT_EQ("bot3", GetTabTitle()); |
133 | 125 |
134 ASSERT_TRUE(tab_->GoBack()); | 126 GoBack(); |
135 EXPECT_EQ(L"bot1", GetTabTitle()); | 127 EXPECT_EQ("bot1", GetTabTitle()); |
136 | 128 |
137 ASSERT_TRUE(tab_->GoBack()); | 129 GoBack(); |
138 EXPECT_EQ(L"about:blank", GetTabTitle()); | 130 EXPECT_EQ("about:blank", GetTabTitle()); |
139 | 131 |
140 ASSERT_FALSE(tab_->GoBack()); | 132 ASSERT_FALSE(browser()->CanGoBack()); |
141 EXPECT_EQ(L"about:blank", GetTabTitle()); | 133 EXPECT_EQ("about:blank", GetTabTitle()); |
142 | 134 |
143 ASSERT_TRUE(tab_->GoForward()); | 135 GoForward(); |
144 EXPECT_EQ(L"bot1", GetTabTitle()); | 136 EXPECT_EQ("bot1", GetTabTitle()); |
145 | 137 |
146 ASSERT_TRUE(tab_->GoForward()); | 138 GoForward(); |
147 EXPECT_EQ(L"bot3", GetTabTitle()); | 139 EXPECT_EQ("bot3", GetTabTitle()); |
148 } | 140 } |
149 | 141 |
150 // Test that back/forward works when navigating in subframes. | 142 // Test that back/forward works when navigating in subframes. |
151 #if defined(OS_WIN) | 143 // If this flakes, use http://crbug.com/48833 |
152 // http://crbug.com/48833 | 144 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) { |
153 #define FrameBackForward DISABLED_FrameBackForward | |
154 #endif | |
155 TEST_F(SessionHistoryTest, FrameBackForward) { | |
156 ASSERT_TRUE(test_server_.Start()); | |
157 | |
158 // about:blank should be loaded first. | 145 // about:blank should be loaded first. |
159 GURL home(homepage()); | 146 GURL home(chrome::kAboutBlankURL); |
160 ASSERT_FALSE(tab_->GoBack()); | 147 ASSERT_FALSE(browser()->CanGoBack()); |
161 EXPECT_EQ(L"about:blank", GetTabTitle()); | 148 EXPECT_EQ("about:blank", GetTabTitle()); |
| 149 EXPECT_EQ(GURL(chrome::kAboutBlankURL), GetTabURL()); |
| 150 |
| 151 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); |
| 152 |
| 153 ClickLink("abot2"); |
| 154 EXPECT_EQ("bot2", GetTabTitle()); |
| 155 GURL frames(GetURL("frames.html")); |
| 156 EXPECT_EQ(frames, GetTabURL()); |
| 157 |
| 158 ClickLink("abot3"); |
| 159 EXPECT_EQ("bot3", GetTabTitle()); |
| 160 EXPECT_EQ(frames, GetTabURL()); |
| 161 |
| 162 // history is [blank, bot1, bot2, *bot3] |
| 163 |
| 164 GoBack(); |
| 165 EXPECT_EQ("bot2", GetTabTitle()); |
| 166 EXPECT_EQ(frames, GetTabURL()); |
| 167 |
| 168 GoBack(); |
| 169 EXPECT_EQ("bot1", GetTabTitle()); |
| 170 EXPECT_EQ(frames, GetTabURL()); |
| 171 |
| 172 GoBack(); |
| 173 EXPECT_EQ("about:blank", GetTabTitle()); |
162 EXPECT_EQ(home, GetTabURL()); | 174 EXPECT_EQ(home, GetTabURL()); |
163 | 175 |
164 GURL frames(test_server_.GetURL("files/session_history/frames.html")); | 176 GoForward(); |
165 ASSERT_TRUE(tab_->NavigateToURL(frames)); | 177 EXPECT_EQ("bot1", GetTabTitle()); |
166 EXPECT_EQ(L"bot1", GetTabTitle()); | 178 EXPECT_EQ(frames, GetTabURL()); |
167 EXPECT_EQ(frames, GetTabURL()); | 179 |
| 180 GoForward(); |
| 181 EXPECT_EQ("bot2", GetTabTitle()); |
| 182 EXPECT_EQ(frames, GetTabURL()); |
| 183 |
| 184 ClickLink("abot1"); |
| 185 EXPECT_EQ("bot1", GetTabTitle()); |
| 186 EXPECT_EQ(frames, GetTabURL()); |
| 187 |
| 188 // history is [blank, bot1, bot2, *bot1] |
| 189 |
| 190 ASSERT_FALSE(browser()->CanGoForward()); |
| 191 EXPECT_EQ("bot1", GetTabTitle()); |
| 192 EXPECT_EQ(frames, GetTabURL()); |
| 193 |
| 194 GoBack(); |
| 195 EXPECT_EQ("bot2", GetTabTitle()); |
| 196 EXPECT_EQ(frames, GetTabURL()); |
| 197 |
| 198 GoBack(); |
| 199 EXPECT_EQ("bot1", GetTabTitle()); |
| 200 EXPECT_EQ(frames, GetTabURL()); |
| 201 } |
| 202 |
| 203 // Test that back/forward preserves POST data and document state in subframes. |
| 204 // If this flakes use http://crbug.com/61619 |
| 205 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameFormBackForward) { |
| 206 // about:blank should be loaded first. |
| 207 ASSERT_FALSE(browser()->CanGoBack()); |
| 208 EXPECT_EQ("about:blank", GetTabTitle()); |
| 209 |
| 210 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); |
| 211 |
| 212 ClickLink("aform"); |
| 213 EXPECT_EQ("form", GetTabTitle()); |
| 214 GURL frames(GetURL("frames.html")); |
| 215 EXPECT_EQ(frames, GetTabURL()); |
| 216 |
| 217 SubmitForm("isubmit"); |
| 218 EXPECT_EQ("text=&select=a", GetTabTitle()); |
| 219 EXPECT_EQ(frames, GetTabURL()); |
| 220 |
| 221 GoBack(); |
| 222 EXPECT_EQ("form", GetTabTitle()); |
| 223 EXPECT_EQ(frames, GetTabURL()); |
| 224 |
| 225 // history is [blank, bot1, *form, post] |
168 | 226 |
169 ClickLink("abot2"); | 227 ClickLink("abot2"); |
170 EXPECT_EQ(L"bot2", GetTabTitle()); | 228 EXPECT_EQ("bot2", GetTabTitle()); |
171 EXPECT_EQ(frames, GetTabURL()); | 229 EXPECT_EQ(frames, GetTabURL()); |
172 | 230 |
173 ClickLink("abot3"); | 231 // history is [blank, bot1, form, *bot2] |
174 EXPECT_EQ(L"bot3", GetTabTitle()); | 232 |
175 EXPECT_EQ(frames, GetTabURL()); | 233 GoBack(); |
176 | 234 EXPECT_EQ("form", GetTabTitle()); |
177 // history is [blank, bot1, bot2, *bot3] | 235 EXPECT_EQ(frames, GetTabURL()); |
178 | 236 |
179 ASSERT_TRUE(tab_->GoBack()); | 237 SubmitForm("isubmit"); |
180 EXPECT_EQ(L"bot2", GetTabTitle()); | 238 EXPECT_EQ("text=&select=a", GetTabTitle()); |
181 EXPECT_EQ(frames, GetTabURL()); | 239 EXPECT_EQ(frames, GetTabURL()); |
182 | 240 |
183 ASSERT_TRUE(tab_->GoBack()); | 241 // history is [blank, bot1, form, *post] |
184 EXPECT_EQ(L"bot1", GetTabTitle()); | 242 |
185 EXPECT_EQ(frames, GetTabURL()); | 243 // TODO(mpcomplete): reenable this when WebKit bug 10199 is fixed: |
186 | 244 // "returning to a POST result within a frame does a GET instead of a POST" |
187 ASSERT_TRUE(tab_->GoBack()); | 245 ClickLink("abot2"); |
188 EXPECT_EQ(L"about:blank", GetTabTitle()); | 246 EXPECT_EQ("bot2", GetTabTitle()); |
189 EXPECT_EQ(home, GetTabURL()); | 247 EXPECT_EQ(frames, GetTabURL()); |
190 | 248 |
191 ASSERT_TRUE(tab_->GoForward()); | 249 GoBack(); |
192 EXPECT_EQ(L"bot1", GetTabTitle()); | 250 EXPECT_EQ("text=&select=a", GetTabTitle()); |
193 EXPECT_EQ(frames, GetTabURL()); | |
194 | |
195 ASSERT_TRUE(tab_->GoForward()); | |
196 EXPECT_EQ(L"bot2", GetTabTitle()); | |
197 EXPECT_EQ(frames, GetTabURL()); | |
198 | |
199 ClickLink("abot1"); | |
200 EXPECT_EQ(L"bot1", GetTabTitle()); | |
201 EXPECT_EQ(frames, GetTabURL()); | |
202 | |
203 // history is [blank, bot1, bot2, *bot1] | |
204 | |
205 ASSERT_FALSE(tab_->GoForward()); | |
206 EXPECT_EQ(L"bot1", GetTabTitle()); | |
207 EXPECT_EQ(frames, GetTabURL()); | |
208 | |
209 ASSERT_TRUE(tab_->GoBack()); | |
210 EXPECT_EQ(L"bot2", GetTabTitle()); | |
211 EXPECT_EQ(frames, GetTabURL()); | |
212 | |
213 ASSERT_TRUE(tab_->GoBack()); | |
214 EXPECT_EQ(L"bot1", GetTabTitle()); | |
215 EXPECT_EQ(frames, GetTabURL()); | 251 EXPECT_EQ(frames, GetTabURL()); |
216 } | 252 } |
217 | 253 |
218 // See http://crbug.com/61619 | |
219 // Test that back/forward preserves POST data and document state in subframes. | |
220 TEST_F(SessionHistoryTest, DISABLED_FrameFormBackForward) { | |
221 ASSERT_TRUE(test_server_.Start()); | |
222 | |
223 // about:blank should be loaded first. | |
224 ASSERT_FALSE(tab_->GoBack()); | |
225 EXPECT_EQ(L"", GetTabTitle()); | |
226 | |
227 GURL frames(test_server_.GetURL("files/session_history/frames.html")); | |
228 ASSERT_TRUE(tab_->NavigateToURL(frames)); | |
229 EXPECT_EQ(L"bot1", GetTabTitle()); | |
230 | |
231 ClickLink("aform"); | |
232 EXPECT_EQ(L"form", GetTabTitle()); | |
233 EXPECT_EQ(frames, GetTabURL()); | |
234 | |
235 SubmitForm("isubmit"); | |
236 EXPECT_EQ(L"text=&select=a", GetTabTitle()); | |
237 EXPECT_EQ(frames, GetTabURL()); | |
238 | |
239 ASSERT_TRUE(tab_->GoBack()); | |
240 EXPECT_EQ(L"form", GetTabTitle()); | |
241 EXPECT_EQ(frames, GetTabURL()); | |
242 | |
243 // history is [blank, bot1, *form, post] | |
244 | |
245 ClickLink("abot2"); | |
246 EXPECT_EQ(L"bot2", GetTabTitle()); | |
247 EXPECT_EQ(frames, GetTabURL()); | |
248 | |
249 // history is [blank, bot1, form, *bot2] | |
250 | |
251 ASSERT_TRUE(tab_->GoBack()); | |
252 EXPECT_EQ(L"form", GetTabTitle()); | |
253 EXPECT_EQ(frames, GetTabURL()); | |
254 | |
255 SubmitForm("isubmit"); | |
256 EXPECT_EQ(L"text=&select=a", GetTabTitle()); | |
257 EXPECT_EQ(frames, GetTabURL()); | |
258 | |
259 // history is [blank, bot1, form, *post] | |
260 | |
261 if (false) { | |
262 // TODO(mpcomplete): reenable this when WebKit bug 10199 is fixed: | |
263 // "returning to a POST result within a frame does a GET instead of a POST" | |
264 ClickLink("abot2"); | |
265 EXPECT_EQ(L"bot2", GetTabTitle()); | |
266 EXPECT_EQ(frames, GetTabURL()); | |
267 | |
268 ASSERT_TRUE(tab_->GoBack()); | |
269 EXPECT_EQ(L"text=&select=a", GetTabTitle()); | |
270 EXPECT_EQ(frames, GetTabURL()); | |
271 } | |
272 } | |
273 | |
274 // TODO(mpcomplete): enable this when Bug 734372 is fixed: | 254 // TODO(mpcomplete): enable this when Bug 734372 is fixed: |
275 // "Doing a session history navigation does not restore newly-created subframe | 255 // "Doing a session history navigation does not restore newly-created subframe |
276 // document state" | 256 // document state" |
277 // Test that back/forward preserves POST data and document state when navigating | 257 // Test that back/forward preserves POST data and document state when navigating |
278 // across frames (ie, from frame -> nonframe). | 258 // across frames (ie, from frame -> nonframe). |
279 // Hangs, see http://crbug.com/45058. | 259 // Hangs, see http://crbug.com/45058. |
280 TEST_F(SessionHistoryTest, DISABLED_CrossFrameFormBackForward) { | 260 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, CrossFrameFormBackForward) { |
281 ASSERT_TRUE(test_server_.Start()); | 261 // about:blank should be loaded first. |
| 262 ASSERT_FALSE(browser()->CanGoBack()); |
| 263 EXPECT_EQ("about:blank", GetTabTitle()); |
282 | 264 |
283 // about:blank should be loaded first. | 265 GURL frames(GetURL("frames.html")); |
284 ASSERT_FALSE(tab_->GoBack()); | 266 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); |
285 EXPECT_EQ(L"", GetTabTitle()); | |
286 | |
287 GURL frames(test_server_.GetURL("files/session_history/frames.html")); | |
288 ASSERT_TRUE(tab_->NavigateToURL(frames)); | |
289 EXPECT_EQ(L"bot1", GetTabTitle()); | |
290 | 267 |
291 ClickLink("aform"); | 268 ClickLink("aform"); |
292 EXPECT_EQ(L"form", GetTabTitle()); | 269 EXPECT_EQ("form", GetTabTitle()); |
293 EXPECT_EQ(frames, GetTabURL()); | 270 EXPECT_EQ(frames, GetTabURL()); |
294 | 271 |
295 SubmitForm("isubmit"); | 272 SubmitForm("isubmit"); |
296 EXPECT_EQ(L"text=&select=a", GetTabTitle()); | 273 EXPECT_EQ("text=&select=a", GetTabTitle()); |
297 EXPECT_EQ(frames, GetTabURL()); | 274 EXPECT_EQ(frames, GetTabURL()); |
298 | 275 |
299 ASSERT_TRUE(tab_->GoBack()); | 276 GoBack(); |
300 EXPECT_EQ(L"form", GetTabTitle()); | 277 EXPECT_EQ("form", GetTabTitle()); |
301 EXPECT_EQ(frames, GetTabURL()); | 278 EXPECT_EQ(frames, GetTabURL()); |
302 | 279 |
303 // history is [blank, bot1, *form, post] | 280 // history is [blank, bot1, *form, post] |
304 | 281 |
305 // ClickLink(L"abot2"); | 282 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2")); |
306 GURL bot2("files/session_history/bot2.html"); | |
307 ASSERT_TRUE(tab_->NavigateToURL(bot2)); | |
308 EXPECT_EQ(L"bot2", GetTabTitle()); | |
309 EXPECT_EQ(bot2, GetTabURL()); | |
310 | 283 |
311 // history is [blank, bot1, form, *bot2] | 284 // history is [blank, bot1, form, *bot2] |
312 | 285 |
313 ASSERT_TRUE(tab_->GoBack()); | 286 GoBack(); |
314 EXPECT_EQ(L"form", GetTabTitle()); | 287 EXPECT_EQ("bot1", GetTabTitle()); |
315 EXPECT_EQ(frames, GetTabURL()); | 288 EXPECT_EQ(frames, GetTabURL()); |
316 | 289 |
317 SubmitForm("isubmit"); | 290 SubmitForm("isubmit"); |
318 EXPECT_EQ(L"text=&select=a", GetTabTitle()); | 291 EXPECT_EQ("text=&select=a", GetTabTitle()); |
319 EXPECT_EQ(frames, GetTabURL()); | 292 EXPECT_EQ(frames, GetTabURL()); |
320 } | 293 } |
321 | 294 |
322 | |
323 #if defined(OS_WIN) | |
324 // See http://crbug.com/61619 | |
325 #define MAYBE_FragmentBackForward DISABLED_FragmentBackForward | |
326 #else | |
327 #define MAYBE_FragmentBackForward FragmentBackForward | |
328 #endif | |
329 | |
330 // Test that back/forward entries are created for reference fragment | 295 // Test that back/forward entries are created for reference fragment |
331 // navigations. Bug 730379. | 296 // navigations. Bug 730379. |
332 TEST_F(SessionHistoryTest, MAYBE_FragmentBackForward) { | 297 // If this flakes use http://crbug.com/61619. |
333 ASSERT_TRUE(test_server_.Start()); | 298 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) { |
| 299 // about:blank should be loaded first. |
| 300 ASSERT_FALSE(browser()->CanGoBack()); |
| 301 EXPECT_EQ("about:blank", GetTabTitle()); |
334 | 302 |
335 // about:blank should be loaded first. | 303 GURL fragment(GetURL("fragment.html")); |
336 ASSERT_FALSE(tab_->GoBack()); | 304 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html", "fragment")); |
337 EXPECT_EQ(L"about:blank", GetTabTitle()); | |
338 | 305 |
339 GURL fragment(test_server_.GetURL("files/session_history/fragment.html")); | 306 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#a", "fragment")); |
340 ASSERT_TRUE(tab_->NavigateToURL(fragment)); | 307 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#b", "fragment")); |
341 EXPECT_EQ(L"fragment", GetTabTitle()); | 308 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#c", "fragment")); |
342 EXPECT_EQ(fragment, GetTabURL()); | |
343 | |
344 GURL::Replacements ref_params; | |
345 | |
346 ref_params.SetRef("a", url_parse::Component(0, 1)); | |
347 GURL fragment_a(fragment.ReplaceComponents(ref_params)); | |
348 ASSERT_TRUE(tab_->NavigateToURL(fragment_a)); | |
349 EXPECT_EQ(L"fragment", GetTabTitle()); | |
350 EXPECT_EQ(fragment_a, GetTabURL()); | |
351 | |
352 ref_params.SetRef("b", url_parse::Component(0, 1)); | |
353 GURL fragment_b(fragment.ReplaceComponents(ref_params)); | |
354 ASSERT_TRUE(tab_->NavigateToURL(fragment_b)); | |
355 EXPECT_EQ(L"fragment", GetTabTitle()); | |
356 EXPECT_EQ(fragment_b, GetTabURL()); | |
357 | |
358 ref_params.SetRef("c", url_parse::Component(0, 1)); | |
359 GURL fragment_c(fragment.ReplaceComponents(ref_params)); | |
360 ASSERT_TRUE(tab_->NavigateToURL(fragment_c)); | |
361 EXPECT_EQ(L"fragment", GetTabTitle()); | |
362 EXPECT_EQ(fragment_c, GetTabURL()); | |
363 | 309 |
364 // history is [blank, fragment, fragment#a, fragment#b, *fragment#c] | 310 // history is [blank, fragment, fragment#a, fragment#b, *fragment#c] |
365 | 311 |
366 ASSERT_TRUE(tab_->GoBack()); | 312 GoBack(); |
367 EXPECT_EQ(fragment_b, GetTabURL()); | 313 EXPECT_EQ(GetURL("fragment.html#b"), GetTabURL()); |
368 | 314 |
369 ASSERT_TRUE(tab_->GoBack()); | 315 GoBack(); |
370 EXPECT_EQ(fragment_a, GetTabURL()); | 316 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL()); |
371 | 317 |
372 ASSERT_TRUE(tab_->GoBack()); | 318 GoBack(); |
373 EXPECT_EQ(fragment, GetTabURL()); | 319 EXPECT_EQ(GetURL("fragment.html"), GetTabURL()); |
374 | 320 |
375 ASSERT_TRUE(tab_->GoForward()); | 321 GoForward(); |
376 EXPECT_EQ(fragment_a, GetTabURL()); | 322 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL()); |
377 | 323 |
378 GURL bot3(test_server_.GetURL("files/session_history/bot3.html")); | 324 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); |
379 ASSERT_TRUE(tab_->NavigateToURL(bot3)); | |
380 EXPECT_EQ(L"bot3", GetTabTitle()); | |
381 EXPECT_EQ(bot3, GetTabURL()); | |
382 | 325 |
383 // history is [blank, fragment, fragment#a, bot3] | 326 // history is [blank, fragment, fragment#a, bot3] |
384 | 327 |
385 ASSERT_FALSE(tab_->GoForward()); | 328 ASSERT_FALSE(browser()->CanGoForward()); |
386 EXPECT_EQ(bot3, GetTabURL()); | 329 EXPECT_EQ(GetURL("bot3.html"), GetTabURL()); |
387 | 330 |
388 ASSERT_TRUE(tab_->GoBack()); | 331 GoBack(); |
389 EXPECT_EQ(fragment_a, GetTabURL()); | 332 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL()); |
390 | 333 |
391 ASSERT_TRUE(tab_->GoBack()); | 334 GoBack(); |
392 EXPECT_EQ(fragment, GetTabURL()); | 335 EXPECT_EQ(GetURL("fragment.html"), GetTabURL()); |
393 } | 336 } |
394 | 337 |
395 // Test that the javascript window.history object works. | 338 // Test that the javascript window.history object works. |
396 // NOTE: history.go(N) does not do anything if N is outside the bounds of the | 339 // NOTE: history.go(N) does not do anything if N is outside the bounds of the |
397 // back/forward list (such as trigger our start/stop loading events). This | 340 // back/forward list (such as trigger our start/stop loading events). This |
398 // means the test will hang if it attempts to navigate too far forward or back, | 341 // means the test will hang if it attempts to navigate too far forward or back, |
399 // since we'll be waiting forever for a load stop event. | 342 // since we'll be waiting forever for a load stop event. |
400 // | 343 // |
401 // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing | 344 // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing |
402 // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug). | 345 // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug). |
403 TEST_F(SessionHistoryTest, DISABLED_JavascriptHistory) { | 346 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) { |
404 ASSERT_TRUE(test_server_.Start()); | 347 // about:blank should be loaded first. |
| 348 ASSERT_FALSE(browser()->CanGoBack()); |
| 349 EXPECT_EQ("about:blank", GetTabTitle()); |
405 | 350 |
406 // about:blank should be loaded first. | 351 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1")); |
407 ASSERT_FALSE(tab_->GoBack()); | 352 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2")); |
408 EXPECT_EQ(L"about:blank", GetTabTitle()); | 353 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); |
409 | |
410 ASSERT_TRUE(tab_->NavigateToURL( | |
411 test_server_.GetURL("files/session_history/bot1.html"))); | |
412 EXPECT_EQ(L"bot1", GetTabTitle()); | |
413 | |
414 ASSERT_TRUE(tab_->NavigateToURL( | |
415 test_server_.GetURL("files/session_history/bot2.html"))); | |
416 EXPECT_EQ(L"bot2", GetTabTitle()); | |
417 | |
418 ASSERT_TRUE(tab_->NavigateToURL( | |
419 test_server_.GetURL("files/session_history/bot3.html"))); | |
420 EXPECT_EQ(L"bot3", GetTabTitle()); | |
421 | 354 |
422 // history is [blank, bot1, bot2, *bot3] | 355 // history is [blank, bot1, bot2, *bot3] |
423 | 356 |
424 JavascriptGo("-1"); | 357 JavascriptGo("-1"); |
425 EXPECT_EQ(L"bot2", GetTabTitle()); | 358 EXPECT_EQ("bot2", GetTabTitle()); |
426 | 359 |
427 JavascriptGo("-1"); | 360 JavascriptGo("-1"); |
428 EXPECT_EQ(L"bot1", GetTabTitle()); | 361 EXPECT_EQ("bot1", GetTabTitle()); |
429 | 362 |
430 JavascriptGo("1"); | 363 JavascriptGo("1"); |
431 EXPECT_EQ(L"bot2", GetTabTitle()); | 364 EXPECT_EQ("bot2", GetTabTitle()); |
432 | 365 |
433 JavascriptGo("-1"); | 366 JavascriptGo("-1"); |
434 EXPECT_EQ(L"bot1", GetTabTitle()); | 367 EXPECT_EQ("bot1", GetTabTitle()); |
435 | 368 |
436 JavascriptGo("2"); | 369 JavascriptGo("2"); |
437 EXPECT_EQ(L"bot3", GetTabTitle()); | 370 EXPECT_EQ("bot3", GetTabTitle()); |
438 | 371 |
439 // history is [blank, bot1, bot2, *bot3] | 372 // history is [blank, bot1, bot2, *bot3] |
440 | 373 |
441 JavascriptGo("-3"); | 374 JavascriptGo("-3"); |
442 EXPECT_EQ(L"about:blank", GetTabTitle()); | 375 EXPECT_EQ("about:blank", GetTabTitle()); |
443 | 376 |
444 ASSERT_FALSE(tab_->GoBack()); | 377 ASSERT_FALSE(browser()->CanGoBack()); |
445 EXPECT_EQ(L"about:blank", GetTabTitle()); | 378 EXPECT_EQ("about:blank", GetTabTitle()); |
446 | 379 |
447 JavascriptGo("1"); | 380 JavascriptGo("1"); |
448 EXPECT_EQ(L"bot1", GetTabTitle()); | 381 EXPECT_EQ("bot1", GetTabTitle()); |
449 | 382 |
450 ASSERT_TRUE(tab_->NavigateToURL( | 383 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); |
451 test_server_.GetURL("files/session_history/bot3.html"))); | |
452 EXPECT_EQ(L"bot3", GetTabTitle()); | |
453 | 384 |
454 // history is [blank, bot1, *bot3] | 385 // history is [blank, bot1, *bot3] |
455 | 386 |
456 ASSERT_FALSE(tab_->GoForward()); | 387 ASSERT_FALSE(browser()->CanGoForward()); |
457 EXPECT_EQ(L"bot3", GetTabTitle()); | 388 EXPECT_EQ("bot3", GetTabTitle()); |
458 | 389 |
459 JavascriptGo("-1"); | 390 JavascriptGo("-1"); |
460 EXPECT_EQ(L"bot1", GetTabTitle()); | 391 EXPECT_EQ("bot1", GetTabTitle()); |
461 | 392 |
462 JavascriptGo("-1"); | 393 JavascriptGo("-1"); |
463 EXPECT_EQ(L"about:blank", GetTabTitle()); | 394 EXPECT_EQ("about:blank", GetTabTitle()); |
464 | 395 |
465 ASSERT_FALSE(tab_->GoBack()); | 396 ASSERT_FALSE(browser()->CanGoBack()); |
466 EXPECT_EQ(L"about:blank", GetTabTitle()); | 397 EXPECT_EQ("about:blank", GetTabTitle()); |
467 | 398 |
468 JavascriptGo("1"); | 399 JavascriptGo("1"); |
469 EXPECT_EQ(L"bot1", GetTabTitle()); | 400 EXPECT_EQ("bot1", GetTabTitle()); |
470 | 401 |
471 JavascriptGo("1"); | 402 JavascriptGo("1"); |
472 EXPECT_EQ(L"bot3", GetTabTitle()); | 403 EXPECT_EQ("bot3", GetTabTitle()); |
473 | 404 |
474 // TODO(creis): Test that JavaScript history navigations work across tab | 405 // TODO(creis): Test that JavaScript history navigations work across tab |
475 // types. For example, load about:network in a tab, then a real page, then | 406 // types. For example, load about:network in a tab, then a real page, then |
476 // try to go back and forward with JavaScript. Bug 1136715. | 407 // try to go back and forward with JavaScript. Bug 1136715. |
477 // (Hard to test right now, because pages like about:network cause the | 408 // (Hard to test right now, because pages like about:network cause the |
478 // TabProxy to hang. This is because they do not appear to use the | 409 // TabProxy to hang. This is because they do not appear to use the |
479 // NotificationService.) | 410 // NotificationService.) |
480 } | 411 } |
481 | 412 |
482 // This test is failing consistently. See http://crbug.com/22560 | 413 // This test is failing consistently. See http://crbug.com/22560 |
483 TEST_F(SessionHistoryTest, FAILS_LocationReplace) { | 414 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationReplace) { |
484 ASSERT_TRUE(test_server_.Start()); | |
485 | |
486 // Test that using location.replace doesn't leave the title of the old page | 415 // Test that using location.replace doesn't leave the title of the old page |
487 // visible. | 416 // visible. |
488 ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL( | 417 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle( |
489 "files/session_history/replace.html?no-title.html"))); | 418 "replace.html?bot1.html", "bot1")); |
490 EXPECT_EQ(L"", GetTabTitle()); | |
491 } | 419 } |
492 | 420 |
493 // This test is flaky. See bug 22111. | 421 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationChangeInSubframe) { |
494 TEST_F(SessionHistoryTest, DISABLED_HistorySearchXSS) { | 422 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle( |
495 // about:blank should be loaded first. | 423 "location_redirect.html", "Default Title")); |
496 ASSERT_FALSE(tab_->GoBack()); | |
497 EXPECT_EQ(L"about:blank", GetTabTitle()); | |
498 | 424 |
499 GURL url(std::string(chrome::kChromeUIHistoryURL) + | 425 ui_test_utils::NavigateToURL( |
500 "#q=%3Cimg%20src%3Dx%3Ax%20onerror%3D%22document.title%3D'XSS'%22%3E"); | 426 browser(), GURL("javascript:void(frames[0].navigate())")); |
501 ASSERT_TRUE(tab_->NavigateToURL(url)); | 427 EXPECT_EQ("foo", GetTabTitle()); |
502 // Mainly, this is to ensure we send a synchronous message to the renderer | |
503 // so that we're not susceptible (less susceptible?) to a race condition. | |
504 // Should a race condition ever trigger, it won't result in flakiness. | |
505 int num = tab_->FindInPage(L"<img", FWD, CASE_SENSITIVE, false, NULL); | |
506 EXPECT_GT(num, 0); | |
507 EXPECT_EQ(L"History", GetTabTitle()); | |
508 } | |
509 | 428 |
510 #if defined(OS_WIN) | 429 GoBack(); |
511 // See http://crbug.com/61619 | 430 EXPECT_EQ("Default Title", GetTabTitle()); |
512 #define MAYBE_LocationChangeInSubframe DISABLED_LocationChangeInSubframe | |
513 #else | |
514 #define MAYBE_LocationChangeInSubframe LocationChangeInSubframe | |
515 #endif | |
516 | |
517 TEST_F(SessionHistoryTest, MAYBE_LocationChangeInSubframe) { | |
518 ASSERT_TRUE(test_server_.Start()); | |
519 | |
520 ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL( | |
521 "files/session_history/location_redirect.html"))); | |
522 EXPECT_EQ(L"Default Title", GetTabTitle()); | |
523 | |
524 ASSERT_TRUE(tab_->NavigateToURL(GURL( | |
525 "javascript:void(frames[0].navigate())"))); | |
526 EXPECT_EQ(L"foo", GetTabTitle()); | |
527 | |
528 ASSERT_TRUE(tab_->GoBack()); | |
529 EXPECT_EQ(L"Default Title", GetTabTitle()); | |
530 } | 431 } |
531 | 432 |
532 // http://code.google.com/p/chromium/issues/detail?id=56267 | 433 // http://code.google.com/p/chromium/issues/detail?id=56267 |
533 TEST_F(SessionHistoryTest, DISABLED_HistoryLength) { | 434 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { |
534 ASSERT_TRUE(test_server_.Start()); | |
535 | |
536 int length; | 435 int length; |
537 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | 436 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( |
| 437 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
538 L"", L"domAutomationController.send(history.length)", &length)); | 438 L"", L"domAutomationController.send(history.length)", &length)); |
539 EXPECT_EQ(1, length); | 439 EXPECT_EQ(1, length); |
540 | 440 |
541 ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL("files/title1.html"))); | 441 ui_test_utils::NavigateToURL(browser(), GetURL("title1.html")); |
542 | 442 |
543 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | 443 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( |
| 444 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
544 L"", L"domAutomationController.send(history.length)", &length)); | 445 L"", L"domAutomationController.send(history.length)", &length)); |
545 EXPECT_EQ(2, length); | 446 EXPECT_EQ(2, length); |
546 | 447 |
547 // Now test that history.length is updated when the navigation is committed. | 448 // Now test that history.length is updated when the navigation is committed. |
548 ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL( | 449 ui_test_utils::NavigateToURL(browser(), GetURL("record_length.html")); |
549 "files/session_history/record_length.html"))); | 450 |
550 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | 451 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( |
| 452 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
551 L"", L"domAutomationController.send(history.length)", &length)); | 453 L"", L"domAutomationController.send(history.length)", &length)); |
552 EXPECT_EQ(3, length); | 454 EXPECT_EQ(3, length); |
553 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | |
554 L"", L"domAutomationController.send(history_length)", &length)); | |
555 EXPECT_EQ(3, length); | |
556 | 455 |
557 ASSERT_TRUE(tab_->GoBack()); | 456 GoBack(); |
558 ASSERT_TRUE(tab_->GoBack()); | 457 GoBack(); |
559 | 458 |
560 // Ensure history.length is properly truncated. | 459 // Ensure history.length is properly truncated. |
561 ASSERT_TRUE(tab_->NavigateToURL(test_server_.GetURL("files/title2.html"))); | 460 ui_test_utils::NavigateToURL(browser(), GetURL("title2.html")); |
562 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | 461 |
| 462 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( |
| 463 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
563 L"", L"domAutomationController.send(history.length)", &length)); | 464 L"", L"domAutomationController.send(history.length)", &length)); |
564 EXPECT_EQ(2, length); | 465 EXPECT_EQ(2, length); |
565 } | 466 } |
566 | |
567 } // namespace | |
OLD | NEW |