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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 278 |
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_ = turl_model->Add(base::MakeUnique<TemplateURL>(data)); |
289 turl_model->Add(default_t_url_); | |
290 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 289 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
291 TemplateURLID default_provider_id = default_t_url_->id(); | 290 TemplateURLID default_provider_id = default_t_url_->id(); |
292 ASSERT_NE(0, default_provider_id); | 291 ASSERT_NE(0, default_provider_id); |
293 | 292 |
294 // Add url1, with search term term1_. | 293 // Add url1, with search term term1_. |
295 term1_url_ = AddSearchToHistory(default_t_url_, term1_, 1); | 294 term1_url_ = AddSearchToHistory(default_t_url_, term1_, 1); |
296 | 295 |
297 // Create another TemplateURL. | 296 // Create another TemplateURL. |
298 data.SetShortName(ASCIIToUTF16("k")); | 297 data.SetShortName(ASCIIToUTF16("k")); |
299 data.SetKeyword(ASCIIToUTF16("k")); | 298 data.SetKeyword(ASCIIToUTF16("k")); |
300 data.SetURL("http://keyword/{searchTerms}"); | 299 data.SetURL("http://keyword/{searchTerms}"); |
301 data.suggestions_url = "http://suggest_keyword/{searchTerms}"; | 300 data.suggestions_url = "http://suggest_keyword/{searchTerms}"; |
302 keyword_t_url_ = new TemplateURL(data); | 301 keyword_t_url_ = turl_model->Add(base::MakeUnique<TemplateURL>(data)); |
303 turl_model->Add(keyword_t_url_); | |
304 ASSERT_NE(0, keyword_t_url_->id()); | 302 ASSERT_NE(0, keyword_t_url_->id()); |
305 | 303 |
306 // Add a page and search term for keyword_t_url_. | 304 // Add a page and search term for keyword_t_url_. |
307 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); | 305 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); |
308 | 306 |
309 // Keywords are updated by the InMemoryHistoryBackend only after the message | 307 // Keywords are updated by the InMemoryHistoryBackend only after the message |
310 // has been processed on the history thread. Block until history processes all | 308 // has been processed on the history thread. Block until history processes all |
311 // requests to ensure the InMemoryDatabase is the state we expect it. | 309 // requests to ensure the InMemoryDatabase is the state we expect it. |
312 profile_.BlockUntilHistoryProcessesPendingRequests(); | 310 profile_.BlockUntilHistoryProcessesPendingRequests(); |
313 | 311 |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 // Ensures command-line flags are reflected in the URLs the search provider | 1152 // Ensures command-line flags are reflected in the URLs the search provider |
1155 // generates. | 1153 // generates. |
1156 TEST_F(SearchProviderTest, CommandLineOverrides) { | 1154 TEST_F(SearchProviderTest, CommandLineOverrides) { |
1157 TemplateURLService* turl_model = | 1155 TemplateURLService* turl_model = |
1158 TemplateURLServiceFactory::GetForProfile(&profile_); | 1156 TemplateURLServiceFactory::GetForProfile(&profile_); |
1159 | 1157 |
1160 TemplateURLData data; | 1158 TemplateURLData data; |
1161 data.SetShortName(ASCIIToUTF16("default")); | 1159 data.SetShortName(ASCIIToUTF16("default")); |
1162 data.SetKeyword(data.short_name()); | 1160 data.SetKeyword(data.short_name()); |
1163 data.SetURL("{google:baseURL}{searchTerms}"); | 1161 data.SetURL("{google:baseURL}{searchTerms}"); |
1164 default_t_url_ = new TemplateURL(data); | 1162 default_t_url_ = turl_model->Add(base::MakeUnique<TemplateURL>(data)); |
1165 turl_model->Add(default_t_url_); | |
1166 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 1163 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
1167 | 1164 |
1168 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1165 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1169 switches::kGoogleBaseURL, "http://www.bar.com/"); | 1166 switches::kGoogleBaseURL, "http://www.bar.com/"); |
1170 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1167 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1171 switches::kExtraSearchQueryParams, "a=b"); | 1168 switches::kExtraSearchQueryParams, "a=b"); |
1172 | 1169 |
1173 TestData cases[] = { | 1170 TestData cases[] = { |
1174 { ASCIIToUTF16("k a"), 2, | 1171 { ASCIIToUTF16("k a"), 2, |
1175 { ResultInfo(GURL("http://keyword/a"), | 1172 { ResultInfo(GURL("http://keyword/a"), |
(...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3375 TEST_F(SearchProviderTest, SuggestQueryUsesToken) { | 3372 TEST_F(SearchProviderTest, SuggestQueryUsesToken) { |
3376 TemplateURLService* turl_model = | 3373 TemplateURLService* turl_model = |
3377 TemplateURLServiceFactory::GetForProfile(&profile_); | 3374 TemplateURLServiceFactory::GetForProfile(&profile_); |
3378 | 3375 |
3379 TemplateURLData data; | 3376 TemplateURLData data; |
3380 data.SetShortName(ASCIIToUTF16("default")); | 3377 data.SetShortName(ASCIIToUTF16("default")); |
3381 data.SetKeyword(data.short_name()); | 3378 data.SetKeyword(data.short_name()); |
3382 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); | 3379 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); |
3383 data.suggestions_url = | 3380 data.suggestions_url = |
3384 "http://suggest/?q={searchTerms}&{google:sessionToken}"; | 3381 "http://suggest/?q={searchTerms}&{google:sessionToken}"; |
3385 default_t_url_ = new TemplateURL(data); | 3382 default_t_url_ = turl_model->Add(base::MakeUnique<TemplateURL>(data)); |
3386 turl_model->Add(default_t_url_); | |
3387 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 3383 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
3388 | 3384 |
3389 base::string16 term = term1_.substr(0, term1_.length() - 1); | 3385 base::string16 term = term1_.substr(0, term1_.length() - 1); |
3390 QueryForInput(term, false, false); | 3386 QueryForInput(term, false, false); |
3391 | 3387 |
3392 // Make sure the default provider's suggest service was queried. | 3388 // Make sure the default provider's suggest service was queried. |
3393 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 3389 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
3394 SearchProvider::kDefaultProviderURLFetcherID); | 3390 SearchProvider::kDefaultProviderURLFetcherID); |
3395 ASSERT_TRUE(fetcher); | 3391 ASSERT_TRUE(fetcher); |
3396 | 3392 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3518 } | 3514 } |
3519 | 3515 |
3520 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { | 3516 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { |
3521 AutocompleteInput input( | 3517 AutocompleteInput input( |
3522 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), | 3518 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), |
3523 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, | 3519 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, |
3524 ChromeAutocompleteSchemeClassifier(&profile_)); | 3520 ChromeAutocompleteSchemeClassifier(&profile_)); |
3525 provider_->Start(input, false); | 3521 provider_->Start(input, false); |
3526 EXPECT_TRUE(provider_->matches().empty()); | 3522 EXPECT_TRUE(provider_->matches().empty()); |
3527 } | 3523 } |
OLD | NEW |