| 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" |
| 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 12 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 12 #include "chrome/browser/managed_mode/managed_user_service.h" | 13 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 13 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 14 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 14 #include "chrome/browser/search/instant_service.h" | 15 #include "chrome/browser/search/instant_service.h" |
| 15 #include "chrome/browser/search/instant_service_factory.h" | 16 #include "chrome/browser/search/instant_service_factory.h" |
| 16 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
| 17 #include "chrome/browser/search_engines/search_terms_data.h" | 18 #include "chrome/browser/search_engines/search_terms_data.h" |
| 18 #include "chrome/browser/search_engines/template_url_service.h" | 19 #include "chrome/browser/search_engines/template_url_service.h" |
| 19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 field_trial_list_.reset(new base::FieldTrialList( | 160 field_trial_list_.reset(new base::FieldTrialList( |
| 160 new metrics::SHA1EntropyProvider("42"))); | 161 new metrics::SHA1EntropyProvider("42"))); |
| 161 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 162 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 162 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 163 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 163 TemplateURLService* template_url_service = | 164 TemplateURLService* template_url_service = |
| 164 TemplateURLServiceFactory::GetForProfile(profile()); | 165 TemplateURLServiceFactory::GetForProfile(profile()); |
| 165 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); | 166 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
| 166 SetSearchProvider(true, false); | 167 SetSearchProvider(true, false); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) { | 170 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) { |
| 170 TemplateURLService* template_url_service = | 171 TemplateURLService* template_url_service = |
| 171 TemplateURLServiceFactory::GetForProfile(profile()); | 172 TemplateURLServiceFactory::GetForProfile(profile()); |
| 172 TemplateURLData data; | 173 TemplateURLData data; |
| 173 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 174 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
| 174 data.instant_url = "http://foo.com/instant?" | 175 data.instant_url = "http://foo.com/instant?" |
| 175 "{google:omniboxStartMarginParameter}{google:forceInstantResults}" | 176 "{google:omniboxStartMarginParameter}{google:forceInstantResults}" |
| 176 "foo=foo#foo=foo&strk"; | 177 "foo=foo#foo=foo&strk"; |
| 177 if (set_ntp_url) { | 178 if (set_ntp_url) { |
| 178 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + | 179 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + |
| 179 std::string("://foo.com/newtab?strk"); | 180 std::string("://foo.com/newtab?strk"); |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 // "prefetch_results" flag is enabled via field trials. | 742 // "prefetch_results" flag is enabled via field trials. |
| 742 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 743 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 743 "EmbeddedSearch", | 744 "EmbeddedSearch", |
| 744 "Group1 espv:80 prefetch_results:1")); | 745 "Group1 espv:80 prefetch_results:1")); |
| 745 EXPECT_TRUE(ShouldPrefetchSearchResults()); | 746 EXPECT_TRUE(ShouldPrefetchSearchResults()); |
| 746 | 747 |
| 747 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), | 748 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), |
| 748 GetSearchResultPrefetchBaseURL(profile())); | 749 GetSearchResultPrefetchBaseURL(profile())); |
| 749 } | 750 } |
| 750 | 751 |
| 752 class SearchURLTest : public SearchTest { |
| 753 protected: |
| 754 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) |
| 755 OVERRIDE { |
| 756 TemplateURLService* template_url_service = |
| 757 TemplateURLServiceFactory::GetForProfile(profile()); |
| 758 TemplateURLData data; |
| 759 data.SetURL("{google:baseURL}search?" |
| 760 "{google:instantExtendedEnabledParameter}q={searchTerms}"); |
| 761 data.search_terms_replacement_key = "espv"; |
| 762 template_url_ = new TemplateURL(profile(), data); |
| 763 // Takes ownership of |template_url|. |
| 764 template_url_service->Add(template_url_); |
| 765 template_url_service->SetDefaultSearchProvider(template_url_); |
| 766 } |
| 767 |
| 768 TemplateURL* template_url_; |
| 769 }; |
| 770 |
| 771 TEST_F(SearchURLTest, QueryExtractionEnabled) { |
| 772 EnableQueryExtractionForTesting(); |
| 773 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 774 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); |
| 775 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args)); |
| 776 ASSERT_TRUE(result.is_valid()); |
| 777 // Query extraction is enabled. Make sure |
| 778 // {google:instantExtendedEnabledParameter} is set in the search URL. |
| 779 EXPECT_EQ("http://www.google.com/search?espv=2&q=foo", result.spec()); |
| 780 } |
| 781 |
| 782 TEST_F(SearchURLTest, QueryExtractionDisabled) { |
| 783 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 784 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); |
| 785 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args)); |
| 786 ASSERT_TRUE(result.is_valid()); |
| 787 // Query extraction is disabled. Make sure |
| 788 // {google:instantExtendedEnabledParameter} is not set in the search URL. |
| 789 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec()); |
| 790 } |
| 791 |
| 792 typedef SearchTest InstantExtendedEnabledParamTest; |
| 793 |
| 794 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionDisabled) { |
| 795 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 796 "Group1 espv:2")); |
| 797 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 798 // Make sure InstantExtendedEnabledParam() returns an empty string for search |
| 799 // requests. |
| 800 EXPECT_EQ("", InstantExtendedEnabledParam(true)); |
| 801 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false)); |
| 802 } |
| 803 |
| 804 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionEnabled) { |
| 805 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 806 "EmbeddedSearch", "Group1 espv:2 query_extraction:1")); |
| 807 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 808 // Make sure InstantExtendedEnabledParam() returns a non-empty param string |
| 809 // for search requests. |
| 810 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(true)); |
| 811 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false)); |
| 812 } |
| 813 |
| 751 typedef SearchTest IsQueryExtractionEnabledTest; | 814 typedef SearchTest IsQueryExtractionEnabledTest; |
| 752 | 815 |
| 753 TEST_F(IsQueryExtractionEnabledTest, NotSet) { | 816 TEST_F(IsQueryExtractionEnabledTest, NotSet) { |
| 754 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 817 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 755 "EmbeddedSearch", "Group1 espv:2")); | 818 "EmbeddedSearch", "Group1 espv:2")); |
| 756 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 819 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 757 EXPECT_FALSE(IsQueryExtractionEnabled()); | 820 EXPECT_FALSE(IsQueryExtractionEnabled()); |
| 758 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | 821 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 759 } | 822 } |
| 760 | 823 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 } | 1031 } |
| 969 | 1032 |
| 970 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) { | 1033 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) { |
| 971 CommandLine::ForCurrentProcess()->AppendSwitch( | 1034 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 972 switches::kEnableOriginChipLeadingMenuButton); | 1035 switches::kEnableOriginChipLeadingMenuButton); |
| 973 EXPECT_TRUE(ShouldDisplayOriginChip()); | 1036 EXPECT_TRUE(ShouldDisplayOriginChip()); |
| 974 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition()); | 1037 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition()); |
| 975 } | 1038 } |
| 976 | 1039 |
| 977 } // namespace chrome | 1040 } // namespace chrome |
| OLD | NEW |