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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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 | Annotate | Revision Log
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 "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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("echo"))); 89 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("echo")));
90 AddResultsWithSearchTermsArgs( 90 AddResultsWithSearchTermsArgs(
91 2, 1, AutocompleteMatchType::NAVSUGGEST, 91 2, 1, AutocompleteMatchType::NAVSUGGEST,
92 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("nav"))); 92 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("nav")));
93 AddResultsWithSearchTermsArgs( 93 AddResultsWithSearchTermsArgs(
94 3, 1, AutocompleteMatchType::SEARCH_SUGGEST, 94 3, 1, AutocompleteMatchType::SEARCH_SUGGEST,
95 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("query"))); 95 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("query")));
96 96
97 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { 97 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) {
98 done_ = false; 98 done_ = false;
99 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&TestProvider::Run, 99 base::MessageLoop::current()->PostTask(
100 this)); 100 FROM_HERE, base::Bind(&TestProvider::Run, this));
101 } 101 }
102 } 102 }
103 103
104 void TestProvider::Run() { 104 void TestProvider::Run() {
105 DCHECK_GT(kResultsPerProvider, 0U); 105 DCHECK_GT(kResultsPerProvider, 0U);
106 AddResults(1, kResultsPerProvider); 106 AddResults(1, kResultsPerProvider);
107 done_ = true; 107 done_ = true;
108 DCHECK(listener_); 108 DCHECK(listener_);
109 listener_->OnProviderUpdate(true); 109 listener_->OnProviderUpdate(true);
110 } 110 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 AutocompleteResult result_; 188 AutocompleteResult result_;
189 scoped_ptr<AutocompleteController> controller_; 189 scoped_ptr<AutocompleteController> controller_;
190 190
191 private: 191 private:
192 // content::NotificationObserver 192 // content::NotificationObserver
193 virtual void Observe(int type, 193 virtual void Observe(int type,
194 const content::NotificationSource& source, 194 const content::NotificationSource& source,
195 const content::NotificationDetails& details) OVERRIDE; 195 const content::NotificationDetails& details) OVERRIDE;
196 196
197 MessageLoopForUI message_loop_; 197 base::MessageLoopForUI message_loop_;
198 content::NotificationRegistrar registrar_; 198 content::NotificationRegistrar registrar_;
199 TestingProfile profile_; 199 TestingProfile profile_;
200 }; 200 };
201 201
202 void AutocompleteProviderTest::RegisterTemplateURL( 202 void AutocompleteProviderTest::RegisterTemplateURL(
203 const string16 keyword, 203 const string16 keyword,
204 const std::string& template_url) { 204 const std::string& template_url) {
205 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 205 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
206 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 206 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
207 TemplateURLData data; 207 TemplateURLData data;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 386
387 void AutocompleteProviderTest::RunQuery(const string16 query) { 387 void AutocompleteProviderTest::RunQuery(const string16 query) {
388 result_.Reset(); 388 result_.Reset();
389 controller_->Start(AutocompleteInput( 389 controller_->Start(AutocompleteInput(
390 query, string16::npos, string16(), GURL(), true, false, true, 390 query, string16::npos, string16(), GURL(), true, false, true,
391 AutocompleteInput::ALL_MATCHES)); 391 AutocompleteInput::ALL_MATCHES));
392 392
393 if (!controller_->done()) 393 if (!controller_->done())
394 // The message loop will terminate when all autocomplete input has been 394 // The message loop will terminate when all autocomplete input has been
395 // collected. 395 // collected.
396 MessageLoop::current()->Run(); 396 base::MessageLoop::current()->Run();
397 } 397 }
398 398
399 void AutocompleteProviderTest::RunExactKeymatchTest( 399 void AutocompleteProviderTest::RunExactKeymatchTest(
400 bool allow_exact_keyword_match) { 400 bool allow_exact_keyword_match) {
401 // Send the controller input which exactly matches the keyword provider we 401 // Send the controller input which exactly matches the keyword provider we
402 // created in ResetControllerWithKeywordAndSearchProviders(). The default 402 // created in ResetControllerWithKeywordAndSearchProviders(). The default
403 // match should thus be a search-other-engine match iff 403 // match should thus be a search-other-engine match iff
404 // |allow_exact_keyword_match| is true. Regardless, the match should 404 // |allow_exact_keyword_match| is true. Regardless, the match should
405 // be from SearchProvider. (It provides all verbatim search matches, 405 // be from SearchProvider. (It provides all verbatim search matches,
406 // keyword or not.) 406 // keyword or not.)
407 controller_->Start(AutocompleteInput( 407 controller_->Start(AutocompleteInput(
408 ASCIIToUTF16("k test"), string16::npos, string16(), GURL(), true, false, 408 ASCIIToUTF16("k test"), string16::npos, string16(), GURL(), true, false,
409 allow_exact_keyword_match, AutocompleteInput::SYNCHRONOUS_MATCHES)); 409 allow_exact_keyword_match, AutocompleteInput::SYNCHRONOUS_MATCHES));
410 EXPECT_TRUE(controller_->done()); 410 EXPECT_TRUE(controller_->done());
411 EXPECT_EQ(AutocompleteProvider::TYPE_SEARCH, 411 EXPECT_EQ(AutocompleteProvider::TYPE_SEARCH,
412 controller_->result().default_match()->provider->type()); 412 controller_->result().default_match()->provider->type());
413 EXPECT_EQ(allow_exact_keyword_match ? 413 EXPECT_EQ(allow_exact_keyword_match ?
414 AutocompleteMatchType::SEARCH_OTHER_ENGINE : 414 AutocompleteMatchType::SEARCH_OTHER_ENGINE :
415 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 415 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
416 controller_->result().default_match()->type); 416 controller_->result().default_match()->type);
417 } 417 }
418 418
419 void AutocompleteProviderTest::Observe( 419 void AutocompleteProviderTest::Observe(
420 int type, 420 int type,
421 const content::NotificationSource& source, 421 const content::NotificationSource& source,
422 const content::NotificationDetails& details) { 422 const content::NotificationDetails& details) {
423 if (controller_->done()) { 423 if (controller_->done()) {
424 result_.CopyFrom(controller_->result()); 424 result_.CopyFrom(controller_->result());
425 MessageLoop::current()->Quit(); 425 base::MessageLoop::current()->Quit();
426 } 426 }
427 } 427 }
428 428
429 // Tests that the default selection is set properly when updating results. 429 // Tests that the default selection is set properly when updating results.
430 TEST_F(AutocompleteProviderTest, Query) { 430 TEST_F(AutocompleteProviderTest, Query) {
431 TestProvider* provider1 = NULL; 431 TestProvider* provider1 = NULL;
432 TestProvider* provider2 = NULL; 432 TestProvider* provider2 = NULL;
433 ResetControllerWithTestProviders(false, &provider1, &provider2); 433 ResetControllerWithTestProviders(false, &provider1, &provider2);
434 RunTest(); 434 RunTest();
435 435
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0&", url.path()); 606 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0&", url.path());
607 607
608 // Test field trial triggered bit set. 608 // Test field trial triggered bit set.
609 controller_->search_provider_->field_trial_triggered_in_session_ = true; 609 controller_->search_provider_->field_trial_triggered_in_session_ = true;
610 EXPECT_TRUE( 610 EXPECT_TRUE(
611 controller_->search_provider_->field_trial_triggered_in_session()); 611 controller_->search_provider_->field_trial_triggered_in_session());
612 url = controller_->GetDestinationURL(match, 612 url = controller_->GetDestinationURL(match,
613 base::TimeDelta::FromMilliseconds(2456)); 613 base::TimeDelta::FromMilliseconds(2456));
614 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1&", url.path()); 614 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1&", url.path());
615 } 615 }
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | chrome/browser/autocomplete/contact_provider_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698