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

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

Issue 10260020: Make Omnibox HistoryURL Provider always aggressive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reordered EXPECT_GT to EXPECT_LT. Created 8 years, 7 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
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 MessageLoop::current()->Run(); 549 MessageLoop::current()->Run();
550 550
551 // None of the matches should attempt to autocomplete. 551 // None of the matches should attempt to autocomplete.
552 matches_ = autocomplete_->matches(); 552 matches_ = autocomplete_->matches();
553 for (size_t i = 0; i < matches_.size(); ++i) 553 for (size_t i = 0; i < matches_.size(); ++i)
554 EXPECT_EQ(string16::npos, matches_[i].inline_autocomplete_offset); 554 EXPECT_EQ(string16::npos, matches_[i].inline_autocomplete_offset);
555 } 555 }
556 556
557 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { 557 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) {
558 // Visiting foo.com should not make this string be treated as a navigation. 558 // Visiting foo.com should not make this string be treated as a navigation.
559 // That means the result should be scored at 1200 ("what you typed") and not 559 // That means the result should be scored around 1200 ("what you typed")
560 // 1400+. 560 // and not 1400+.
561 const std::string expected[] = {"http://user@foo.com/"}; 561 const std::string expected[] = {"http://user@foo.com/"};
562 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(), 562 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(),
563 false, expected, arraysize(expected))); 563 false, expected, arraysize(expected)));
564 EXPECT_EQ(1200, matches_[0].relevance); 564 EXPECT_LE(1200, matches_[0].relevance);
565 EXPECT_LT(matches_[0].relevance, 1210);
565 } 566 }
566 567
567 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) { 568 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) {
568 struct TestCase { 569 struct TestCase {
569 const char* input; 570 const char* input;
570 int relevance; 571 int relevance;
571 } test_cases[] = { 572 } test_cases[] = {
572 { "fooey", 0 }, 573 { "fooey", 0 },
573 { "fooey/", 1200 }, // 1200 for URL would still navigate by default. 574 { "fooey/", 1200 }, // 1200 for URL would still navigate by default.
574 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not. 575 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not.
575 { "fooey/a b", 1200 }, // Also UNKNOWN. 576 { "fooey/a b", 1200 }, // Also UNKNOWN.
576 { "gooey", 1410 }, 577 { "gooey", 1410 },
577 { "gooey/", 1410 }, 578 { "gooey/", 1410 },
578 { "gooey/a", 1400 }, 579 { "gooey/a", 1400 },
579 { "gooey/a b", 1400 }, 580 { "gooey/a b", 1400 },
580 }; 581 };
581 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 582 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
582 SCOPED_TRACE(test_cases[i].input); 583 SCOPED_TRACE(test_cases[i].input);
583 if (test_cases[i].relevance == 0) { 584 if (test_cases[i].relevance == 0) {
584 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, NULL, 0); 585 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, NULL, 0);
585 } else { 586 } else {
586 const std::string output[] = { 587 const std::string output[] = {
587 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() 588 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec()
588 }; 589 };
589 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 590 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
590 string16(), false, output, arraysize(output))); 591 string16(), false, output, arraysize(output)));
591 EXPECT_EQ(test_cases[i].relevance, matches_[0].relevance); 592 // Actual relevance should be at least what test_cases expects and
593 // and no more than 10 more.
594 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance);
595 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10);
592 } 596 }
593 } 597 }
594 } 598 }
595 599
596 // Makes sure autocompletion happens for intranet sites that have been 600 // Makes sure autocompletion happens for intranet sites that have been
597 // previoulsy visited. 601 // previoulsy visited.
598 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { 602 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) {
599 sort_matches_ = true; 603 sort_matches_ = true;
600 604
601 const std::string expected1[] = { 605 const std::string expected1[] = {
602 "http://intra/three", 606 "http://intra/three",
603 "http://intra/two", 607 "http://intra/two",
604 }; 608 };
605 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false, 609 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false,
606 expected1, arraysize(expected1))); 610 expected1, arraysize(expected1)));
607 EXPECT_EQ(1410, matches_[0].relevance); 611 EXPECT_LE(1410, matches_[0].relevance);
608 EXPECT_EQ(900, matches_[1].relevance); 612 EXPECT_LT(matches_[0].relevance, 1420);
613 EXPECT_EQ(matches_[0].relevance - 1, matches_[1].relevance);
609 614
610 const std::string expected2[] = { 615 const std::string expected2[] = {
611 "http://moo/b", 616 "http://moo/b",
612 "http://moo/bar", 617 "http://moo/bar",
613 }; 618 };
614 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("moo/b"), string16(), false, 619 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("moo/b"), string16(), false,
615 expected2, arraysize(expected2))); 620 expected2, arraysize(expected2)));
616 // The what you typed match should be 1400, otherwise the search what you 621 // The url what you typed match should be around 1400, otherwise the
617 // typed match is going to be first. 622 // search what you typed match is going to be first.
618 EXPECT_EQ(1400, matches_[0].relevance); 623 EXPECT_LE(1400, matches_[0].relevance);
624 EXPECT_LT(matches_[0].relevance, 1410);
619 625
620 const std::string expected3[] = { 626 const std::string expected3[] = {
621 "http://intra/one", 627 "http://intra/one",
622 "http://intra/three", 628 "http://intra/three",
623 "http://intra/two", 629 "http://intra/two",
624 }; 630 };
625 RunTest(ASCIIToUTF16("intra"), string16(), false, expected3, 631 RunTest(ASCIIToUTF16("intra"), string16(), false, expected3,
626 arraysize(expected3)); 632 arraysize(expected3));
627 633
628 const std::string expected4[] = { 634 const std::string expected4[] = {
629 "http://intra/one", 635 "http://intra/one",
630 "http://intra/three", 636 "http://intra/three",
631 "http://intra/two", 637 "http://intra/two",
632 }; 638 };
633 RunTest(ASCIIToUTF16("intra/"), string16(), false, expected4, 639 RunTest(ASCIIToUTF16("intra/"), string16(), false, expected4,
634 arraysize(expected4)); 640 arraysize(expected4));
635 641
636 const std::string expected5[] = { 642 const std::string expected5[] = {
637 "http://intra/one", 643 "http://intra/one",
638 }; 644 };
639 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/o"), string16(), false, 645 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/o"), string16(), false,
640 expected5, arraysize(expected5))); 646 expected5, arraysize(expected5)));
641 EXPECT_EQ(1410, matches_[0].relevance); 647 EXPECT_LE(1410, matches_[0].relevance);
648 EXPECT_LT(matches_[0].relevance, 1420);
642 649
643 const std::string expected6[] = { 650 const std::string expected6[] = {
644 "http://intra/x", 651 "http://intra/x",
645 }; 652 };
646 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/x"), string16(), false, 653 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/x"), string16(), false,
647 expected6, arraysize(expected6))); 654 expected6, arraysize(expected6)));
648 EXPECT_EQ(1400, matches_[0].relevance); 655 EXPECT_LE(1400, matches_[0].relevance);
656 EXPECT_LT(matches_[0].relevance, 1410);
649 657
650 const std::string expected7[] = { 658 const std::string expected7[] = {
651 "http://typedhost/untypedpath", 659 "http://typedhost/untypedpath",
652 }; 660 };
653 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("typedhost/untypedpath"), 661 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("typedhost/untypedpath"),
654 string16(), false, expected7, arraysize(expected7))); 662 string16(), false, expected7, arraysize(expected7)));
655 EXPECT_EQ(1400, matches_[0].relevance); 663 EXPECT_LE(1400, matches_[0].relevance);
664 EXPECT_LT(matches_[0].relevance, 1410);
656 } 665 }
657 666
658 TEST_F(HistoryURLProviderTest, CrashDueToFixup) { 667 TEST_F(HistoryURLProviderTest, CrashDueToFixup) {
659 // This test passes if we don't crash. The results don't matter. 668 // This test passes if we don't crash. The results don't matter.
660 const char* const test_cases[] = { 669 const char* const test_cases[] = {
661 "//c", 670 "//c",
662 "\\@st" 671 "\\@st"
663 }; 672 };
664 for (size_t i = 0; i < arraysize(test_cases); ++i) { 673 for (size_t i = 0; i < arraysize(test_cases); ++i) {
665 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16(), false, 674 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16(), false,
666 false, true, AutocompleteInput::ALL_MATCHES); 675 false, true, AutocompleteInput::ALL_MATCHES);
667 autocomplete_->Start(input, false); 676 autocomplete_->Start(input, false);
668 if (!autocomplete_->done()) 677 if (!autocomplete_->done())
669 MessageLoop::current()->Run(); 678 MessageLoop::current()->Run();
670 } 679 }
671 } 680 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698