Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/history/redirect_browsertest.cc

Issue 12066003: Remove TabStripModel wrapper use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gtk Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.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_service.h" 20 #include "chrome/browser/history/history_service.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/tabs/tab_strip_model.h"
25 #include "chrome/browser/ui/view_ids.h" 25 #include "chrome/browser/ui/view_ids.h"
26 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "content/public/test/browser_test_utils.h" 29 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/test_navigation_observer.h" 30 #include "content/public/test/test_navigation_observer.h"
31 #include "net/base/net_util.h" 31 #include "net/base/net_util.h"
32 #include "net/test/test_server.h" 32 #include "net/test/test_server.h"
33 #include "ui/base/events/event_constants.h" 33 #include "ui/base/events/event_constants.h"
34 34
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // The client redirect appears as two page visits in the browser. 95 // The client redirect appears as two page visits in the browser.
96 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 96 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
97 browser(), first_url, 2); 97 browser(), first_url, 2);
98 98
99 std::vector<GURL> redirects = GetRedirects(first_url); 99 std::vector<GURL> redirects = GetRedirects(first_url);
100 100
101 ASSERT_EQ(1U, redirects.size()); 101 ASSERT_EQ(1U, redirects.size());
102 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 102 EXPECT_EQ(final_url.spec(), redirects[0].spec());
103 103
104 // The address bar should display the final URL. 104 // The address bar should display the final URL.
105 EXPECT_EQ(final_url, chrome::GetActiveWebContents(browser())->GetURL()); 105 EXPECT_EQ(final_url,
106 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
106 107
107 // Navigate one more time. 108 // Navigate one more time.
108 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 109 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
109 browser(), first_url, 2); 110 browser(), first_url, 2);
110 111
111 // The address bar should still display the final URL. 112 // The address bar should still display the final URL.
112 EXPECT_EQ(final_url, chrome::GetActiveWebContents(browser())->GetURL()); 113 EXPECT_EQ(final_url,
114 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
113 } 115 }
114 116
115 // http://code.google.com/p/chromium/issues/detail?id=62772 117 // http://code.google.com/p/chromium/issues/detail?id=62772
116 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientEmptyReferer) { 118 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientEmptyReferer) {
117 ASSERT_TRUE(test_server()->Start()); 119 ASSERT_TRUE(test_server()->Start());
118 120
119 // Create the file contents, which will do a redirect to the 121 // Create the file contents, which will do a redirect to the
120 // test server. 122 // test server.
121 GURL final_url = test_server()->GetURL(std::string()); 123 GURL final_url = test_server()->GetURL(std::string());
122 ASSERT_TRUE(final_url.is_valid()); 124 ASSERT_TRUE(final_url.is_valid());
(...skipping 26 matching lines...) Expand all
149 EXPECT_EQ(final_url.spec(), redirects[0].spec()); 151 EXPECT_EQ(final_url.spec(), redirects[0].spec());
150 } 152 }
151 153
152 // Tests to make sure a location change when a pending redirect exists isn't 154 // Tests to make sure a location change when a pending redirect exists isn't
153 // flagged as a redirect. 155 // flagged as a redirect.
154 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientCancelled) { 156 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientCancelled) {
155 GURL first_url = ui_test_utils::GetTestUrl( 157 GURL first_url = ui_test_utils::GetTestUrl(
156 FilePath(), FilePath().AppendASCII("cancelled_redirect_test.html")); 158 FilePath(), FilePath().AppendASCII("cancelled_redirect_test.html"));
157 ui_test_utils::NavigateToURL(browser(), first_url); 159 ui_test_utils::NavigateToURL(browser(), first_url);
158 160
159 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 161 content::WebContents* web_contents =
162 browser()->tab_strip_model()->GetActiveWebContents();
160 content::TestNavigationObserver navigation_observer( 163 content::TestNavigationObserver navigation_observer(
161 content::Source<content::NavigationController>( 164 content::Source<content::NavigationController>(
162 &web_contents->GetController())); 165 &web_contents->GetController()));
163 166
164 // Simulate a click to force to make a user-initiated location change; 167 // Simulate a click to force to make a user-initiated location change;
165 // otherwise, a non user-initiated in-page location change will be treated 168 // otherwise, a non user-initiated in-page location change will be treated
166 // as client redirect and the redirect will be recoreded, which can cause 169 // as client redirect and the redirect will be recoreded, which can cause
167 // this test failed. 170 // this test failed.
168 content::SimulateMouseClick(web_contents, 0, 171 content::SimulateMouseClick(web_contents, 0,
169 WebKit::WebMouseEvent::ButtonLeft); 172 WebKit::WebMouseEvent::ButtonLeft);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ASSERT_TRUE(test_server()->Start()); 208 ASSERT_TRUE(test_server()->Start());
206 209
207 const std::string ref("reference"); 210 const std::string ref("reference");
208 211
209 GURL final_url = test_server()->GetURL(std::string()); 212 GURL final_url = test_server()->GetURL(std::string());
210 GURL initial_url = test_server()->GetURL( 213 GURL initial_url = test_server()->GetURL(
211 "server-redirect?" + final_url.spec() + "#" + ref); 214 "server-redirect?" + final_url.spec() + "#" + ref);
212 215
213 ui_test_utils::NavigateToURL(browser(), initial_url); 216 ui_test_utils::NavigateToURL(browser(), initial_url);
214 217
215 EXPECT_EQ(ref, chrome::GetActiveWebContents(browser())->GetURL().ref()); 218 EXPECT_EQ(ref,
219 browser()->tab_strip_model()->GetActiveWebContents()->
220 GetURL().ref());
216 } 221 }
217 222
218 // Test that redirect from http:// to file:// : 223 // Test that redirect from http:// to file:// :
219 // A) does not crash the browser or confuse the redirect chain, see bug 1080873 224 // A) does not crash the browser or confuse the redirect chain, see bug 1080873
220 // B) does not take place. 225 // B) does not take place.
221 // 226 //
222 // Flaky on XP and Vista, http://crbug.com/69390. 227 // Flaky on XP and Vista, http://crbug.com/69390.
223 IN_PROC_BROWSER_TEST_F(RedirectTest, NoHttpToFile) { 228 IN_PROC_BROWSER_TEST_F(RedirectTest, NoHttpToFile) {
224 ASSERT_TRUE(test_server()->Start()); 229 ASSERT_TRUE(test_server()->Start());
225 GURL file_url = ui_test_utils::GetTestUrl( 230 GURL file_url = ui_test_utils::GetTestUrl(
226 FilePath(), FilePath().AppendASCII("http_to_file.html")); 231 FilePath(), FilePath().AppendASCII("http_to_file.html"));
227 232
228 GURL initial_url = test_server()->GetURL( 233 GURL initial_url = test_server()->GetURL(
229 "client-redirect?" + file_url.spec()); 234 "client-redirect?" + file_url.spec());
230 235
231 ui_test_utils::NavigateToURL(browser(), initial_url); 236 ui_test_utils::NavigateToURL(browser(), initial_url);
232 // We make sure the title doesn't match the title from the file, because the 237 // We make sure the title doesn't match the title from the file, because the
233 // nav should not have taken place. 238 // nav should not have taken place.
234 EXPECT_NE(ASCIIToUTF16("File!"), 239 EXPECT_NE(ASCIIToUTF16("File!"),
235 chrome::GetActiveWebContents(browser())->GetTitle()); 240 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
236 } 241 }
237 242
238 // Ensures that non-user initiated location changes (within page) are 243 // Ensures that non-user initiated location changes (within page) are
239 // flagged as client redirects. See bug 1139823. 244 // flagged as client redirects. See bug 1139823.
240 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientFragments) { 245 IN_PROC_BROWSER_TEST_F(RedirectTest, ClientFragments) {
241 ASSERT_TRUE(test_server()->Start()); 246 ASSERT_TRUE(test_server()->Start());
242 GURL first_url = ui_test_utils::GetTestUrl( 247 GURL first_url = ui_test_utils::GetTestUrl(
243 FilePath(), FilePath().AppendASCII("ref_redirect.html")); 248 FilePath(), FilePath().AppendASCII("ref_redirect.html"));
244 ui_test_utils::NavigateToURL(browser(), first_url); 249 ui_test_utils::NavigateToURL(browser(), first_url);
245 std::vector<GURL> redirects = GetRedirects(first_url); 250 std::vector<GURL> redirects = GetRedirects(first_url);
(...skipping 17 matching lines...) Expand all
263 // which causes it to start a provisional load, and while it is waiting 268 // which causes it to start a provisional load, and while it is waiting
264 // for the response (which means it hasn't committed the load for the client 269 // for the response (which means it hasn't committed the load for the client
265 // redirect destination page yet), we issue a new navigation request. 270 // redirect destination page yet), we issue a new navigation request.
266 ASSERT_TRUE(test_server()->Start()); 271 ASSERT_TRUE(test_server()->Start());
267 272
268 GURL final_url = test_server()->GetURL("files/title2.html"); 273 GURL final_url = test_server()->GetURL("files/title2.html");
269 GURL slow = test_server()->GetURL("slow?60"); 274 GURL slow = test_server()->GetURL("slow?60");
270 GURL first_url = test_server()->GetURL( 275 GURL first_url = test_server()->GetURL(
271 "client-redirect?" + slow.spec()); 276 "client-redirect?" + slow.spec());
272 277
273 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 278 content::WebContents* web_contents =
279 browser()->tab_strip_model()->GetActiveWebContents();
274 content::TestNavigationObserver observer( 280 content::TestNavigationObserver observer(
275 content::Source<content::NavigationController>( 281 content::Source<content::NavigationController>(
276 &web_contents->GetController()), 282 &web_contents->GetController()),
277 NULL, 2); 283 NULL, 2);
278 284
279 ui_test_utils::NavigateToURLWithDisposition( 285 ui_test_utils::NavigateToURLWithDisposition(
280 browser(), first_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); 286 browser(), first_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
281 // We don't sleep here - the first navigation won't have been committed yet 287 // We don't sleep here - the first navigation won't have been committed yet
282 // because we told the server to wait a minute. This means the browser has 288 // because we told the server to wait a minute. This means the browser has
283 // started it's provisional load for the client redirect destination page but 289 // started it's provisional load for the client redirect destination page but
284 // hasn't completed. Our time is now! 290 // hasn't completed. Our time is now!
285 ui_test_utils::NavigateToURLWithDisposition( 291 ui_test_utils::NavigateToURLWithDisposition(
286 browser(), final_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); 292 browser(), final_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
287 observer.Wait(); 293 observer.Wait();
288 294
289 // Check to make sure the navigation did in fact take place and we are 295 // Check to make sure the navigation did in fact take place and we are
290 // at the expected page. 296 // at the expected page.
291 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), 297 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"),
292 chrome::GetActiveWebContents(browser())->GetTitle()); 298 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
293 299
294 bool final_navigation_not_redirect = true; 300 bool final_navigation_not_redirect = true;
295 std::vector<GURL> redirects = GetRedirects(first_url); 301 std::vector<GURL> redirects = GetRedirects(first_url);
296 // Check to make sure our request for files/title2.html doesn't get flagged 302 // Check to make sure our request for files/title2.html doesn't get flagged
297 // as a client redirect from the first (/client-redirect?) page. 303 // as a client redirect from the first (/client-redirect?) page.
298 for (std::vector<GURL>::iterator it = redirects.begin(); 304 for (std::vector<GURL>::iterator it = redirects.begin();
299 it != redirects.end(); ++it) { 305 it != redirects.end(); ++it) {
300 if (final_url.spec() == it->spec()) { 306 if (final_url.spec() == it->spec()) {
301 final_navigation_not_redirect = false; 307 final_navigation_not_redirect = false;
302 break; 308 break;
303 } 309 }
304 } 310 }
305 EXPECT_TRUE(final_navigation_not_redirect); 311 EXPECT_TRUE(final_navigation_not_redirect);
306 } 312 }
OLDNEW
« no previous file with comments | « chrome/browser/history/multipart_browsertest.cc ('k') | chrome/browser/instant/instant_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698