| 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" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 registrar_.Add(this, | 175 registrar_.Add(this, |
| 176 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 176 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 177 content::Source<AutocompleteController>(controller)); | 177 content::Source<AutocompleteController>(controller)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void AutocompleteProviderTest:: | 180 void AutocompleteProviderTest:: |
| 181 ResetControllerWithTestProvidersWithKeywordAndSearchProviders() { | 181 ResetControllerWithTestProvidersWithKeywordAndSearchProviders() { |
| 182 profile_.CreateTemplateURLService(); | 182 profile_.CreateTemplateURLService(); |
| 183 | 183 |
| 184 // Reset the default TemplateURL. | 184 // Reset the default TemplateURL. |
| 185 TemplateURL* default_t_url = new TemplateURL(); | 185 TemplateURLData data; |
| 186 default_t_url->SetURL("http://defaultturl/{searchTerms}"); | 186 data.SetURL("http://defaultturl/{searchTerms}"); |
| 187 TemplateURL* default_t_url = new TemplateURL(data); |
| 187 TemplateURLService* turl_model = | 188 TemplateURLService* turl_model = |
| 188 TemplateURLServiceFactory::GetForProfile(&profile_); | 189 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 189 turl_model->Add(default_t_url); | 190 turl_model->Add(default_t_url); |
| 190 turl_model->SetDefaultSearchProvider(default_t_url); | 191 turl_model->SetDefaultSearchProvider(default_t_url); |
| 191 TemplateURLID default_provider_id = default_t_url->id(); | 192 TemplateURLID default_provider_id = default_t_url->id(); |
| 192 ASSERT_NE(0, default_provider_id); | 193 ASSERT_NE(0, default_provider_id); |
| 193 | 194 |
| 194 // Create another TemplateURL for KeywordProvider. | 195 // Create another TemplateURL for KeywordProvider. |
| 195 TemplateURL* keyword_t_url = new TemplateURL(); | 196 data.short_name = ASCIIToUTF16("k"); |
| 196 keyword_t_url->set_short_name(ASCIIToUTF16("k")); | 197 data.SetKeyword(ASCIIToUTF16("k")); |
| 197 keyword_t_url->set_keyword(ASCIIToUTF16("k")); | 198 data.SetURL("http://keyword/{searchTerms}"); |
| 198 keyword_t_url->SetURL("http://keyword/{searchTerms}"); | 199 TemplateURL* keyword_t_url = new TemplateURL(data); |
| 199 turl_model->Add(keyword_t_url); | 200 turl_model->Add(keyword_t_url); |
| 200 ASSERT_NE(0, keyword_t_url->id()); | 201 ASSERT_NE(0, keyword_t_url->id()); |
| 201 | 202 |
| 202 // Forget about any existing providers. The controller owns them and will | 203 // Forget about any existing providers. The controller owns them and will |
| 203 // Release() them below, when we delete it during the call to reset(). | 204 // Release() them below, when we delete it during the call to reset(). |
| 204 providers_.clear(); | 205 providers_.clear(); |
| 205 | 206 |
| 206 // Create both a keyword and search provider, and add them in that order. | 207 // Create both a keyword and search provider, and add them in that order. |
| 207 // (Order is important; see comments in RunExactKeymatchTest().) | 208 // (Order is important; see comments in RunExactKeymatchTest().) |
| 208 AutocompleteProvider* keyword_provider = new KeywordProvider(NULL, &profile_); | 209 AutocompleteProvider* keyword_provider = new KeywordProvider(NULL, &profile_); |
| 209 keyword_provider->AddRef(); | 210 keyword_provider->AddRef(); |
| 210 providers_.push_back(keyword_provider); | 211 providers_.push_back(keyword_provider); |
| 211 AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_); | 212 AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_); |
| 212 search_provider->AddRef(); | 213 search_provider->AddRef(); |
| 213 providers_.push_back(search_provider); | 214 providers_.push_back(search_provider); |
| 214 | 215 |
| 215 controller_.reset(new AutocompleteController(providers_, &profile_)); | 216 controller_.reset(new AutocompleteController(providers_, &profile_)); |
| 216 } | 217 } |
| 217 | 218 |
| 218 void AutocompleteProviderTest:: | 219 void AutocompleteProviderTest:: |
| 219 ResetControllerWithKeywordProvider() { | 220 ResetControllerWithKeywordProvider() { |
| 220 profile_.CreateTemplateURLService(); | 221 profile_.CreateTemplateURLService(); |
| 221 | 222 |
| 222 TemplateURLService* turl_model = | 223 TemplateURLService* turl_model = |
| 223 TemplateURLServiceFactory::GetForProfile(&profile_); | 224 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 224 | 225 |
| 225 // Create a TemplateURL for KeywordProvider. | 226 // Create a TemplateURL for KeywordProvider. |
| 226 TemplateURL* keyword_t_url = new TemplateURL(); | 227 TemplateURLData data; |
| 227 keyword_t_url->set_short_name(ASCIIToUTF16("foo.com")); | 228 data.short_name = ASCIIToUTF16("foo.com"); |
| 228 keyword_t_url->set_keyword(ASCIIToUTF16("foo.com")); | 229 data.SetKeyword(ASCIIToUTF16("foo.com")); |
| 229 keyword_t_url->SetURL("http://foo.com/{searchTerms}"); | 230 data.SetURL("http://foo.com/{searchTerms}"); |
| 231 TemplateURL* keyword_t_url = new TemplateURL(data); |
| 230 turl_model->Add(keyword_t_url); | 232 turl_model->Add(keyword_t_url); |
| 231 ASSERT_NE(0, keyword_t_url->id()); | 233 ASSERT_NE(0, keyword_t_url->id()); |
| 232 | 234 |
| 233 // Create another TemplateURL for KeywordProvider. | 235 // Create another TemplateURL for KeywordProvider. |
| 234 keyword_t_url = new TemplateURL(); | 236 data.short_name = ASCIIToUTF16("bar.com"); |
| 235 keyword_t_url->set_short_name(ASCIIToUTF16("bar.com")); | 237 data.SetKeyword(ASCIIToUTF16("bar.com")); |
| 236 keyword_t_url->set_keyword(ASCIIToUTF16("bar.com")); | 238 data.SetURL("http://bar.com/{searchTerms}"); |
| 237 keyword_t_url->SetURL("http://bar.com/{searchTerms}"); | 239 keyword_t_url = new TemplateURL(data); |
| 238 turl_model->Add(keyword_t_url); | 240 turl_model->Add(keyword_t_url); |
| 239 ASSERT_NE(0, keyword_t_url->id()); | 241 ASSERT_NE(0, keyword_t_url->id()); |
| 240 | 242 |
| 241 // Forget about any existing providers. The controller owns them and will | 243 // Forget about any existing providers. The controller owns them and will |
| 242 // Release() them below, when we delete it during the call to reset(). | 244 // Release() them below, when we delete it during the call to reset(). |
| 243 providers_.clear(); | 245 providers_.clear(); |
| 244 | 246 |
| 245 // Create both a keyword and search provider, and add them in that order. | 247 // Create both a keyword and search provider, and add them in that order. |
| 246 // (Order is important; see comments in RunExactKeymatchTest().) | 248 // (Order is important; see comments in RunExactKeymatchTest().) |
| 247 KeywordProvider* keyword_provider = new KeywordProvider(NULL, &profile_); | 249 KeywordProvider* keyword_provider = new KeywordProvider(NULL, &profile_); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 &scheme, | 607 &scheme, |
| 606 &host); | 608 &host); |
| 607 AutocompleteInput input(input_cases[i].input, string16(), true, false, | 609 AutocompleteInput input(input_cases[i].input, string16(), true, false, |
| 608 true, AutocompleteInput::ALL_MATCHES); | 610 true, AutocompleteInput::ALL_MATCHES); |
| 609 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin); | 611 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin); |
| 610 EXPECT_EQ(input_cases[i].scheme.len, scheme.len); | 612 EXPECT_EQ(input_cases[i].scheme.len, scheme.len); |
| 611 EXPECT_EQ(input_cases[i].host.begin, host.begin); | 613 EXPECT_EQ(input_cases[i].host.begin, host.begin); |
| 612 EXPECT_EQ(input_cases[i].host.len, host.len); | 614 EXPECT_EQ(input_cases[i].host.len, host.len); |
| 613 } | 615 } |
| 614 } | 616 } |
| OLD | NEW |