| 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_, NULL, 0, TemplateURLServiceFactory::GetForProfile(&profile_))); |
| 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 26 matching lines...) Expand all Loading... |
| 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_, NULL, |
| 318 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); | 321 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH, |
| 322 TemplateURLServiceFactory::GetForProfile(&profile_))); |
| 319 } | 323 } |
| 320 | 324 |
| 321 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { | 325 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { |
| 322 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 326 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 323 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 327 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
| 324 | 328 |
| 325 TemplateURLService* turl_model = | 329 TemplateURLService* turl_model = |
| 326 TemplateURLServiceFactory::GetForProfile(&profile_); | 330 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 327 | 331 |
| 328 // Create a TemplateURL for KeywordProvider. | 332 // Create a TemplateURL for KeywordProvider. |
| 329 TemplateURLData data; | 333 TemplateURLData data; |
| 330 data.short_name = base::ASCIIToUTF16("foo.com"); | 334 data.short_name = base::ASCIIToUTF16("foo.com"); |
| 331 data.SetKeyword(base::ASCIIToUTF16("foo.com")); | 335 data.SetKeyword(base::ASCIIToUTF16("foo.com")); |
| 332 data.SetURL("http://foo.com/{searchTerms}"); | 336 data.SetURL("http://foo.com/{searchTerms}"); |
| 333 TemplateURL* keyword_t_url = new TemplateURL(data); | 337 TemplateURL* keyword_t_url = new TemplateURL(data); |
| 334 turl_model->Add(keyword_t_url); | 338 turl_model->Add(keyword_t_url); |
| 335 ASSERT_NE(0, keyword_t_url->id()); | 339 ASSERT_NE(0, keyword_t_url->id()); |
| 336 | 340 |
| 337 // Create another TemplateURL for KeywordProvider. | 341 // Create another TemplateURL for KeywordProvider. |
| 338 data.short_name = base::ASCIIToUTF16("bar.com"); | 342 data.short_name = base::ASCIIToUTF16("bar.com"); |
| 339 data.SetKeyword(base::ASCIIToUTF16("bar.com")); | 343 data.SetKeyword(base::ASCIIToUTF16("bar.com")); |
| 340 data.SetURL("http://bar.com/{searchTerms}"); | 344 data.SetURL("http://bar.com/{searchTerms}"); |
| 341 keyword_t_url = new TemplateURL(data); | 345 keyword_t_url = new TemplateURL(data); |
| 342 turl_model->Add(keyword_t_url); | 346 turl_model->Add(keyword_t_url); |
| 343 ASSERT_NE(0, keyword_t_url->id()); | 347 ASSERT_NE(0, keyword_t_url->id()); |
| 344 | 348 |
| 345 controller_.reset(new AutocompleteController( | 349 controller_.reset(new AutocompleteController( |
| 346 &profile_, NULL, AutocompleteProvider::TYPE_KEYWORD)); | 350 &profile_, NULL, AutocompleteProvider::TYPE_KEYWORD, |
| 351 TemplateURLServiceFactory::GetForProfile(&profile_))); |
| 347 } | 352 } |
| 348 | 353 |
| 349 void AutocompleteProviderTest::RunTest() { | 354 void AutocompleteProviderTest::RunTest() { |
| 350 RunQuery(base::ASCIIToUTF16("a")); | 355 RunQuery(base::ASCIIToUTF16("a")); |
| 351 } | 356 } |
| 352 | 357 |
| 353 void AutocompleteProviderTest::RunRedundantKeywordTest( | 358 void AutocompleteProviderTest::RunRedundantKeywordTest( |
| 354 const KeywordTestData* match_data, | 359 const KeywordTestData* match_data, |
| 355 size_t size) { | 360 size_t size) { |
| 356 ACMatches matches; | 361 ACMatches matches; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 665 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 661 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 666 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
| 662 | 667 |
| 663 // Test page classification and field trial triggered set. | 668 // Test page classification and field trial triggered set. |
| 664 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 669 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
| 665 EXPECT_TRUE( | 670 EXPECT_TRUE( |
| 666 controller_->search_provider_->field_trial_triggered_in_session()); | 671 controller_->search_provider_->field_trial_triggered_in_session()); |
| 667 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 672 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 668 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 673 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
| 669 } | 674 } |
| OLD | NEW |