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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if (set_ntp_url) { | 178 if (set_ntp_url) { |
179 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + | 179 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + |
180 std::string("://foo.com/newtab?strk"); | 180 std::string("://foo.com/newtab?strk"); |
181 } | 181 } |
182 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); | 182 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); |
183 data.search_terms_replacement_key = "strk"; | 183 data.search_terms_replacement_key = "strk"; |
184 | 184 |
185 TemplateURL* template_url = new TemplateURL(profile(), data); | 185 TemplateURL* template_url = new TemplateURL(profile(), data); |
186 // Takes ownership of |template_url|. | 186 // Takes ownership of |template_url|. |
187 template_url_service->Add(template_url); | 187 template_url_service->Add(template_url); |
188 template_url_service->SetDefaultSearchProvider(template_url); | 188 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
189 } | 189 } |
190 | 190 |
191 // Build an Instant URL with or without a valid search terms replacement key | 191 // Build an Instant URL with or without a valid search terms replacement key |
192 // as per |has_search_term_replacement_key|. Set that URL as the instant URL | 192 // as per |has_search_term_replacement_key|. Set that URL as the instant URL |
193 // for the default search provider. | 193 // for the default search provider. |
194 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) { | 194 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) { |
195 TemplateURLService* template_url_service = | 195 TemplateURLService* template_url_service = |
196 TemplateURLServiceFactory::GetForProfile(profile()); | 196 TemplateURLServiceFactory::GetForProfile(profile()); |
197 | 197 |
198 static const char kInstantURLWithStrk[] = | 198 static const char kInstantURLWithStrk[] = |
199 "http://foo.com/instant?foo=foo#foo=foo&strk"; | 199 "http://foo.com/instant?foo=foo#foo=foo&strk"; |
200 static const char kInstantURLNoStrk[] = | 200 static const char kInstantURLNoStrk[] = |
201 "http://foo.com/instant?foo=foo#foo=foo"; | 201 "http://foo.com/instant?foo=foo#foo=foo"; |
202 | 202 |
203 TemplateURLData data; | 203 TemplateURLData data; |
204 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 204 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
205 data.instant_url = (has_search_term_replacement_key ? | 205 data.instant_url = (has_search_term_replacement_key ? |
206 kInstantURLWithStrk : kInstantURLNoStrk); | 206 kInstantURLWithStrk : kInstantURLNoStrk); |
207 data.search_terms_replacement_key = "strk"; | 207 data.search_terms_replacement_key = "strk"; |
208 | 208 |
209 TemplateURL* template_url = new TemplateURL(profile(), data); | 209 TemplateURL* template_url = new TemplateURL(profile(), data); |
210 // Takes ownership of |template_url|. | 210 // Takes ownership of |template_url|. |
211 template_url_service->Add(template_url); | 211 template_url_service->Add(template_url); |
212 template_url_service->SetDefaultSearchProvider(template_url); | 212 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
213 } | 213 } |
214 | 214 |
215 bool InInstantProcess(const content::WebContents* contents) { | 215 bool InInstantProcess(const content::WebContents* contents) { |
216 InstantService* instant_service = | 216 InstantService* instant_service = |
217 InstantServiceFactory::GetForProfile(profile()); | 217 InstantServiceFactory::GetForProfile(profile()); |
218 return instant_service->IsInstantProcess( | 218 return instant_service->IsInstantProcess( |
219 contents->GetRenderProcessHost()->GetID()); | 219 contents->GetRenderProcessHost()->GetID()); |
220 } | 220 } |
221 | 221 |
222 scoped_ptr<base::FieldTrialList> field_trial_list_; | 222 scoped_ptr<base::FieldTrialList> field_trial_list_; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 | 620 |
621 TemplateURLService* template_url_service = | 621 TemplateURLService* template_url_service = |
622 TemplateURLServiceFactory::GetForProfile(profile()); | 622 TemplateURLServiceFactory::GetForProfile(profile()); |
623 TemplateURLData data; | 623 TemplateURLData data; |
624 data.SetURL("{google:baseURL}search?q={searchTerms}"); | 624 data.SetURL("{google:baseURL}search?q={searchTerms}"); |
625 data.instant_url = "{google:baseURL}webhp?strk"; | 625 data.instant_url = "{google:baseURL}webhp?strk"; |
626 data.search_terms_replacement_key = "strk"; | 626 data.search_terms_replacement_key = "strk"; |
627 TemplateURL* template_url = new TemplateURL(profile(), data); | 627 TemplateURL* template_url = new TemplateURL(profile(), data); |
628 // Takes ownership of |template_url|. | 628 // Takes ownership of |template_url|. |
629 template_url_service->Add(template_url); | 629 template_url_service->Add(template_url); |
630 template_url_service->SetDefaultSearchProvider(template_url); | 630 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
631 | 631 |
632 // By default, Instant Extended forces the instant URL to be HTTPS, so even if | 632 // By default, Instant Extended forces the instant URL to be HTTPS, so even if |
633 // we set a Google base URL that is HTTP, we should get an HTTPS URL. | 633 // we set a Google base URL that is HTTP, we should get an HTTPS URL. |
634 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); | 634 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); |
635 GURL instant_url(GetInstantURL(profile(), kDisableStartMargin, false)); | 635 GURL instant_url(GetInstantURL(profile(), kDisableStartMargin, false)); |
636 ASSERT_TRUE(instant_url.is_valid()); | 636 ASSERT_TRUE(instant_url.is_valid()); |
637 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); | 637 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); |
638 | 638 |
639 // However, if the Google base URL is specified on the command line, the | 639 // However, if the Google base URL is specified on the command line, the |
640 // instant URL should just use it, even if it's HTTP. | 640 // instant URL should just use it, even if it's HTTP. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 OVERRIDE { | 864 OVERRIDE { |
865 TemplateURLService* template_url_service = | 865 TemplateURLService* template_url_service = |
866 TemplateURLServiceFactory::GetForProfile(profile()); | 866 TemplateURLServiceFactory::GetForProfile(profile()); |
867 TemplateURLData data; | 867 TemplateURLData data; |
868 data.SetURL("{google:baseURL}search?" | 868 data.SetURL("{google:baseURL}search?" |
869 "{google:instantExtendedEnabledParameter}q={searchTerms}"); | 869 "{google:instantExtendedEnabledParameter}q={searchTerms}"); |
870 data.search_terms_replacement_key = "espv"; | 870 data.search_terms_replacement_key = "espv"; |
871 template_url_ = new TemplateURL(profile(), data); | 871 template_url_ = new TemplateURL(profile(), data); |
872 // |template_url_service| takes ownership of |template_url_|. | 872 // |template_url_service| takes ownership of |template_url_|. |
873 template_url_service->Add(template_url_); | 873 template_url_service->Add(template_url_); |
874 template_url_service->SetDefaultSearchProvider(template_url_); | 874 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); |
875 } | 875 } |
876 | 876 |
877 TemplateURL* template_url_; | 877 TemplateURL* template_url_; |
878 }; | 878 }; |
879 | 879 |
880 TEST_F(SearchURLTest, QueryExtractionEnabled) { | 880 TEST_F(SearchURLTest, QueryExtractionEnabled) { |
881 EnableQueryExtractionForTesting(); | 881 EnableQueryExtractionForTesting(); |
882 EXPECT_TRUE(IsQueryExtractionEnabled()); | 882 EXPECT_TRUE(IsQueryExtractionEnabled()); |
883 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); | 883 TemplateURLRef::SearchTermsArgs search_terms_args(base::ASCIIToUTF16("foo")); |
884 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args)); | 884 GURL result(template_url_->url_ref().ReplaceSearchTerms(search_terms_args)); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 } | 1234 } |
1235 | 1235 |
1236 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) { | 1236 TEST_F(OriginChipV2Test, CommandLineHideOnUserInput) { |
1237 CommandLine::ForCurrentProcess()->AppendSwitch( | 1237 CommandLine::ForCurrentProcess()->AppendSwitch( |
1238 switches::kEnableOriginChipV2HideOnUserInput); | 1238 switches::kEnableOriginChipV2HideOnUserInput); |
1239 EXPECT_TRUE(ShouldDisplayOriginChipV2()); | 1239 EXPECT_TRUE(ShouldDisplayOriginChipV2()); |
1240 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger()); | 1240 EXPECT_EQ(ORIGIN_CHIP_V2_HIDE_ON_USER_INPUT, GetOriginChipV2HideTrigger()); |
1241 } | 1241 } |
1242 | 1242 |
1243 } // namespace chrome | 1243 } // namespace chrome |
OLD | NEW |