OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 turl_model->Load(); | 279 turl_model->Load(); |
280 | 280 |
281 // Reset the default TemplateURL. | 281 // Reset the default TemplateURL. |
282 TemplateURLData data; | 282 TemplateURLData data; |
283 data.SetShortName(ASCIIToUTF16("t")); | 283 data.SetShortName(ASCIIToUTF16("t")); |
284 data.SetURL("http://defaultturl/{searchTerms}"); | 284 data.SetURL("http://defaultturl/{searchTerms}"); |
285 data.suggestions_url = "http://defaultturl2/{searchTerms}"; | 285 data.suggestions_url = "http://defaultturl2/{searchTerms}"; |
286 data.instant_url = "http://does/not/exist?strk=1"; | 286 data.instant_url = "http://does/not/exist?strk=1"; |
287 data.search_terms_replacement_key = "strk"; | 287 data.search_terms_replacement_key = "strk"; |
288 default_t_url_ = new TemplateURL(data); | 288 default_t_url_ = new TemplateURL(data); |
289 turl_model->Add(default_t_url_); | 289 turl_model->Add(base::WrapUnique(default_t_url_)); |
Peter Kasting
2016/09/01 08:21:39
Nit: These two lines could become:
default_t_ur
Avi (use Gerrit)
2016/09/01 15:14:46
Done.
| |
290 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 290 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
291 TemplateURLID default_provider_id = default_t_url_->id(); | 291 TemplateURLID default_provider_id = default_t_url_->id(); |
292 ASSERT_NE(0, default_provider_id); | 292 ASSERT_NE(0, default_provider_id); |
293 | 293 |
294 // Add url1, with search term term1_. | 294 // Add url1, with search term term1_. |
295 term1_url_ = AddSearchToHistory(default_t_url_, term1_, 1); | 295 term1_url_ = AddSearchToHistory(default_t_url_, term1_, 1); |
296 | 296 |
297 // Create another TemplateURL. | 297 // Create another TemplateURL. |
298 data.SetShortName(ASCIIToUTF16("k")); | 298 data.SetShortName(ASCIIToUTF16("k")); |
299 data.SetKeyword(ASCIIToUTF16("k")); | 299 data.SetKeyword(ASCIIToUTF16("k")); |
300 data.SetURL("http://keyword/{searchTerms}"); | 300 data.SetURL("http://keyword/{searchTerms}"); |
301 data.suggestions_url = "http://suggest_keyword/{searchTerms}"; | 301 data.suggestions_url = "http://suggest_keyword/{searchTerms}"; |
302 keyword_t_url_ = new TemplateURL(data); | 302 keyword_t_url_ = new TemplateURL(data); |
303 turl_model->Add(keyword_t_url_); | 303 turl_model->Add(base::WrapUnique(keyword_t_url_)); |
304 ASSERT_NE(0, keyword_t_url_->id()); | 304 ASSERT_NE(0, keyword_t_url_->id()); |
305 | 305 |
306 // Add a page and search term for keyword_t_url_. | 306 // Add a page and search term for keyword_t_url_. |
307 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); | 307 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); |
308 | 308 |
309 // Keywords are updated by the InMemoryHistoryBackend only after the message | 309 // Keywords are updated by the InMemoryHistoryBackend only after the message |
310 // has been processed on the history thread. Block until history processes all | 310 // has been processed on the history thread. Block until history processes all |
311 // requests to ensure the InMemoryDatabase is the state we expect it. | 311 // requests to ensure the InMemoryDatabase is the state we expect it. |
312 profile_.BlockUntilHistoryProcessesPendingRequests(); | 312 profile_.BlockUntilHistoryProcessesPendingRequests(); |
313 | 313 |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 // generates. | 1155 // generates. |
1156 TEST_F(SearchProviderTest, CommandLineOverrides) { | 1156 TEST_F(SearchProviderTest, CommandLineOverrides) { |
1157 TemplateURLService* turl_model = | 1157 TemplateURLService* turl_model = |
1158 TemplateURLServiceFactory::GetForProfile(&profile_); | 1158 TemplateURLServiceFactory::GetForProfile(&profile_); |
1159 | 1159 |
1160 TemplateURLData data; | 1160 TemplateURLData data; |
1161 data.SetShortName(ASCIIToUTF16("default")); | 1161 data.SetShortName(ASCIIToUTF16("default")); |
1162 data.SetKeyword(data.short_name()); | 1162 data.SetKeyword(data.short_name()); |
1163 data.SetURL("{google:baseURL}{searchTerms}"); | 1163 data.SetURL("{google:baseURL}{searchTerms}"); |
1164 default_t_url_ = new TemplateURL(data); | 1164 default_t_url_ = new TemplateURL(data); |
1165 turl_model->Add(default_t_url_); | 1165 turl_model->Add(base::WrapUnique(default_t_url_)); |
1166 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 1166 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
1167 | 1167 |
1168 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1168 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1169 switches::kGoogleBaseURL, "http://www.bar.com/"); | 1169 switches::kGoogleBaseURL, "http://www.bar.com/"); |
1170 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1170 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1171 switches::kExtraSearchQueryParams, "a=b"); | 1171 switches::kExtraSearchQueryParams, "a=b"); |
1172 | 1172 |
1173 TestData cases[] = { | 1173 TestData cases[] = { |
1174 { ASCIIToUTF16("k a"), 2, | 1174 { ASCIIToUTF16("k a"), 2, |
1175 { ResultInfo(GURL("http://keyword/a"), | 1175 { ResultInfo(GURL("http://keyword/a"), |
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3376 TemplateURLService* turl_model = | 3376 TemplateURLService* turl_model = |
3377 TemplateURLServiceFactory::GetForProfile(&profile_); | 3377 TemplateURLServiceFactory::GetForProfile(&profile_); |
3378 | 3378 |
3379 TemplateURLData data; | 3379 TemplateURLData data; |
3380 data.SetShortName(ASCIIToUTF16("default")); | 3380 data.SetShortName(ASCIIToUTF16("default")); |
3381 data.SetKeyword(data.short_name()); | 3381 data.SetKeyword(data.short_name()); |
3382 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); | 3382 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); |
3383 data.suggestions_url = | 3383 data.suggestions_url = |
3384 "http://suggest/?q={searchTerms}&{google:sessionToken}"; | 3384 "http://suggest/?q={searchTerms}&{google:sessionToken}"; |
3385 default_t_url_ = new TemplateURL(data); | 3385 default_t_url_ = new TemplateURL(data); |
3386 turl_model->Add(default_t_url_); | 3386 turl_model->Add(base::WrapUnique(default_t_url_)); |
3387 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 3387 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
3388 | 3388 |
3389 base::string16 term = term1_.substr(0, term1_.length() - 1); | 3389 base::string16 term = term1_.substr(0, term1_.length() - 1); |
3390 QueryForInput(term, false, false); | 3390 QueryForInput(term, false, false); |
3391 | 3391 |
3392 // Make sure the default provider's suggest service was queried. | 3392 // Make sure the default provider's suggest service was queried. |
3393 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 3393 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
3394 SearchProvider::kDefaultProviderURLFetcherID); | 3394 SearchProvider::kDefaultProviderURLFetcherID); |
3395 ASSERT_TRUE(fetcher); | 3395 ASSERT_TRUE(fetcher); |
3396 | 3396 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3518 } | 3518 } |
3519 | 3519 |
3520 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { | 3520 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { |
3521 AutocompleteInput input( | 3521 AutocompleteInput input( |
3522 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), | 3522 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), |
3523 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, | 3523 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, |
3524 ChromeAutocompleteSchemeClassifier(&profile_)); | 3524 ChromeAutocompleteSchemeClassifier(&profile_)); |
3525 provider_->Start(input, false); | 3525 provider_->Start(input, false); |
3526 EXPECT_TRUE(provider_->matches().empty()); | 3526 EXPECT_TRUE(provider_->matches().empty()); |
3527 } | 3527 } |
OLD | NEW |