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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/search/instant_service.h" | 11 #include "chrome/browser/search/instant_service.h" |
12 #include "chrome/browser/search/instant_service_factory.h" | 12 #include "chrome/browser/search/instant_service_factory.h" |
13 #include "chrome/browser/search/search.h" | 13 #include "chrome/browser/search/search.h" |
14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
15 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 15 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
16 #include "chrome/browser/supervised_user/supervised_user_service.h" | |
17 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | |
18 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
23 #include "chrome/test/base/browser_with_test_window_test.h" | 20 #include "chrome/test/base/browser_with_test_window_test.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
25 #include "components/google/core/browser/google_switches.h" | 22 #include "components/google/core/browser/google_switches.h" |
26 #include "components/search/search.h" | 23 #include "components/search/search.h" |
27 #include "components/search_engines/search_engines_switches.h" | 24 #include "components/search_engines/search_engines_switches.h" |
28 #include "components/search_engines/template_url_service.h" | 25 #include "components/search_engines/template_url_service.h" |
29 #include "components/variations/entropy_provider.h" | 26 #include "components/variations/entropy_provider.h" |
30 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/site_instance.h" | 29 #include "content/public/browser/site_instance.h" |
33 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
34 #include "content/public/common/renderer_preferences.h" | 31 #include "content/public/common/renderer_preferences.h" |
35 #include "url/gurl.h" | 32 #include "url/gurl.h" |
36 | 33 |
| 34 #if defined(ENABLE_MANAGED_USERS) |
| 35 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 36 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 37 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
| 38 #endif |
| 39 |
37 namespace chrome { | 40 namespace chrome { |
38 | 41 |
39 class SearchTest : public BrowserWithTestWindowTest { | 42 class SearchTest : public BrowserWithTestWindowTest { |
40 protected: | 43 protected: |
41 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
42 BrowserWithTestWindowTest::SetUp(); | 45 BrowserWithTestWindowTest::SetUp(); |
43 field_trial_list_.reset(new base::FieldTrialList( | 46 field_trial_list_.reset(new base::FieldTrialList( |
44 new metrics::SHA1EntropyProvider("42"))); | 47 new metrics::SHA1EntropyProvider("42"))); |
45 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 48 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
46 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 49 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { | 427 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) { |
425 // Set an insecure new tab page URL and verify that it's ignored. | 428 // Set an insecure new tab page URL and verify that it's ignored. |
426 SetSearchProvider(false, true); | 429 SetSearchProvider(false, true); |
427 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 430 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
428 chrome::GetNewTabPageURL(profile())); | 431 chrome::GetNewTabPageURL(profile())); |
429 GURL new_tab_url(chrome::kChromeUINewTabURL); | 432 GURL new_tab_url(chrome::kChromeUINewTabURL); |
430 EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile())); | 433 EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile())); |
431 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); | 434 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); |
432 } | 435 } |
433 | 436 |
| 437 #if defined(ENABLE_MANAGED_USERS) |
434 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { | 438 TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { |
435 // Block access to foo.com in the URL filter. | 439 // Block access to foo.com in the URL filter. |
436 SupervisedUserService* supervised_user_service = | 440 SupervisedUserService* supervised_user_service = |
437 SupervisedUserServiceFactory::GetForProfile(profile()); | 441 SupervisedUserServiceFactory::GetForProfile(profile()); |
438 SupervisedUserURLFilter* url_filter = | 442 SupervisedUserURLFilter* url_filter = |
439 supervised_user_service->GetURLFilterForUIThread(); | 443 supervised_user_service->GetURLFilterForUIThread(); |
440 std::map<std::string, bool> hosts; | 444 std::map<std::string, bool> hosts; |
441 hosts["foo.com"] = false; | 445 hosts["foo.com"] = false; |
442 url_filter->SetManualHosts(&hosts); | 446 url_filter->SetManualHosts(&hosts); |
443 | 447 |
444 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 448 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
445 chrome::GetNewTabPageURL(profile())); | 449 chrome::GetNewTabPageURL(profile())); |
446 GURL new_tab_url(chrome::kChromeUINewTabURL); | 450 GURL new_tab_url(chrome::kChromeUINewTabURL); |
447 EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile())); | 451 EXPECT_TRUE(HandleNewTabURLRewrite(&new_tab_url, profile())); |
448 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); | 452 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), new_tab_url); |
449 EXPECT_EQ(GURL(), GetInstantURL(profile(), false)); | 453 EXPECT_EQ(GURL(), GetInstantURL(profile(), false)); |
450 } | 454 } |
| 455 #endif |
451 | 456 |
452 TEST_F(SearchTest, GetInstantURL) { | 457 TEST_F(SearchTest, GetInstantURL) { |
453 // No Instant URL because "strk" is missing. | 458 // No Instant URL because "strk" is missing. |
454 SetDefaultInstantTemplateUrl(false); | 459 SetDefaultInstantTemplateUrl(false); |
455 EXPECT_EQ(GURL(), GetInstantURL(profile(), false)); | 460 EXPECT_EQ(GURL(), GetInstantURL(profile(), false)); |
456 | 461 |
457 // Set an Instant URL with a valid search terms replacement key. | 462 // Set an Instant URL with a valid search terms replacement key. |
458 SetDefaultInstantTemplateUrl(true); | 463 SetDefaultInstantTemplateUrl(true); |
459 | 464 |
460 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". | 465 // Now there should be a valid Instant URL. Note the HTTPS "upgrade". |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 } | 1005 } |
1001 | 1006 |
1002 TEST_F(OriginChipTest, CommandLineOnSrp) { | 1007 TEST_F(OriginChipTest, CommandLineOnSrp) { |
1003 CommandLine::ForCurrentProcess()->AppendSwitch( | 1008 CommandLine::ForCurrentProcess()->AppendSwitch( |
1004 switches::kEnableOriginChipOnSrp); | 1009 switches::kEnableOriginChipOnSrp); |
1005 EXPECT_TRUE(ShouldDisplayOriginChip()); | 1010 EXPECT_TRUE(ShouldDisplayOriginChip()); |
1006 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); | 1011 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); |
1007 } | 1012 } |
1008 | 1013 |
1009 } // namespace chrome | 1014 } // namespace chrome |
OLD | NEW |