Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_provider_unittest.cc

Issue 1192373002: Prepare AutocompleteController for componentization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@componentize_zero_suggest_provider
Patch Set: Response to review Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "chrome/browser/autocomplete/autocomplete_controller.h" 17 #include "chrome/browser/autocomplete/autocomplete_controller.h"
18 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
19 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 21 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "components/metrics/proto/omnibox_event.pb.h" 24 #include "components/metrics/proto/omnibox_event.pb.h"
24 #include "components/omnibox/autocomplete_input.h" 25 #include "components/omnibox/autocomplete_input.h"
25 #include "components/omnibox/autocomplete_match.h" 26 #include "components/omnibox/autocomplete_match.h"
26 #include "components/omnibox/autocomplete_provider_listener.h" 27 #include "components/omnibox/autocomplete_provider_listener.h"
27 #include "components/omnibox/keyword_provider.h" 28 #include "components/omnibox/keyword_provider.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 TestProvider* provider2 = new TestProvider( 291 TestProvider* provider2 = new TestProvider(
291 kResultsPerProvider * 2, 292 kResultsPerProvider * 2,
292 same_destinations ? base::ASCIIToUTF16("http://a") 293 same_destinations ? base::ASCIIToUTF16("http://a")
293 : base::ASCIIToUTF16("http://b"), 294 : base::ASCIIToUTF16("http://b"),
294 &profile_, 295 &profile_,
295 base::string16()); 296 base::string16());
296 providers.push_back(provider2); 297 providers.push_back(provider2);
297 298
298 // Reset the controller to contain our new providers. 299 // Reset the controller to contain our new providers.
299 controller_.reset(new AutocompleteController( 300 controller_.reset(new AutocompleteController(
300 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, 0)); 301
302 make_scoped_ptr(new ChromeAutocompleteProviderClient(&profile_)), NULL,
303 0));
301 // We're going to swap the providers vector, but the old vector should be 304 // We're going to swap the providers vector, but the old vector should be
302 // empty so no elements need to be freed at this point. 305 // empty so no elements need to be freed at this point.
303 EXPECT_TRUE(controller_->providers_.empty()); 306 EXPECT_TRUE(controller_->providers_.empty());
304 controller_->providers_.swap(providers); 307 controller_->providers_.swap(providers);
305 provider1->set_listener(controller_.get()); 308 provider1->set_listener(controller_.get());
306 provider2->set_listener(controller_.get()); 309 provider2->set_listener(controller_.get());
307 310
308 // The providers don't complete synchronously, so listen for "result updated" 311 // The providers don't complete synchronously, so listen for "result updated"
309 // notifications. 312 // notifications.
310 registrar_.Add(this, 313 registrar_.Add(this,
(...skipping 27 matching lines...) Expand all
338 // Create another TemplateURL for KeywordProvider. 341 // Create another TemplateURL for KeywordProvider.
339 TemplateURLData data2; 342 TemplateURLData data2;
340 data2.SetShortName(base::ASCIIToUTF16("k")); 343 data2.SetShortName(base::ASCIIToUTF16("k"));
341 data2.SetKeyword(base::ASCIIToUTF16("k")); 344 data2.SetKeyword(base::ASCIIToUTF16("k"));
342 data2.SetURL("http://keyword/{searchTerms}"); 345 data2.SetURL("http://keyword/{searchTerms}");
343 TemplateURL* keyword_t_url = new TemplateURL(data2); 346 TemplateURL* keyword_t_url = new TemplateURL(data2);
344 turl_model->Add(keyword_t_url); 347 turl_model->Add(keyword_t_url);
345 ASSERT_NE(0, keyword_t_url->id()); 348 ASSERT_NE(0, keyword_t_url->id());
346 349
347 controller_.reset(new AutocompleteController( 350 controller_.reset(new AutocompleteController(
348 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, 351
352 make_scoped_ptr(new ChromeAutocompleteProviderClient(&profile_)), NULL,
349 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); 353 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH));
350 } 354 }
351 355
352 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { 356 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() {
353 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 357 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
354 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 358 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
355 359
356 TemplateURLService* turl_model = 360 TemplateURLService* turl_model =
357 TemplateURLServiceFactory::GetForProfile(&profile_); 361 TemplateURLServiceFactory::GetForProfile(&profile_);
358 362
(...skipping 17 matching lines...) Expand all
376 380
377 // Create another TemplateURL for KeywordProvider. 381 // Create another TemplateURL for KeywordProvider.
378 data.SetShortName(base::ASCIIToUTF16("bar.com")); 382 data.SetShortName(base::ASCIIToUTF16("bar.com"));
379 data.SetKeyword(base::ASCIIToUTF16("bar.com")); 383 data.SetKeyword(base::ASCIIToUTF16("bar.com"));
380 data.SetURL("http://bar.com/{searchTerms}"); 384 data.SetURL("http://bar.com/{searchTerms}");
381 keyword_t_url = new TemplateURL(data); 385 keyword_t_url = new TemplateURL(data);
382 turl_model->Add(keyword_t_url); 386 turl_model->Add(keyword_t_url);
383 ASSERT_NE(0, keyword_t_url->id()); 387 ASSERT_NE(0, keyword_t_url->id());
384 388
385 controller_.reset(new AutocompleteController( 389 controller_.reset(new AutocompleteController(
386 &profile_, TemplateURLServiceFactory::GetForProfile(&profile_), NULL, 390 make_scoped_ptr(new ChromeAutocompleteProviderClient(&profile_)), NULL,
387 AutocompleteProvider::TYPE_KEYWORD)); 391 AutocompleteProvider::TYPE_KEYWORD));
388 } 392 }
389 393
390 void AutocompleteProviderTest::RunTest() { 394 void AutocompleteProviderTest::RunTest() {
391 RunQuery(base::ASCIIToUTF16("a")); 395 RunQuery(base::ASCIIToUTF16("a"));
392 } 396 }
393 397
394 void AutocompleteProviderTest::RunKeywordTest(const base::string16& input, 398 void AutocompleteProviderTest::RunKeywordTest(const base::string16& input,
395 const KeywordTestData* match_data, 399 const KeywordTestData* match_data,
396 size_t size) { 400 size_t size) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); 747 EXPECT_FALSE(search_provider_field_trial_triggered_in_session());
744 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); 748 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456));
745 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); 749 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path());
746 750
747 // Test page classification and field trial triggered set. 751 // Test page classification and field trial triggered set.
748 set_search_provider_field_trial_triggered_in_session(true); 752 set_search_provider_field_trial_triggered_in_session(true);
749 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); 753 EXPECT_TRUE(search_provider_field_trial_triggered_in_session());
750 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); 754 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456));
751 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); 755 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path());
752 } 756 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698