| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/search/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 browser()->tab_strip_model()->GetWebContentsAt(0); | 287 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 288 content::NavigationController* controller = &contents->GetController(); | 288 content::NavigationController* controller = &contents->GetController(); |
| 289 | 289 |
| 290 SearchTabHelper* search_tab_helper = | 290 SearchTabHelper* search_tab_helper = |
| 291 SearchTabHelper::FromWebContents(contents); | 291 SearchTabHelper::FromWebContents(contents); |
| 292 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 292 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 293 | 293 |
| 294 // A failed provisional load of a cacheable NTP should be redirected to local | 294 // A failed provisional load of a cacheable NTP should be redirected to local |
| 295 // NTP. | 295 // NTP. |
| 296 const GURL cacheableNTPURL = chrome::GetNewTabPageURL(profile()); | 296 const GURL cacheableNTPURL = chrome::GetNewTabPageURL(profile()); |
| 297 search_tab_helper->DidFailProvisionalLoad(1, string16(), true, | 297 search_tab_helper->DidFailProvisionalLoad(1, base::string16(), true, |
| 298 cacheableNTPURL, 1, string16(), NULL); | 298 cacheableNTPURL, 1, base::string16(), NULL); |
| 299 CommitPendingLoad(controller); | 299 CommitPendingLoad(controller); |
| 300 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 300 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
| 301 controller->GetLastCommittedEntry()->GetURL()); | 301 controller->GetLastCommittedEntry()->GetURL()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 TEST_F(SearchTabHelperWindowTest, OnProvisionalLoadFailDontRedirectIfAborted) { | 304 TEST_F(SearchTabHelperWindowTest, OnProvisionalLoadFailDontRedirectIfAborted) { |
| 305 AddTab(browser(), GURL("chrome://blank")); | 305 AddTab(browser(), GURL("chrome://blank")); |
| 306 content::WebContents* contents = | 306 content::WebContents* contents = |
| 307 browser()->tab_strip_model()->GetWebContentsAt(0); | 307 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 308 content::NavigationController* controller = &contents->GetController(); | 308 content::NavigationController* controller = &contents->GetController(); |
| 309 | 309 |
| 310 SearchTabHelper* search_tab_helper = | 310 SearchTabHelper* search_tab_helper = |
| 311 SearchTabHelper::FromWebContents(contents); | 311 SearchTabHelper::FromWebContents(contents); |
| 312 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 312 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 313 | 313 |
| 314 // A failed provisional load of a cacheable NTP should be redirected to local | 314 // A failed provisional load of a cacheable NTP should be redirected to local |
| 315 // NTP. | 315 // NTP. |
| 316 const GURL cacheableNTPURL = chrome::GetNewTabPageURL(profile()); | 316 const GURL cacheableNTPURL = chrome::GetNewTabPageURL(profile()); |
| 317 search_tab_helper->DidFailProvisionalLoad(1, string16(), true, | 317 search_tab_helper->DidFailProvisionalLoad(1, base::string16(), true, |
| 318 cacheableNTPURL, net::ERR_ABORTED, string16(), NULL); | 318 cacheableNTPURL, net::ERR_ABORTED, base::string16(), NULL); |
| 319 CommitPendingLoad(controller); | 319 CommitPendingLoad(controller); |
| 320 EXPECT_EQ(GURL("chrome://blank"), | 320 EXPECT_EQ(GURL("chrome://blank"), |
| 321 controller->GetLastCommittedEntry()->GetURL()); | 321 controller->GetLastCommittedEntry()->GetURL()); |
| 322 } | 322 } |
| 323 | 323 |
| 324 TEST_F(SearchTabHelperWindowTest, OnProvisionalLoadFailDontRedirectNonNTP) { | 324 TEST_F(SearchTabHelperWindowTest, OnProvisionalLoadFailDontRedirectNonNTP) { |
| 325 AddTab(browser(), GURL(chrome::kChromeUINewTabURL)); | 325 AddTab(browser(), GURL(chrome::kChromeUINewTabURL)); |
| 326 content::WebContents* contents = | 326 content::WebContents* contents = |
| 327 browser()->tab_strip_model()->GetWebContentsAt(0); | 327 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 328 content::NavigationController* controller = &contents->GetController(); | 328 content::NavigationController* controller = &contents->GetController(); |
| 329 | 329 |
| 330 SearchTabHelper* search_tab_helper = | 330 SearchTabHelper* search_tab_helper = |
| 331 SearchTabHelper::FromWebContents(contents); | 331 SearchTabHelper::FromWebContents(contents); |
| 332 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 332 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 333 | 333 |
| 334 // Any other web page shouldn't be redirected when provisional load fails. | 334 // Any other web page shouldn't be redirected when provisional load fails. |
| 335 search_tab_helper->DidFailProvisionalLoad(1, string16(), true, | 335 search_tab_helper->DidFailProvisionalLoad(1, base::string16(), true, |
| 336 GURL("http://www.example.com"), 1, string16(), NULL); | 336 GURL("http://www.example.com"), 1, base::string16(), NULL); |
| 337 CommitPendingLoad(controller); | 337 CommitPendingLoad(controller); |
| 338 EXPECT_NE(GURL(chrome::kChromeSearchLocalNtpUrl), | 338 EXPECT_NE(GURL(chrome::kChromeSearchLocalNtpUrl), |
| 339 controller->GetLastCommittedEntry()->GetURL()); | 339 controller->GetLastCommittedEntry()->GetURL()); |
| 340 } | 340 } |
| OLD | NEW |