OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("FOO"), 1)); | 659 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("FOO"), 1)); |
660 profile_.BlockUntilHistoryProcessesPendingRequests(); | 660 profile_.BlockUntilHistoryProcessesPendingRequests(); |
661 | 661 |
662 AutocompleteMatch wyt_match; | 662 AutocompleteMatch wyt_match; |
663 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("f"), | 663 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("f"), |
664 &wyt_match)); | 664 &wyt_match)); |
665 ASSERT_EQ(2u, provider_->matches().size()); | 665 ASSERT_EQ(2u, provider_->matches().size()); |
666 AutocompleteMatch term_match; | 666 AutocompleteMatch term_match; |
667 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); | 667 EXPECT_TRUE(FindMatchWithDestination(term_url, &term_match)); |
668 EXPECT_GT(term_match.relevance, wyt_match.relevance); | 668 EXPECT_GT(term_match.relevance, wyt_match.relevance); |
669 EXPECT_EQ(1u, term_match.inline_autocomplete_offset); | |
670 EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit); | 669 EXPECT_EQ(ASCIIToUTF16("FOO"), term_match.fill_into_edit); |
670 EXPECT_EQ(ASCIIToUTF16("OO"), term_match.inline_autocompletion); | |
671 } | 671 } |
672 | 672 |
673 // Verifies AutocompleteControllers return results (including keyword | 673 // Verifies AutocompleteControllers return results (including keyword |
674 // results) in the right order and set descriptions for them correctly. | 674 // results) in the right order and set descriptions for them correctly. |
675 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { | 675 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { |
676 // Add an entry that corresponds to a keyword search with 'term2'. | 676 // Add an entry that corresponds to a keyword search with 'term2'. |
677 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); | 677 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); |
678 profile_.BlockUntilHistoryProcessesPendingRequests(); | 678 profile_.BlockUntilHistoryProcessesPendingRequests(); |
679 | 679 |
680 AutocompleteController controller(&profile_, NULL, | 680 AutocompleteController controller(&profile_, NULL, |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 } | 888 } |
889 | 889 |
890 // Verifies that suggest results with relevance scores are added | 890 // Verifies that suggest results with relevance scores are added |
891 // properly when using the default fetcher. When adding a new test | 891 // properly when using the default fetcher. When adding a new test |
892 // case to this test, please consider adding it to the tests in | 892 // case to this test, please consider adding it to the tests in |
893 // KeywordFetcherSuggestRelevance below. | 893 // KeywordFetcherSuggestRelevance below. |
894 TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) { | 894 TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) { |
895 struct { | 895 struct { |
896 const std::string json; | 896 const std::string json; |
897 const std::string matches[4]; | 897 const std::string matches[4]; |
898 const std::string inline_autocompletion; | |
898 } cases[] = { | 899 } cases[] = { |
899 // Ensure that suggestrelevance scores reorder matches. | 900 // Ensure that suggestrelevance scores reorder matches. |
900 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", | 901 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", |
901 { "a", "c", "b", kNotApplicable } }, | 902 { "a", "c", "b", kNotApplicable }, "" }, |
Peter Kasting
2013/07/16 18:09:05
Nit: If we're constructing a string from this inst
Mark P
2013/07/16 18:53:23
Done everywhere, though I think it looks a little
| |
902 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," | 903 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," |
903 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 904 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
904 "\"google:suggestrelevance\":[1, 2]}]", | 905 "\"google:suggestrelevance\":[1, 2]}]", |
905 { "a", "c.com", "b.com", kNotApplicable } }, | 906 { "a", "c.com", "b.com", kNotApplicable }, "" }, |
906 | 907 |
907 // Without suggested relevance scores, we should only allow one | 908 // Without suggested relevance scores, we should only allow one |
908 // navsuggest result to be be displayed. | 909 // navsuggest result to be be displayed. |
909 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," | 910 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," |
910 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", | 911 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", |
911 { "a", "b.com", kNotApplicable, kNotApplicable } }, | 912 { "a", "b.com", kNotApplicable, kNotApplicable }, "" }, |
912 | 913 |
913 // Ensure that verbatimrelevance scores reorder or suppress verbatim. | 914 // Ensure that verbatimrelevance scores reorder or suppress verbatim. |
914 // Negative values will have no effect; the calculated value will be used. | 915 // Negative values will have no effect; the calculated value will be used. |
915 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," | 916 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," |
916 "\"google:suggestrelevance\":[9998]}]", | 917 "\"google:suggestrelevance\":[9998]}]", |
917 { "a", "a1", kNotApplicable, kNotApplicable } }, | 918 { "a", "a1", kNotApplicable, kNotApplicable }, "" }, |
918 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," | 919 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," |
919 "\"google:suggestrelevance\":[9999]}]", | 920 "\"google:suggestrelevance\":[9999]}]", |
920 { "a1", "a", kNotApplicable, kNotApplicable } }, | 921 { "a1", "a", kNotApplicable, kNotApplicable }, "1" }, |
921 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," | 922 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," |
922 "\"google:suggestrelevance\":[9999]}]", | 923 "\"google:suggestrelevance\":[9999]}]", |
923 { "a1", kNotApplicable, kNotApplicable, kNotApplicable } }, | 924 { "a1", kNotApplicable, kNotApplicable, kNotApplicable }, "1" }, |
924 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," | 925 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," |
925 "\"google:suggestrelevance\":[9999]}]", | 926 "\"google:suggestrelevance\":[9999]}]", |
926 { "a1", "a", kNotApplicable, kNotApplicable } }, | 927 { "a1", "a", kNotApplicable, kNotApplicable }, "1" }, |
927 { "[\"a\",[\"http://a.com\"],[],[]," | 928 { "[\"a\",[\"http://a.com\"],[],[]," |
928 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 929 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
929 "\"google:verbatimrelevance\":9999," | 930 "\"google:verbatimrelevance\":9999," |
930 "\"google:suggestrelevance\":[9998]}]", | 931 "\"google:suggestrelevance\":[9998]}]", |
931 { "a", "a.com", kNotApplicable, kNotApplicable } }, | 932 { "a", "a.com", kNotApplicable, kNotApplicable }, "" }, |
932 { "[\"a\",[\"http://a.com\"],[],[]," | 933 { "[\"a\",[\"http://a.com\"],[],[]," |
933 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 934 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
934 "\"google:verbatimrelevance\":9998," | 935 "\"google:verbatimrelevance\":9998," |
935 "\"google:suggestrelevance\":[9999]}]", | 936 "\"google:suggestrelevance\":[9999]}]", |
936 { "a.com", "a", kNotApplicable, kNotApplicable } }, | 937 { "a.com", "a", kNotApplicable, kNotApplicable }, ".com" }, |
937 { "[\"a\",[\"http://a.com\"],[],[]," | 938 { "[\"a\",[\"http://a.com\"],[],[]," |
938 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 939 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
939 "\"google:verbatimrelevance\":0," | 940 "\"google:verbatimrelevance\":0," |
940 "\"google:suggestrelevance\":[9999]}]", | 941 "\"google:suggestrelevance\":[9999]}]", |
941 { "a.com", kNotApplicable, kNotApplicable, kNotApplicable } }, | 942 { "a.com", kNotApplicable, kNotApplicable, kNotApplicable }, ".com" }, |
942 { "[\"a\",[\"http://a.com\"],[],[]," | 943 { "[\"a\",[\"http://a.com\"],[],[]," |
943 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 944 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
944 "\"google:verbatimrelevance\":-1," | 945 "\"google:verbatimrelevance\":-1," |
945 "\"google:suggestrelevance\":[9999]}]", | 946 "\"google:suggestrelevance\":[9999]}]", |
946 { "a.com", "a", kNotApplicable, kNotApplicable } }, | 947 { "a.com", "a", kNotApplicable, kNotApplicable }, ".com" }, |
947 | 948 |
948 // Ensure that both types of relevance scores reorder matches together. | 949 // Ensure that both types of relevance scores reorder matches together. |
949 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," | 950 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," |
950 "\"google:verbatimrelevance\":9998}]", | 951 "\"google:verbatimrelevance\":9998}]", |
951 { "a1", "a", "a2", kNotApplicable } }, | 952 { "a1", "a", "a2", kNotApplicable }, "1" }, |
952 | 953 |
953 // Ensure that only inlinable matches may be ranked as the highest result. | 954 // Ensure that only inlinable matches may be ranked as the highest result. |
954 // Ignore all suggested relevance scores if this constraint is violated. | 955 // Ignore all suggested relevance scores if this constraint is violated. |
955 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", | 956 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", |
956 { "a", "b", kNotApplicable, kNotApplicable } }, | 957 { "a", "b", kNotApplicable, kNotApplicable }, "" }, |
957 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," | 958 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," |
958 "\"google:verbatimrelevance\":0}]", | 959 "\"google:verbatimrelevance\":0}]", |
959 { "a", "b", kNotApplicable, kNotApplicable } }, | 960 { "a", "b", kNotApplicable, kNotApplicable }, "" }, |
960 { "[\"a\",[\"http://b.com\"],[],[]," | 961 { "[\"a\",[\"http://b.com\"],[],[]," |
961 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 962 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
962 "\"google:suggestrelevance\":[9999]}]", | 963 "\"google:suggestrelevance\":[9999]}]", |
963 { "a", "b.com", kNotApplicable, kNotApplicable } }, | 964 { "a", "b.com", kNotApplicable, kNotApplicable }, "" }, |
964 { "[\"a\",[\"http://b.com\"],[],[]," | 965 { "[\"a\",[\"http://b.com\"],[],[]," |
965 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 966 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
966 "\"google:suggestrelevance\":[9999]," | 967 "\"google:suggestrelevance\":[9999]," |
967 "\"google:verbatimrelevance\":0}]", | 968 "\"google:verbatimrelevance\":0}]", |
968 { "a", "b.com", kNotApplicable, kNotApplicable } }, | 969 { "a", "b.com", kNotApplicable, kNotApplicable }, "" }, |
969 | 970 |
970 // Ensure that the top result is ranked as highly as calculated verbatim. | 971 // Ensure that the top result is ranked as highly as calculated verbatim. |
971 // Ignore the suggested verbatim relevance if this constraint is violated. | 972 // Ignore the suggested verbatim relevance if this constraint is violated. |
972 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", | 973 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", |
973 { "a", "a1", kNotApplicable, kNotApplicable } }, | 974 { "a", "a1", kNotApplicable, kNotApplicable }, "" }, |
974 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", | 975 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", |
975 { "a", "a1", kNotApplicable, kNotApplicable } }, | 976 { "a", "a1", kNotApplicable, kNotApplicable }, "" }, |
976 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," | 977 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," |
977 "\"google:verbatimrelevance\":0}]", | 978 "\"google:verbatimrelevance\":0}]", |
978 { "a", "a1", kNotApplicable, kNotApplicable } }, | 979 { "a", "a1", kNotApplicable, kNotApplicable }, "" }, |
979 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," | 980 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," |
980 "\"google:verbatimrelevance\":0}]", | 981 "\"google:verbatimrelevance\":0}]", |
981 { "a", "a2", "a1", kNotApplicable } }, | 982 { "a", "a2", "a1", kNotApplicable }, "" }, |
982 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," | 983 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," |
983 "\"google:verbatimrelevance\":2}]", | 984 "\"google:verbatimrelevance\":2}]", |
984 { "a", "a2", "a1", kNotApplicable } }, | 985 { "a", "a2", "a1", kNotApplicable }, "" }, |
985 { "[\"a\",[\"http://a.com\"],[],[]," | 986 { "[\"a\",[\"http://a.com\"],[],[]," |
986 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 987 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
987 "\"google:suggestrelevance\":[1]," | 988 "\"google:suggestrelevance\":[1]," |
988 "\"google:verbatimrelevance\":0}]", | 989 "\"google:verbatimrelevance\":0}]", |
989 { "a", "a.com", kNotApplicable, kNotApplicable } }, | 990 { "a", "a.com", kNotApplicable, kNotApplicable }, "" }, |
990 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 991 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
991 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 992 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
992 "\"google:suggestrelevance\":[1, 2]," | 993 "\"google:suggestrelevance\":[1, 2]," |
993 "\"google:verbatimrelevance\":0}]", | 994 "\"google:verbatimrelevance\":0}]", |
994 { "a", "a2.com", "a1.com", kNotApplicable } }, | 995 { "a", "a2.com", "a1.com", kNotApplicable }, "" }, |
995 | 996 |
996 // Ensure that all suggestions are considered, regardless of order. | 997 // Ensure that all suggestions are considered, regardless of order. |
997 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," | 998 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," |
998 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 999 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
999 { "a", "h", "g", "f" } }, | 1000 { "a", "h", "g", "f" }, "" }, |
1000 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," | 1001 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," |
1001 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," | 1002 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," |
1002 "\"http://h.com\"],[],[]," | 1003 "\"http://h.com\"],[],[]," |
1003 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," | 1004 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," |
1004 "\"NAVIGATION\", \"NAVIGATION\"," | 1005 "\"NAVIGATION\", \"NAVIGATION\"," |
1005 "\"NAVIGATION\", \"NAVIGATION\"," | 1006 "\"NAVIGATION\", \"NAVIGATION\"," |
1006 "\"NAVIGATION\"]," | 1007 "\"NAVIGATION\"]," |
1007 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1008 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
1008 { "a", "h.com", "g.com", "f.com" } }, | 1009 { "a", "h.com", "g.com", "f.com" }, "" }, |
1009 | 1010 |
1010 // Ensure that incorrectly sized suggestion relevance lists are ignored. | 1011 // Ensure that incorrectly sized suggestion relevance lists are ignored. |
1011 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", | 1012 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", |
1012 { "a", "a1", "a2", kNotApplicable } }, | 1013 { "a", "a1", "a2", kNotApplicable }, "" }, |
1013 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", | 1014 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", |
1014 { "a", "a1", kNotApplicable, kNotApplicable } }, | 1015 { "a", "a1", kNotApplicable, kNotApplicable }, "" }, |
1015 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1016 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
1016 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1017 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
1017 "\"google:suggestrelevance\":[1]}]", | 1018 "\"google:suggestrelevance\":[1]}]", |
1018 { "a", "a1.com", kNotApplicable, kNotApplicable } }, | 1019 { "a", "a1.com", kNotApplicable, kNotApplicable }, "" }, |
1019 { "[\"a\",[\"http://a1.com\"],[],[]," | 1020 { "[\"a\",[\"http://a1.com\"],[],[]," |
1020 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1021 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
1021 "\"google:suggestrelevance\":[9999, 1]}]", | 1022 "\"google:suggestrelevance\":[9999, 1]}]", |
1022 { "a", "a1.com", kNotApplicable, kNotApplicable } }, | 1023 { "a", "a1.com", kNotApplicable, kNotApplicable }, "" }, |
1023 | 1024 |
1024 // Ensure that all 'verbatim' results are merged with their maximum score. | 1025 // Ensure that all 'verbatim' results are merged with their maximum score. |
1025 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1026 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
1026 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", | 1027 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", |
1027 { "a2", "a", "a1", kNotApplicable } }, | 1028 { "a2", "a", "a1", kNotApplicable }, "2" }, |
1028 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1029 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
1029 "{\"google:suggestrelevance\":[9998, 9997, 9999]," | 1030 "{\"google:suggestrelevance\":[9998, 9997, 9999]," |
1030 "\"google:verbatimrelevance\":0}]", | 1031 "\"google:verbatimrelevance\":0}]", |
1031 { "a2", "a", "a1", kNotApplicable } }, | 1032 { "a2", "a", "a1", kNotApplicable }, "2" }, |
1032 | 1033 |
1033 // Ensure that verbatim is always generated without other suggestions. | 1034 // Ensure that verbatim is always generated without other suggestions. |
1034 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). | 1035 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). |
1035 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", | 1036 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", |
1036 { "a", kNotApplicable, kNotApplicable, kNotApplicable } }, | 1037 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, "" }, |
1037 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", | 1038 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", |
1038 { "a", kNotApplicable, kNotApplicable, kNotApplicable } }, | 1039 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, "" }, |
1039 }; | 1040 }; |
1040 | 1041 |
1041 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1042 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
1042 QueryForInput(ASCIIToUTF16("a"), false, false); | 1043 QueryForInput(ASCIIToUTF16("a"), false, false); |
1043 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( | 1044 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( |
1044 SearchProvider::kDefaultProviderURLFetcherID); | 1045 SearchProvider::kDefaultProviderURLFetcherID); |
1045 ASSERT_TRUE(fetcher); | 1046 ASSERT_TRUE(fetcher); |
1046 fetcher->set_response_code(200); | 1047 fetcher->set_response_code(200); |
1047 fetcher->SetResponseString(cases[i].json); | 1048 fetcher->SetResponseString(cases[i].json); |
1048 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1049 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1049 RunTillProviderDone(); | 1050 RunTillProviderDone(); |
1050 | 1051 |
1051 const std::string description = "for input with json=" + cases[i].json; | 1052 const std::string description = "for input with json=" + cases[i].json; |
1052 const ACMatches& matches = provider_->matches(); | 1053 const ACMatches& matches = provider_->matches(); |
1053 // The top match must inline and score as highly as calculated verbatim. | 1054 // The top match must inline and score as highly as calculated verbatim. |
1054 ASSERT_FALSE(matches.empty()); | 1055 ASSERT_FALSE(matches.empty()); |
1055 EXPECT_NE(string16::npos, matches[0].inline_autocomplete_offset) << | 1056 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
1056 description; | 1057 matches[0].inline_autocompletion) << description; |
1057 EXPECT_GE(matches[0].relevance, 1300) << description; | 1058 EXPECT_GE(matches[0].relevance, 1300) << description; |
1058 | 1059 |
1059 size_t j = 0; | 1060 size_t j = 0; |
1060 // Ensure that the returned matches equal the expectations. | 1061 // Ensure that the returned matches equal the expectations. |
1061 for (; j < matches.size(); ++j) | 1062 for (; j < matches.size(); ++j) |
1062 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), | 1063 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), |
1063 matches[j].contents) << description; | 1064 matches[j].contents) << description; |
1064 // Ensure that no expected matches are missing. | 1065 // Ensure that no expected matches are missing. |
1065 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) | 1066 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) |
1066 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) << | 1067 EXPECT_EQ(kNotApplicable, cases[i].matches[j]) << |
1067 "Case # " << i << " " << description; | 1068 "Case # " << i << " " << description; |
1068 } | 1069 } |
1069 } | 1070 } |
1070 | 1071 |
1071 // Verifies that suggest results with relevance scores are added | 1072 // Verifies that suggest results with relevance scores are added |
1072 // properly when using the keyword fetcher. This is similar to the | 1073 // properly when using the keyword fetcher. This is similar to the |
1073 // test DefaultFetcherSuggestRelevance above but this uses inputs that | 1074 // test DefaultFetcherSuggestRelevance above but this uses inputs that |
1074 // trigger keyword suggestions (i.e., "k a" rather than "a") and has | 1075 // trigger keyword suggestions (i.e., "k a" rather than "a") and has |
1075 // different expectations (because now the results are a mix of | 1076 // different expectations (because now the results are a mix of |
1076 // keyword suggestions and default provider suggestions). When a new | 1077 // keyword suggestions and default provider suggestions). When a new |
1077 // test is added to this TEST_F, please consider if it would be | 1078 // test is added to this TEST_F, please consider if it would be |
1078 // appropriate to add to DefaultFetcherSuggestRelevance as well. | 1079 // appropriate to add to DefaultFetcherSuggestRelevance as well. |
1079 TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) { | 1080 TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) { |
1080 struct { | 1081 struct { |
1081 const std::string json; | 1082 const std::string json; |
1082 const struct { | 1083 const struct { |
1083 const std::string contents; | 1084 const std::string contents; |
1084 const bool from_keyword; | 1085 const bool from_keyword; |
1085 } matches[5]; | 1086 } matches[5]; |
1087 const std::string inline_autocompletion; | |
1086 } cases[] = { | 1088 } cases[] = { |
1087 // Ensure that suggest relevance scores reorder matches and that | 1089 // Ensure that suggest relevance scores reorder matches and that |
1088 // the keyword verbatim (lacking a suggested verbatim score) beats | 1090 // the keyword verbatim (lacking a suggested verbatim score) beats |
1089 // the default provider verbatim. | 1091 // the default provider verbatim. |
1090 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", | 1092 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", |
1091 { { "a", true }, | 1093 { { "a", true }, |
1092 { "k a", false }, | 1094 { "k a", false }, |
1093 { "c", true }, | 1095 { "c", true }, |
1094 { "b", true }, | 1096 { "b", true }, |
1095 { kNotApplicable, false } } }, | 1097 { kNotApplicable, false } }, |
1098 "" }, | |
1096 // Again, check that relevance scores reorder matches, just this | 1099 // Again, check that relevance scores reorder matches, just this |
1097 // time with navigation matches. This also checks that with | 1100 // time with navigation matches. This also checks that with |
1098 // suggested relevance scores we allow multiple navsuggest results. | 1101 // suggested relevance scores we allow multiple navsuggest results. |
1099 // It's odd that navsuggest results that come from a keyword | 1102 // It's odd that navsuggest results that come from a keyword |
1100 // provider are marked as not a keyword result. I think this | 1103 // provider are marked as not a keyword result. I think this |
1101 // comes from them not going to a keyword search engine). | 1104 // comes from them not going to a keyword search engine). |
1102 // TODO(mpearson): Investigate the implications (if any) of | 1105 // TODO(mpearson): Investigate the implications (if any) of |
1103 // tagging these results appropriately. If so, do it because it | 1106 // tagging these results appropriately. If so, do it because it |
1104 // makes more sense. | 1107 // makes more sense. |
1105 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[]," | 1108 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[]," |
1106 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1109 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1107 "\"google:suggestrelevance\":[1301, 1302, 1303]}]", | 1110 "\"google:suggestrelevance\":[1301, 1302, 1303]}]", |
1108 { { "a", true }, | 1111 { { "a", true }, |
1109 { "d", true }, | 1112 { "d", true }, |
1110 { "c.com", false }, | 1113 { "c.com", false }, |
1111 { "b.com", false }, | 1114 { "b.com", false }, |
1112 { "k a", false }, } }, | 1115 { "k a", false }, }, |
1116 "" }, | |
1113 | 1117 |
1114 // Without suggested relevance scores, we should only allow one | 1118 // Without suggested relevance scores, we should only allow one |
1115 // navsuggest result to be be displayed. | 1119 // navsuggest result to be be displayed. |
1116 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," | 1120 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," |
1117 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", | 1121 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", |
1118 { { "a", true }, | 1122 { { "a", true }, |
1119 { "b.com", false }, | 1123 { "b.com", false }, |
1120 { "k a", false }, | 1124 { "k a", false }, |
1121 { kNotApplicable, false }, | 1125 { kNotApplicable, false }, |
1122 { kNotApplicable, false } } }, | 1126 { kNotApplicable, false } }, |
1127 "" }, | |
1123 | 1128 |
1124 // Ensure that verbatimrelevance scores reorder or suppress verbatim. | 1129 // Ensure that verbatimrelevance scores reorder or suppress verbatim. |
1125 // Negative values will have no effect; the calculated value will be used. | 1130 // Negative values will have no effect; the calculated value will be used. |
1126 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," | 1131 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," |
1127 "\"google:suggestrelevance\":[9998]}]", | 1132 "\"google:suggestrelevance\":[9998]}]", |
1128 { { "a", true }, | 1133 { { "a", true }, |
1129 { "a1", true }, | 1134 { "a1", true }, |
1130 { "k a", false }, | 1135 { "k a", false }, |
1131 { kNotApplicable, false }, | 1136 { kNotApplicable, false }, |
1132 { kNotApplicable, false } } }, | 1137 { kNotApplicable, false } }, |
1138 "" }, | |
1133 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," | 1139 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," |
1134 "\"google:suggestrelevance\":[9999]}]", | 1140 "\"google:suggestrelevance\":[9999]}]", |
1135 { { "a1", true }, | 1141 { { "a1", true }, |
1136 { "a", true }, | 1142 { "a", true }, |
1137 { "k a", false }, | 1143 { "k a", false }, |
1138 { kNotApplicable, false }, | 1144 { kNotApplicable, false }, |
1139 { kNotApplicable, false } } }, | 1145 { kNotApplicable, false } }, |
1146 "1" }, | |
1140 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," | 1147 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," |
1141 "\"google:suggestrelevance\":[9999]}]", | 1148 "\"google:suggestrelevance\":[9999]}]", |
1142 { { "a1", true }, | 1149 { { "a1", true }, |
1143 { "k a", false }, | 1150 { "k a", false }, |
1144 { kNotApplicable, false }, | 1151 { kNotApplicable, false }, |
1145 { kNotApplicable, false }, | 1152 { kNotApplicable, false }, |
1146 { kNotApplicable, false } } }, | 1153 { kNotApplicable, false } }, |
1154 "1" }, | |
1147 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," | 1155 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," |
1148 "\"google:suggestrelevance\":[9999]}]", | 1156 "\"google:suggestrelevance\":[9999]}]", |
1149 { { "a1", true }, | 1157 { { "a1", true }, |
1150 { "a", true }, | 1158 { "a", true }, |
1151 { "k a", false }, | 1159 { "k a", false }, |
1152 { kNotApplicable, false }, | 1160 { kNotApplicable, false }, |
1153 { kNotApplicable, false } } }, | 1161 { kNotApplicable, false } }, |
1162 "1" }, | |
1154 { "[\"a\",[\"http://a.com\"],[],[]," | 1163 { "[\"a\",[\"http://a.com\"],[],[]," |
1155 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1164 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
1156 "\"google:verbatimrelevance\":9999," | 1165 "\"google:verbatimrelevance\":9999," |
1157 "\"google:suggestrelevance\":[9998]}]", | 1166 "\"google:suggestrelevance\":[9998]}]", |
1158 { { "a", true }, | 1167 { { "a", true }, |
1159 { "a.com", false }, | 1168 { "a.com", false }, |
1160 { "k a", false }, | 1169 { "k a", false }, |
1161 { kNotApplicable, false }, | 1170 { kNotApplicable, false }, |
1162 { kNotApplicable, false } } }, | 1171 { kNotApplicable, false } }, |
1172 "" }, | |
1163 | 1173 |
1164 // Ensure that both types of relevance scores reorder matches together. | 1174 // Ensure that both types of relevance scores reorder matches together. |
1165 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," | 1175 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," |
1166 "\"google:verbatimrelevance\":9998}]", | 1176 "\"google:verbatimrelevance\":9998}]", |
1167 { { "a1", true }, | 1177 { { "a1", true }, |
1168 { "a", true }, | 1178 { "a", true }, |
1169 { "a2", true }, | 1179 { "a2", true }, |
1170 { "k a", false }, | 1180 { "k a", false }, |
1171 { kNotApplicable, false } } }, | 1181 { kNotApplicable, false } }, |
1182 "1" }, | |
1172 | 1183 |
1173 // Ensure that only inlinable matches may be ranked as the highest result. | 1184 // Ensure that only inlinable matches may be ranked as the highest result. |
1174 // Ignore all suggested relevance scores if this constraint is violated. | 1185 // Ignore all suggested relevance scores if this constraint is violated. |
1175 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", | 1186 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", |
1176 { { "a", true }, | 1187 { { "a", true }, |
1177 { "b", true }, | 1188 { "b", true }, |
1178 { "k a", false }, | 1189 { "k a", false }, |
1179 { kNotApplicable, false }, | 1190 { kNotApplicable, false }, |
1180 { kNotApplicable, false } } }, | 1191 { kNotApplicable, false } }, |
1192 "" }, | |
1181 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," | 1193 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," |
1182 "\"google:verbatimrelevance\":0}]", | 1194 "\"google:verbatimrelevance\":0}]", |
1183 { { "a", true }, | 1195 { { "a", true }, |
1184 { "b", true }, | 1196 { "b", true }, |
1185 { "k a", false }, | 1197 { "k a", false }, |
1186 { kNotApplicable, false }, | 1198 { kNotApplicable, false }, |
1187 { kNotApplicable, false } } }, | 1199 { kNotApplicable, false } }, |
1200 "" }, | |
1188 { "[\"a\",[\"http://b.com\"],[],[]," | 1201 { "[\"a\",[\"http://b.com\"],[],[]," |
1189 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1202 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
1190 "\"google:suggestrelevance\":[9999]}]", | 1203 "\"google:suggestrelevance\":[9999]}]", |
1191 { { "a", true }, | 1204 { { "a", true }, |
1192 { "b.com", false }, | 1205 { "b.com", false }, |
1193 { "k a", false }, | 1206 { "k a", false }, |
1194 { kNotApplicable, false }, | 1207 { kNotApplicable, false }, |
1195 { kNotApplicable, false } } }, | 1208 { kNotApplicable, false } }, |
1209 "" }, | |
1196 { "[\"a\",[\"http://b.com\"],[],[]," | 1210 { "[\"a\",[\"http://b.com\"],[],[]," |
1197 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1211 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
1198 "\"google:suggestrelevance\":[9999]," | 1212 "\"google:suggestrelevance\":[9999]," |
1199 "\"google:verbatimrelevance\":0}]", | 1213 "\"google:verbatimrelevance\":0}]", |
1200 { { "a", true }, | 1214 { { "a", true }, |
1201 { "b.com", false }, | 1215 { "b.com", false }, |
1202 { "k a", false }, | 1216 { "k a", false }, |
1203 { kNotApplicable, false }, | 1217 { kNotApplicable, false }, |
1204 { kNotApplicable, false } } }, | 1218 { kNotApplicable, false } }, |
1219 "" }, | |
1205 | 1220 |
1206 // Ensure that the top result is ranked as highly as calculated verbatim. | 1221 // Ensure that the top result is ranked as highly as calculated verbatim. |
1207 // Ignore the suggested verbatim relevance if this constraint is violated. | 1222 // Ignore the suggested verbatim relevance if this constraint is violated. |
1208 // Note that keyword suggestions by default (not in suggested relevance | 1223 // Note that keyword suggestions by default (not in suggested relevance |
1209 // mode) score more highly than the default verbatim. | 1224 // mode) score more highly than the default verbatim. |
1210 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", | 1225 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", |
1211 { { "a", true }, | 1226 { { "a", true }, |
1212 { "a1", true }, | 1227 { "a1", true }, |
1213 { "k a", false }, | 1228 { "k a", false }, |
1214 { kNotApplicable, false }, | 1229 { kNotApplicable, false }, |
1215 { kNotApplicable, false } } }, | 1230 { kNotApplicable, false } }, |
1231 "" }, | |
1216 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", | 1232 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", |
1217 { { "a", true }, | 1233 { { "a", true }, |
1218 { "a1", true }, | 1234 { "a1", true }, |
1219 { "k a", false }, | 1235 { "k a", false }, |
1220 { kNotApplicable, false }, | 1236 { kNotApplicable, false }, |
1221 { kNotApplicable, false } } }, | 1237 { kNotApplicable, false } }, |
1238 "" }, | |
1222 // Continuing the same category of tests, but make sure we keep the | 1239 // Continuing the same category of tests, but make sure we keep the |
1223 // suggested relevance scores even as we discard the verbatim relevance | 1240 // suggested relevance scores even as we discard the verbatim relevance |
1224 // scores. | 1241 // scores. |
1225 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," | 1242 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," |
1226 "\"google:verbatimrelevance\":0}]", | 1243 "\"google:verbatimrelevance\":0}]", |
1227 { { "a", true }, | 1244 { { "a", true }, |
1228 { "k a", false }, | 1245 { "k a", false }, |
1229 { "a1", true }, | 1246 { "a1", true }, |
1230 { kNotApplicable, false }, | 1247 { kNotApplicable, false }, |
1231 { kNotApplicable, false } } }, | 1248 { kNotApplicable, false } }, |
1249 "" }, | |
1232 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," | 1250 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," |
1233 "\"google:verbatimrelevance\":0}]", | 1251 "\"google:verbatimrelevance\":0}]", |
1234 { { "a", true }, | 1252 { { "a", true }, |
1235 { "k a", false }, | 1253 { "k a", false }, |
1236 { "a2", true }, | 1254 { "a2", true }, |
1237 { "a1", true }, | 1255 { "a1", true }, |
1238 { kNotApplicable, false } } }, | 1256 { kNotApplicable, false } }, |
1257 "" }, | |
1239 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," | 1258 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," |
1240 "\"google:verbatimrelevance\":2}]", | 1259 "\"google:verbatimrelevance\":2}]", |
1241 { { "a", true }, | 1260 { { "a", true }, |
1242 { "k a", false }, | 1261 { "k a", false }, |
1243 { "a2", true }, | 1262 { "a2", true }, |
1244 { "a1", true }, | 1263 { "a1", true }, |
1245 { kNotApplicable, false } } }, | 1264 { kNotApplicable, false } }, |
1265 "" }, | |
1246 | 1266 |
1247 // Ensure that all suggestions are considered, regardless of order. | 1267 // Ensure that all suggestions are considered, regardless of order. |
1248 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," | 1268 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," |
1249 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1269 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
1250 { { "a", true }, | 1270 { { "a", true }, |
1251 { "k a", false }, | 1271 { "k a", false }, |
1252 { "h", true }, | 1272 { "h", true }, |
1253 { "g", true }, | 1273 { "g", true }, |
1254 { "f", true } } }, | 1274 { "f", true } }, |
1275 "" }, | |
1255 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," | 1276 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," |
1256 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," | 1277 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," |
1257 "\"http://h.com\"],[],[]," | 1278 "\"http://h.com\"],[],[]," |
1258 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," | 1279 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," |
1259 "\"NAVIGATION\", \"NAVIGATION\"," | 1280 "\"NAVIGATION\", \"NAVIGATION\"," |
1260 "\"NAVIGATION\", \"NAVIGATION\"," | 1281 "\"NAVIGATION\", \"NAVIGATION\"," |
1261 "\"NAVIGATION\"]," | 1282 "\"NAVIGATION\"]," |
1262 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1283 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
1263 { { "a", true }, | 1284 { { "a", true }, |
1264 { "k a", false }, | 1285 { "k a", false }, |
1265 { "h.com", false }, | 1286 { "h.com", false }, |
1266 { "g.com", false }, | 1287 { "g.com", false }, |
1267 { "f.com", false } } }, | 1288 { "f.com", false } }, |
1289 "" }, | |
1268 | 1290 |
1269 // Ensure that incorrectly sized suggestion relevance lists are ignored. | 1291 // Ensure that incorrectly sized suggestion relevance lists are ignored. |
1270 // Note that keyword suggestions by default (not in suggested relevance | 1292 // Note that keyword suggestions by default (not in suggested relevance |
1271 // mode) score more highly than the default verbatim. | 1293 // mode) score more highly than the default verbatim. |
1272 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", | 1294 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", |
1273 { { "a", true }, | 1295 { { "a", true }, |
1274 { "a1", true }, | 1296 { "a1", true }, |
1275 { "a2", true }, | 1297 { "a2", true }, |
1276 { "k a", false }, | 1298 { "k a", false }, |
1277 { kNotApplicable, false } } }, | 1299 { kNotApplicable, false } }, |
1300 "" }, | |
1278 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", | 1301 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", |
1279 { { "a", true }, | 1302 { { "a", true }, |
1280 { "a1", true }, | 1303 { "a1", true }, |
1281 { "k a", false }, | 1304 { "k a", false }, |
1282 { kNotApplicable, false }, | 1305 { kNotApplicable, false }, |
1283 { kNotApplicable, false } } }, | 1306 { kNotApplicable, false } }, |
1307 "" }, | |
1284 // In this case, ignored the suggested relevance scores means we keep | 1308 // In this case, ignored the suggested relevance scores means we keep |
1285 // only one navsuggest result. | 1309 // only one navsuggest result. |
1286 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1310 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
1287 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1311 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
1288 "\"google:suggestrelevance\":[1]}]", | 1312 "\"google:suggestrelevance\":[1]}]", |
1289 { { "a", true }, | 1313 { { "a", true }, |
1290 { "a1.com", false }, | 1314 { "a1.com", false }, |
1291 { "k a", false }, | 1315 { "k a", false }, |
1292 { kNotApplicable, false }, | 1316 { kNotApplicable, false }, |
1293 { kNotApplicable, false } } }, | 1317 { kNotApplicable, false } }, |
1318 "" }, | |
1294 { "[\"a\",[\"http://a1.com\"],[],[]," | 1319 { "[\"a\",[\"http://a1.com\"],[],[]," |
1295 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1320 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
1296 "\"google:suggestrelevance\":[9999, 1]}]", | 1321 "\"google:suggestrelevance\":[9999, 1]}]", |
1297 { { "a", true }, | 1322 { { "a", true }, |
1298 { "a1.com", false }, | 1323 { "a1.com", false }, |
1299 { "k a", false }, | 1324 { "k a", false }, |
1300 { kNotApplicable, false }, | 1325 { kNotApplicable, false }, |
1301 { kNotApplicable, false } } }, | 1326 { kNotApplicable, false } }, |
1327 "" }, | |
1302 | 1328 |
1303 // Ensure that all 'verbatim' results are merged with their maximum score. | 1329 // Ensure that all 'verbatim' results are merged with their maximum score. |
1304 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1330 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
1305 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", | 1331 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", |
1306 { { "a2", true }, | 1332 { { "a2", true }, |
1307 { "a", true }, | 1333 { "a", true }, |
1308 { "a1", true }, | 1334 { "a1", true }, |
1309 { "k a", false }, | 1335 { "k a", false }, |
1310 { kNotApplicable, false } } }, | 1336 { kNotApplicable, false } }, |
1337 "2" }, | |
1311 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1338 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
1312 "{\"google:suggestrelevance\":[9998, 9997, 9999]," | 1339 "{\"google:suggestrelevance\":[9998, 9997, 9999]," |
1313 "\"google:verbatimrelevance\":0}]", | 1340 "\"google:verbatimrelevance\":0}]", |
1314 { { "a2", true }, | 1341 { { "a2", true }, |
1315 { "a", true }, | 1342 { "a", true }, |
1316 { "a1", true }, | 1343 { "a1", true }, |
1317 { "k a", false }, | 1344 { "k a", false }, |
1318 { kNotApplicable, false } } }, | 1345 { kNotApplicable, false } }, |
1346 "2" }, | |
1319 | 1347 |
1320 // Ensure that verbatim is always generated without other suggestions. | 1348 // Ensure that verbatim is always generated without other suggestions. |
1321 // TODO(mpearson): Ensure the value of verbatimrelevance is respected | 1349 // TODO(mpearson): Ensure the value of verbatimrelevance is respected |
1322 // (except when suggested relevances are ignored). | 1350 // (except when suggested relevances are ignored). |
1323 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", | 1351 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", |
1324 { { "a", true }, | 1352 { { "a", true }, |
1325 { "k a", false }, | 1353 { "k a", false }, |
1326 { kNotApplicable, false }, | 1354 { kNotApplicable, false }, |
1327 { kNotApplicable, false }, | 1355 { kNotApplicable, false }, |
1328 { kNotApplicable, false } } }, | 1356 { kNotApplicable, false } }, |
1357 "" }, | |
1329 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", | 1358 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", |
1330 { { "a", true }, | 1359 { { "a", true }, |
1331 { "k a", false }, | 1360 { "k a", false }, |
1332 { kNotApplicable, false }, | 1361 { kNotApplicable, false }, |
1333 { kNotApplicable, false }, | 1362 { kNotApplicable, false }, |
1334 { kNotApplicable, false } } }, | 1363 { kNotApplicable, false } }, |
1364 "" }, | |
1335 | 1365 |
1336 // Check that navsuggestions will be demoted below queries. | 1366 // Check that navsuggestions will be demoted below queries. |
1337 // (Navsuggestions are not allowed to appear first.) In the process, | 1367 // (Navsuggestions are not allowed to appear first.) In the process, |
1338 // make sure the navsuggestions still remain in the same order. | 1368 // make sure the navsuggestions still remain in the same order. |
1339 // First, check the situation where navsuggest scores more than verbatim | 1369 // First, check the situation where navsuggest scores more than verbatim |
1340 // and there are no query suggestions. | 1370 // and there are no query suggestions. |
1341 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1371 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
1342 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1372 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
1343 "\"google:verbatimrelevance\":9990," | 1373 "\"google:verbatimrelevance\":9990," |
1344 "\"google:suggestrelevance\":[9998, 9999]}]", | 1374 "\"google:suggestrelevance\":[9998, 9999]}]", |
1345 { { "a", true }, | 1375 { { "a", true }, |
1346 { "a2.com", false }, | 1376 { "a2.com", false }, |
1347 { "a1.com", false }, | 1377 { "a1.com", false }, |
1348 { "k a", false }, | 1378 { "k a", false }, |
1349 { kNotApplicable, false } } }, | 1379 { kNotApplicable, false } }, |
1380 "" }, | |
1350 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1381 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
1351 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1382 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
1352 "\"google:verbatimrelevance\":9990," | 1383 "\"google:verbatimrelevance\":9990," |
1353 "\"google:suggestrelevance\":[9999, 9998]}]", | 1384 "\"google:suggestrelevance\":[9999, 9998]}]", |
1354 { { "a", true }, | 1385 { { "a", true }, |
1355 { "a1.com", false }, | 1386 { "a1.com", false }, |
1356 { "a2.com", false }, | 1387 { "a2.com", false }, |
1357 { "k a", false }, | 1388 { "k a", false }, |
1358 { kNotApplicable, false } } }, | 1389 { kNotApplicable, false } }, |
1390 "" }, | |
1359 // Check when navsuggest scores more than verbatim and there is query | 1391 // Check when navsuggest scores more than verbatim and there is query |
1360 // suggestion but it scores lower. | 1392 // suggestion but it scores lower. |
1361 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1393 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1362 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1394 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1363 "\"google:verbatimrelevance\":9990," | 1395 "\"google:verbatimrelevance\":9990," |
1364 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", | 1396 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", |
1365 { { "a", true }, | 1397 { { "a", true }, |
1366 { "a2.com", false }, | 1398 { "a2.com", false }, |
1367 { "a1.com", false }, | 1399 { "a1.com", false }, |
1368 { "a3", true }, | 1400 { "a3", true }, |
1369 { "k a", false } } }, | 1401 { "k a", false } }, |
1402 "" }, | |
1370 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1403 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1371 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1404 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1372 "\"google:verbatimrelevance\":9990," | 1405 "\"google:verbatimrelevance\":9990," |
1373 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", | 1406 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", |
1374 { { "a", true }, | 1407 { { "a", true }, |
1375 { "a1.com", false }, | 1408 { "a1.com", false }, |
1376 { "a2.com", false }, | 1409 { "a2.com", false }, |
1377 { "a3", true }, | 1410 { "a3", true }, |
1378 { "k a", false } } }, | 1411 { "k a", false } }, |
1412 "" }, | |
1379 // Check when navsuggest scores more than a query suggestion. There is | 1413 // Check when navsuggest scores more than a query suggestion. There is |
1380 // a verbatim but it scores lower. | 1414 // a verbatim but it scores lower. |
1381 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1415 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1382 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1416 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1383 "\"google:verbatimrelevance\":9990," | 1417 "\"google:verbatimrelevance\":9990," |
1384 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", | 1418 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", |
1385 { { "a3", true }, | 1419 { { "a3", true }, |
1386 { "a2.com", false }, | 1420 { "a2.com", false }, |
1387 { "a1.com", false }, | 1421 { "a1.com", false }, |
1388 { "a", true }, | 1422 { "a", true }, |
1389 { "k a", false } } }, | 1423 { "k a", false } }, |
1424 "3" }, | |
1390 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1425 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1391 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1426 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1392 "\"google:verbatimrelevance\":9990," | 1427 "\"google:verbatimrelevance\":9990," |
1393 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", | 1428 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", |
1394 { { "a3", true }, | 1429 { { "a3", true }, |
1395 { "a1.com", false }, | 1430 { "a1.com", false }, |
1396 { "a2.com", false }, | 1431 { "a2.com", false }, |
1397 { "a", true }, | 1432 { "a", true }, |
1398 { "k a", false } } }, | 1433 { "k a", false } }, |
1434 "3" }, | |
1399 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1435 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1400 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1436 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1401 "\"google:verbatimrelevance\":0," | 1437 "\"google:verbatimrelevance\":0," |
1402 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", | 1438 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", |
1403 { { "a3", true }, | 1439 { { "a3", true }, |
1404 { "a2.com", false }, | 1440 { "a2.com", false }, |
1405 { "a1.com", false }, | 1441 { "a1.com", false }, |
1406 { "k a", false }, | 1442 { "k a", false }, |
1407 { kNotApplicable, false } } }, | 1443 { kNotApplicable, false } }, |
1444 "3" }, | |
1408 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1445 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1409 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1446 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1410 "\"google:verbatimrelevance\":0," | 1447 "\"google:verbatimrelevance\":0," |
1411 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", | 1448 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", |
1412 { { "a3", true }, | 1449 { { "a3", true }, |
1413 { "a1.com", false }, | 1450 { "a1.com", false }, |
1414 { "a2.com", false }, | 1451 { "a2.com", false }, |
1415 { "k a", false }, | 1452 { "k a", false }, |
1416 { kNotApplicable, false } } }, | 1453 { kNotApplicable, false } }, |
1454 "3" }, | |
1417 // Check when there is neither verbatim nor a query suggestion that, | 1455 // Check when there is neither verbatim nor a query suggestion that, |
1418 // because we can't demote navsuggestions below a query suggestion, | 1456 // because we can't demote navsuggestions below a query suggestion, |
1419 // we abandon suggested relevance scores entirely. One consequence is | 1457 // we abandon suggested relevance scores entirely. One consequence is |
1420 // that this means we restore the keyword verbatim match. Note | 1458 // that this means we restore the keyword verbatim match. Note |
1421 // that in this case of abandoning suggested relevance scores, we still | 1459 // that in this case of abandoning suggested relevance scores, we still |
1422 // keep the navsuggestions in the same order, but we revert to only allowing | 1460 // keep the navsuggestions in the same order, but we revert to only allowing |
1423 // one navigation to appear because the scores are completely local. | 1461 // one navigation to appear because the scores are completely local. |
1424 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1462 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
1425 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1463 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
1426 "\"google:verbatimrelevance\":0," | 1464 "\"google:verbatimrelevance\":0," |
1427 "\"google:suggestrelevance\":[9998, 9999]}]", | 1465 "\"google:suggestrelevance\":[9998, 9999]}]", |
1428 { { "a", true }, | 1466 { { "a", true }, |
1429 { "a2.com", false }, | 1467 { "a2.com", false }, |
1430 { "k a", false }, | 1468 { "k a", false }, |
1431 { kNotApplicable, false }, | 1469 { kNotApplicable, false }, |
1432 { kNotApplicable, false } } }, | 1470 { kNotApplicable, false } }, |
1471 "" }, | |
1433 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1472 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
1434 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1473 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
1435 "\"google:verbatimrelevance\":0," | 1474 "\"google:verbatimrelevance\":0," |
1436 "\"google:suggestrelevance\":[9999, 9998]}]", | 1475 "\"google:suggestrelevance\":[9999, 9998]}]", |
1437 { { "a", true }, | 1476 { { "a", true }, |
1438 { "a1.com", false }, | 1477 { "a1.com", false }, |
1439 { "k a", false }, | 1478 { "k a", false }, |
1440 { kNotApplicable, false }, | 1479 { kNotApplicable, false }, |
1441 { kNotApplicable, false } } }, | 1480 { kNotApplicable, false } }, |
1481 "" }, | |
1442 // More checks that everything works when it's not necessary to demote. | 1482 // More checks that everything works when it's not necessary to demote. |
1443 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1483 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1444 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1484 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1445 "\"google:verbatimrelevance\":9990," | 1485 "\"google:verbatimrelevance\":9990," |
1446 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", | 1486 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", |
1447 { { "a3", true }, | 1487 { { "a3", true }, |
1448 { "a2.com", false }, | 1488 { "a2.com", false }, |
1449 { "a1.com", false }, | 1489 { "a1.com", false }, |
1450 { "a", true }, | 1490 { "a", true }, |
1451 { "k a", false } } }, | 1491 { "k a", false } }, |
1492 "3" }, | |
1452 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1493 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
1453 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1494 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
1454 "\"google:verbatimrelevance\":9990," | 1495 "\"google:verbatimrelevance\":9990," |
1455 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", | 1496 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", |
1456 { { "a3", true }, | 1497 { { "a3", true }, |
1457 { "a1.com", false }, | 1498 { "a1.com", false }, |
1458 { "a2.com", false }, | 1499 { "a2.com", false }, |
1459 { "a", true }, | 1500 { "a", true }, |
1460 { "k a", false } } }, | 1501 { "k a", false } }, |
1502 "3" }, | |
1461 }; | 1503 }; |
1462 | 1504 |
1463 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1505 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
1464 QueryForInput(ASCIIToUTF16("k a"), false, true); | 1506 QueryForInput(ASCIIToUTF16("k a"), false, true); |
1465 | 1507 |
1466 // Set up a default fetcher with no results. | 1508 // Set up a default fetcher with no results. |
1467 net::TestURLFetcher* default_fetcher = WaitUntilURLFetcherIsReady( | 1509 net::TestURLFetcher* default_fetcher = WaitUntilURLFetcherIsReady( |
1468 SearchProvider::kDefaultProviderURLFetcherID); | 1510 SearchProvider::kDefaultProviderURLFetcherID); |
1469 ASSERT_TRUE(default_fetcher); | 1511 ASSERT_TRUE(default_fetcher); |
1470 default_fetcher->set_response_code(200); | 1512 default_fetcher->set_response_code(200); |
1471 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); | 1513 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
1472 default_fetcher = NULL; | 1514 default_fetcher = NULL; |
1473 | 1515 |
1474 // Set up a keyword fetcher with provided results. | 1516 // Set up a keyword fetcher with provided results. |
1475 net::TestURLFetcher* keyword_fetcher = WaitUntilURLFetcherIsReady( | 1517 net::TestURLFetcher* keyword_fetcher = WaitUntilURLFetcherIsReady( |
1476 SearchProvider::kKeywordProviderURLFetcherID); | 1518 SearchProvider::kKeywordProviderURLFetcherID); |
1477 ASSERT_TRUE(keyword_fetcher); | 1519 ASSERT_TRUE(keyword_fetcher); |
1478 keyword_fetcher->set_response_code(200); | 1520 keyword_fetcher->set_response_code(200); |
1479 keyword_fetcher->SetResponseString(cases[i].json); | 1521 keyword_fetcher->SetResponseString(cases[i].json); |
1480 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); | 1522 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); |
1481 keyword_fetcher = NULL; | 1523 keyword_fetcher = NULL; |
1482 RunTillProviderDone(); | 1524 RunTillProviderDone(); |
1483 | 1525 |
1484 const std::string description = "for input with json=" + cases[i].json; | 1526 const std::string description = "for input with json=" + cases[i].json; |
1485 const ACMatches& matches = provider_->matches(); | 1527 const ACMatches& matches = provider_->matches(); |
1486 // The top match must inline and score as highly as calculated verbatim. | 1528 // The top match must inline and score as highly as calculated verbatim. |
1487 ASSERT_FALSE(matches.empty()); | 1529 ASSERT_FALSE(matches.empty()); |
1488 EXPECT_NE(string16::npos, matches[0].inline_autocomplete_offset) << | 1530 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
1489 description; | 1531 matches[0].inline_autocompletion) << description; |
1490 EXPECT_GE(matches[0].relevance, 1300) << description; | 1532 EXPECT_GE(matches[0].relevance, 1300) << description; |
1491 | 1533 |
1492 size_t j = 0; | 1534 size_t j = 0; |
1493 // Ensure that the returned matches equal the expectations. | 1535 // Ensure that the returned matches equal the expectations. |
1494 for (; j < matches.size(); ++j) { | 1536 for (; j < matches.size(); ++j) { |
1495 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), | 1537 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), |
1496 matches[j].contents) << description; | 1538 matches[j].contents) << description; |
1497 EXPECT_EQ(cases[i].matches[j].from_keyword, | 1539 EXPECT_EQ(cases[i].matches[j].from_keyword, |
1498 matches[j].keyword == ASCIIToUTF16("k")) << description; | 1540 matches[j].keyword == ASCIIToUTF16("k")) << description; |
1499 } | 1541 } |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1750 } | 1792 } |
1751 | 1793 |
1752 // Verifies inline autocompletion of navigational results. | 1794 // Verifies inline autocompletion of navigational results. |
1753 TEST_F(SearchProviderTest, NavigationInline) { | 1795 TEST_F(SearchProviderTest, NavigationInline) { |
1754 struct { | 1796 struct { |
1755 const std::string input; | 1797 const std::string input; |
1756 const std::string url; | 1798 const std::string url; |
1757 // Test the expected fill_into_edit, which may drop "http://". | 1799 // Test the expected fill_into_edit, which may drop "http://". |
1758 // Some cases do not trim "http://" to match from the start of the scheme. | 1800 // Some cases do not trim "http://" to match from the start of the scheme. |
1759 const std::string fill_into_edit; | 1801 const std::string fill_into_edit; |
1760 size_t inline_offset; | 1802 const std::string inline_autocompletion; |
1761 } cases[] = { | 1803 } cases[] = { |
1762 // Do not inline matches that do not contain the input; trim http as needed. | 1804 // Do not inline matches that do not contain the input; trim http as needed. |
1763 { "x", "http://www.abc.com", | 1805 { "x", "http://www.abc.com", |
1764 "www.abc.com", string16::npos }, | 1806 "www.abc.com", "" }, |
1765 { "https:", "http://www.abc.com", | 1807 { "https:", "http://www.abc.com", |
1766 "www.abc.com", string16::npos }, | 1808 "www.abc.com", "" }, |
1767 { "abc.com/", "http://www.abc.com", | 1809 { "abc.com/", "http://www.abc.com", |
1768 "www.abc.com", string16::npos }, | 1810 "www.abc.com", "" }, |
1769 { "http://www.abc.com/a", "http://www.abc.com", | 1811 { "http://www.abc.com/a", "http://www.abc.com", |
1770 "http://www.abc.com", string16::npos }, | 1812 "http://www.abc.com", "" }, |
1771 { "http://www.abc.com", "https://www.abc.com", | 1813 { "http://www.abc.com", "https://www.abc.com", |
1772 "https://www.abc.com", string16::npos }, | 1814 "https://www.abc.com", "" }, |
1773 { "http://abc.com", "ftp://abc.com", | 1815 { "http://abc.com", "ftp://abc.com", |
1774 "ftp://abc.com", string16::npos }, | 1816 "ftp://abc.com", "" }, |
1775 { "https://www.abc.com", "http://www.abc.com", | 1817 { "https://www.abc.com", "http://www.abc.com", |
1776 "www.abc.com", string16::npos }, | 1818 "www.abc.com", "" }, |
1777 { "ftp://abc.com", "http://abc.com", | 1819 { "ftp://abc.com", "http://abc.com", |
1778 "abc.com", string16::npos }, | 1820 "abc.com", "" }, |
1779 | 1821 |
1780 // Do not inline matches with invalid input prefixes; trim http as needed. | 1822 // Do not inline matches with invalid input prefixes; trim http as needed. |
1781 { "ttp", "http://www.abc.com", | 1823 { "ttp", "http://www.abc.com", |
1782 "www.abc.com", string16::npos }, | 1824 "www.abc.com", "" }, |
1783 { "://w", "http://www.abc.com", | 1825 { "://w", "http://www.abc.com", |
1784 "www.abc.com", string16::npos }, | 1826 "www.abc.com", "" }, |
1785 { "ww.", "http://www.abc.com", | 1827 { "ww.", "http://www.abc.com", |
1786 "www.abc.com", string16::npos }, | 1828 "www.abc.com", "" }, |
1787 { ".ab", "http://www.abc.com", | 1829 { ".ab", "http://www.abc.com", |
1788 "www.abc.com", string16::npos }, | 1830 "www.abc.com", "" }, |
1789 { "bc", "http://www.abc.com", | 1831 { "bc", "http://www.abc.com", |
1790 "www.abc.com", string16::npos }, | 1832 "www.abc.com", "" }, |
1791 { ".com", "http://www.abc.com", | 1833 { ".com", "http://www.abc.com", |
1792 "www.abc.com", string16::npos }, | 1834 "www.abc.com", "" }, |
1793 | 1835 |
1794 // Do not inline matches that omit input domain labels; trim http as needed. | 1836 // Do not inline matches that omit input domain labels; trim http as needed. |
1795 { "www.a", "http://a.com", | 1837 { "www.a", "http://a.com", |
1796 "a.com", string16::npos }, | 1838 "a.com", "" }, |
1797 { "http://www.a", "http://a.com", | 1839 { "http://www.a", "http://a.com", |
1798 "http://a.com", string16::npos }, | 1840 "http://a.com", "" }, |
1799 { "www.a", "ftp://a.com", | 1841 { "www.a", "ftp://a.com", |
1800 "ftp://a.com", string16::npos }, | 1842 "ftp://a.com", "" }, |
1801 { "ftp://www.a", "ftp://a.com", | 1843 { "ftp://www.a", "ftp://a.com", |
1802 "ftp://a.com", string16::npos }, | 1844 "ftp://a.com", "" }, |
1803 | 1845 |
1804 // Input matching but with nothing to inline will not yield an offset. | 1846 // Input matching but with nothing to inline will not yield an offset. |
1805 { "abc.com", "http://www.abc.com", | 1847 { "abc.com", "http://www.abc.com", |
1806 "www.abc.com", string16::npos }, | 1848 "www.abc.com", "" }, |
1807 { "http://www.abc.com", "http://www.abc.com", | 1849 { "http://www.abc.com", "http://www.abc.com", |
1808 "http://www.abc.com", string16::npos }, | 1850 "http://www.abc.com", "" }, |
1809 | 1851 |
1810 // Inline matches when the input is a leading substring of the scheme. | 1852 // Inline matches when the input is a leading substring of the scheme. |
1811 { "h", "http://www.abc.com", | 1853 { "h", "http://www.abc.com", |
1812 "http://www.abc.com", 1 }, | 1854 "http://www.abc.com", "ttp://www.abc.com" }, |
1813 { "http", "http://www.abc.com", | 1855 { "http", "http://www.abc.com", |
1814 "http://www.abc.com", 4 }, | 1856 "http://www.abc.com", "://www.abc.com" }, |
1815 | 1857 |
1816 // Inline matches when the input is a leading substring of the full URL. | 1858 // Inline matches when the input is a leading substring of the full URL. |
1817 { "http:", "http://www.abc.com", | 1859 { "http:", "http://www.abc.com", |
1818 "http://www.abc.com", 5 }, | 1860 "http://www.abc.com", "//www.abc.com" }, |
1819 { "http://w", "http://www.abc.com", | 1861 { "http://w", "http://www.abc.com", |
1820 "http://www.abc.com", 8 }, | 1862 "http://www.abc.com", "ww.abc.com" }, |
1821 { "http://www.", "http://www.abc.com", | 1863 { "http://www.", "http://www.abc.com", |
1822 "http://www.abc.com", 11 }, | 1864 "http://www.abc.com", "abc.com" }, |
1823 { "http://www.ab", "http://www.abc.com", | 1865 { "http://www.ab", "http://www.abc.com", |
1824 "http://www.abc.com", 13 }, | 1866 "http://www.abc.com", "c.com" }, |
1825 { "http://www.abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", | 1867 { "http://www.abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", |
1826 "http://www.abc.com/path/file.htm?q=x#foo", 20 }, | 1868 "http://www.abc.com/path/file.htm?q=x#foo", |
1869 "ath/file.htm?q=x#foo" }, | |
1827 { "http://abc.com/p", "http://abc.com/path/file.htm?q=x#foo", | 1870 { "http://abc.com/p", "http://abc.com/path/file.htm?q=x#foo", |
1828 "http://abc.com/path/file.htm?q=x#foo", 16 }, | 1871 "http://abc.com/path/file.htm?q=x#foo", |
1872 "ath/file.htm?q=x#foo"}, | |
1829 | 1873 |
1830 // Inline matches with valid URLPrefixes; only trim "http://". | 1874 // Inline matches with valid URLPrefixes; only trim "http://". |
1831 { "w", "http://www.abc.com", | 1875 { "w", "http://www.abc.com", |
1832 "www.abc.com", 1 }, | 1876 "www.abc.com", "ww.abc.com" }, |
1833 { "www.a", "http://www.abc.com", | 1877 { "www.a", "http://www.abc.com", |
1834 "www.abc.com", 5 }, | 1878 "www.abc.com", "bc.com" }, |
1835 { "abc", "http://www.abc.com", | 1879 { "abc", "http://www.abc.com", |
1836 "www.abc.com", 7 }, | 1880 "www.abc.com", ".com" }, |
1837 { "abc.c", "http://www.abc.com", | 1881 { "abc.c", "http://www.abc.com", |
1838 "www.abc.com", 9 }, | 1882 "www.abc.com", "om" }, |
1839 { "abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", | 1883 { "abc.com/p", "http://www.abc.com/path/file.htm?q=x#foo", |
1840 "www.abc.com/path/file.htm?q=x#foo", 13 }, | 1884 "www.abc.com/path/file.htm?q=x#foo", |
1885 "ath/file.htm?q=x#foo" }, | |
1841 { "abc.com/p", "http://abc.com/path/file.htm?q=x#foo", | 1886 { "abc.com/p", "http://abc.com/path/file.htm?q=x#foo", |
1842 "abc.com/path/file.htm?q=x#foo", 9 }, | 1887 "abc.com/path/file.htm?q=x#foo", |
1888 "ath/file.htm?q=x#foo" }, | |
1843 | 1889 |
1844 // Inline matches using the maximal URLPrefix components. | 1890 // Inline matches using the maximal URLPrefix components. |
1845 { "h", "http://help.com", | 1891 { "h", "http://help.com", |
1846 "help.com", 1 }, | 1892 "help.com", "elp.com" }, |
1847 { "http", "http://http.com", | 1893 { "http", "http://http.com", |
1848 "http.com", 4 }, | 1894 "http.com", ".com" }, |
1849 { "h", "http://www.help.com", | 1895 { "h", "http://www.help.com", |
1850 "www.help.com", 5 }, | 1896 "www.help.com", "elp.com" }, |
1851 { "http", "http://www.http.com", | 1897 { "http", "http://www.http.com", |
1852 "www.http.com", 8 }, | 1898 "www.http.com", ".com" }, |
1853 { "w", "http://www.www.com", | 1899 { "w", "http://www.www.com", |
1854 "www.www.com", 5 }, | 1900 "www.www.com", "ww.com" }, |
1855 | 1901 |
1856 // Test similar behavior for the ftp and https schemes. | 1902 // Test similar behavior for the ftp and https schemes. |
1857 { "ftp://www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", | 1903 { "ftp://www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", |
1858 "ftp://www.abc.com/path/file.htm?q=x#foo", 12 }, | 1904 "ftp://www.abc.com/path/file.htm?q=x#foo", |
1905 "c.com/path/file.htm?q=x#foo" }, | |
1859 { "www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", | 1906 { "www.ab", "ftp://www.abc.com/path/file.htm?q=x#foo", |
1860 "ftp://www.abc.com/path/file.htm?q=x#foo", 12 }, | 1907 "ftp://www.abc.com/path/file.htm?q=x#foo", |
1908 "c.com/path/file.htm?q=x#foo" }, | |
1861 { "ab", "ftp://www.abc.com/path/file.htm?q=x#foo", | 1909 { "ab", "ftp://www.abc.com/path/file.htm?q=x#foo", |
1862 "ftp://www.abc.com/path/file.htm?q=x#foo", 12 }, | 1910 "ftp://www.abc.com/path/file.htm?q=x#foo", |
1911 "c.com/path/file.htm?q=x#foo" }, | |
1863 { "ab", "ftp://abc.com/path/file.htm?q=x#foo", | 1912 { "ab", "ftp://abc.com/path/file.htm?q=x#foo", |
1864 "ftp://abc.com/path/file.htm?q=x#foo", 8 }, | 1913 "ftp://abc.com/path/file.htm?q=x#foo", |
1914 "c.com/path/file.htm?q=x#foo" }, | |
1865 { "https://www.ab", "https://www.abc.com/path/file.htm?q=x#foo", | 1915 { "https://www.ab", "https://www.abc.com/path/file.htm?q=x#foo", |
1866 "https://www.abc.com/path/file.htm?q=x#foo", 14 }, | 1916 "https://www.abc.com/path/file.htm?q=x#foo", |
1917 "c.com/path/file.htm?q=x#foo" }, | |
1867 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo", | 1918 { "www.ab", "https://www.abc.com/path/file.htm?q=x#foo", |
1868 "https://www.abc.com/path/file.htm?q=x#foo", 14 }, | 1919 "https://www.abc.com/path/file.htm?q=x#foo", |
1920 "c.com/path/file.htm?q=x#foo" }, | |
1869 { "ab", "https://www.abc.com/path/file.htm?q=x#foo", | 1921 { "ab", "https://www.abc.com/path/file.htm?q=x#foo", |
1870 "https://www.abc.com/path/file.htm?q=x#foo", 14 }, | 1922 "https://www.abc.com/path/file.htm?q=x#foo", |
1923 "c.com/path/file.htm?q=x#foo" }, | |
1871 { "ab", "https://abc.com/path/file.htm?q=x#foo", | 1924 { "ab", "https://abc.com/path/file.htm?q=x#foo", |
1872 "https://abc.com/path/file.htm?q=x#foo", 10 }, | 1925 "https://abc.com/path/file.htm?q=x#foo", |
1926 "c.com/path/file.htm?q=x#foo"}, | |
1873 | 1927 |
1874 // Forced query input should inline and retain the "?" prefix. | 1928 // Forced query input should inline and retain the "?" prefix. |
1875 { "?http://www.ab", "http://www.abc.com", | 1929 { "?http://www.ab", "http://www.abc.com", |
1876 "?http://www.abc.com", 14 }, | 1930 "?http://www.abc.com", "c.com" }, |
1877 { "?www.ab", "http://www.abc.com", | 1931 { "?www.ab", "http://www.abc.com", |
1878 "?www.abc.com", 7 }, | 1932 "?www.abc.com", "c.com" }, |
1879 { "?ab", "http://www.abc.com", | 1933 { "?ab", "http://www.abc.com", |
1880 "?www.abc.com", 7 }, | 1934 "?www.abc.com", "c.com" }, |
1881 }; | 1935 }; |
1882 | 1936 |
1883 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1937 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
1884 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 1938 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
1885 AutocompleteMatch match( | 1939 AutocompleteMatch match( |
1886 provider_->NavigationToMatch(SearchProvider::NavigationResult( | 1940 provider_->NavigationToMatch(SearchProvider::NavigationResult( |
1887 *provider_.get(), GURL(cases[i].url), string16(), false, 0, | 1941 *provider_.get(), GURL(cases[i].url), string16(), false, 0, |
1888 false))); | 1942 false))); |
1889 EXPECT_EQ(cases[i].inline_offset, match.inline_autocomplete_offset); | 1943 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
1944 match.inline_autocompletion); | |
1890 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); | 1945 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); |
1891 } | 1946 } |
1892 } | 1947 } |
1893 | 1948 |
1894 // Verifies that "http://" is not trimmed for input that is a leading substring. | 1949 // Verifies that "http://" is not trimmed for input that is a leading substring. |
1895 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { | 1950 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { |
1896 const string16 input(ASCIIToUTF16("ht")); | 1951 const string16 input(ASCIIToUTF16("ht")); |
1897 const string16 url(ASCIIToUTF16("http://a.com")); | 1952 const string16 url(ASCIIToUTF16("http://a.com")); |
1898 const SearchProvider::NavigationResult result( | 1953 const SearchProvider::NavigationResult result( |
1899 *provider_.get(), GURL(url), string16(), false, 0, false); | 1954 *provider_.get(), GURL(url), string16(), false, 0, false); |
1900 | 1955 |
1901 // Check the offset and strings when inline autocompletion is allowed. | 1956 // Check the offset and strings when inline autocompletion is allowed. |
1902 QueryForInput(input, false, false); | 1957 QueryForInput(input, false, false); |
1903 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); | 1958 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); |
1904 EXPECT_EQ(2U, match_inline.inline_autocomplete_offset); | |
1905 EXPECT_EQ(url, match_inline.fill_into_edit); | 1959 EXPECT_EQ(url, match_inline.fill_into_edit); |
1960 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); | |
1906 EXPECT_EQ(url, match_inline.contents); | 1961 EXPECT_EQ(url, match_inline.contents); |
1907 | 1962 |
1908 // Check the same offset and strings when inline autocompletion is prevented. | 1963 // Check the same offset and strings when inline autocompletion is prevented. |
1909 QueryForInput(input, true, false); | 1964 QueryForInput(input, true, false); |
1910 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); | 1965 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); |
1911 EXPECT_EQ(string16::npos, match_prevent.inline_autocomplete_offset); | 1966 EXPECT_TRUE(match_prevent.inline_autocompletion.empty()); |
1912 EXPECT_EQ(url, match_prevent.fill_into_edit); | 1967 EXPECT_EQ(url, match_prevent.fill_into_edit); |
1913 EXPECT_EQ(url, match_prevent.contents); | 1968 EXPECT_EQ(url, match_prevent.contents); |
1914 } | 1969 } |
1915 | 1970 |
1916 // Verifies that input "w" marks a more significant domain label than "www.". | 1971 // Verifies that input "w" marks a more significant domain label than "www.". |
1917 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { | 1972 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { |
1918 QueryForInput(ASCIIToUTF16("w"), false, false); | 1973 QueryForInput(ASCIIToUTF16("w"), false, false); |
1919 AutocompleteMatch match( | 1974 AutocompleteMatch match( |
1920 provider_->NavigationToMatch(SearchProvider::NavigationResult( | 1975 provider_->NavigationToMatch(SearchProvider::NavigationResult( |
1921 *provider_.get(), GURL("http://www.wow.com"), string16(), false, 0, | 1976 *provider_.get(), GURL("http://www.wow.com"), string16(), false, 0, |
1922 false))); | 1977 false))); |
1923 EXPECT_EQ(5U, match.inline_autocomplete_offset); | 1978 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); |
1924 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); | 1979 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); |
1925 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); | 1980 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); |
1926 | 1981 |
1927 // Ensure that the match for input "w" is marked on "wow" and not "www". | 1982 // Ensure that the match for input "w" is marked on "wow" and not "www". |
1928 ASSERT_EQ(3U, match.contents_class.size()); | 1983 ASSERT_EQ(3U, match.contents_class.size()); |
1929 EXPECT_EQ(0U, match.contents_class[0].offset); | 1984 EXPECT_EQ(0U, match.contents_class[0].offset); |
1930 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, | 1985 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, |
1931 match.contents_class[0].style); | 1986 match.contents_class[0].style); |
1932 EXPECT_EQ(4U, match.contents_class[1].offset); | 1987 EXPECT_EQ(4U, match.contents_class[1].offset); |
1933 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | | 1988 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2117 } else { | 2172 } else { |
2118 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; | 2173 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; |
2119 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); | 2174 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); |
2120 ++sug_it; | 2175 ++sug_it; |
2121 } | 2176 } |
2122 } | 2177 } |
2123 EXPECT_EQ(sug_end, sug_it); | 2178 EXPECT_EQ(sug_end, sug_it); |
2124 EXPECT_EQ(nav_end, nav_it); | 2179 EXPECT_EQ(nav_end, nav_it); |
2125 } | 2180 } |
2126 } | 2181 } |
OLD | NEW |