OLD | NEW |
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" |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 // the results to be in A,B,C order. Note also that our visit counts are | 441 // the results to be in A,B,C order. Note also that our visit counts are |
442 // all high enough so that domain synthesizing won't get triggered. | 442 // all high enough so that domain synthesizing won't get triggered. |
443 struct TestCase { | 443 struct TestCase { |
444 const char* url; | 444 const char* url; |
445 int count; | 445 int count; |
446 } test_cases[] = { | 446 } test_cases[] = { |
447 {"http://redirects/A", 30}, | 447 {"http://redirects/A", 30}, |
448 {"http://redirects/B", 20}, | 448 {"http://redirects/B", 20}, |
449 {"http://redirects/C", 10} | 449 {"http://redirects/C", 10} |
450 }; | 450 }; |
451 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 451 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
452 history_service_->AddPageWithDetails(GURL(test_cases[i].url), | 452 history_service_->AddPageWithDetails(GURL(test_cases[i].url), |
453 ASCIIToUTF16("Title"), test_cases[i].count, test_cases[i].count, | 453 ASCIIToUTF16("Title"), test_cases[i].count, test_cases[i].count, |
454 Time::Now(), false, history::SOURCE_BROWSED); | 454 Time::Now(), false, history::SOURCE_BROWSED); |
455 } | 455 } |
456 | 456 |
457 // Create a B->C->A redirect chain, but set the visit counts such that they | 457 // Create a B->C->A redirect chain, but set the visit counts such that they |
458 // will appear in A,B,C order in the results. The autocomplete query will | 458 // will appear in A,B,C order in the results. The autocomplete query will |
459 // search for the most recent visit when looking for redirects, so this will | 459 // search for the most recent visit when looking for redirects, so this will |
460 // be found even though the previous visits had no redirects. | 460 // be found even though the previous visits had no redirects. |
461 history::RedirectList redirects_to_a; | 461 history::RedirectList redirects_to_a; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 } test_cases[] = { | 650 } test_cases[] = { |
651 { "fooey", 0 }, | 651 { "fooey", 0 }, |
652 { "fooey/", 1200 }, // 1200 for URL would still navigate by default. | 652 { "fooey/", 1200 }, // 1200 for URL would still navigate by default. |
653 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not. | 653 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not. |
654 { "fooey/a b", 1200 }, // Also UNKNOWN. | 654 { "fooey/a b", 1200 }, // Also UNKNOWN. |
655 { "gooey", 1410 }, | 655 { "gooey", 1410 }, |
656 { "gooey/", 1410 }, | 656 { "gooey/", 1410 }, |
657 { "gooey/a", 1400 }, | 657 { "gooey/a", 1400 }, |
658 { "gooey/a b", 1400 }, | 658 { "gooey/a b", 1400 }, |
659 }; | 659 }; |
660 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 660 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
661 SCOPED_TRACE(test_cases[i].input); | 661 SCOPED_TRACE(test_cases[i].input); |
662 if (test_cases[i].relevance == 0) { | 662 if (test_cases[i].relevance == 0) { |
663 RunTest(ASCIIToUTF16(test_cases[i].input), std::string(), false, NULL, 0); | 663 RunTest(ASCIIToUTF16(test_cases[i].input), std::string(), false, NULL, 0); |
664 } else { | 664 } else { |
665 const UrlAndLegalDefault output[] = { | 665 const UrlAndLegalDefault output[] = { |
666 {url_fixer::FixupURL(test_cases[i].input, std::string()).spec(), | 666 {url_fixer::FixupURL(test_cases[i].input, std::string()).spec(), |
667 true}}; | 667 true}}; |
668 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 668 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
669 std::string(), false, output, arraysize(output))); | 669 std::string(), false, output, arraysize(output))); |
670 // Actual relevance should be at least what test_cases expects and | 670 // Actual relevance should be at least what test_cases expects and |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 // the results to be in A,B,C order. Note also that our visit counts are | 779 // the results to be in A,B,C order. Note also that our visit counts are |
780 // all high enough so that domain synthesizing won't get triggered. | 780 // all high enough so that domain synthesizing won't get triggered. |
781 struct TestCase { | 781 struct TestCase { |
782 const char* url; | 782 const char* url; |
783 int count; | 783 int count; |
784 } test_cases[] = { | 784 } test_cases[] = { |
785 {"https://testsearch.com/", 30}, | 785 {"https://testsearch.com/", 30}, |
786 {"https://testsearch.com/?q=foobar", 20}, | 786 {"https://testsearch.com/?q=foobar", 20}, |
787 {"http://foobar.com/", 10} | 787 {"http://foobar.com/", 10} |
788 }; | 788 }; |
789 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 789 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
790 history_service_->AddPageWithDetails(GURL(test_cases[i].url), | 790 history_service_->AddPageWithDetails(GURL(test_cases[i].url), |
791 base::UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, | 791 base::UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, |
792 Time::Now(), false, history::SOURCE_BROWSED); | 792 Time::Now(), false, history::SOURCE_BROWSED); |
793 } | 793 } |
794 | 794 |
795 // We should not see search URLs when typing a previously used query. | 795 // We should not see search URLs when typing a previously used query. |
796 const UrlAndLegalDefault expected_when_searching_query[] = { | 796 const UrlAndLegalDefault expected_when_searching_query[] = { |
797 { test_cases[2].url, false } | 797 { test_cases[2].url, false } |
798 }; | 798 }; |
799 RunTest(ASCIIToUTF16("foobar"), std::string(), true, | 799 RunTest(ASCIIToUTF16("foobar"), std::string(), true, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 "http://w.com", {0, npos, npos}, npos }, | 857 "http://w.com", {0, npos, npos}, npos }, |
858 { " http:////////www.w.com", false, | 858 { " http:////////www.w.com", false, |
859 "http://www.w.com", {0, npos, npos}, npos }, | 859 "http://www.w.com", {0, npos, npos}, npos }, |
860 { "http:a///www.w.com", false, | 860 { "http:a///www.w.com", false, |
861 "http://a///www.w.com", {0, npos, npos}, npos }, | 861 "http://a///www.w.com", {0, npos, npos}, npos }, |
862 { "mailto://a@b.com", true, | 862 { "mailto://a@b.com", true, |
863 "mailto://a@b.com", {0, npos, npos}, 0 }, | 863 "mailto://a@b.com", {0, npos, npos}, 0 }, |
864 { "mailto://a@b.com", false, | 864 { "mailto://a@b.com", false, |
865 "mailto://a@b.com", {0, npos, npos}, 0 }, | 865 "mailto://a@b.com", {0, npos, npos}, 0 }, |
866 }; | 866 }; |
867 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 867 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
868 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " | 868 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " |
869 << test_cases[i].input << ", trim_http: " | 869 << test_cases[i].input << ", trim_http: " |
870 << test_cases[i].trim_http); | 870 << test_cases[i].trim_http); |
871 | 871 |
872 AutocompleteInput input(ASCIIToUTF16(test_cases[i].input), | 872 AutocompleteInput input(ASCIIToUTF16(test_cases[i].input), |
873 base::string16::npos, std::string(), | 873 base::string16::npos, std::string(), |
874 GURL("about:blank"), | 874 GURL("about:blank"), |
875 metrics::OmniboxEventProto::INVALID_SPEC, false, | 875 metrics::OmniboxEventProto::INVALID_SPEC, false, |
876 false, true, true, | 876 false, true, true, |
877 ChromeAutocompleteSchemeClassifier(profile_.get())); | 877 ChromeAutocompleteSchemeClassifier(profile_.get())); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 { "7.com/1", max_1100_with_time_decay_and_max_cap, | 954 { "7.com/1", max_1100_with_time_decay_and_max_cap, |
955 {{"7.com/1a", 1413, 1413}, {NULL, 0, 0}, {NULL, 0, 0}} }, | 955 {{"7.com/1a", 1413, 1413}, {NULL, 0, 0}, {NULL, 0, 0}} }, |
956 { "7.com/4", max_1100_with_time_decay_and_max_cap, | 956 { "7.com/4", max_1100_with_time_decay_and_max_cap, |
957 {{"7.com/4", 1203, 1203}, {"7.com/4a", 1202, 200}, | 957 {{"7.com/4", 1203, 1203}, {"7.com/4a", 1202, 200}, |
958 {"7.com/4b", 1201, 100}} }, | 958 {"7.com/4b", 1201, 100}} }, |
959 | 959 |
960 // Max relevance cap is 1400 and half-life is 16 days for both visit/typed. | 960 // Max relevance cap is 1400 and half-life is 16 days for both visit/typed. |
961 { "7.com/5", max_1100_visit_typed_decays, | 961 { "7.com/5", max_1100_visit_typed_decays, |
962 {{"7.com/5", 1203, 1203}, {"7.com/5a", 1202, 50}, {NULL, 0, 0}} }, | 962 {{"7.com/5", 1203, 1203}, {"7.com/5a", 1202, 50}, {NULL, 0, 0}} }, |
963 }; | 963 }; |
964 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 964 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
965 SCOPED_TRACE(test_cases[i].input); | 965 SCOPED_TRACE(test_cases[i].input); |
966 UrlAndLegalDefault output[kMaxMatches]; | 966 UrlAndLegalDefault output[kMaxMatches]; |
967 int max_matches; | 967 int max_matches; |
968 for (max_matches = 0; max_matches < kMaxMatches; ++max_matches) { | 968 for (max_matches = 0; max_matches < kMaxMatches; ++max_matches) { |
969 if (test_cases[i].matches[max_matches].url == NULL) | 969 if (test_cases[i].matches[max_matches].url == NULL) |
970 break; | 970 break; |
971 output[max_matches].url = | 971 output[max_matches].url = |
972 url_fixer::FixupURL(test_cases[i].matches[max_matches].url, | 972 url_fixer::FixupURL(test_cases[i].matches[max_matches].url, |
973 std::string()).spec(); | 973 std::string()).spec(); |
974 output[max_matches].allowed_to_be_default_match = true; | 974 output[max_matches].allowed_to_be_default_match = true; |
(...skipping 12 matching lines...) Expand all Loading... |
987 // Test the experiment (scoring enabled). | 987 // Test the experiment (scoring enabled). |
988 autocomplete_->scoring_params_.experimental_scoring_enabled = true; | 988 autocomplete_->scoring_params_.experimental_scoring_enabled = true; |
989 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 989 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
990 std::string(), false, output, max_matches)); | 990 std::string(), false, output, max_matches)); |
991 for (int j = 0; j < max_matches; ++j) { | 991 for (int j = 0; j < max_matches; ++j) { |
992 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, | 992 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, |
993 matches_[j].relevance); | 993 matches_[j].relevance); |
994 } | 994 } |
995 } | 995 } |
996 } | 996 } |
OLD | NEW |