| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 void AutocompleteProviderTest::RegisterTemplateURL( | 213 void AutocompleteProviderTest::RegisterTemplateURL( |
| 214 const base::string16 keyword, | 214 const base::string16 keyword, |
| 215 const std::string& template_url) { | 215 const std::string& template_url) { |
| 216 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 216 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 217 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 217 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
| 218 TemplateURLData data; | 218 TemplateURLData data; |
| 219 data.SetURL(template_url); | 219 data.SetURL(template_url); |
| 220 data.SetKeyword(keyword); | 220 data.SetKeyword(keyword); |
| 221 TemplateURL* default_t_url = new TemplateURL(&profile_, data); | 221 TemplateURL* default_t_url = new TemplateURL(data); |
| 222 TemplateURLService* turl_model = | 222 TemplateURLService* turl_model = |
| 223 TemplateURLServiceFactory::GetForProfile(&profile_); | 223 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 224 turl_model->Add(default_t_url); | 224 turl_model->Add(default_t_url); |
| 225 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); | 225 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); |
| 226 turl_model->Load(); | 226 turl_model->Load(); |
| 227 TemplateURLID default_provider_id = default_t_url->id(); | 227 TemplateURLID default_provider_id = default_t_url->id(); |
| 228 ASSERT_NE(0, default_provider_id); | 228 ASSERT_NE(0, default_provider_id); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void AutocompleteProviderTest::ResetControllerWithTestProviders( | 231 void AutocompleteProviderTest::ResetControllerWithTestProviders( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 287 } |
| 288 | 288 |
| 289 void AutocompleteProviderTest:: | 289 void AutocompleteProviderTest:: |
| 290 ResetControllerWithKeywordAndSearchProviders() { | 290 ResetControllerWithKeywordAndSearchProviders() { |
| 291 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 291 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 292 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 292 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
| 293 | 293 |
| 294 // Reset the default TemplateURL. | 294 // Reset the default TemplateURL. |
| 295 TemplateURLData data; | 295 TemplateURLData data; |
| 296 data.SetURL("http://defaultturl/{searchTerms}"); | 296 data.SetURL("http://defaultturl/{searchTerms}"); |
| 297 TemplateURL* default_t_url = new TemplateURL(&profile_, data); | 297 TemplateURL* default_t_url = new TemplateURL(data); |
| 298 TemplateURLService* turl_model = | 298 TemplateURLService* turl_model = |
| 299 TemplateURLServiceFactory::GetForProfile(&profile_); | 299 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 300 turl_model->Add(default_t_url); | 300 turl_model->Add(default_t_url); |
| 301 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); | 301 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); |
| 302 TemplateURLID default_provider_id = default_t_url->id(); | 302 TemplateURLID default_provider_id = default_t_url->id(); |
| 303 ASSERT_NE(0, default_provider_id); | 303 ASSERT_NE(0, default_provider_id); |
| 304 | 304 |
| 305 // Create another TemplateURL for KeywordProvider. | 305 // Create another TemplateURL for KeywordProvider. |
| 306 TemplateURLData data2; | 306 TemplateURLData data2; |
| 307 data2.short_name = base::ASCIIToUTF16("k"); | 307 data2.short_name = base::ASCIIToUTF16("k"); |
| 308 data2.SetKeyword(base::ASCIIToUTF16("k")); | 308 data2.SetKeyword(base::ASCIIToUTF16("k")); |
| 309 data2.SetURL("http://keyword/{searchTerms}"); | 309 data2.SetURL("http://keyword/{searchTerms}"); |
| 310 TemplateURL* keyword_t_url = new TemplateURL(&profile_, data2); | 310 TemplateURL* keyword_t_url = new TemplateURL(data2); |
| 311 turl_model->Add(keyword_t_url); | 311 turl_model->Add(keyword_t_url); |
| 312 ASSERT_NE(0, keyword_t_url->id()); | 312 ASSERT_NE(0, keyword_t_url->id()); |
| 313 | 313 |
| 314 controller_.reset(new AutocompleteController( | 314 controller_.reset(new AutocompleteController( |
| 315 &profile_, NULL, | 315 &profile_, NULL, |
| 316 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); | 316 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { | 319 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { |
| 320 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 320 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 321 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 321 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
| 322 | 322 |
| 323 TemplateURLService* turl_model = | 323 TemplateURLService* turl_model = |
| 324 TemplateURLServiceFactory::GetForProfile(&profile_); | 324 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 325 | 325 |
| 326 // Create a TemplateURL for KeywordProvider. | 326 // Create a TemplateURL for KeywordProvider. |
| 327 TemplateURLData data; | 327 TemplateURLData data; |
| 328 data.short_name = base::ASCIIToUTF16("foo.com"); | 328 data.short_name = base::ASCIIToUTF16("foo.com"); |
| 329 data.SetKeyword(base::ASCIIToUTF16("foo.com")); | 329 data.SetKeyword(base::ASCIIToUTF16("foo.com")); |
| 330 data.SetURL("http://foo.com/{searchTerms}"); | 330 data.SetURL("http://foo.com/{searchTerms}"); |
| 331 TemplateURL* keyword_t_url = new TemplateURL(&profile_, data); | 331 TemplateURL* keyword_t_url = new TemplateURL(data); |
| 332 turl_model->Add(keyword_t_url); | 332 turl_model->Add(keyword_t_url); |
| 333 ASSERT_NE(0, keyword_t_url->id()); | 333 ASSERT_NE(0, keyword_t_url->id()); |
| 334 | 334 |
| 335 // Create another TemplateURL for KeywordProvider. | 335 // Create another TemplateURL for KeywordProvider. |
| 336 data.short_name = base::ASCIIToUTF16("bar.com"); | 336 data.short_name = base::ASCIIToUTF16("bar.com"); |
| 337 data.SetKeyword(base::ASCIIToUTF16("bar.com")); | 337 data.SetKeyword(base::ASCIIToUTF16("bar.com")); |
| 338 data.SetURL("http://bar.com/{searchTerms}"); | 338 data.SetURL("http://bar.com/{searchTerms}"); |
| 339 keyword_t_url = new TemplateURL(&profile_, data); | 339 keyword_t_url = new TemplateURL(data); |
| 340 turl_model->Add(keyword_t_url); | 340 turl_model->Add(keyword_t_url); |
| 341 ASSERT_NE(0, keyword_t_url->id()); | 341 ASSERT_NE(0, keyword_t_url->id()); |
| 342 | 342 |
| 343 controller_.reset(new AutocompleteController( | 343 controller_.reset(new AutocompleteController( |
| 344 &profile_, NULL, AutocompleteProvider::TYPE_KEYWORD)); | 344 &profile_, NULL, AutocompleteProvider::TYPE_KEYWORD)); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void AutocompleteProviderTest::RunTest() { | 347 void AutocompleteProviderTest::RunTest() { |
| 348 RunQuery(base::ASCIIToUTF16("a")); | 348 RunQuery(base::ASCIIToUTF16("a")); |
| 349 } | 349 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 655 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 656 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 656 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
| 657 | 657 |
| 658 // Test page classification and field trial triggered set. | 658 // Test page classification and field trial triggered set. |
| 659 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 659 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
| 660 EXPECT_TRUE( | 660 EXPECT_TRUE( |
| 661 controller_->search_provider_->field_trial_triggered_in_session()); | 661 controller_->search_provider_->field_trial_triggered_in_session()); |
| 662 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 662 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 663 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 663 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
| 664 } | 664 } |
| OLD | NEW |