| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 | 786 |
| 787 // We should not see search URLs when typing the search engine name. | 787 // We should not see search URLs when typing the search engine name. |
| 788 const std::string expected_when_searching_site[] = { | 788 const std::string expected_when_searching_site[] = { |
| 789 test_cases[0].url | 789 test_cases[0].url |
| 790 }; | 790 }; |
| 791 RunTest(ASCIIToUTF16("testsearch"), string16(), true, | 791 RunTest(ASCIIToUTF16("testsearch"), string16(), true, |
| 792 expected_when_searching_site, arraysize(expected_when_searching_site)); | 792 expected_when_searching_site, arraysize(expected_when_searching_site)); |
| 793 } | 793 } |
| 794 | 794 |
| 795 TEST_F(HistoryURLProviderTest, SuggestExactInput) { | 795 TEST_F(HistoryURLProviderTest, SuggestExactInput) { |
| 796 const size_t npos = std::string::npos; |
| 796 struct TestCase { | 797 struct TestCase { |
| 797 // Inputs: | 798 // Inputs: |
| 798 const char* input; | 799 const char* input; |
| 799 bool trim_http; | 800 bool trim_http; |
| 800 // Expected Outputs: | 801 // Expected Outputs: |
| 801 const char* contents; | 802 const char* contents; |
| 802 // Offsets of the ACMatchClassifications, terminated by -1s. | 803 // Offsets of the ACMatchClassifications, terminated by npos. |
| 803 size_t offsets[3]; | 804 size_t offsets[3]; |
| 804 // The index of the ACMatchClassification that should have the MATCH bit | 805 // The index of the ACMatchClassification that should have the MATCH bit |
| 805 // set, -1 if there no ACMatchClassification should have the MATCH bit set. | 806 // set, npos if no ACMatchClassification should have the MATCH bit set. |
| 806 size_t match_classification_index; | 807 size_t match_classification_index; |
| 807 } test_cases[] = { | 808 } test_cases[] = { |
| 808 { "http://www.somesite.com", false, | 809 { "http://www.somesite.com", false, |
| 809 "http://www.somesite.com", {0, -1, -1}, 0 }, | 810 "http://www.somesite.com", {0, npos, npos}, 0 }, |
| 810 { "www.somesite.com", true, | 811 { "www.somesite.com", true, |
| 811 "www.somesite.com", {0, -1, -1}, 0 }, | 812 "www.somesite.com", {0, npos, npos}, 0 }, |
| 812 { "www.somesite.com", false, | 813 { "www.somesite.com", false, |
| 813 "http://www.somesite.com", {0, 7, -1}, 1 }, | 814 "http://www.somesite.com", {0, 7, npos}, 1 }, |
| 814 { "somesite.com", true, | 815 { "somesite.com", true, |
| 815 "somesite.com", {0, -1, -1}, 0 }, | 816 "somesite.com", {0, npos, npos}, 0 }, |
| 816 { "somesite.com", false, | 817 { "somesite.com", false, |
| 817 "http://somesite.com", {0, 7, -1}, 1 }, | 818 "http://somesite.com", {0, 7, npos}, 1 }, |
| 818 { "w", true, | 819 { "w", true, |
| 819 "w", {0, -1, -1}, 0 }, | 820 "w", {0, npos, npos}, 0 }, |
| 820 { "w", false, | 821 { "w", false, |
| 821 "http://w", {0, 7, -1}, 1 }, | 822 "http://w", {0, 7, npos}, 1 }, |
| 822 { "w.com", true, | 823 { "w.com", true, |
| 823 "w.com", {0, -1, -1}, 0 }, | 824 "w.com", {0, npos, npos}, 0 }, |
| 824 { "w.com", false, | 825 { "w.com", false, |
| 825 "http://w.com", {0, 7, -1}, 1 }, | 826 "http://w.com", {0, 7, npos}, 1 }, |
| 826 { "www.w.com", true, | 827 { "www.w.com", true, |
| 827 "www.w.com", {0, -1, -1}, 0 }, | 828 "www.w.com", {0, npos, npos}, 0 }, |
| 828 { "www.w.com", false, | 829 { "www.w.com", false, |
| 829 "http://www.w.com", {0, 7, -1}, 1 }, | 830 "http://www.w.com", {0, 7, npos}, 1 }, |
| 830 { "view-source:www.w.com/", true, | 831 { "view-source:www.w.com/", true, |
| 831 "view-source:www.w.com", {0, -1, -1}, -1 }, | 832 "view-source:www.w.com", {0, npos, npos}, npos }, |
| 832 { "view-source:www.w.com/", false, | 833 { "view-source:www.w.com/", false, |
| 833 "view-source:http://www.w.com", {0, -1, -1}, -1 }, | 834 "view-source:http://www.w.com", {0, npos, npos}, npos }, |
| 834 { "view-source:http://www.w.com/", false, | 835 { "view-source:http://www.w.com/", false, |
| 835 "view-source:http://www.w.com", {0, -1, -1}, 0 }, | 836 "view-source:http://www.w.com", {0, npos, npos}, 0 }, |
| 836 { " view-source:", true, | 837 { " view-source:", true, |
| 837 "view-source:", {0, -1, -1}, 0 }, | 838 "view-source:", {0, npos, npos}, 0 }, |
| 838 { "http:////////w.com", false, | 839 { "http:////////w.com", false, |
| 839 "http://w.com", {0, -1, -1}, -1 }, | 840 "http://w.com", {0, npos, npos}, npos }, |
| 840 { " http:////////www.w.com", false, | 841 { " http:////////www.w.com", false, |
| 841 "http://www.w.com", {0, -1, -1}, -1 }, | 842 "http://www.w.com", {0, npos, npos}, npos }, |
| 842 { "http:a///www.w.com", false, | 843 { "http:a///www.w.com", false, |
| 843 "http://a///www.w.com", {0, -1, -1}, -1 }, | 844 "http://a///www.w.com", {0, npos, npos}, npos }, |
| 844 { "mailto://a@b.com", true, | 845 { "mailto://a@b.com", true, |
| 845 "mailto://a@b.com", {0, -1, -1}, 0 }, | 846 "mailto://a@b.com", {0, npos, npos}, 0 }, |
| 846 { "mailto://a@b.com", false, | 847 { "mailto://a@b.com", false, |
| 847 "mailto://a@b.com", {0, -1, -1}, 0 }, | 848 "mailto://a@b.com", {0, npos, npos}, 0 }, |
| 848 }; | 849 }; |
| 849 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 850 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 850 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " | 851 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " |
| 851 << test_cases[i].input << ", trim_http: " | 852 << test_cases[i].input << ", trim_http: " |
| 852 << test_cases[i].trim_http); | 853 << test_cases[i].trim_http); |
| 853 | 854 |
| 854 AutocompleteInput input(ASCIIToUTF16(test_cases[i].input), string16::npos, | 855 AutocompleteInput input(ASCIIToUTF16(test_cases[i].input), string16::npos, |
| 855 string16(), GURL("about:blank"), | 856 string16(), GURL("about:blank"), |
| 856 false, false, true, AutocompleteInput::ALL_MATCHES); | 857 false, false, true, AutocompleteInput::ALL_MATCHES); |
| 857 AutocompleteMatch match = | 858 AutocompleteMatch match = |
| 858 HistoryURLProvider::SuggestExactInput(autocomplete_, input, | 859 HistoryURLProvider::SuggestExactInput(autocomplete_, input, |
| 859 test_cases[i].trim_http); | 860 test_cases[i].trim_http); |
| 860 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); | 861 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); |
| 861 for (size_t match_index = 0; match_index < match.contents_class.size(); | 862 for (size_t match_index = 0; match_index < match.contents_class.size(); |
| 862 ++match_index) { | 863 ++match_index) { |
| 863 EXPECT_EQ(test_cases[i].offsets[match_index], | 864 EXPECT_EQ(test_cases[i].offsets[match_index], |
| 864 match.contents_class[match_index].offset); | 865 match.contents_class[match_index].offset); |
| 865 EXPECT_EQ(ACMatchClassification::URL | | 866 EXPECT_EQ(ACMatchClassification::URL | |
| 866 (match_index == test_cases[i].match_classification_index ? | 867 (match_index == test_cases[i].match_classification_index ? |
| 867 ACMatchClassification::MATCH : 0), | 868 ACMatchClassification::MATCH : 0), |
| 868 match.contents_class[match_index].style); | 869 match.contents_class[match_index].style); |
| 869 } | 870 } |
| 870 EXPECT_EQ(std::string::npos, | 871 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); |
| 871 test_cases[i].offsets[match.contents_class.size()]); | |
| 872 } | 872 } |
| 873 } | 873 } |
| OLD | NEW |