| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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( |
| 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::GetNewTabPageURL(profile())); |
| 533 chrome::GetNewTabPageURL(profile())); | 542 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 543 EXPECT_TRUE( |
| 544 HandleNewTabURLRewrite(&new_tab_url, AsBrowserContext(profile()))); |
| 545 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); |
| 534 } | 546 } |
| 535 | 547 |
| 536 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { | 548 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { |
| 537 // Set an insecure new tab page URL and verify that it's ignored. | 549 // Set an insecure new tab page URL and verify that it's ignored. |
| 538 SetSearchProvider(false, true); | 550 SetSearchProvider(false, true); |
| 539 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 551 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL(profile())); |
| 540 chrome::GetNewTabPageURL(profile())); | 552 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 553 EXPECT_TRUE( |
| 554 HandleNewTabURLRewrite(&new_tab_url, AsBrowserContext(profile()))); |
| 555 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); |
| 541 } | 556 } |
| 542 | 557 |
| 543 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { | 558 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { |
| 544 // Block access to foo.com in the URL filter. | 559 // Block access to foo.com in the URL filter. |
| 545 ManagedUserService* managed_user_service = | 560 ManagedUserService* managed_user_service = |
| 546 ManagedUserServiceFactory::GetForProfile(profile()); | 561 ManagedUserServiceFactory::GetForProfile(profile()); |
| 547 ManagedModeURLFilter* url_filter = | 562 ManagedModeURLFilter* url_filter = |
| 548 managed_user_service->GetURLFilterForUIThread(); | 563 managed_user_service->GetURLFilterForUIThread(); |
| 549 std::map<std::string, bool> hosts; | 564 std::map<std::string, bool> hosts; |
| 550 hosts["foo.com"] = false; | 565 hosts["foo.com"] = false; |
| 551 url_filter->SetManualHosts(&hosts); | 566 url_filter->SetManualHosts(&hosts); |
| 552 | 567 |
| 553 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 568 EXPECT_EQ(GURL(), chrome::GetNewTabPageURL(profile())); |
| 554 chrome::GetNewTabPageURL(profile())); | 569 GURL new_tab_url(chrome::kChromeUINewTabURL); |
| 570 EXPECT_TRUE( |
| 571 HandleNewTabURLRewrite(&new_tab_url, AsBrowserContext(profile()))); |
| 572 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); |
| 555 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); | 573 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); |
| 556 } | 574 } |
| 557 | 575 |
| 558 TEST_F(SearchTest, GetInstantURL) { | 576 TEST_F(SearchTest, GetInstantURL) { |
| 559 // No Instant URL because "strk" is missing. | 577 // No Instant URL because "strk" is missing. |
| 560 SetDefaultInstantTemplateUrl(false); | 578 SetDefaultInstantTemplateUrl(false); |
| 561 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); | 579 EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); |
| 562 | 580 |
| 563 // Set an Instant URL with a valid search terms replacement key. | 581 // Set an Instant URL with a valid search terms replacement key. |
| 564 SetDefaultInstantTemplateUrl(true); | 582 SetDefaultInstantTemplateUrl(true); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 } | 986 } |
| 969 | 987 |
| 970 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) { | 988 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) { |
| 971 CommandLine::ForCurrentProcess()->AppendSwitch( | 989 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 972 switches::kEnableOriginChipLeadingMenuButton); | 990 switches::kEnableOriginChipLeadingMenuButton); |
| 973 EXPECT_TRUE(ShouldDisplayOriginChip()); | 991 EXPECT_TRUE(ShouldDisplayOriginChip()); |
| 974 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition()); | 992 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition()); |
| 975 } | 993 } |
| 976 | 994 |
| 977 } // namespace chrome | 995 } // namespace chrome |
| OLD | NEW |