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 // Navigates the browser to server and client redirect pages and makes sure | 5 // Navigates the browser to server and client redirect pages and makes sure |
6 // that the correct redirects are reflected in the history database. Errors | 6 // that the correct redirects are reflected in the history database. Errors |
7 // here might indicate that WebKit changed the calls our glue layer gets in | 7 // here might indicate that WebKit changed the calls our glue layer gets in |
8 // the case of redirects. It may also mean problems with the history system. | 8 // the case of redirects. It may also mean problems with the history system. |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "chrome/browser/history/history.h" | 20 #include "chrome/browser/history/history.h" |
21 #include "chrome/browser/history/history_service_factory.h" | 21 #include "chrome/browser/history/history_service_factory.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_tabstrip.h" |
24 #include "chrome/browser/ui/view_ids.h" | 25 #include "chrome/browser/ui/view_ids.h" |
25 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/test_navigation_observer.h" | 29 #include "content/public/test/test_navigation_observer.h" |
29 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
30 #include "net/test/test_server.h" | 31 #include "net/test/test_server.h" |
31 #include "ui/base/events.h" | 32 #include "ui/base/events.h" |
32 | 33 |
33 class RedirectTest : public InProcessBrowserTest { | 34 class RedirectTest : public InProcessBrowserTest { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // The client redirect appears as two page visits in the browser. | 94 // The client redirect appears as two page visits in the browser. |
94 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 95 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
95 browser(), first_url, 2); | 96 browser(), first_url, 2); |
96 | 97 |
97 std::vector<GURL> redirects = GetRedirects(first_url); | 98 std::vector<GURL> redirects = GetRedirects(first_url); |
98 | 99 |
99 ASSERT_EQ(1U, redirects.size()); | 100 ASSERT_EQ(1U, redirects.size()); |
100 EXPECT_EQ(final_url.spec(), redirects[0].spec()); | 101 EXPECT_EQ(final_url.spec(), redirects[0].spec()); |
101 | 102 |
102 // The address bar should display the final URL. | 103 // The address bar should display the final URL. |
103 EXPECT_EQ(final_url, browser()->GetActiveWebContents()->GetURL()); | 104 EXPECT_EQ(final_url, chrome::GetActiveWebContents(browser())->GetURL()); |
104 | 105 |
105 // Navigate one more time. | 106 // Navigate one more time. |
106 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 107 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
107 browser(), first_url, 2); | 108 browser(), first_url, 2); |
108 | 109 |
109 // The address bar should still display the final URL. | 110 // The address bar should still display the final URL. |
110 EXPECT_EQ(final_url, browser()->GetActiveWebContents()->GetURL()); | 111 EXPECT_EQ(final_url, chrome::GetActiveWebContents(browser())->GetURL()); |
111 } | 112 } |
112 | 113 |
113 // http://code.google.com/p/chromium/issues/detail?id=62772 | 114 // http://code.google.com/p/chromium/issues/detail?id=62772 |
114 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientEmptyReferer) { | 115 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientEmptyReferer) { |
115 ASSERT_TRUE(test_server()->Start()); | 116 ASSERT_TRUE(test_server()->Start()); |
116 | 117 |
117 // Create the file contents, which will do a redirect to the | 118 // Create the file contents, which will do a redirect to the |
118 // test server. | 119 // test server. |
119 GURL final_url = test_server()->GetURL(std::string()); | 120 GURL final_url = test_server()->GetURL(std::string()); |
120 ASSERT_TRUE(final_url.is_valid()); | 121 ASSERT_TRUE(final_url.is_valid()); |
(...skipping 26 matching lines...) Expand all Loading... |
147 EXPECT_EQ(final_url.spec(), redirects[0].spec()); | 148 EXPECT_EQ(final_url.spec(), redirects[0].spec()); |
148 } | 149 } |
149 | 150 |
150 // Tests to make sure a location change when a pending redirect exists isn't | 151 // Tests to make sure a location change when a pending redirect exists isn't |
151 // flagged as a redirect. | 152 // flagged as a redirect. |
152 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientCancelled) { | 153 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientCancelled) { |
153 GURL first_url = ui_test_utils::GetTestUrl( | 154 GURL first_url = ui_test_utils::GetTestUrl( |
154 FilePath(), FilePath().AppendASCII("cancelled_redirect_test.html")); | 155 FilePath(), FilePath().AppendASCII("cancelled_redirect_test.html")); |
155 ui_test_utils::NavigateToURL(browser(), first_url); | 156 ui_test_utils::NavigateToURL(browser(), first_url); |
156 | 157 |
157 content::WebContents* web_contents = browser()->GetActiveWebContents(); | 158 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
158 content::TestNavigationObserver navigation_observer( | 159 content::TestNavigationObserver navigation_observer( |
159 content::Source<content::NavigationController>( | 160 content::Source<content::NavigationController>( |
160 &web_contents->GetController())); | 161 &web_contents->GetController())); |
161 | 162 |
162 // Simulate a click to force to make a user-initiated location change; | 163 // Simulate a click to force to make a user-initiated location change; |
163 // otherwise, a non user-initiated in-page location change will be treated | 164 // otherwise, a non user-initiated in-page location change will be treated |
164 // as client redirect and the redirect will be recoreded, which can cause | 165 // as client redirect and the redirect will be recoreded, which can cause |
165 // this test failed. | 166 // this test failed. |
166 ui_test_utils::SimulateMouseClick(web_contents); | 167 ui_test_utils::SimulateMouseClick(web_contents); |
167 navigation_observer.Wait(); | 168 navigation_observer.Wait(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ASSERT_TRUE(test_server()->Start()); | 203 ASSERT_TRUE(test_server()->Start()); |
203 | 204 |
204 const std::string ref("reference"); | 205 const std::string ref("reference"); |
205 | 206 |
206 GURL final_url = test_server()->GetURL(std::string()); | 207 GURL final_url = test_server()->GetURL(std::string()); |
207 GURL initial_url = test_server()->GetURL( | 208 GURL initial_url = test_server()->GetURL( |
208 "server-redirect?" + final_url.spec() + "#" + ref); | 209 "server-redirect?" + final_url.spec() + "#" + ref); |
209 | 210 |
210 ui_test_utils::NavigateToURL(browser(), initial_url); | 211 ui_test_utils::NavigateToURL(browser(), initial_url); |
211 | 212 |
212 EXPECT_EQ(ref, browser()->GetActiveWebContents()->GetURL().ref()); | 213 EXPECT_EQ(ref, chrome::GetActiveWebContents(browser())->GetURL().ref()); |
213 } | 214 } |
214 | 215 |
215 // Test that redirect from http:// to file:// : | 216 // Test that redirect from http:// to file:// : |
216 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 | 217 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 |
217 // B) does not take place. | 218 // B) does not take place. |
218 // | 219 // |
219 // Flaky on XP and Vista, http://crbug.com/69390. | 220 // Flaky on XP and Vista, http://crbug.com/69390. |
220 IN_PROC_BROWSER_TEST_F(RedirectTest, NoHttpToFile) { | 221 IN_PROC_BROWSER_TEST_F(RedirectTest, NoHttpToFile) { |
221 ASSERT_TRUE(test_server()->Start()); | 222 ASSERT_TRUE(test_server()->Start()); |
222 GURL file_url = ui_test_utils::GetTestUrl( | 223 GURL file_url = ui_test_utils::GetTestUrl( |
223 FilePath(), FilePath().AppendASCII("http_to_file.html")); | 224 FilePath(), FilePath().AppendASCII("http_to_file.html")); |
224 | 225 |
225 GURL initial_url = test_server()->GetURL( | 226 GURL initial_url = test_server()->GetURL( |
226 "client-redirect?" + file_url.spec()); | 227 "client-redirect?" + file_url.spec()); |
227 | 228 |
228 ui_test_utils::NavigateToURL(browser(), initial_url); | 229 ui_test_utils::NavigateToURL(browser(), initial_url); |
229 // We make sure the title doesn't match the title from the file, because the | 230 // We make sure the title doesn't match the title from the file, because the |
230 // nav should not have taken place. | 231 // nav should not have taken place. |
231 EXPECT_NE(ASCIIToUTF16("File!"), | 232 EXPECT_NE(ASCIIToUTF16("File!"), |
232 browser()->GetActiveWebContents()->GetTitle()); | 233 chrome::GetActiveWebContents(browser())->GetTitle()); |
233 } | 234 } |
234 | 235 |
235 // Ensures that non-user initiated location changes (within page) are | 236 // Ensures that non-user initiated location changes (within page) are |
236 // flagged as client redirects. See bug 1139823. | 237 // flagged as client redirects. See bug 1139823. |
237 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientFragments) { | 238 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientFragments) { |
238 ASSERT_TRUE(test_server()->Start()); | 239 ASSERT_TRUE(test_server()->Start()); |
239 GURL first_url = ui_test_utils::GetTestUrl( | 240 GURL first_url = ui_test_utils::GetTestUrl( |
240 FilePath(), FilePath().AppendASCII("ref_redirect.html")); | 241 FilePath(), FilePath().AppendASCII("ref_redirect.html")); |
241 ui_test_utils::NavigateToURL(browser(), first_url); | 242 ui_test_utils::NavigateToURL(browser(), first_url); |
242 std::vector<GURL> redirects = GetRedirects(first_url); | 243 std::vector<GURL> redirects = GetRedirects(first_url); |
(...skipping 17 matching lines...) Expand all Loading... |
260 // which causes it to start a provisional load, and while it is waiting | 261 // which causes it to start a provisional load, and while it is waiting |
261 // for the response (which means it hasn't committed the load for the client | 262 // for the response (which means it hasn't committed the load for the client |
262 // redirect destination page yet), we issue a new navigation request. | 263 // redirect destination page yet), we issue a new navigation request. |
263 ASSERT_TRUE(test_server()->Start()); | 264 ASSERT_TRUE(test_server()->Start()); |
264 | 265 |
265 GURL final_url = test_server()->GetURL("files/title2.html"); | 266 GURL final_url = test_server()->GetURL("files/title2.html"); |
266 GURL slow = test_server()->GetURL("slow?60"); | 267 GURL slow = test_server()->GetURL("slow?60"); |
267 GURL first_url = test_server()->GetURL( | 268 GURL first_url = test_server()->GetURL( |
268 "client-redirect?" + slow.spec()); | 269 "client-redirect?" + slow.spec()); |
269 | 270 |
270 content::WebContents* web_contents = browser()->GetActiveWebContents(); | 271 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
271 content::TestNavigationObserver observer( | 272 content::TestNavigationObserver observer( |
272 content::Source<content::NavigationController>( | 273 content::Source<content::NavigationController>( |
273 &web_contents->GetController()), | 274 &web_contents->GetController()), |
274 NULL, 2); | 275 NULL, 2); |
275 | 276 |
276 ui_test_utils::NavigateToURLWithDisposition( | 277 ui_test_utils::NavigateToURLWithDisposition( |
277 browser(), first_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | 278 browser(), first_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); |
278 // We don't sleep here - the first navigation won't have been committed yet | 279 // We don't sleep here - the first navigation won't have been committed yet |
279 // because we told the server to wait a minute. This means the browser has | 280 // because we told the server to wait a minute. This means the browser has |
280 // started it's provisional load for the client redirect destination page but | 281 // started it's provisional load for the client redirect destination page but |
281 // hasn't completed. Our time is now! | 282 // hasn't completed. Our time is now! |
282 ui_test_utils::NavigateToURLWithDisposition( | 283 ui_test_utils::NavigateToURLWithDisposition( |
283 browser(), final_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | 284 browser(), final_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); |
284 observer.Wait(); | 285 observer.Wait(); |
285 | 286 |
286 // Check to make sure the navigation did in fact take place and we are | 287 // Check to make sure the navigation did in fact take place and we are |
287 // at the expected page. | 288 // at the expected page. |
288 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), | 289 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), |
289 browser()->GetActiveWebContents()->GetTitle()); | 290 chrome::GetActiveWebContents(browser())->GetTitle()); |
290 | 291 |
291 bool final_navigation_not_redirect = true; | 292 bool final_navigation_not_redirect = true; |
292 std::vector<GURL> redirects = GetRedirects(first_url); | 293 std::vector<GURL> redirects = GetRedirects(first_url); |
293 // Check to make sure our request for files/title2.html doesn't get flagged | 294 // Check to make sure our request for files/title2.html doesn't get flagged |
294 // as a client redirect from the first (/client-redirect?) page. | 295 // as a client redirect from the first (/client-redirect?) page. |
295 for (std::vector<GURL>::iterator it = redirects.begin(); | 296 for (std::vector<GURL>::iterator it = redirects.begin(); |
296 it != redirects.end(); ++it) { | 297 it != redirects.end(); ++it) { |
297 if (final_url.spec() == it->spec()) { | 298 if (final_url.spec() == it->spec()) { |
298 final_navigation_not_redirect = false; | 299 final_navigation_not_redirect = false; |
299 break; | 300 break; |
300 } | 301 } |
301 } | 302 } |
302 EXPECT_TRUE(final_navigation_not_redirect); | 303 EXPECT_TRUE(final_navigation_not_redirect); |
303 } | 304 } |
OLD | NEW |