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

Side by Side Diff: chrome/browser/search/search_unittest.cc

Issue 150033002: NTP: add histogram to track New Tab page URL status. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean things up. Created 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/metrics/field_trial.h" 6 #include "base/metrics/field_trial.h"
7 #include "base/metrics/histogram_base.h" 7 #include "base/metrics/histogram_base.h"
8 #include "base/metrics/histogram_samples.h" 8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 template_url_service->SetDefaultSearchProvider(template_url); 211 template_url_service->SetDefaultSearchProvider(template_url);
212 } 212 }
213 213
214 bool InInstantProcess(const content::WebContents* contents) { 214 bool InInstantProcess(const content::WebContents* contents) {
215 InstantService* instant_service = 215 InstantService* instant_service =
216 InstantServiceFactory::GetForProfile(profile()); 216 InstantServiceFactory::GetForProfile(profile());
217 return instant_service->IsInstantProcess( 217 return instant_service->IsInstantProcess(
218 contents->GetRenderProcessHost()->GetID()); 218 contents->GetRenderProcessHost()->GetID());
219 } 219 }
220 220
221 content::BrowserContext* AsBrowserContext(Profile* profile) {
222 // Following implementation of FromBrowserContext:
223 return static_cast<Profile*>(profile);
224 }
225
221 scoped_ptr<base::FieldTrialList> field_trial_list_; 226 scoped_ptr<base::FieldTrialList> field_trial_list_;
222 }; 227 };
223 228
224 struct SearchTestCase { 229 struct SearchTestCase {
225 const char* url; 230 const char* url;
226 bool expected_result; 231 bool expected_result;
227 const char* comment; 232 const char* comment;
228 }; 233 };
229 234
230 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { 235 TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 content::NavigationController& controller = contents->GetController(); 519 content::NavigationController& controller = contents->GetController();
515 // Test virtual url chrome://newtab for first NTP of a new profile 520 // Test virtual url chrome://newtab for first NTP of a new profile
516 EXPECT_TRUE(NavEntryIsInstantNTP(contents, 521 EXPECT_TRUE(NavEntryIsInstantNTP(contents,
517 controller.GetLastCommittedEntry())); 522 controller.GetLastCommittedEntry()));
518 // The new_tab_url gets set after the first NTP is visible. 523 // The new_tab_url gets set after the first NTP is visible.
519 SetSearchProvider(true, false); 524 SetSearchProvider(true, false);
520 EXPECT_TRUE(NavEntryIsInstantNTP(contents, 525 EXPECT_TRUE(NavEntryIsInstantNTP(contents,
521 controller.GetLastCommittedEntry())); 526 controller.GetLastCommittedEntry()));
522 } 527 }
523 528
524 TEST_F(SearchTest, UseLocalNTPInIncognito) { 529 TEST_F(SearchTest, NoRewriteInIncognito) {
525 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL( 530 profile()->ForceIncognito(true);
526 profile()->GetOffTheRecordProfile())); 531 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL(profile()));
532 GURL new_tab_url(chrome::kChromeUINewTabURL);
533 EXPECT_FALSE(HandleNewTabURLRewrite(&new_tab_url, AsBrowserContext(
Jered 2014/02/03 15:58:11 nit: Just profile() should work.
samarth 2014/02/03 18:33:31 Done.
534 profile())));
535 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), new_tab_url);
527 } 536 }
528 537
529 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) { 538 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) {
530 // Set an insecure new tab page URL and verify that it's ignored. 539 // Set an insecure new tab page URL and verify that it's ignored.
531 SetSearchProvider(true, true); 540 SetSearchProvider(true, true);
532 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 541 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
533 chrome::GetNewTabPageURL(profile())); 542 chrome::GetNewTabPageURL(profile()));
543 GURL new_tab_url(chrome::kChromeUINewTabURL);
544 EXPECT_TRUE(
545 HandleNewTabURLRewrite(&new_tab_url, AsBrowserContext(profile())));
546 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url);
534 } 547 }
535 548
536 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { 549 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) {
537 // Set an insecure new tab page URL and verify that it's ignored. 550 // Set an insecure new tab page URL and verify that it's ignored.
538 SetSearchProvider(false, true); 551 SetSearchProvider(false, true);
539 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 552 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
540 chrome::GetNewTabPageURL(profile())); 553 chrome::GetNewTabPageURL(profile()));
554 GURL new_tab_url(chrome::kChromeUINewTabURL);
555 EXPECT_TRUE(
556 HandleNewTabURLRewrite(&new_tab_url, AsBrowserContext(profile())));
557 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url);
541 } 558 }
542 559
543 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { 560 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) {
544 // Block access to foo.com in the URL filter. 561 // Block access to foo.com in the URL filter.
545 ManagedUserService* managed_user_service = 562 ManagedUserService* managed_user_service =
546 ManagedUserServiceFactory::GetForProfile(profile()); 563 ManagedUserServiceFactory::GetForProfile(profile());
547 ManagedModeURLFilter* url_filter = 564 ManagedModeURLFilter* url_filter =
548 managed_user_service->GetURLFilterForUIThread(); 565 managed_user_service->GetURLFilterForUIThread();
549 std::map<std::string, bool> hosts; 566 std::map<std::string, bool> hosts;
550 hosts["foo.com"] = false; 567 hosts["foo.com"] = false;
551 url_filter->SetManualHosts(&hosts); 568 url_filter->SetManualHosts(&hosts);
552 569
553 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 570 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
554 chrome::GetNewTabPageURL(profile())); 571 chrome::GetNewTabPageURL(profile()));
572 GURL new_tab_url(chrome::kChromeUINewTabURL);
573 EXPECT_TRUE(
574 HandleNewTabURLRewrite(&new_tab_url, AsBrowserContext(profile())));
575 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url);
555 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 576 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
556 } 577 }
557 578
558 TEST_F(SearchTest, GetInstantURL) { 579 TEST_F(SearchTest, GetInstantURL) {
559 // No Instant URL because "strk" is missing. 580 // No Instant URL because "strk" is missing.
560 SetDefaultInstantTemplateUrl(false); 581 SetDefaultInstantTemplateUrl(false);
561 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); 582 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false));
562 583
563 // Set an Instant URL with a valid search terms replacement key. 584 // Set an Instant URL with a valid search terms replacement key.
564 SetDefaultInstantTemplateUrl(true); 585 SetDefaultInstantTemplateUrl(true);
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 } 989 }
969 990
970 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) { 991 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) {
971 CommandLine::ForCurrentProcess()->AppendSwitch( 992 CommandLine::ForCurrentProcess()->AppendSwitch(
972 switches::kEnableOriginChipLeadingMenuButton); 993 switches::kEnableOriginChipLeadingMenuButton);
973 EXPECT_TRUE(ShouldDisplayOriginChip()); 994 EXPECT_TRUE(ShouldDisplayOriginChip());
974 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition()); 995 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition());
975 } 996 }
976 997
977 } // namespace chrome 998 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698