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

Side by Side Diff: chrome/browser/ui/search/search_tab_helper_unittest.cc

Issue 845973005: [New Tab Page] Change the mechanism to intercept online NTP errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved to profile_io_data Created 5 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
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 data.new_tab_url = std::string("https://foo.com/newtab?strk"); 343 data.new_tab_url = std::string("https://foo.com/newtab?strk");
344 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); 344 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
345 data.search_terms_replacement_key = "strk"; 345 data.search_terms_replacement_key = "strk";
346 346
347 TemplateURL* template_url = new TemplateURL(data); 347 TemplateURL* template_url = new TemplateURL(data);
348 template_url_service->Add(template_url); 348 template_url_service->Add(template_url);
349 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 349 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
350 } 350 }
351 }; 351 };
352 352
353 TEST_F(SearchTabHelperWindowTest, OnProvisionalLoadFailRedirectNTPToLocal) {
354 AddTab(browser(), GURL(chrome::kChromeUINewTabURL));
355 content::WebContents* contents =
356 browser()->tab_strip_model()->GetWebContentsAt(0);
357 content::NavigationController* controller = &contents->GetController();
358
359 SearchTabHelper* search_tab_helper =
360 SearchTabHelper::FromWebContents(contents);
361 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
362
363 // A failed provisional load of a cacheable NTP should be redirected to local
364 // NTP.
365 const GURL cacheableNTPURL = chrome::GetNewTabPageURL(profile());
366 search_tab_helper->DidFailProvisionalLoad(
367 contents->GetMainFrame(), cacheableNTPURL, 1, base::string16());
368 CommitPendingLoad(controller);
369 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
370 controller->GetLastCommittedEntry()->GetURL());
371 }
372
373 TEST_F(SearchTabHelperWindowTest, OnProvisionalLoadFailDontRedirectIfAborted) {
374 AddTab(browser(), GURL("chrome://blank"));
375 content::WebContents* contents =
376 browser()->tab_strip_model()->GetWebContentsAt(0);
377 content::NavigationController* controller = &contents->GetController();
378
379 SearchTabHelper* search_tab_helper =
380 SearchTabHelper::FromWebContents(contents);
381 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
382
383 // A failed provisional load of a cacheable NTP should be redirected to local
384 // NTP.
385 const GURL cacheableNTPURL = chrome::GetNewTabPageURL(profile());
386 search_tab_helper->DidFailProvisionalLoad(contents->GetMainFrame(),
387 cacheableNTPURL,
388 net::ERR_ABORTED,
389 base::string16());
390 CommitPendingLoad(controller);
391 EXPECT_EQ(GURL("chrome://blank"),
392 controller->GetLastCommittedEntry()->GetURL());
393 }
394
395 TEST_F(SearchTabHelperWindowTest, OnProvisionalLoadFailDontRedirectNonNTP) {
396 AddTab(browser(), GURL(chrome::kChromeUINewTabURL));
397 content::WebContents* contents =
398 browser()->tab_strip_model()->GetWebContentsAt(0);
399 content::NavigationController* controller = &contents->GetController();
400
401 SearchTabHelper* search_tab_helper =
402 SearchTabHelper::FromWebContents(contents);
403 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
404
405 // Any other web page shouldn't be redirected when provisional load fails.
406 search_tab_helper->DidFailProvisionalLoad(contents->GetMainFrame(),
407 GURL("http://www.example.com"),
408 1,
409 base::string16());
410 CommitPendingLoad(controller);
411 EXPECT_NE(GURL(chrome::kChromeSearchLocalNtpUrl),
412 controller->GetLastCommittedEntry()->GetURL());
413 }
414
415 class SearchTabHelperPrerenderTest : public InstantUnitTestBase { 353 class SearchTabHelperPrerenderTest : public InstantUnitTestBase {
416 public: 354 public:
417 ~SearchTabHelperPrerenderTest() override {} 355 ~SearchTabHelperPrerenderTest() override {}
418 356
419 protected: 357 protected:
420 void SetUp() override { 358 void SetUp() override {
421 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 359 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
422 "EmbeddedSearch", 360 "EmbeddedSearch",
423 "Group1 espv:89 prefetch_results:1 " 361 "Group1 espv:89 prefetch_results:1 "
424 "prerender_instant_url_on_omnibox_focus:1")); 362 "prerender_instant_url_on_omnibox_focus:1"));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 409 }
472 410
473 TEST_F(SearchTabHelperPrerenderTest, 411 TEST_F(SearchTabHelperPrerenderTest,
474 OnTabActivatedNoPrerenderIfOmniboxBlurred) { 412 OnTabActivatedNoPrerenderIfOmniboxBlurred) {
475 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false; 413 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false;
476 SearchTabHelper* search_tab_helper = 414 SearchTabHelper* search_tab_helper =
477 SearchTabHelper::FromWebContents(web_contents()); 415 SearchTabHelper::FromWebContents(web_contents());
478 search_tab_helper->OnTabActivated(); 416 search_tab_helper->OnTabActivated();
479 ASSERT_FALSE(IsInstantURLMarkedForPrerendering()); 417 ASSERT_FALSE(IsInstantURLMarkedForPrerendering());
480 } 418 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698