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