| 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 "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 246 |
| 247 turl_model->Load(); | 247 turl_model->Load(); |
| 248 | 248 |
| 249 // Reset the default TemplateURL. | 249 // Reset the default TemplateURL. |
| 250 TemplateURLData data; | 250 TemplateURLData data; |
| 251 data.short_name = ASCIIToUTF16("t"); | 251 data.short_name = ASCIIToUTF16("t"); |
| 252 data.SetURL("http://defaultturl/{searchTerms}"); | 252 data.SetURL("http://defaultturl/{searchTerms}"); |
| 253 data.suggestions_url = "http://defaultturl2/{searchTerms}"; | 253 data.suggestions_url = "http://defaultturl2/{searchTerms}"; |
| 254 data.instant_url = "http://does/not/exist?strk=1"; | 254 data.instant_url = "http://does/not/exist?strk=1"; |
| 255 data.search_terms_replacement_key = "strk"; | 255 data.search_terms_replacement_key = "strk"; |
| 256 default_t_url_ = new TemplateURL(&profile_, data); | 256 default_t_url_ = new TemplateURL(data); |
| 257 turl_model->Add(default_t_url_); | 257 turl_model->Add(default_t_url_); |
| 258 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 258 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
| 259 TemplateURLID default_provider_id = default_t_url_->id(); | 259 TemplateURLID default_provider_id = default_t_url_->id(); |
| 260 ASSERT_NE(0, default_provider_id); | 260 ASSERT_NE(0, default_provider_id); |
| 261 | 261 |
| 262 // Add url1, with search term term1_. | 262 // Add url1, with search term term1_. |
| 263 term1_url_ = AddSearchToHistory(default_t_url_, term1_, 1); | 263 term1_url_ = AddSearchToHistory(default_t_url_, term1_, 1); |
| 264 | 264 |
| 265 // Create another TemplateURL. | 265 // Create another TemplateURL. |
| 266 data.short_name = ASCIIToUTF16("k"); | 266 data.short_name = ASCIIToUTF16("k"); |
| 267 data.SetKeyword(ASCIIToUTF16("k")); | 267 data.SetKeyword(ASCIIToUTF16("k")); |
| 268 data.SetURL("http://keyword/{searchTerms}"); | 268 data.SetURL("http://keyword/{searchTerms}"); |
| 269 data.suggestions_url = "http://suggest_keyword/{searchTerms}"; | 269 data.suggestions_url = "http://suggest_keyword/{searchTerms}"; |
| 270 keyword_t_url_ = new TemplateURL(&profile_, data); | 270 keyword_t_url_ = new TemplateURL(data); |
| 271 turl_model->Add(keyword_t_url_); | 271 turl_model->Add(keyword_t_url_); |
| 272 ASSERT_NE(0, keyword_t_url_->id()); | 272 ASSERT_NE(0, keyword_t_url_->id()); |
| 273 | 273 |
| 274 // Add a page and search term for keyword_t_url_. | 274 // Add a page and search term for keyword_t_url_. |
| 275 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); | 275 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); |
| 276 | 276 |
| 277 // Keywords are updated by the InMemoryHistoryBackend only after the message | 277 // Keywords are updated by the InMemoryHistoryBackend only after the message |
| 278 // has been processed on the history thread. Block until history processes all | 278 // has been processed on the history thread. Block until history processes all |
| 279 // requests to ensure the InMemoryDatabase is the state we expect it. | 279 // requests to ensure the InMemoryDatabase is the state we expect it. |
| 280 profile_.BlockUntilHistoryProcessesPendingRequests(); | 280 profile_.BlockUntilHistoryProcessesPendingRequests(); |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 // Ensures command-line flags are reflected in the URLs the search provider | 1026 // Ensures command-line flags are reflected in the URLs the search provider |
| 1027 // generates. | 1027 // generates. |
| 1028 TEST_F(SearchProviderTest, CommandLineOverrides) { | 1028 TEST_F(SearchProviderTest, CommandLineOverrides) { |
| 1029 TemplateURLService* turl_model = | 1029 TemplateURLService* turl_model = |
| 1030 TemplateURLServiceFactory::GetForProfile(&profile_); | 1030 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 1031 | 1031 |
| 1032 TemplateURLData data; | 1032 TemplateURLData data; |
| 1033 data.short_name = ASCIIToUTF16("default"); | 1033 data.short_name = ASCIIToUTF16("default"); |
| 1034 data.SetKeyword(data.short_name); | 1034 data.SetKeyword(data.short_name); |
| 1035 data.SetURL("{google:baseURL}{searchTerms}"); | 1035 data.SetURL("{google:baseURL}{searchTerms}"); |
| 1036 default_t_url_ = new TemplateURL(&profile_, data); | 1036 default_t_url_ = new TemplateURL(data); |
| 1037 turl_model->Add(default_t_url_); | 1037 turl_model->Add(default_t_url_); |
| 1038 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 1038 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
| 1039 | 1039 |
| 1040 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 1040 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, |
| 1041 "http://www.bar.com/"); | 1041 "http://www.bar.com/"); |
| 1042 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1042 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1043 switches::kExtraSearchQueryParams, "a=b"); | 1043 switches::kExtraSearchQueryParams, "a=b"); |
| 1044 | 1044 |
| 1045 TestData cases[] = { | 1045 TestData cases[] = { |
| 1046 { ASCIIToUTF16("k a"), 2, | 1046 { ASCIIToUTF16("k a"), 2, |
| (...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2889 } | 2889 } |
| 2890 | 2890 |
| 2891 TEST_F(SearchProviderTest, CanSendURL) { | 2891 TEST_F(SearchProviderTest, CanSendURL) { |
| 2892 TemplateURLData template_url_data; | 2892 TemplateURLData template_url_data; |
| 2893 template_url_data.short_name = ASCIIToUTF16("t"); | 2893 template_url_data.short_name = ASCIIToUTF16("t"); |
| 2894 template_url_data.SetURL("http://www.google.com/{searchTerms}"); | 2894 template_url_data.SetURL("http://www.google.com/{searchTerms}"); |
| 2895 template_url_data.suggestions_url = "http://www.google.com/{searchTerms}"; | 2895 template_url_data.suggestions_url = "http://www.google.com/{searchTerms}"; |
| 2896 template_url_data.instant_url = "http://does/not/exist?strk=1"; | 2896 template_url_data.instant_url = "http://does/not/exist?strk=1"; |
| 2897 template_url_data.search_terms_replacement_key = "strk"; | 2897 template_url_data.search_terms_replacement_key = "strk"; |
| 2898 template_url_data.id = SEARCH_ENGINE_GOOGLE; | 2898 template_url_data.id = SEARCH_ENGINE_GOOGLE; |
| 2899 TemplateURL google_template_url(&profile_, template_url_data); | 2899 TemplateURL google_template_url(template_url_data); |
| 2900 | 2900 |
| 2901 // Create field trial. | 2901 // Create field trial. |
| 2902 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( | 2902 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( |
| 2903 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); | 2903 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); |
| 2904 field_trial->group(); | 2904 field_trial->group(); |
| 2905 | 2905 |
| 2906 // Not signed in. | 2906 // Not signed in. |
| 2907 EXPECT_FALSE(SearchProvider::CanSendURL( | 2907 EXPECT_FALSE(SearchProvider::CanSendURL( |
| 2908 GURL("http://www.google.com/search"), | 2908 GURL("http://www.google.com/search"), |
| 2909 GURL("https://www.google.com/complete/search"), &google_template_url, | 2909 GURL("https://www.google.com/complete/search"), &google_template_url, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3124 | 3124 |
| 3125 TemplateURLService* turl_model = | 3125 TemplateURLService* turl_model = |
| 3126 TemplateURLServiceFactory::GetForProfile(&profile_); | 3126 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 3127 | 3127 |
| 3128 TemplateURLData data; | 3128 TemplateURLData data; |
| 3129 data.short_name = ASCIIToUTF16("default"); | 3129 data.short_name = ASCIIToUTF16("default"); |
| 3130 data.SetKeyword(data.short_name); | 3130 data.SetKeyword(data.short_name); |
| 3131 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); | 3131 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); |
| 3132 data.suggestions_url = | 3132 data.suggestions_url = |
| 3133 "http://suggest/?q={searchTerms}&{google:sessionToken}"; | 3133 "http://suggest/?q={searchTerms}&{google:sessionToken}"; |
| 3134 default_t_url_ = new TemplateURL(&profile_, data); | 3134 default_t_url_ = new TemplateURL(data); |
| 3135 turl_model->Add(default_t_url_); | 3135 turl_model->Add(default_t_url_); |
| 3136 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | 3136 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
| 3137 | 3137 |
| 3138 base::string16 term = term1_.substr(0, term1_.length() - 1); | 3138 base::string16 term = term1_.substr(0, term1_.length() - 1); |
| 3139 QueryForInput(term, false, false); | 3139 QueryForInput(term, false, false); |
| 3140 | 3140 |
| 3141 // Make sure the default provider's suggest service was queried. | 3141 // Make sure the default provider's suggest service was queried. |
| 3142 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 3142 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| 3143 SearchProvider::kDefaultProviderURLFetcherID); | 3143 SearchProvider::kDefaultProviderURLFetcherID); |
| 3144 ASSERT_TRUE(fetcher); | 3144 ASSERT_TRUE(fetcher); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3178 | 3178 |
| 3179 // The expiration time is always updated. | 3179 // The expiration time is always updated. |
| 3180 provider_->GetSessionToken(); | 3180 provider_->GetSessionToken(); |
| 3181 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; | 3181 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; |
| 3182 base::PlatformThread::Sleep(kSmallDelta); | 3182 base::PlatformThread::Sleep(kSmallDelta); |
| 3183 provider_->GetSessionToken(); | 3183 provider_->GetSessionToken(); |
| 3184 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; | 3184 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; |
| 3185 EXPECT_GT(expiration_time_2, expiration_time_1); | 3185 EXPECT_GT(expiration_time_2, expiration_time_1); |
| 3186 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); | 3186 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); |
| 3187 } | 3187 } |
| OLD | NEW |