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

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: Fix compile error 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"
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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 // "prefetch_results" flag is enabled via field trials. 754 // "prefetch_results" flag is enabled via field trials.
754 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 755 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
755 "EmbeddedSearch", 756 "EmbeddedSearch",
756 "Group1 espv:80 prefetch_results:1")); 757 "Group1 espv:80 prefetch_results:1"));
757 EXPECT_TRUE(ShouldPrefetchSearchResults()); 758 EXPECT_TRUE(ShouldPrefetchSearchResults());
758 759
759 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), 760 EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
760 GetSearchResultPrefetchBaseURL(profile())); 761 GetSearchResultPrefetchBaseURL(profile()));
761 } 762 }
762 763
764 class SearchURLTest : public SearchTest {
765 protected:
766 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url)
767 OVERRIDE {
768 TemplateURLService* template_url_service =
769 TemplateURLServiceFactory::GetForProfile(profile());
770 TemplateURLData data;
771 data.SetURL("{google:baseURL}search?"
772 "{google:instantExtendedEnabledParameter}q={searchTerms}");
773 data.search_terms_replacement_key = "espv";
774 template_url_ = new TemplateURL(profile(), data);
775 // Takes ownership of |template_url|.
776 template_url_service->Add(template_url_);
777 template_url_service->SetDefaultSearchProvider(template_url_);
778 }
779
780 TemplateURL* template_url_;
beaudoin 2014/02/04 13:55:23 Nit: Make this a scoped_ptr<> so it's deallocated
kmadhusu 2014/02/04 16:52:26 I have a raw pointer because TemplateURLService to
beaudoin 2014/02/04 16:57:07 SG. Just update the comment to make it clearer: //
kmadhusu 2014/02/04 17:09:06 Done.
781 };
782
783 TEST_F(SearchURLTest, QueryExtractionEnabled) {
784 EnableQueryExtractionForTesting();
785 EXPECT_TRUE(IsQueryExtractionEnabled());
786 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo"));
787 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args));
788 ASSERT_TRUE(result.is_valid());
789 // Query extraction is enabled. Make sure
790 // {google:instantExtendedEnabledParameter} is set in the search URL.
791 EXPECT_EQ("http://www.google.com/search?espv=2&q=foo", result.spec());
792 }
793
794 TEST_F(SearchURLTest, QueryExtractionDisabled) {
795 EXPECT_FALSE(IsQueryExtractionEnabled());
796 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo"));
797 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args));
798 ASSERT_TRUE(result.is_valid());
799 // Query extraction is disabled. Make sure
800 // {google:instantExtendedEnabledParameter} is not set in the search URL.
801 EXPECT_EQ("http://www.google.com/search?q=foo", result.spec());
802 }
803
804 typedef SearchTest InstantExtendedEnabledParamTest;
805
806 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionDisabled) {
807 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
808 "Group1 espv:2"));
809 EXPECT_FALSE(IsQueryExtractionEnabled());
810 // Make sure InstantExtendedEnabledParam() returns an empty string for search
811 // requests.
812 EXPECT_EQ("", InstantExtendedEnabledParam(true));
813 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false));
814 }
815
816 TEST_F(InstantExtendedEnabledParamTest, QueryExtractionEnabled) {
817 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
818 "EmbeddedSearch", "Group1 espv:2 query_extraction:1"));
819 EXPECT_TRUE(IsQueryExtractionEnabled());
820 // Make sure InstantExtendedEnabledParam() returns a non-empty param string
821 // for search requests.
822 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(true));
823 EXPECT_EQ("espv=2&", InstantExtendedEnabledParam(false));
824 }
825
763 typedef SearchTest IsQueryExtractionEnabledTest; 826 typedef SearchTest IsQueryExtractionEnabledTest;
764 827
765 TEST_F(IsQueryExtractionEnabledTest, NotSet) { 828 TEST_F(IsQueryExtractionEnabledTest, NotSet) {
766 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 829 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
767 "EmbeddedSearch", "Group1 espv:2")); 830 "EmbeddedSearch", "Group1 espv:2"));
768 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); 831 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
769 EXPECT_FALSE(IsQueryExtractionEnabled()); 832 EXPECT_FALSE(IsQueryExtractionEnabled());
770 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); 833 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
771 } 834 }
772 835
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 1043 }
981 1044
982 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) { 1045 TEST_F(OriginChipTest, CommandLineOriginChipLeadingMenuButton) {
983 CommandLine::ForCurrentProcess()->AppendSwitch( 1046 CommandLine::ForCurrentProcess()->AppendSwitch(
984 switches::kEnableOriginChipLeadingMenuButton); 1047 switches::kEnableOriginChipLeadingMenuButton);
985 EXPECT_TRUE(ShouldDisplayOriginChip()); 1048 EXPECT_TRUE(ShouldDisplayOriginChip());
986 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition()); 1049 EXPECT_EQ(ORIGIN_CHIP_LEADING_MENU_BUTTON, GetOriginChipPosition());
987 } 1050 }
988 1051
989 } // namespace chrome 1052 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698