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

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

Issue 11414303: Make Google Search autocomplete provider cursor aware. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years 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/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 Time::Now() - 230 Time::Now() -
231 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), 231 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1),
232 false, history::SOURCE_BROWSED); 232 false, history::SOURCE_BROWSED);
233 } 233 }
234 234
235 void HistoryURLProviderTest::RunTest(const string16 text, 235 void HistoryURLProviderTest::RunTest(const string16 text,
236 const string16& desired_tld, 236 const string16& desired_tld,
237 bool prevent_inline_autocomplete, 237 bool prevent_inline_autocomplete,
238 const std::string* expected_urls, 238 const std::string* expected_urls,
239 size_t num_results) { 239 size_t num_results) {
240 AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete, 240 AutocompleteInput input(text, string16::npos, desired_tld,
241 false, true, AutocompleteInput::ALL_MATCHES); 241 prevent_inline_autocomplete, false, true,
242 AutocompleteInput::ALL_MATCHES);
242 autocomplete_->Start(input, false); 243 autocomplete_->Start(input, false);
243 if (!autocomplete_->done()) 244 if (!autocomplete_->done())
244 MessageLoop::current()->Run(); 245 MessageLoop::current()->Run();
245 246
246 matches_ = autocomplete_->matches(); 247 matches_ = autocomplete_->matches();
247 if (sort_matches_) { 248 if (sort_matches_) {
248 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) 249 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i)
249 i->ComputeStrippedDestinationURL(profile_.get()); 250 i->ComputeStrippedDestinationURL(profile_.get());
250 std::sort(matches_.begin(), matches_.end(), 251 std::sort(matches_.begin(), matches_.end(),
251 &AutocompleteMatch::DestinationSortFunc); 252 &AutocompleteMatch::DestinationSortFunc);
252 matches_.erase(std::unique(matches_.begin(), matches_.end(), 253 matches_.erase(std::unique(matches_.begin(), matches_.end(),
253 &AutocompleteMatch::DestinationsEqual), 254 &AutocompleteMatch::DestinationsEqual),
254 matches_.end()); 255 matches_.end());
255 std::sort(matches_.begin(), matches_.end(), 256 std::sort(matches_.begin(), matches_.end(),
256 &AutocompleteMatch::MoreRelevant); 257 &AutocompleteMatch::MoreRelevant);
257 } 258 }
258 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text 259 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text
259 << "\nTLD: \"" << desired_tld << "\""; 260 << "\nTLD: \"" << desired_tld << "\"";
260 for (size_t i = 0; i < num_results; ++i) 261 for (size_t i = 0; i < num_results; ++i)
261 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); 262 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec());
262 } 263 }
263 264
264 void HistoryURLProviderTest::RunAdjustOffsetTest(const string16 text, 265 void HistoryURLProviderTest::RunAdjustOffsetTest(const string16 text,
265 size_t expected_offset) { 266 size_t expected_offset) {
266 AutocompleteInput input(text, string16(), false, false, true, 267 AutocompleteInput input(text, string16::npos, string16(), false, false, true,
267 AutocompleteInput::ALL_MATCHES); 268 AutocompleteInput::ALL_MATCHES);
268 autocomplete_->Start(input, false); 269 autocomplete_->Start(input, false);
269 if (!autocomplete_->done()) 270 if (!autocomplete_->done())
270 MessageLoop::current()->Run(); 271 MessageLoop::current()->Run();
271 272
272 matches_ = autocomplete_->matches(); 273 matches_ = autocomplete_->matches();
273 ASSERT_GE(matches_.size(), 1U) << "Input text: " << text; 274 ASSERT_GE(matches_.size(), 1U) << "Input text: " << text;
274 EXPECT_EQ(expected_offset, matches_[0].inline_autocomplete_offset); 275 EXPECT_EQ(expected_offset, matches_[0].inline_autocomplete_offset);
275 } 276 }
276 277
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 RunAdjustOffsetTest(ASCIIToUTF16("http://spaces.com/path%20with%20spa"), 31); 532 RunAdjustOffsetTest(ASCIIToUTF16("http://spaces.com/path%20with%20spa"), 31);
532 RunAdjustOffsetTest(ASCIIToUTF16("http://ms/c++ s"), 15); 533 RunAdjustOffsetTest(ASCIIToUTF16("http://ms/c++ s"), 15);
533 } 534 }
534 535
535 // Make sure the results for the input 'p' don't change between the first and 536 // Make sure the results for the input 'p' don't change between the first and
536 // second passes. 537 // second passes.
537 TEST_F(HistoryURLProviderTest, EmptyVisits) { 538 TEST_F(HistoryURLProviderTest, EmptyVisits) {
538 // Wait for history to create the in memory DB. 539 // Wait for history to create the in memory DB.
539 profile_->BlockUntilHistoryProcessesPendingRequests(); 540 profile_->BlockUntilHistoryProcessesPendingRequests();
540 541
541 AutocompleteInput input(ASCIIToUTF16("p"), string16(), false, false, true, 542 AutocompleteInput input(ASCIIToUTF16("p"), string16::npos, string16(), false,
542 AutocompleteInput::ALL_MATCHES); 543 false, true, AutocompleteInput::ALL_MATCHES);
543 autocomplete_->Start(input, false); 544 autocomplete_->Start(input, false);
544 // HistoryURLProvider shouldn't be done (waiting on async results). 545 // HistoryURLProvider shouldn't be done (waiting on async results).
545 EXPECT_FALSE(autocomplete_->done()); 546 EXPECT_FALSE(autocomplete_->done());
546 547
547 // We should get back an entry for pandora. 548 // We should get back an entry for pandora.
548 matches_ = autocomplete_->matches(); 549 matches_ = autocomplete_->matches();
549 ASSERT_GT(matches_.size(), 0u); 550 ASSERT_GT(matches_.size(), 0u);
550 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); 551 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url);
551 int pandora_relevance = matches_[0].relevance; 552 int pandora_relevance = matches_[0].relevance;
552 553
(...skipping 14 matching lines...) Expand all
567 arraysize(navigation_1)); 568 arraysize(navigation_1));
568 569
569 std::string navigation_2[] = {"http://slash/"}; 570 std::string navigation_2[] = {"http://slash/"};
570 RunTest(ASCIIToUTF16("slash"), string16(), false, navigation_2, 571 RunTest(ASCIIToUTF16("slash"), string16(), false, navigation_2,
571 arraysize(navigation_2)); 572 arraysize(navigation_2));
572 573
573 RunTest(ASCIIToUTF16("this is a query"), string16(), false, NULL, 0); 574 RunTest(ASCIIToUTF16("this is a query"), string16(), false, NULL, 0);
574 } 575 }
575 576
576 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { 577 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) {
577 AutocompleteInput input(ASCIIToUTF16("slash "), string16(), false, 578 AutocompleteInput input(ASCIIToUTF16("slash "), string16::npos, string16(),
578 false, true, AutocompleteInput::ALL_MATCHES); 579 false, false, true, AutocompleteInput::ALL_MATCHES);
579 autocomplete_->Start(input, false); 580 autocomplete_->Start(input, false);
580 if (!autocomplete_->done()) 581 if (!autocomplete_->done())
581 MessageLoop::current()->Run(); 582 MessageLoop::current()->Run();
582 583
583 // None of the matches should attempt to autocomplete. 584 // None of the matches should attempt to autocomplete.
584 matches_ = autocomplete_->matches(); 585 matches_ = autocomplete_->matches();
585 for (size_t i = 0; i < matches_.size(); ++i) 586 for (size_t i = 0; i < matches_.size(); ++i)
586 EXPECT_EQ(string16::npos, matches_[i].inline_autocomplete_offset); 587 EXPECT_EQ(string16::npos, matches_[i].inline_autocomplete_offset);
587 } 588 }
588 589
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 EXPECT_LT(matches_[0].relevance, 1410); 697 EXPECT_LT(matches_[0].relevance, 1410);
697 } 698 }
698 699
699 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { 700 TEST_F(HistoryURLProviderTest, CrashDueToFixup) {
700 // This test passes if we don't crash. The results don't matter. 701 // This test passes if we don't crash. The results don't matter.
701 const char* const test_cases[] = { 702 const char* const test_cases[] = {
702 "//c", 703 "//c",
703 "\\@st" 704 "\\@st"
704 }; 705 };
705 for (size_t i = 0; i < arraysize(test_cases); ++i) { 706 for (size_t i = 0; i < arraysize(test_cases); ++i) {
706 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16(), false, 707 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16::npos,
707 false, true, AutocompleteInput::ALL_MATCHES); 708 string16(), false, false, true,
709 AutocompleteInput::ALL_MATCHES);
708 autocomplete_->Start(input, false); 710 autocomplete_->Start(input, false);
709 if (!autocomplete_->done()) 711 if (!autocomplete_->done())
710 MessageLoop::current()->Run(); 712 MessageLoop::current()->Run();
711 } 713 }
712 } 714 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698