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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 data.instant_url = "http://foo.com/instant?" | 176 data.instant_url = "http://foo.com/instant?" |
177 "{google:omniboxStartMarginParameter}{google:forceInstantResults}" | 177 "{google:omniboxStartMarginParameter}{google:forceInstantResults}" |
178 "foo=foo#foo=foo&strk"; | 178 "foo=foo#foo=foo&strk"; |
179 if (set_ntp_url) { | 179 if (set_ntp_url) { |
180 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + | 180 data.new_tab_url = (insecure_ntp_url ? "http" : "https") + |
181 std::string("://foo.com/newtab?strk"); | 181 std::string("://foo.com/newtab?strk"); |
182 } | 182 } |
183 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); | 183 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); |
184 data.search_terms_replacement_key = "strk"; | 184 data.search_terms_replacement_key = "strk"; |
185 | 185 |
186 TemplateURL* template_url = new TemplateURL(profile(), data); | 186 TemplateURL* template_url = new TemplateURL(data); |
187 // Takes ownership of |template_url|. | 187 // Takes ownership of |template_url|. |
188 template_url_service->Add(template_url); | 188 template_url_service->Add(template_url); |
189 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 189 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
190 } | 190 } |
191 | 191 |
192 // Build an Instant URL with or without a valid search terms replacement key | 192 // Build an Instant URL with or without a valid search terms replacement key |
193 // as per |has_search_term_replacement_key|. Set that URL as the instant URL | 193 // as per |has_search_term_replacement_key|. Set that URL as the instant URL |
194 // for the default search provider. | 194 // for the default search provider. |
195 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) { | 195 void SetDefaultInstantTemplateUrl(bool has_search_term_replacement_key) { |
196 TemplateURLService* template_url_service = | 196 TemplateURLService* template_url_service = |
197 TemplateURLServiceFactory::GetForProfile(profile()); | 197 TemplateURLServiceFactory::GetForProfile(profile()); |
198 | 198 |
199 static const char kInstantURLWithStrk[] = | 199 static const char kInstantURLWithStrk[] = |
200 "http://foo.com/instant?foo=foo#foo=foo&strk"; | 200 "http://foo.com/instant?foo=foo#foo=foo&strk"; |
201 static const char kInstantURLNoStrk[] = | 201 static const char kInstantURLNoStrk[] = |
202 "http://foo.com/instant?foo=foo#foo=foo"; | 202 "http://foo.com/instant?foo=foo#foo=foo"; |
203 | 203 |
204 TemplateURLData data; | 204 TemplateURLData data; |
205 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 205 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
206 data.instant_url = (has_search_term_replacement_key ? | 206 data.instant_url = (has_search_term_replacement_key ? |
207 kInstantURLWithStrk : kInstantURLNoStrk); | 207 kInstantURLWithStrk : kInstantURLNoStrk); |
208 data.search_terms_replacement_key = "strk"; | 208 data.search_terms_replacement_key = "strk"; |
209 | 209 |
210 TemplateURL* template_url = new TemplateURL(profile(), data); | 210 TemplateURL* template_url = new TemplateURL(data); |
211 // Takes ownership of |template_url|. | 211 // Takes ownership of |template_url|. |
212 template_url_service->Add(template_url); | 212 template_url_service->Add(template_url); |
213 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 213 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
214 } | 214 } |
215 | 215 |
216 bool InInstantProcess(const content::WebContents* contents) { | 216 bool InInstantProcess(const content::WebContents* contents) { |
217 InstantService* instant_service = | 217 InstantService* instant_service = |
218 InstantServiceFactory::GetForProfile(profile()); | 218 InstantServiceFactory::GetForProfile(profile()); |
219 return instant_service->IsInstantProcess( | 219 return instant_service->IsInstantProcess( |
220 contents->GetRenderProcessHost()->GetID()); | 220 contents->GetRenderProcessHost()->GetID()); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 TEST_F(SearchTest, CommandLineOverrides) { | 618 TEST_F(SearchTest, CommandLineOverrides) { |
619 GURL local_instant_url(GetLocalInstantURL(profile())); | 619 GURL local_instant_url(GetLocalInstantURL(profile())); |
620 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); | 620 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); |
621 | 621 |
622 TemplateURLService* template_url_service = | 622 TemplateURLService* template_url_service = |
623 TemplateURLServiceFactory::GetForProfile(profile()); | 623 TemplateURLServiceFactory::GetForProfile(profile()); |
624 TemplateURLData data; | 624 TemplateURLData data; |
625 data.SetURL("{google:baseURL}search?q={searchTerms}"); | 625 data.SetURL("{google:baseURL}search?q={searchTerms}"); |
626 data.instant_url = "{google:baseURL}webhp?strk"; | 626 data.instant_url = "{google:baseURL}webhp?strk"; |
627 data.search_terms_replacement_key = "strk"; | 627 data.search_terms_replacement_key = "strk"; |
628 TemplateURL* template_url = new TemplateURL(profile(), data); | 628 TemplateURL* template_url = new TemplateURL(data); |
629 // Takes ownership of |template_url|. | 629 // Takes ownership of |template_url|. |
630 template_url_service->Add(template_url); | 630 template_url_service->Add(template_url); |
631 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 631 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
632 | 632 |
633 // By default, Instant Extended forces the instant URL to be HTTPS, so even if | 633 // By default, Instant Extended forces the instant URL to be HTTPS, so even if |
634 // we set a Google base URL that is HTTP, we should get an HTTPS URL. | 634 // we set a Google base URL that is HTTP, we should get an HTTPS URL. |
635 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); | 635 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); |
636 GURL instant_url(GetInstantURL(profile(), kDisableStartMargin, false)); | 636 GURL instant_url(GetInstantURL(profile(), kDisableStartMargin, false)); |
637 ASSERT_TRUE(instant_url.is_valid()); | 637 ASSERT_TRUE(instant_url.is_valid()); |
638 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); | 638 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 class SearchURLTest : public SearchTest { | 892 class SearchURLTest : public SearchTest { |
893 protected: | 893 protected: |
894 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) | 894 virtual void SetSearchProvider(bool set_ntp_url, bool insecure_ntp_url) |
895 OVERRIDE { | 895 OVERRIDE { |
896 TemplateURLService* template_url_service = | 896 TemplateURLService* template_url_service = |
897 TemplateURLServiceFactory::GetForProfile(profile()); | 897 TemplateURLServiceFactory::GetForProfile(profile()); |
898 TemplateURLData data; | 898 TemplateURLData data; |
899 data.SetURL("{google:baseURL}search?" | 899 data.SetURL("{google:baseURL}search?" |
900 "{google:instantExtendedEnabledParameter}q={searchTerms}"); | 900 "{google:instantExtendedEnabledParameter}q={searchTerms}"); |
901 data.search_terms_replacement_key = "espv"; | 901 data.search_terms_replacement_key = "espv"; |
902 template_url_ = new TemplateURL(profile(), data); | 902 template_url_ = new TemplateURL(data); |
903 // |template_url_service| takes ownership of |template_url_|. | 903 // |template_url_service| takes ownership of |template_url_|. |
904 template_url_service->Add(template_url_); | 904 template_url_service->Add(template_url_); |
905 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); | 905 template_url_service->SetUserSelectedDefaultSearchProvider(template_url_); |
906 } | 906 } |
907 | 907 |
908 TemplateURL* template_url_; | 908 TemplateURL* template_url_; |
909 }; | 909 }; |
910 | 910 |
911 TEST_F(SearchURLTest, QueryExtractionEnabled) { | 911 TEST_F(SearchURLTest, QueryExtractionEnabled) { |
912 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/"); | 912 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/"); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 } | 1169 } |
1170 | 1170 |
1171 TEST_F(OriginChipTest, CommandLineOnSrp) { | 1171 TEST_F(OriginChipTest, CommandLineOnSrp) { |
1172 CommandLine::ForCurrentProcess()->AppendSwitch( | 1172 CommandLine::ForCurrentProcess()->AppendSwitch( |
1173 switches::kEnableOriginChipOnSrp); | 1173 switches::kEnableOriginChipOnSrp); |
1174 EXPECT_TRUE(ShouldDisplayOriginChip()); | 1174 EXPECT_TRUE(ShouldDisplayOriginChip()); |
1175 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); | 1175 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); |
1176 } | 1176 } |
1177 | 1177 |
1178 } // namespace chrome | 1178 } // namespace chrome |
OLD | NEW |