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 "components/omnibox/autocomplete_provider.h" | 5 #include "components/omnibox/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/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 void AutocompleteProviderTest::RegisterTemplateURL( | 243 void AutocompleteProviderTest::RegisterTemplateURL( |
244 const base::string16 keyword, | 244 const base::string16 keyword, |
245 const std::string& template_url) { | 245 const std::string& template_url) { |
246 if (TemplateURLServiceFactory::GetForProfile(&profile_) == NULL) { | 246 if (TemplateURLServiceFactory::GetForProfile(&profile_) == NULL) { |
247 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 247 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
248 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 248 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
249 } | 249 } |
250 TemplateURLData data; | 250 TemplateURLData data; |
251 data.SetURL(template_url); | 251 data.SetURL(template_url); |
| 252 data.SetShortName(keyword); |
252 data.SetKeyword(keyword); | 253 data.SetKeyword(keyword); |
253 TemplateURL* default_t_url = new TemplateURL(data); | 254 TemplateURL* default_t_url = new TemplateURL(data); |
254 TemplateURLService* turl_model = | 255 TemplateURLService* turl_model = |
255 TemplateURLServiceFactory::GetForProfile(&profile_); | 256 TemplateURLServiceFactory::GetForProfile(&profile_); |
256 turl_model->Add(default_t_url); | 257 turl_model->Add(default_t_url); |
257 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); | 258 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); |
258 turl_model->Load(); | 259 turl_model->Load(); |
259 TemplateURLID default_provider_id = default_t_url->id(); | 260 TemplateURLID default_provider_id = default_t_url->id(); |
260 ASSERT_NE(0, default_provider_id); | 261 ASSERT_NE(0, default_provider_id); |
261 } | 262 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 *provider2_ptr = provider2; | 318 *provider2_ptr = provider2; |
318 } | 319 } |
319 | 320 |
320 void AutocompleteProviderTest:: | 321 void AutocompleteProviderTest:: |
321 ResetControllerWithKeywordAndSearchProviders() { | 322 ResetControllerWithKeywordAndSearchProviders() { |
322 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 323 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
323 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 324 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
324 | 325 |
325 // Reset the default TemplateURL. | 326 // Reset the default TemplateURL. |
326 TemplateURLData data; | 327 TemplateURLData data; |
| 328 data.SetShortName(base::ASCIIToUTF16("default")); |
| 329 data.SetKeyword(base::ASCIIToUTF16("default")); |
327 data.SetURL("http://defaultturl/{searchTerms}"); | 330 data.SetURL("http://defaultturl/{searchTerms}"); |
328 TemplateURL* default_t_url = new TemplateURL(data); | 331 TemplateURL* default_t_url = new TemplateURL(data); |
329 TemplateURLService* turl_model = | 332 TemplateURLService* turl_model = |
330 TemplateURLServiceFactory::GetForProfile(&profile_); | 333 TemplateURLServiceFactory::GetForProfile(&profile_); |
331 turl_model->Add(default_t_url); | 334 turl_model->Add(default_t_url); |
332 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); | 335 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); |
333 TemplateURLID default_provider_id = default_t_url->id(); | 336 TemplateURLID default_provider_id = default_t_url->id(); |
334 ASSERT_NE(0, default_provider_id); | 337 ASSERT_NE(0, default_provider_id); |
335 | 338 |
336 // Create another TemplateURL for KeywordProvider. | 339 // Create another TemplateURL for KeywordProvider. |
337 TemplateURLData data2; | 340 TemplateURLData data2; |
338 data2.short_name = base::ASCIIToUTF16("k"); | 341 data2.SetShortName(base::ASCIIToUTF16("k")); |
339 data2.SetKeyword(base::ASCIIToUTF16("k")); | 342 data2.SetKeyword(base::ASCIIToUTF16("k")); |
340 data2.SetURL("http://keyword/{searchTerms}"); | 343 data2.SetURL("http://keyword/{searchTerms}"); |
341 TemplateURL* keyword_t_url = new TemplateURL(data2); | 344 TemplateURL* keyword_t_url = new TemplateURL(data2); |
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_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, | 349 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, |
347 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); | 350 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); |
348 } | 351 } |
349 | 352 |
350 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { | 353 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { |
351 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 354 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
352 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 355 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
353 | 356 |
354 TemplateURLService* turl_model = | 357 TemplateURLService* turl_model = |
355 TemplateURLServiceFactory::GetForProfile(&profile_); | 358 TemplateURLServiceFactory::GetForProfile(&profile_); |
356 | 359 |
357 // Create a TemplateURL for KeywordProvider. | 360 // Create a TemplateURL for KeywordProvider. |
358 TemplateURLData data; | 361 TemplateURLData data; |
359 data.short_name = base::ASCIIToUTF16("foo.com"); | 362 data.SetShortName(base::ASCIIToUTF16("foo.com")); |
360 data.SetKeyword(base::ASCIIToUTF16("foo.com")); | 363 data.SetKeyword(base::ASCIIToUTF16("foo.com")); |
361 data.SetURL("http://foo.com/{searchTerms}"); | 364 data.SetURL("http://foo.com/{searchTerms}"); |
362 TemplateURL* keyword_t_url = new TemplateURL(data); | 365 TemplateURL* keyword_t_url = new TemplateURL(data); |
363 turl_model->Add(keyword_t_url); | 366 turl_model->Add(keyword_t_url); |
364 ASSERT_NE(0, keyword_t_url->id()); | 367 ASSERT_NE(0, keyword_t_url->id()); |
365 | 368 |
366 // Make a TemplateURL for KeywordProvider that a shorter version of the | 369 // Make a TemplateURL for KeywordProvider that a shorter version of the |
367 // first. | 370 // first. |
368 data.short_name = base::ASCIIToUTF16("f"); | 371 data.SetShortName(base::ASCIIToUTF16("f")); |
369 data.SetKeyword(base::ASCIIToUTF16("f")); | 372 data.SetKeyword(base::ASCIIToUTF16("f")); |
370 data.SetURL("http://f.com/{searchTerms}"); | 373 data.SetURL("http://f.com/{searchTerms}"); |
371 keyword_t_url = new TemplateURL(data); | 374 keyword_t_url = new TemplateURL(data); |
372 turl_model->Add(keyword_t_url); | 375 turl_model->Add(keyword_t_url); |
373 ASSERT_NE(0, keyword_t_url->id()); | 376 ASSERT_NE(0, keyword_t_url->id()); |
374 | 377 |
375 // Create another TemplateURL for KeywordProvider. | 378 // Create another TemplateURL for KeywordProvider. |
376 data.short_name = base::ASCIIToUTF16("bar.com"); | 379 data.SetShortName(base::ASCIIToUTF16("bar.com")); |
377 data.SetKeyword(base::ASCIIToUTF16("bar.com")); | 380 data.SetKeyword(base::ASCIIToUTF16("bar.com")); |
378 data.SetURL("http://bar.com/{searchTerms}"); | 381 data.SetURL("http://bar.com/{searchTerms}"); |
379 keyword_t_url = new TemplateURL(data); | 382 keyword_t_url = new TemplateURL(data); |
380 turl_model->Add(keyword_t_url); | 383 turl_model->Add(keyword_t_url); |
381 ASSERT_NE(0, keyword_t_url->id()); | 384 ASSERT_NE(0, keyword_t_url->id()); |
382 | 385 |
383 controller_.reset(new AutocompleteController( | 386 controller_.reset(new AutocompleteController( |
384 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, | 387 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, |
385 AutocompleteProvider::TYPE_KEYWORD)); | 388 AutocompleteProvider::TYPE_KEYWORD)); |
386 } | 389 } |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); | 743 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); |
741 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 744 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
742 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 745 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
743 | 746 |
744 // Test page classification and field trial triggered set. | 747 // Test page classification and field trial triggered set. |
745 set_search_provider_field_trial_triggered_in_session(true); | 748 set_search_provider_field_trial_triggered_in_session(true); |
746 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); | 749 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); |
747 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 750 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
748 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 751 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
749 } | 752 } |
OLD | NEW |