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 "chrome/browser/autocomplete/autocomplete_provider.h" | 5 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 match.contents = match.fill_into_edit; | 136 match.contents = match.fill_into_edit; |
137 match.contents_class.push_back( | 137 match.contents_class.push_back( |
138 ACMatchClassification(0, ACMatchClassification::NONE)); | 138 ACMatchClassification(0, ACMatchClassification::NONE)); |
139 match.description = match.fill_into_edit; | 139 match.description = match.fill_into_edit; |
140 match.description_class.push_back( | 140 match.description_class.push_back( |
141 ACMatchClassification(0, ACMatchClassification::NONE)); | 141 ACMatchClassification(0, ACMatchClassification::NONE)); |
142 match.search_terms_args.reset( | 142 match.search_terms_args.reset( |
143 new TemplateURLRef::SearchTermsArgs(search_terms_args)); | 143 new TemplateURLRef::SearchTermsArgs(search_terms_args)); |
144 if (!match_keyword_.empty()) { | 144 if (!match_keyword_.empty()) { |
145 match.keyword = match_keyword_; | 145 match.keyword = match_keyword_; |
146 ASSERT_TRUE(match.GetTemplateURL(profile_, false) != NULL); | 146 TemplateURLService* service = |
| 147 TemplateURLServiceFactory::GetForProfile(profile_); |
| 148 ASSERT_TRUE(match.GetTemplateURL(service, false) != NULL); |
147 } | 149 } |
148 | 150 |
149 matches_.push_back(match); | 151 matches_.push_back(match); |
150 } | 152 } |
151 } | 153 } |
152 | 154 |
153 class AutocompleteProviderTest : public testing::Test, | 155 class AutocompleteProviderTest : public testing::Test, |
154 public content::NotificationObserver { | 156 public content::NotificationObserver { |
155 protected: | 157 protected: |
156 struct KeywordTestData { | 158 struct KeywordTestData { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 TestProvider* provider2 = new TestProvider( | 263 TestProvider* provider2 = new TestProvider( |
262 kResultsPerProvider * 2, | 264 kResultsPerProvider * 2, |
263 same_destinations ? base::ASCIIToUTF16("http://a") | 265 same_destinations ? base::ASCIIToUTF16("http://a") |
264 : base::ASCIIToUTF16("http://b"), | 266 : base::ASCIIToUTF16("http://b"), |
265 &profile_, | 267 &profile_, |
266 base::string16()); | 268 base::string16()); |
267 provider2->AddRef(); | 269 provider2->AddRef(); |
268 providers.push_back(provider2); | 270 providers.push_back(provider2); |
269 | 271 |
270 // Reset the controller to contain our new providers. | 272 // Reset the controller to contain our new providers. |
271 controller_.reset(new AutocompleteController(&profile_, NULL, 0)); | 273 controller_.reset(new AutocompleteController( |
| 274 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, 0)); |
272 // We're going to swap the providers vector, but the old vector should be | 275 // We're going to swap the providers vector, but the old vector should be |
273 // empty so no elements need to be freed at this point. | 276 // empty so no elements need to be freed at this point. |
274 EXPECT_TRUE(controller_->providers_.empty()); | 277 EXPECT_TRUE(controller_->providers_.empty()); |
275 controller_->providers_.swap(providers); | 278 controller_->providers_.swap(providers); |
276 provider1->set_listener(controller_.get()); | 279 provider1->set_listener(controller_.get()); |
277 provider2->set_listener(controller_.get()); | 280 provider2->set_listener(controller_.get()); |
278 | 281 |
279 // The providers don't complete synchronously, so listen for "result updated" | 282 // The providers don't complete synchronously, so listen for "result updated" |
280 // notifications. | 283 // notifications. |
281 registrar_.Add(this, | 284 registrar_.Add(this, |
(...skipping 25 matching lines...) Expand all Loading... |
307 // Create another TemplateURL for KeywordProvider. | 310 // Create another TemplateURL for KeywordProvider. |
308 TemplateURLData data2; | 311 TemplateURLData data2; |
309 data2.short_name = base::ASCIIToUTF16("k"); | 312 data2.short_name = base::ASCIIToUTF16("k"); |
310 data2.SetKeyword(base::ASCIIToUTF16("k")); | 313 data2.SetKeyword(base::ASCIIToUTF16("k")); |
311 data2.SetURL("http://keyword/{searchTerms}"); | 314 data2.SetURL("http://keyword/{searchTerms}"); |
312 TemplateURL* keyword_t_url = new TemplateURL(data2); | 315 TemplateURL* keyword_t_url = new TemplateURL(data2); |
313 turl_model->Add(keyword_t_url); | 316 turl_model->Add(keyword_t_url); |
314 ASSERT_NE(0, keyword_t_url->id()); | 317 ASSERT_NE(0, keyword_t_url->id()); |
315 | 318 |
316 controller_.reset(new AutocompleteController( | 319 controller_.reset(new AutocompleteController( |
317 &profile_, NULL, | 320 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, |
318 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); | 321 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); |
319 } | 322 } |
320 | 323 |
321 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { | 324 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { |
322 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 325 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
323 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 326 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
324 | 327 |
325 TemplateURLService* turl_model = | 328 TemplateURLService* turl_model = |
326 TemplateURLServiceFactory::GetForProfile(&profile_); | 329 TemplateURLServiceFactory::GetForProfile(&profile_); |
327 | 330 |
328 // Create a TemplateURL for KeywordProvider. | 331 // Create a TemplateURL for KeywordProvider. |
329 TemplateURLData data; | 332 TemplateURLData data; |
330 data.short_name = base::ASCIIToUTF16("foo.com"); | 333 data.short_name = base::ASCIIToUTF16("foo.com"); |
331 data.SetKeyword(base::ASCIIToUTF16("foo.com")); | 334 data.SetKeyword(base::ASCIIToUTF16("foo.com")); |
332 data.SetURL("http://foo.com/{searchTerms}"); | 335 data.SetURL("http://foo.com/{searchTerms}"); |
333 TemplateURL* keyword_t_url = new TemplateURL(data); | 336 TemplateURL* keyword_t_url = new TemplateURL(data); |
334 turl_model->Add(keyword_t_url); | 337 turl_model->Add(keyword_t_url); |
335 ASSERT_NE(0, keyword_t_url->id()); | 338 ASSERT_NE(0, keyword_t_url->id()); |
336 | 339 |
337 // Create another TemplateURL for KeywordProvider. | 340 // Create another TemplateURL for KeywordProvider. |
338 data.short_name = base::ASCIIToUTF16("bar.com"); | 341 data.short_name = base::ASCIIToUTF16("bar.com"); |
339 data.SetKeyword(base::ASCIIToUTF16("bar.com")); | 342 data.SetKeyword(base::ASCIIToUTF16("bar.com")); |
340 data.SetURL("http://bar.com/{searchTerms}"); | 343 data.SetURL("http://bar.com/{searchTerms}"); |
341 keyword_t_url = new TemplateURL(data); | 344 keyword_t_url = new TemplateURL(data); |
342 turl_model->Add(keyword_t_url); | 345 turl_model->Add(keyword_t_url); |
343 ASSERT_NE(0, keyword_t_url->id()); | 346 ASSERT_NE(0, keyword_t_url->id()); |
344 | 347 |
345 controller_.reset(new AutocompleteController( | 348 controller_.reset(new AutocompleteController( |
346 &profile_, NULL, AutocompleteProvider::TYPE_KEYWORD)); | 349 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, |
| 350 AutocompleteProvider::TYPE_KEYWORD)); |
347 } | 351 } |
348 | 352 |
349 void AutocompleteProviderTest::RunTest() { | 353 void AutocompleteProviderTest::RunTest() { |
350 RunQuery(base::ASCIIToUTF16("a")); | 354 RunQuery(base::ASCIIToUTF16("a")); |
351 } | 355 } |
352 | 356 |
353 void AutocompleteProviderTest::RunRedundantKeywordTest( | 357 void AutocompleteProviderTest::RunRedundantKeywordTest( |
354 const KeywordTestData* match_data, | 358 const KeywordTestData* match_data, |
355 size_t size) { | 359 size_t size) { |
356 ACMatches matches; | 360 ACMatches matches; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 664 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
661 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 665 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
662 | 666 |
663 // Test page classification and field trial triggered set. | 667 // Test page classification and field trial triggered set. |
664 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 668 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
665 EXPECT_TRUE( | 669 EXPECT_TRUE( |
666 controller_->search_provider_->field_trial_triggered_in_session()); | 670 controller_->search_provider_->field_trial_triggered_in_session()); |
667 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 671 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
668 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 672 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
669 } | 673 } |
OLD | NEW |