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

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

Issue 320253004: Componentize URLFixerUpper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win64 fix Created 6 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/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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/autocomplete/autocomplete_match.h" 15 #include "chrome/browser/autocomplete/autocomplete_match.h"
16 #include "chrome/browser/autocomplete/autocomplete_provider.h" 16 #include "chrome/browser/autocomplete/autocomplete_provider.h"
17 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 17 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
18 #include "chrome/browser/autocomplete/autocomplete_result.h" 18 #include "chrome/browser/autocomplete/autocomplete_result.h"
19 #include "chrome/browser/autocomplete/history_quick_provider.h" 19 #include "chrome/browser/autocomplete/history_quick_provider.h"
20 #include "chrome/browser/history/history_service.h" 20 #include "chrome/browser/history/history_service.h"
21 #include "chrome/browser/history/history_service_factory.h" 21 #include "chrome/browser/history/history_service_factory.h"
22 #include "chrome/browser/search_engines/template_url.h" 22 #include "chrome/browser/search_engines/template_url.h"
23 #include "chrome/browser/search_engines/template_url_service.h" 23 #include "chrome/browser/search_engines/template_url_service.h"
24 #include "chrome/browser/search_engines/template_url_service_factory.h" 24 #include "chrome/browser/search_engines/template_url_service_factory.h"
25 #include "chrome/common/net/url_fixer_upper.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/testing_browser_process.h" 26 #include "chrome/test/base/testing_browser_process.h"
28 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "components/url_fixer/url_fixer.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 31
32 using base::ASCIIToUTF16; 32 using base::ASCIIToUTF16;
33 using base::Time; 33 using base::Time;
34 using base::TimeDelta; 34 using base::TimeDelta;
35 35
36 using content::TestBrowserThreadBundle; 36 using content::TestBrowserThreadBundle;
37 37
38 struct TestURLInfo { 38 struct TestURLInfo {
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 { "gooey/a", 1400 }, 643 { "gooey/a", 1400 },
644 { "gooey/a b", 1400 }, 644 { "gooey/a b", 1400 },
645 }; 645 };
646 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 646 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
647 SCOPED_TRACE(test_cases[i].input); 647 SCOPED_TRACE(test_cases[i].input);
648 if (test_cases[i].relevance == 0) { 648 if (test_cases[i].relevance == 0) {
649 RunTest(ASCIIToUTF16(test_cases[i].input), base::string16(), false, 649 RunTest(ASCIIToUTF16(test_cases[i].input), base::string16(), false,
650 NULL, 0); 650 NULL, 0);
651 } else { 651 } else {
652 const UrlAndLegalDefault output[] = { 652 const UrlAndLegalDefault output[] = {
653 { URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec(), 653 {url_fixer::FixupURL(test_cases[i].input, std::string()).spec(),
654 true } 654 true}};
655 };
656 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 655 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
657 base::string16(), false, 656 base::string16(), false,
658 output, arraysize(output))); 657 output, arraysize(output)));
659 // Actual relevance should be at least what test_cases expects and 658 // Actual relevance should be at least what test_cases expects and
660 // and no more than 10 more. 659 // and no more than 10 more.
661 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); 660 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance);
662 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); 661 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10);
663 } 662 }
664 } 663 }
665 } 664 }
666 665
667 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) { 666 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) {
668 struct TestCase { 667 struct TestCase {
669 const char* input; 668 const char* input;
670 int relevance; 669 int relevance;
671 AutocompleteInput::Type type; 670 AutocompleteInput::Type type;
672 } test_cases[] = { 671 } test_cases[] = {
673 { "gooey", 1410, metrics::OmniboxInputType::UNKNOWN }, 672 { "gooey", 1410, metrics::OmniboxInputType::UNKNOWN },
674 { "gooey/", 1410, metrics::OmniboxInputType::URL }, 673 { "gooey/", 1410, metrics::OmniboxInputType::URL },
675 { "gooey#", 1200, metrics::OmniboxInputType::UNKNOWN }, 674 { "gooey#", 1200, metrics::OmniboxInputType::UNKNOWN },
676 { "gooey/#", 1200, metrics::OmniboxInputType::URL }, 675 { "gooey/#", 1200, metrics::OmniboxInputType::URL },
677 { "gooey#foo", 1200, metrics::OmniboxInputType::UNKNOWN }, 676 { "gooey#foo", 1200, metrics::OmniboxInputType::UNKNOWN },
678 { "gooey/#foo", 1200, metrics::OmniboxInputType::URL }, 677 { "gooey/#foo", 1200, metrics::OmniboxInputType::URL },
679 { "gooey# foo", 1200, metrics::OmniboxInputType::UNKNOWN }, 678 { "gooey# foo", 1200, metrics::OmniboxInputType::UNKNOWN },
680 { "gooey/# foo", 1200, metrics::OmniboxInputType::URL }, 679 { "gooey/# foo", 1200, metrics::OmniboxInputType::URL },
681 }; 680 };
682 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 681 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
683 SCOPED_TRACE(test_cases[i].input); 682 SCOPED_TRACE(test_cases[i].input);
684 const UrlAndLegalDefault output[] = { 683 const UrlAndLegalDefault output[] = {
685 { URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec(), 684 {url_fixer::FixupURL(test_cases[i].input, std::string()).spec(), true}};
686 true }
687 };
688 AutocompleteInput::Type type; 685 AutocompleteInput::Type type;
689 ASSERT_NO_FATAL_FAILURE( 686 ASSERT_NO_FATAL_FAILURE(
690 RunTest(ASCIIToUTF16(test_cases[i].input), 687 RunTest(ASCIIToUTF16(test_cases[i].input),
691 base::string16(), false, output, arraysize(output), &type)); 688 base::string16(), false, output, arraysize(output), &type));
692 // Actual relevance should be at least what test_cases expects and 689 // Actual relevance should be at least what test_cases expects and
693 // and no more than 10 more. 690 // and no more than 10 more.
694 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); 691 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance);
695 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); 692 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10);
696 // Input type should be what we expect. This is important because 693 // Input type should be what we expect. This is important because
697 // this provider counts on SearchProvider to give queries a relevance 694 // this provider counts on SearchProvider to give queries a relevance
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 { "7.com/5", max_1100_visit_typed_decays, 983 { "7.com/5", max_1100_visit_typed_decays,
987 {{"7.com/5", 1203, 1203}, {"7.com/5a", 1202, 50}, {NULL, 0, 0}} }, 984 {{"7.com/5", 1203, 1203}, {"7.com/5a", 1202, 50}, {NULL, 0, 0}} },
988 }; 985 };
989 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 986 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
990 SCOPED_TRACE(test_cases[i].input); 987 SCOPED_TRACE(test_cases[i].input);
991 UrlAndLegalDefault output[kMaxMatches]; 988 UrlAndLegalDefault output[kMaxMatches];
992 int max_matches; 989 int max_matches;
993 for (max_matches = 0; max_matches < kMaxMatches; ++max_matches) { 990 for (max_matches = 0; max_matches < kMaxMatches; ++max_matches) {
994 if (test_cases[i].matches[max_matches].url == NULL) 991 if (test_cases[i].matches[max_matches].url == NULL)
995 break; 992 break;
996 output[max_matches].url = URLFixerUpper::FixupURL( 993 output[max_matches].url =
997 test_cases[i].matches[max_matches].url, std::string()).spec(); 994 url_fixer::FixupURL(test_cases[i].matches[max_matches].url,
995 std::string()).spec();
998 output[max_matches].allowed_to_be_default_match = true; 996 output[max_matches].allowed_to_be_default_match = true;
999 } 997 }
1000 autocomplete_->scoring_params_ = test_cases[i].scoring_params; 998 autocomplete_->scoring_params_ = test_cases[i].scoring_params;
1001 999
1002 // Test the control (scoring disabled). 1000 // Test the control (scoring disabled).
1003 autocomplete_->scoring_params_.experimental_scoring_enabled = false; 1001 autocomplete_->scoring_params_.experimental_scoring_enabled = false;
1004 ASSERT_NO_FATAL_FAILURE( 1002 ASSERT_NO_FATAL_FAILURE(
1005 RunTest(ASCIIToUTF16(test_cases[i].input), 1003 RunTest(ASCIIToUTF16(test_cases[i].input),
1006 base::string16(), false, output, max_matches)); 1004 base::string16(), false, output, max_matches));
1007 for (int j = 0; j < max_matches; ++j) { 1005 for (int j = 0; j < max_matches; ++j) {
1008 EXPECT_EQ(test_cases[i].matches[j].control_relevance, 1006 EXPECT_EQ(test_cases[i].matches[j].control_relevance,
1009 matches_[j].relevance); 1007 matches_[j].relevance);
1010 } 1008 }
1011 1009
1012 // Test the experiment (scoring enabled). 1010 // Test the experiment (scoring enabled).
1013 autocomplete_->scoring_params_.experimental_scoring_enabled = true; 1011 autocomplete_->scoring_params_.experimental_scoring_enabled = true;
1014 ASSERT_NO_FATAL_FAILURE( 1012 ASSERT_NO_FATAL_FAILURE(
1015 RunTest(ASCIIToUTF16(test_cases[i].input), 1013 RunTest(ASCIIToUTF16(test_cases[i].input),
1016 base::string16(), false, output, max_matches)); 1014 base::string16(), false, output, max_matches));
1017 for (int j = 0; j < max_matches; ++j) { 1015 for (int j = 0; j < max_matches; ++j) {
1018 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, 1016 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance,
1019 matches_[j].relevance); 1017 matches_[j].relevance);
1020 } 1018 }
1021 } 1019 }
1022 } 1020 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/browser/autocomplete/shortcuts_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698