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

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

Issue 151813002: Adds InstantExtendedEnabledParam to the search request URL iff the query extraction flag is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/search_engines/search_terms_data.h » ('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 (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
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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 // "prefetch_results" flag is enabled via field trials. 793 // "prefetch_results" flag is enabled via field trials.
793 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 794 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
794 "EmbeddedSearch", 795 "EmbeddedSearch",
795 "Group1 espv:80 prefetch_results:1")); 796 "Group1 espv:80 prefetch_results:1"));
796 EXPECT_TRUE(ShouldPrefetchSearchResults()); 797 EXPECT_TRUE(ShouldPrefetchSearchResults());
797 798
798 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), 799 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
799 GetSearchResultPrefetchBaseURL(profile())); 800 GetSearchResultPrefetchBaseURL(profile()));
800 } 801 }
801 802
803 class SearchURLTest : public SearchTest {
804 protected:
805 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url)
806 OVERRIDE {
807 TemplateURLService* template_url_service =
808 TemplateURLServiceFactory::GetForProfile(profile());
809 TemplateURLData data;
810 data.SetURL("{google:baseURL}search?"
811 "{google:instantExtendedEnabledParameter}q={searchTerms}");
812 data.search_terms_replacement_key = "espv";
813 template_url_ = new TemplateURL(profile(), data);
814 // |template_url_service| takes ownership of |template_url_|.
815 template_url_service->Add(template_url_);
816 template_url_service->SetDefaultSearchProvider(template_url_);
817 }
818
819 TemplateURL* template_url_;
820 };
821
822 TEST_F(SearchURLTest, QueryExtractionEnabled) {
823 EnableQueryExtractionForTesting();
824 EXPECT_TRUE(IsQueryExtractionEnabled());
825 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo"));
826 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args));
827 ASSERT_TRUE(result.is_valid());
828 // Query extraction is enabled. Make sure
829 // {google:instantExtendedEnabledParameter} is set in the search URL.
830 EXPECT_EQ("http://www.google.com/search?espv=2&q=foo", result.spec());
831 }
832
833 TEST_F(SearchURLTest, QueryExtractionDisabled) {
834 EXPECT_FALSE(IsQueryExtractionEnabled());
835 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo"));
836 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args));
837 ASSERT_TRUE(result.is_valid());
838 // Query extraction is disabled. Make sure
839 // {google:instantExtendedEnabledParameter} is not set in the search URL.
840 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec());
841 }
842
843 typedef SearchTest InstantExtendedEnabledParamTest;
844
845 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionDisabled) {
846 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
847 "Group1 espv:12"));
848 // Make sure InstantExtendedEnabledParam() returns an empty string for search
849 // requests.
850 #if defined(OS_IOS) || defined(OS_ANDROID)
851 // Query extraction is always enabled on mobile.
852 EXPECT_TRUE(IsQueryExtractionEnabled());
853 EXPECT_EQ("espv=12&", InstantExtendedEnabledParam(true));
854 #else
855 EXPECT_FALSE(IsQueryExtractionEnabled());
856 EXPECT_EQ("", InstantExtendedEnabledParam(true));
857 #endif
858 EXPECT_EQ("espv=12&", InstantExtendedEnabledParam(false));
859 }
860
861 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionEnabled) {
862 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
863 "EmbeddedSearch", "Group1 espv:10 query_extraction:1"));
864 EXPECT_TRUE(IsQueryExtractionEnabled());
865 // Make sure InstantExtendedEnabledParam() returns a non-empty param string
866 // for search requests.
867 EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(true));
868 EXPECT_EQ("espv=10&", InstantExtendedEnabledParam(false));
869 }
870
871 TEST_F(InstantExtendedEnabledParamTest, UseDefaultEmbeddedSearchPageVersion) {
872 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
873 "EmbeddedSearch", "Group1 espv:-1 query_extraction:1"));
874 EXPECT_TRUE(IsQueryExtractionEnabled());
875 #if defined(OS_IOS) || defined(OS_ANDROID)
876 EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(true));
877 EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(false));
878 #else
879 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(true));
880 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false));
881 #endif
882 }
883
802 typedef SearchTest IsQueryExtractionEnabledTest; 884 typedef SearchTest IsQueryExtractionEnabledTest;
803 885
804 TEST_F(IsQueryExtractionEnabledTest, NotSet) { 886 TEST_F(IsQueryExtractionEnabledTest, NotSet) {
805 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 887 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
806 "EmbeddedSearch", "Group1 espv:2")); 888 "EmbeddedSearch", "Group1 espv:2"));
807 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); 889 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
808 EXPECT_FALSE(IsQueryExtractionEnabled()); 890 EXPECT_FALSE(IsQueryExtractionEnabled());
809 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); 891 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
810 } 892 }
811 893
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 } 1176 }
1095 1177
1096 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) { 1178 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) {
1097 CommandLine::ForCurrentProcess()->AppendSwitch( 1179 CommandLine::ForCurrentProcess()->AppendSwitch(
1098 switches::kEnableOriginChipV2HideOnUserInput); 1180 switches::kEnableOriginChipV2HideOnUserInput);
1099 EXPECT_TRUE(ShouldDisplayOriginChipV2()); 1181 EXPECT_TRUE(ShouldDisplayOriginChipV2());
1100 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger()); 1182 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger());
1101 } 1183 }
1102 1184
1103 } // namespace chrome 1185 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.cc ('k') | chrome/browser/search_engines/search_terms_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698