| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete.h" | 12 #include "chrome/browser/autocomplete/autocomplete.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 14 #include "chrome/browser/autocomplete/keyword_provider.h" | 14 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 15 #include "chrome/browser/autocomplete/search_provider.h" | 15 #include "chrome/browser/autocomplete/search_provider.h" |
| 16 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
| 17 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
| 18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 19 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 static std::ostream& operator<<(std::ostream& os, | 28 static std::ostream& operator<<(std::ostream& os, |
| 28 const AutocompleteResult::const_iterator& it) { | 29 const AutocompleteResult::const_iterator& it) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 173 |
| 173 // The providers don't complete synchronously, so listen for "result updated" | 174 // The providers don't complete synchronously, so listen for "result updated" |
| 174 // notifications. | 175 // notifications. |
| 175 registrar_.Add(this, | 176 registrar_.Add(this, |
| 176 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 177 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 177 content::Source<AutocompleteController>(controller)); | 178 content::Source<AutocompleteController>(controller)); |
| 178 } | 179 } |
| 179 | 180 |
| 180 void AutocompleteProviderTest:: | 181 void AutocompleteProviderTest:: |
| 181 ResetControllerWithTestProvidersWithKeywordAndSearchProviders() { | 182 ResetControllerWithTestProvidersWithKeywordAndSearchProviders() { |
| 183 // WebDataService is not used in the test, but requires DB thread if |
| 184 // instantiated. |
| 185 WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile_, NULL); |
| 186 |
| 182 profile_.CreateTemplateURLService(); | 187 profile_.CreateTemplateURLService(); |
| 183 | 188 |
| 184 // Reset the default TemplateURL. | 189 // Reset the default TemplateURL. |
| 185 TemplateURLData data; | 190 TemplateURLData data; |
| 186 data.SetURL("http://defaultturl/{searchTerms}"); | 191 data.SetURL("http://defaultturl/{searchTerms}"); |
| 187 TemplateURL* default_t_url = new TemplateURL(data); | 192 TemplateURL* default_t_url = new TemplateURL(data); |
| 188 TemplateURLService* turl_model = | 193 TemplateURLService* turl_model = |
| 189 TemplateURLServiceFactory::GetForProfile(&profile_); | 194 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 190 turl_model->Add(default_t_url); | 195 turl_model->Add(default_t_url); |
| 191 turl_model->SetDefaultSearchProvider(default_t_url); | 196 turl_model->SetDefaultSearchProvider(default_t_url); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 211 providers_.push_back(keyword_provider); | 216 providers_.push_back(keyword_provider); |
| 212 AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_); | 217 AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_); |
| 213 search_provider->AddRef(); | 218 search_provider->AddRef(); |
| 214 providers_.push_back(search_provider); | 219 providers_.push_back(search_provider); |
| 215 | 220 |
| 216 controller_.reset(new AutocompleteController(providers_, &profile_)); | 221 controller_.reset(new AutocompleteController(providers_, &profile_)); |
| 217 } | 222 } |
| 218 | 223 |
| 219 void AutocompleteProviderTest:: | 224 void AutocompleteProviderTest:: |
| 220 ResetControllerWithKeywordProvider() { | 225 ResetControllerWithKeywordProvider() { |
| 226 // WebDataService is not used in the test, but requires DB thread if |
| 227 // instantiated. |
| 228 WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile_, NULL); |
| 221 profile_.CreateTemplateURLService(); | 229 profile_.CreateTemplateURLService(); |
| 222 | 230 |
| 223 TemplateURLService* turl_model = | 231 TemplateURLService* turl_model = |
| 224 TemplateURLServiceFactory::GetForProfile(&profile_); | 232 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 225 | 233 |
| 226 // Create a TemplateURL for KeywordProvider. | 234 // Create a TemplateURL for KeywordProvider. |
| 227 TemplateURLData data; | 235 TemplateURLData data; |
| 228 data.short_name = ASCIIToUTF16("foo.com"); | 236 data.short_name = ASCIIToUTF16("foo.com"); |
| 229 data.SetKeyword(ASCIIToUTF16("foo.com")); | 237 data.SetKeyword(ASCIIToUTF16("foo.com")); |
| 230 data.SetURL("http://foo.com/{searchTerms}"); | 238 data.SetURL("http://foo.com/{searchTerms}"); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 &scheme, | 615 &scheme, |
| 608 &host); | 616 &host); |
| 609 AutocompleteInput input(input_cases[i].input, string16(), true, false, | 617 AutocompleteInput input(input_cases[i].input, string16(), true, false, |
| 610 true, AutocompleteInput::ALL_MATCHES); | 618 true, AutocompleteInput::ALL_MATCHES); |
| 611 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin); | 619 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin); |
| 612 EXPECT_EQ(input_cases[i].scheme.len, scheme.len); | 620 EXPECT_EQ(input_cases[i].scheme.len, scheme.len); |
| 613 EXPECT_EQ(input_cases[i].host.begin, host.begin); | 621 EXPECT_EQ(input_cases[i].host.begin, host.begin); |
| 614 EXPECT_EQ(input_cases[i].host.len, host.len); | 622 EXPECT_EQ(input_cases[i].host.len, host.len); |
| 615 } | 623 } |
| 616 } | 624 } |
| OLD | NEW |