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

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

Issue 19197005: Omnibox: Change |inline_autocomplete_offset| to |inline_autocompletion| (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: drop user_text() in omnibox_edit_model Created 7 years, 5 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/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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void RunTest(const string16 text, 176 void RunTest(const string16 text,
177 const string16& desired_tld, 177 const string16& desired_tld,
178 bool prevent_inline_autocomplete, 178 bool prevent_inline_autocomplete,
179 const std::string* expected_urls, 179 const std::string* expected_urls,
180 size_t num_results) { 180 size_t num_results) {
181 AutocompleteInput::Type type; 181 AutocompleteInput::Type type;
182 return RunTest(text, desired_tld, prevent_inline_autocomplete, 182 return RunTest(text, desired_tld, prevent_inline_autocomplete,
183 expected_urls, num_results, &type); 183 expected_urls, num_results, &type);
184 } 184 }
185 185
186 void RunAdjustOffsetTest(const string16 text, size_t expected_offset);
187
188 content::TestBrowserThreadBundle thread_bundle_; 186 content::TestBrowserThreadBundle thread_bundle_;
189 ACMatches matches_; 187 ACMatches matches_;
190 scoped_ptr<TestingProfile> profile_; 188 scoped_ptr<TestingProfile> profile_;
191 HistoryService* history_service_; 189 HistoryService* history_service_;
192 scoped_refptr<HistoryURLProvider> autocomplete_; 190 scoped_refptr<HistoryURLProvider> autocomplete_;
193 // Should the matches be sorted and duplicates removed? 191 // Should the matches be sorted and duplicates removed?
194 bool sort_matches_; 192 bool sort_matches_;
195 }; 193 };
196 194
197 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { 195 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 matches_.end()); 277 matches_.end());
280 std::sort(matches_.begin(), matches_.end(), 278 std::sort(matches_.begin(), matches_.end(),
281 &AutocompleteMatch::MoreRelevant); 279 &AutocompleteMatch::MoreRelevant);
282 } 280 }
283 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text 281 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text
284 << "\nTLD: \"" << desired_tld << "\""; 282 << "\nTLD: \"" << desired_tld << "\"";
285 for (size_t i = 0; i < num_results; ++i) 283 for (size_t i = 0; i < num_results; ++i)
286 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); 284 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec());
287 } 285 }
288 286
289 void HistoryURLProviderTest::RunAdjustOffsetTest(const string16 text,
290 size_t expected_offset) {
291 AutocompleteInput input(text, string16::npos, string16(), GURL(), false,
292 false, true, AutocompleteInput::ALL_MATCHES);
293 autocomplete_->Start(input, false);
294 if (!autocomplete_->done())
295 base::MessageLoop::current()->Run();
296
297 matches_ = autocomplete_->matches();
298 ASSERT_GE(matches_.size(), 1U) << "Input text: " << text;
299 EXPECT_EQ(expected_offset, matches_[0].inline_autocomplete_offset);
300 }
301
302 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { 287 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
303 // Test that hosts get synthesized below popular pages. 288 // Test that hosts get synthesized below popular pages.
304 const std::string expected_nonsynth[] = { 289 const std::string expected_nonsynth[] = {
305 "http://slashdot.org/favorite_page.html", 290 "http://slashdot.org/favorite_page.html",
306 "http://slashdot.org/", 291 "http://slashdot.org/",
307 }; 292 };
308 RunTest(ASCIIToUTF16("slash"), string16(), true, expected_nonsynth, 293 RunTest(ASCIIToUTF16("slash"), string16(), true, expected_nonsynth,
309 arraysize(expected_nonsynth)); 294 arraysize(expected_nonsynth));
310 295
311 // Test that hosts get synthesized above less popular pages. 296 // Test that hosts get synthesized above less popular pages.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, fixup_crash, 468 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, fixup_crash,
484 arraysize(fixup_crash)); 469 arraysize(fixup_crash));
485 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0); 470 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0);
486 471
487 // Fixing up "file:" should result in an inline autocomplete offset of just 472 // Fixing up "file:" should result in an inline autocomplete offset of just
488 // after "file:", not just after "file://". 473 // after "file:", not just after "file://".
489 const string16 input_1(ASCIIToUTF16("file:")); 474 const string16 input_1(ASCIIToUTF16("file:"));
490 const std::string fixup_1[] = {"file:///C:/foo.txt"}; 475 const std::string fixup_1[] = {"file:///C:/foo.txt"};
491 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1, 476 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1,
492 arraysize(fixup_1))); 477 arraysize(fixup_1)));
493 EXPECT_EQ(input_1.length(), matches_.front().inline_autocomplete_offset); 478 EXPECT_EQ(ASCIIToUTF16("///C:/foo.txt"),
479 matches_.front().inline_autocompletion);
494 480
495 // Fixing up "http:/" should result in an inline autocomplete offset of just 481 // Fixing up "http:/" should result in an inline autocomplete offset of just
496 // after "http:/", not just after "http:". 482 // after "http:/", not just after "http:".
497 const string16 input_2(ASCIIToUTF16("http:/")); 483 const string16 input_2(ASCIIToUTF16("http:/"));
498 const std::string fixup_2[] = { 484 const std::string fixup_2[] = {
499 "http://bogussite.com/a", 485 "http://bogussite.com/a",
500 "http://bogussite.com/b", 486 "http://bogussite.com/b",
501 "http://bogussite.com/c", 487 "http://bogussite.com/c",
502 }; 488 };
503 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, string16(), false, fixup_2, 489 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, string16(), false, fixup_2,
504 arraysize(fixup_2))); 490 arraysize(fixup_2)));
505 EXPECT_EQ(input_2.length(), matches_.front().inline_autocomplete_offset); 491 EXPECT_EQ(ASCIIToUTF16("/bogussite.com/a"),
492 matches_.front().inline_autocompletion);
506 493
507 // Adding a TLD to a small number like "56" should result in "www.56.com" 494 // Adding a TLD to a small number like "56" should result in "www.56.com"
508 // rather than "0.0.0.56.com". 495 // rather than "0.0.0.56.com".
509 const std::string fixup_3[] = {"http://www.56.com/"}; 496 const std::string fixup_3[] = {"http://www.56.com/"};
510 RunTest(ASCIIToUTF16("56"), ASCIIToUTF16("com"), true, fixup_3, 497 RunTest(ASCIIToUTF16("56"), ASCIIToUTF16("com"), true, fixup_3,
511 arraysize(fixup_3)); 498 arraysize(fixup_3));
512 499
513 // An input looks like a IP address like "127.0.0.1" should result in 500 // An input looks like a IP address like "127.0.0.1" should result in
514 // "http://127.0.0.1/". 501 // "http://127.0.0.1/".
515 const std::string fixup_4[] = {"http://127.0.0.1/"}; 502 const std::string fixup_4[] = {"http://127.0.0.1/"};
516 RunTest(ASCIIToUTF16("127.0.0.1"), string16(), false, fixup_4, 503 RunTest(ASCIIToUTF16("127.0.0.1"), string16(), false, fixup_4,
517 arraysize(fixup_4)); 504 arraysize(fixup_4));
518 505
519 // An number "17173" should result in "http://www.17173.com/" in db. 506 // An number "17173" should result in "http://www.17173.com/" in db.
520 const std::string fixup_5[] = {"http://www.17173.com/"}; 507 const std::string fixup_5[] = {"http://www.17173.com/"};
521 RunTest(ASCIIToUTF16("17173"), string16(), false, fixup_5, 508 RunTest(ASCIIToUTF16("17173"), string16(), false, fixup_5,
522 arraysize(fixup_5)); 509 arraysize(fixup_5));
523 } 510 }
524 511
525 TEST_F(HistoryURLProviderTest, AdjustOffset) {
526 RunAdjustOffsetTest(WideToUTF16(L"http://www.\uAD50\uC721"), 13);
527 RunAdjustOffsetTest(ASCIIToUTF16("http://spaces.com/path%20with%20spa"), 31);
528 RunAdjustOffsetTest(ASCIIToUTF16("http://ms/c++ s"), 15);
529 }
530
531 // Make sure the results for the input 'p' don't change between the first and 512 // Make sure the results for the input 'p' don't change between the first and
532 // second passes. 513 // second passes.
533 TEST_F(HistoryURLProviderTest, EmptyVisits) { 514 TEST_F(HistoryURLProviderTest, EmptyVisits) {
534 // Wait for history to create the in memory DB. 515 // Wait for history to create the in memory DB.
535 profile_->BlockUntilHistoryProcessesPendingRequests(); 516 profile_->BlockUntilHistoryProcessesPendingRequests();
536 517
537 AutocompleteInput input(ASCIIToUTF16("p"), string16::npos, string16(), GURL(), 518 AutocompleteInput input(ASCIIToUTF16("p"), string16::npos, string16(), GURL(),
538 false, false, true, AutocompleteInput::ALL_MATCHES); 519 false, false, true, AutocompleteInput::ALL_MATCHES);
539 autocomplete_->Start(input, false); 520 autocomplete_->Start(input, false);
540 // HistoryURLProvider shouldn't be done (waiting on async results). 521 // HistoryURLProvider shouldn't be done (waiting on async results).
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 AutocompleteInput input(ASCIIToUTF16("slash "), string16::npos, string16(), 554 AutocompleteInput input(ASCIIToUTF16("slash "), string16::npos, string16(),
574 GURL(), false, false, true, 555 GURL(), false, false, true,
575 AutocompleteInput::ALL_MATCHES); 556 AutocompleteInput::ALL_MATCHES);
576 autocomplete_->Start(input, false); 557 autocomplete_->Start(input, false);
577 if (!autocomplete_->done()) 558 if (!autocomplete_->done())
578 base::MessageLoop::current()->Run(); 559 base::MessageLoop::current()->Run();
579 560
580 // None of the matches should attempt to autocomplete. 561 // None of the matches should attempt to autocomplete.
581 matches_ = autocomplete_->matches(); 562 matches_ = autocomplete_->matches();
582 for (size_t i = 0; i < matches_.size(); ++i) 563 for (size_t i = 0; i < matches_.size(); ++i)
583 EXPECT_EQ(string16::npos, matches_[i].inline_autocomplete_offset); 564 EXPECT_TRUE(matches_[i].inline_autocompletion.empty());
584 } 565 }
585 566
586 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { 567 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) {
587 // Visiting foo.com should not make this string be treated as a navigation. 568 // Visiting foo.com should not make this string be treated as a navigation.
588 // That means the result should be scored around 1200 ("what you typed") 569 // That means the result should be scored around 1200 ("what you typed")
589 // and not 1400+. 570 // and not 1400+.
590 const std::string expected[] = {"http://user@foo.com/"}; 571 const std::string expected[] = {"http://user@foo.com/"};
591 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(), 572 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(),
592 false, expected, arraysize(expected))); 573 false, expected, arraysize(expected)));
593 EXPECT_LE(1200, matches_[0].relevance); 574 EXPECT_LE(1200, matches_[0].relevance);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 EXPECT_EQ(test_cases[i].offsets[match_index], 844 EXPECT_EQ(test_cases[i].offsets[match_index],
864 match.contents_class[match_index].offset); 845 match.contents_class[match_index].offset);
865 EXPECT_EQ(ACMatchClassification::URL | 846 EXPECT_EQ(ACMatchClassification::URL |
866 (match_index == test_cases[i].match_classification_index ? 847 (match_index == test_cases[i].match_classification_index ?
867 ACMatchClassification::MATCH : 0), 848 ACMatchClassification::MATCH : 0),
868 match.contents_class[match_index].style); 849 match.contents_class[match_index].style);
869 } 850 }
870 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); 851 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]);
871 } 852 }
872 } 853 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/browser/autocomplete/keyword_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698