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

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

Issue 67693004: Omnibox: Don't Let Users Escape Keyword Mode Accidentally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mike's comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // TemplateURL has a valid suggest and search URL. 53 // TemplateURL has a valid suggest and search URL.
54 // . The URL created by using the search term term1_ with default_t_url_ is 54 // . The URL created by using the search term term1_ with default_t_url_ is
55 // added to history. 55 // added to history.
56 // . The URL created by using the search term keyword_term_ with keyword_t_url_ 56 // . The URL created by using the search term keyword_term_ with keyword_t_url_
57 // is added to history. 57 // is added to history.
58 // . test_factory_ is set as the URLFetcherFactory. 58 // . test_factory_ is set as the URLFetcherFactory.
59 class SearchProviderTest : public testing::Test, 59 class SearchProviderTest : public testing::Test,
60 public AutocompleteProviderListener { 60 public AutocompleteProviderListener {
61 public: 61 public:
62 struct ResultInfo { 62 struct ResultInfo {
63 ResultInfo() : result_type(AutocompleteMatchType::NUM_TYPES) { 63 ResultInfo() : result_type(AutocompleteMatchType::NUM_TYPES),
64 allowed_to_be_default_match(false) {
64 } 65 }
65 ResultInfo(GURL gurl, 66 ResultInfo(GURL gurl,
66 AutocompleteMatch::Type result_type, 67 AutocompleteMatch::Type result_type,
68 bool allowed_to_be_default_match,
67 string16 fill_into_edit) 69 string16 fill_into_edit)
68 : gurl(gurl), 70 : gurl(gurl),
69 result_type(result_type), 71 result_type(result_type),
72 allowed_to_be_default_match(allowed_to_be_default_match),
70 fill_into_edit(fill_into_edit) { 73 fill_into_edit(fill_into_edit) {
71 } 74 }
72 75
73 const GURL gurl; 76 const GURL gurl;
74 const AutocompleteMatch::Type result_type; 77 const AutocompleteMatch::Type result_type;
78 const bool allowed_to_be_default_match;
75 const string16 fill_into_edit; 79 const string16 fill_into_edit;
76 }; 80 };
77 81
78 struct TestData { 82 struct TestData {
79 const string16 input; 83 const string16 input;
80 const size_t num_results; 84 const size_t num_results;
81 const ResultInfo output[3]; 85 const ResultInfo output[3];
82 }; 86 };
83 87
84 SearchProviderTest() 88 SearchProviderTest()
(...skipping 24 matching lines...) Expand all
109 113
110 // Looks for a match in |provider_| with |contents| equal to |contents|. 114 // Looks for a match in |provider_| with |contents| equal to |contents|.
111 // Sets |match| to it if found. Returns whether |match| was set. 115 // Sets |match| to it if found. Returns whether |match| was set.
112 bool FindMatchWithContents(const string16& contents, 116 bool FindMatchWithContents(const string16& contents,
113 AutocompleteMatch* match); 117 AutocompleteMatch* match);
114 118
115 // Looks for a match in |provider_| with destination |url|. Sets |match| to 119 // Looks for a match in |provider_| with destination |url|. Sets |match| to
116 // it if found. Returns whether |match| was set. 120 // it if found. Returns whether |match| was set.
117 bool FindMatchWithDestination(const GURL& url, AutocompleteMatch* match); 121 bool FindMatchWithDestination(const GURL& url, AutocompleteMatch* match);
118 122
123 // Returns the first matches in |matches| with |allowed_to_be_default_match|
msw 2013/11/21 22:11:11 nit: s/matches/match/
Mark P 2013/11/22 01:17:57 Done.
124 // set to true.
125 ACMatches::const_iterator FindDefaultMatch(const ACMatches& matches);
msw 2013/11/21 22:11:11 nit: This doesn't use any class members, it should
Mark P 2013/11/22 01:17:57 Done.
126
119 // AutocompleteProviderListener: 127 // AutocompleteProviderListener:
120 // If we're waiting for the provider to finish, this exits the message loop. 128 // If we're waiting for the provider to finish, this exits the message loop.
121 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; 129 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE;
122 130
123 // Runs a nested message loop until provider_ is done. The message loop is 131 // Runs a nested message loop until provider_ is done. The message loop is
124 // exited by way of OnProviderUpdate. 132 // exited by way of OnProviderUpdate.
125 void RunTillProviderDone(); 133 void RunTillProviderDone();
126 134
127 // Invokes Start on provider_, then runs all pending tasks. 135 // Invokes Start on provider_, then runs all pending tasks.
128 void QueryForInput(const string16& text, 136 void QueryForInput(const string16& text,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ASCIIToUTF16("; prefer_keyword was: ") + 262 ASCIIToUTF16("; prefer_keyword was: ") +
255 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")); 263 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false"));
256 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; 264 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details;
257 if (matches.size() == cases[i].num_results) { 265 if (matches.size() == cases[i].num_results) {
258 for (size_t j = 0; j < cases[i].num_results; ++j) { 266 for (size_t j = 0; j < cases[i].num_results; ++j) {
259 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) << 267 EXPECT_EQ(cases[i].output[j].gurl, matches[j].destination_url) <<
260 diagnostic_details; 268 diagnostic_details;
261 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) << 269 EXPECT_EQ(cases[i].output[j].result_type, matches[j].type) <<
262 diagnostic_details; 270 diagnostic_details;
263 EXPECT_EQ(cases[i].output[j].fill_into_edit, 271 EXPECT_EQ(cases[i].output[j].fill_into_edit,
264 matches[j].fill_into_edit) << 272 matches[j].fill_into_edit) << diagnostic_details;
265 diagnostic_details; 273 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match,
266 // All callers that use this helper function at the moment produce 274 matches[j].allowed_to_be_default_match) << diagnostic_details;
267 // matches that are always allowed to be the default match.
268 EXPECT_TRUE(matches[j].allowed_to_be_default_match);
269 } 275 }
270 } 276 }
271 } 277 }
272 } 278 }
273 279
274 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { 280 void SearchProviderTest::OnProviderUpdate(bool updated_matches) {
275 if (run_loop_ && provider_->done()) { 281 if (run_loop_ && provider_->done()) {
276 run_loop_->Quit(); 282 run_loop_->Quit();
277 run_loop_ = NULL; 283 run_loop_ = NULL;
278 } 284 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 for (ACMatches::const_iterator i = provider_->matches().begin(); 357 for (ACMatches::const_iterator i = provider_->matches().begin();
352 i != provider_->matches().end(); ++i) { 358 i != provider_->matches().end(); ++i) {
353 if (i->destination_url == url) { 359 if (i->destination_url == url) {
354 *match = *i; 360 *match = *i;
355 return true; 361 return true;
356 } 362 }
357 } 363 }
358 return false; 364 return false;
359 } 365 }
360 366
367 ACMatches::const_iterator SearchProviderTest::FindDefaultMatch(
368 const ACMatches& matches) {
369 ACMatches::const_iterator it = matches.begin();
370 while ((it != matches.end()) && !it->allowed_to_be_default_match)
371 ++it;
372 return it;
373 }
374
361 void SearchProviderTest::FinishDefaultSuggestQuery() { 375 void SearchProviderTest::FinishDefaultSuggestQuery() {
362 net::TestURLFetcher* default_fetcher = 376 net::TestURLFetcher* default_fetcher =
363 test_factory_.GetFetcherByID( 377 test_factory_.GetFetcherByID(
364 SearchProvider::kDefaultProviderURLFetcherID); 378 SearchProvider::kDefaultProviderURLFetcherID);
365 ASSERT_TRUE(default_fetcher); 379 ASSERT_TRUE(default_fetcher);
366 380
367 // Tell the SearchProvider the default suggest query is done. 381 // Tell the SearchProvider the default suggest query is done.
368 default_fetcher->set_response_code(200); 382 default_fetcher->set_response_code(200);
369 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); 383 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
370 } 384 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 ASSERT_EQ(3u, result.size()); 837 ASSERT_EQ(3u, result.size());
824 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type); 838 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type);
825 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE, 839 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE,
826 result.match_at(1).type); 840 result.match_at(1).type);
827 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 841 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
828 result.match_at(2).type); 842 result.match_at(2).type);
829 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance); 843 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance);
830 EXPECT_GT(result.match_at(1).relevance, result.match_at(2).relevance); 844 EXPECT_GT(result.match_at(1).relevance, result.match_at(2).relevance);
831 EXPECT_TRUE(result.match_at(0).allowed_to_be_default_match); 845 EXPECT_TRUE(result.match_at(0).allowed_to_be_default_match);
832 EXPECT_TRUE(result.match_at(1).allowed_to_be_default_match); 846 EXPECT_TRUE(result.match_at(1).allowed_to_be_default_match);
833 EXPECT_TRUE(result.match_at(2).allowed_to_be_default_match); 847 EXPECT_FALSE(result.match_at(2).allowed_to_be_default_match);
834 848
835 // The two keyword results should come with the keyword we expect. 849 // The two keyword results should come with the keyword we expect.
836 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(0).keyword); 850 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(0).keyword);
837 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(1).keyword); 851 EXPECT_EQ(ASCIIToUTF16("k"), result.match_at(1).keyword);
838 // The default provider has a different keyword. (We don't explicitly 852 // The default provider has a different keyword. (We don't explicitly
839 // set it during this test, so all we do is assert that it's different.) 853 // set it during this test, so all we do is assert that it's different.)
840 EXPECT_NE(result.match_at(0).keyword, result.match_at(2).keyword); 854 EXPECT_NE(result.match_at(0).keyword, result.match_at(2).keyword);
841 855
842 // The top result will always have a description. The third result, 856 // The top result will always have a description. The third result,
843 // coming from a different provider than the first two, should also. 857 // coming from a different provider than the first two, should also.
844 // Whether the second result has one doesn't matter much. (If it was 858 // Whether the second result has one doesn't matter much. (If it was
845 // missing, people would infer that it's the same search provider as 859 // missing, people would infer that it's the same search provider as
846 // the one above it.) 860 // the one above it.)
847 EXPECT_FALSE(result.match_at(0).description.empty()); 861 EXPECT_FALSE(result.match_at(0).description.empty());
848 EXPECT_FALSE(result.match_at(2).description.empty()); 862 EXPECT_FALSE(result.match_at(2).description.empty());
849 EXPECT_NE(result.match_at(0).description, result.match_at(2).description); 863 EXPECT_NE(result.match_at(0).description, result.match_at(2).description);
850 } 864 }
851 865
852 TEST_F(SearchProviderTest, KeywordVerbatim) { 866 TEST_F(SearchProviderTest, KeywordVerbatim) {
853 TestData cases[] = { 867 TestData cases[] = {
854 // Test a simple keyword input. 868 // Test a simple keyword input.
855 { ASCIIToUTF16("k foo"), 2, 869 { ASCIIToUTF16("k foo"), 2,
856 { ResultInfo(GURL("http://keyword/foo"), 870 { ResultInfo(GURL("http://keyword/foo"),
857 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 871 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
872 true,
858 ASCIIToUTF16("k foo")), 873 ASCIIToUTF16("k foo")),
859 ResultInfo(GURL("http://defaultturl/k%20foo"), 874 ResultInfo(GURL("http://defaultturl/k%20foo"),
860 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 875 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
876 false,
861 ASCIIToUTF16("k foo") ) } }, 877 ASCIIToUTF16("k foo") ) } },
862 878
863 // Make sure extra whitespace after the keyword doesn't change the 879 // Make sure extra whitespace after the keyword doesn't change the
864 // keyword verbatim query. 880 // keyword verbatim query.
865 { ASCIIToUTF16("k foo"), 2, 881 { ASCIIToUTF16("k foo"), 2,
866 { ResultInfo(GURL("http://keyword/foo"), 882 { ResultInfo(GURL("http://keyword/foo"),
867 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 883 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
884 true,
868 ASCIIToUTF16("k foo")), 885 ASCIIToUTF16("k foo")),
869 ResultInfo(GURL("http://defaultturl/k%20%20%20foo"), 886 ResultInfo(GURL("http://defaultturl/k%20%20%20foo"),
870 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 887 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
888 false,
871 ASCIIToUTF16("k foo")) } }, 889 ASCIIToUTF16("k foo")) } },
872 // Leading whitespace should be stripped before SearchProvider gets the 890 // Leading whitespace should be stripped before SearchProvider gets the
873 // input; hence there are no tests here about how it handles those inputs. 891 // input; hence there are no tests here about how it handles those inputs.
874 892
875 // But whitespace elsewhere in the query string should matter to both 893 // But whitespace elsewhere in the query string should matter to both
876 // matches. 894 // matches.
877 { ASCIIToUTF16("k foo bar"), 2, 895 { ASCIIToUTF16("k foo bar"), 2,
878 { ResultInfo(GURL("http://keyword/foo%20%20bar"), 896 { ResultInfo(GURL("http://keyword/foo%20%20bar"),
879 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 897 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
898 true,
880 ASCIIToUTF16("k foo bar")), 899 ASCIIToUTF16("k foo bar")),
881 ResultInfo(GURL("http://defaultturl/k%20%20foo%20%20bar"), 900 ResultInfo(GURL("http://defaultturl/k%20%20foo%20%20bar"),
882 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 901 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
902 false,
883 ASCIIToUTF16("k foo bar")) } }, 903 ASCIIToUTF16("k foo bar")) } },
884 // Note in the above test case we don't test trailing whitespace because 904 // Note in the above test case we don't test trailing whitespace because
885 // SearchProvider still doesn't handle this well. See related bugs: 905 // SearchProvider still doesn't handle this well. See related bugs:
886 // 102690, 99239, 164635. 906 // 102690, 99239, 164635.
887 907
888 // Keywords can be prefixed by certain things that should get ignored 908 // Keywords can be prefixed by certain things that should get ignored
889 // when constructing the keyword match. 909 // when constructing the keyword match.
890 { ASCIIToUTF16("www.k foo"), 2, 910 { ASCIIToUTF16("www.k foo"), 2,
891 { ResultInfo(GURL("http://keyword/foo"), 911 { ResultInfo(GURL("http://keyword/foo"),
892 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 912 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
913 true,
893 ASCIIToUTF16("k foo")), 914 ASCIIToUTF16("k foo")),
894 ResultInfo(GURL("http://defaultturl/www.k%20foo"), 915 ResultInfo(GURL("http://defaultturl/www.k%20foo"),
895 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 916 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
917 false,
896 ASCIIToUTF16("www.k foo")) } }, 918 ASCIIToUTF16("www.k foo")) } },
897 { ASCIIToUTF16("http://k foo"), 2, 919 { ASCIIToUTF16("http://k foo"), 2,
898 { ResultInfo(GURL("http://keyword/foo"), 920 { ResultInfo(GURL("http://keyword/foo"),
899 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 921 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
922 true,
900 ASCIIToUTF16("k foo")), 923 ASCIIToUTF16("k foo")),
901 ResultInfo(GURL("http://defaultturl/http%3A//k%20foo"), 924 ResultInfo(GURL("http://defaultturl/http%3A//k%20foo"),
902 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 925 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
926 false,
903 ASCIIToUTF16("http://k foo")) } }, 927 ASCIIToUTF16("http://k foo")) } },
904 { ASCIIToUTF16("http://www.k foo"), 2, 928 { ASCIIToUTF16("http://www.k foo"), 2,
905 { ResultInfo(GURL("http://keyword/foo"), 929 { ResultInfo(GURL("http://keyword/foo"),
906 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 930 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
931 true,
907 ASCIIToUTF16("k foo")), 932 ASCIIToUTF16("k foo")),
908 ResultInfo(GURL("http://defaultturl/http%3A//www.k%20foo"), 933 ResultInfo(GURL("http://defaultturl/http%3A//www.k%20foo"),
909 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 934 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
935 false,
910 ASCIIToUTF16("http://www.k foo")) } }, 936 ASCIIToUTF16("http://www.k foo")) } },
911 937
912 // A keyword with no remaining input shouldn't get a keyword 938 // A keyword with no remaining input shouldn't get a keyword
913 // verbatim match. 939 // verbatim match.
914 { ASCIIToUTF16("k"), 1, 940 { ASCIIToUTF16("k"), 1,
915 { ResultInfo(GURL("http://defaultturl/k"), 941 { ResultInfo(GURL("http://defaultturl/k"),
916 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 942 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
943 true,
917 ASCIIToUTF16("k")) } }, 944 ASCIIToUTF16("k")) } },
918 { ASCIIToUTF16("k "), 1, 945 { ASCIIToUTF16("k "), 1,
919 { ResultInfo(GURL("http://defaultturl/k%20"), 946 { ResultInfo(GURL("http://defaultturl/k%20"),
920 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 947 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
948 true,
921 ASCIIToUTF16("k ")) } } 949 ASCIIToUTF16("k ")) } }
922 950
923 // The fact that verbatim queries to keyword are handled by KeywordProvider 951 // The fact that verbatim queries to keyword are handled by KeywordProvider
924 // not SearchProvider is tested in 952 // not SearchProvider is tested in
925 // chrome/browser/extensions/api/omnibox/omnibox_apitest.cc. 953 // chrome/browser/extensions/api/omnibox/omnibox_apitest.cc.
926 }; 954 };
927 955
928 // Test not in keyword mode. 956 // Test not in keyword mode.
929 RunTest(cases, arraysize(cases), false); 957 RunTest(cases, arraysize(cases), false);
930 958
(...skipping 17 matching lines...) Expand all
948 976
949 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, 977 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
950 "http://www.bar.com/"); 978 "http://www.bar.com/");
951 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 979 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
952 switches::kExtraSearchQueryParams, "a=b"); 980 switches::kExtraSearchQueryParams, "a=b");
953 981
954 TestData cases[] = { 982 TestData cases[] = {
955 { ASCIIToUTF16("k a"), 2, 983 { ASCIIToUTF16("k a"), 2,
956 { ResultInfo(GURL("http://keyword/a"), 984 { ResultInfo(GURL("http://keyword/a"),
957 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 985 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
986 true,
958 ASCIIToUTF16("k a")), 987 ASCIIToUTF16("k a")),
959 ResultInfo(GURL("http://www.bar.com/k%20a?a=b"), 988 ResultInfo(GURL("http://www.bar.com/k%20a?a=b"),
960 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 989 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
990 false,
961 ASCIIToUTF16("k a")) } }, 991 ASCIIToUTF16("k a")) } },
962 }; 992 };
963 993
964 RunTest(cases, arraysize(cases), false); 994 RunTest(cases, arraysize(cases), false);
965 } 995 }
966 996
967 // Verifies Navsuggest results don't set a TemplateURL, which Instant relies on. 997 // Verifies Navsuggest results don't set a TemplateURL, which Instant relies on.
968 // Also verifies that just the *first* navigational result is listed as a match 998 // Also verifies that just the *first* navigational result is listed as a match
969 // if suggested relevance scores were not sent. 999 // if suggested relevance scores were not sent.
970 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) { 1000 TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) {
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 test_factory_.GetFetcherByID( 1624 test_factory_.GetFetcherByID(
1595 SearchProvider::kDefaultProviderURLFetcherID); 1625 SearchProvider::kDefaultProviderURLFetcherID);
1596 ASSERT_TRUE(fetcher); 1626 ASSERT_TRUE(fetcher);
1597 fetcher->set_response_code(200); 1627 fetcher->set_response_code(200);
1598 fetcher->SetResponseString(cases[i].json); 1628 fetcher->SetResponseString(cases[i].json);
1599 fetcher->delegate()->OnURLFetchComplete(fetcher); 1629 fetcher->delegate()->OnURLFetchComplete(fetcher);
1600 RunTillProviderDone(); 1630 RunTillProviderDone();
1601 1631
1602 const std::string description = "for input with json=" + cases[i].json; 1632 const std::string description = "for input with json=" + cases[i].json;
1603 const ACMatches& matches = provider_->matches(); 1633 const ACMatches& matches = provider_->matches();
1604 // The top match must inline and score as highly as calculated verbatim.
1605 ASSERT_FALSE(matches.empty()); 1634 ASSERT_FALSE(matches.empty());
1635 // Find the first match that's allowed to be the default match and check
1636 // its inline_autocompletion.
1637 ACMatches::const_iterator it = FindDefaultMatch(matches);
1638 ASSERT_NE(matches.end(), it);
1606 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 1639 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
1607 matches[0].inline_autocompletion) << description; 1640 it->inline_autocompletion) << description;
1608 1641
1609 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 1642 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
1610 size_t j = 0; 1643 size_t j = 0;
1611 // Ensure that the returned matches equal the expectations. 1644 // Ensure that the returned matches equal the expectations.
1612 for (; j < matches.size(); ++j) { 1645 for (; j < matches.size(); ++j) {
1613 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), 1646 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
1614 matches[j].contents) << description; 1647 matches[j].contents) << description;
1615 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, 1648 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
1616 matches[j].allowed_to_be_default_match) << description; 1649 matches[j].allowed_to_be_default_match) << description;
1617 } 1650 }
(...skipping 22 matching lines...) Expand all
1640 struct { 1673 struct {
1641 const std::string json; 1674 const std::string json;
1642 const KeywordFetcherMatch matches[6]; 1675 const KeywordFetcherMatch matches[6];
1643 const std::string inline_autocompletion; 1676 const std::string inline_autocompletion;
1644 } cases[] = { 1677 } cases[] = {
1645 // Ensure that suggest relevance scores reorder matches and that 1678 // Ensure that suggest relevance scores reorder matches and that
1646 // the keyword verbatim (lacking a suggested verbatim score) beats 1679 // the keyword verbatim (lacking a suggested verbatim score) beats
1647 // the default provider verbatim. 1680 // the default provider verbatim.
1648 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", 1681 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
1649 { { "a", true, true }, 1682 { { "a", true, true },
1650 { "k a", false, true }, 1683 { "k a", false, false },
1651 { "c", true, false }, 1684 { "c", true, false },
1652 { "b", true, false }, 1685 { "b", true, false },
1653 kEmptyMatch, kEmptyMatch }, 1686 kEmptyMatch, kEmptyMatch },
1654 std::string() }, 1687 std::string() },
1655 // Again, check that relevance scores reorder matches, just this 1688 // Again, check that relevance scores reorder matches, just this
1656 // time with navigation matches. This also checks that with 1689 // time with navigation matches. This also checks that with
1657 // suggested relevance scores we allow multiple navsuggest results. 1690 // suggested relevance scores we allow multiple navsuggest results.
1658 // It's odd that navsuggest results that come from a keyword 1691 // Note that navsuggest results that come from a keyword provider
1659 // provider are marked as not a keyword result. I think this 1692 // are marked as not a keyword result. (They don't go to a
1660 // comes from them not going to a keyword search engine). 1693 // keyword search engine.)
1661 // TODO(mpearson): Investigate the implications (if any) of
1662 // tagging these results appropriately. If so, do it because it
1663 // makes more sense.
1664 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[]," 1694 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[],"
1665 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1695 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1666 "\"google:suggestrelevance\":[1301, 1302, 1303]}]", 1696 "\"google:suggestrelevance\":[1301, 1302, 1303]}]",
1667 { { "a", true, true }, 1697 { { "a", true, true },
1668 { "d", true, false }, 1698 { "d", true, false },
1669 { "c.com", false, false }, 1699 { "c.com", false, false },
1670 { "b.com", false, false }, 1700 { "b.com", false, false },
1671 { "k a", false, true }, 1701 { "k a", false, false },
1672 kEmptyMatch }, 1702 kEmptyMatch },
1673 std::string() }, 1703 std::string() },
1674 1704
1675 // Without suggested relevance scores, we should only allow one 1705 // Without suggested relevance scores, we should only allow one
1676 // navsuggest result to be be displayed. 1706 // navsuggest result to be be displayed.
1677 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 1707 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
1678 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", 1708 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
1679 { { "a", true, true }, 1709 { { "a", true, true },
1680 { "b.com", false, false }, 1710 { "b.com", false, false },
1681 { "k a", false, true }, 1711 { "k a", false, false },
1682 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1712 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1683 std::string() }, 1713 std::string() },
1684 1714
1685 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 1715 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
1686 // Negative values will have no effect; the calculated value will be used. 1716 // Negative values will have no effect; the calculated value will be used.
1687 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 1717 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
1688 "\"google:suggestrelevance\":[9998]}]", 1718 "\"google:suggestrelevance\":[9998]}]",
1689 { { "a", true, true }, 1719 { { "a", true, true },
1690 { "a1", true, true }, 1720 { "a1", true, true },
1691 { "k a", false, true }, 1721 { "k a", false, false },
1692 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1722 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1693 std::string() }, 1723 std::string() },
1694 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 1724 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
1695 "\"google:suggestrelevance\":[9999]}]", 1725 "\"google:suggestrelevance\":[9999]}]",
1696 { { "a1", true, true }, 1726 { { "a1", true, true },
1697 { "a", true, true }, 1727 { "a", true, true },
1698 { "k a", false, true }, 1728 { "k a", false, false },
1699 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1729 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1700 "1" }, 1730 "1" },
1701 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," 1731 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0,"
1702 "\"google:suggestrelevance\":[9999]}]", 1732 "\"google:suggestrelevance\":[9999]}]",
1703 { { "a1", true, true }, 1733 { { "a1", true, true },
1704 { "k a", false, true }, 1734 { "k a", false, false },
1705 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1735 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1706 "1" }, 1736 "1" },
1707 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," 1737 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1,"
1708 "\"google:suggestrelevance\":[9999]}]", 1738 "\"google:suggestrelevance\":[9999]}]",
1709 { { "a1", true, true }, 1739 { { "a1", true, true },
1710 { "a", true, true }, 1740 { "a", true, true },
1711 { "k a", false, true }, 1741 { "k a", false, false },
1712 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1742 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1713 "1" }, 1743 "1" },
1714 { "[\"a\",[\"http://a.com\"],[],[]," 1744 { "[\"a\",[\"http://a.com\"],[],[],"
1715 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1745 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1716 "\"google:verbatimrelevance\":9999," 1746 "\"google:verbatimrelevance\":9999,"
1717 "\"google:suggestrelevance\":[9998]}]", 1747 "\"google:suggestrelevance\":[9998]}]",
1718 { { "a", true, true }, 1748 { { "a", true, true },
1719 { "a.com", false, true }, 1749 { "a.com", false, false },
1720 { "k a", false, true }, 1750 { "k a", false, false },
1721 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1751 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1722 std::string() }, 1752 std::string() },
1723 1753
1724 // Ensure that both types of relevance scores reorder matches together. 1754 // Ensure that both types of relevance scores reorder matches together.
1725 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 1755 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
1726 "\"google:verbatimrelevance\":9998}]", 1756 "\"google:verbatimrelevance\":9998}]",
1727 { { "a1", true, true }, 1757 { { "a1", true, true },
1728 { "a", true, true }, 1758 { "a", true, true },
1729 { "a2", true, true }, 1759 { "a2", true, true },
1730 { "k a", false, true }, 1760 { "k a", false, false },
1731 kEmptyMatch, kEmptyMatch }, 1761 kEmptyMatch, kEmptyMatch },
1732 "1" }, 1762 "1" },
1733 1763
1734 // Ensure that only inlinable matches may be ranked as the highest result. 1764 // Ensure that only inlinable matches may be ranked as the highest result.
1735 // Ignore all suggested relevance scores if this constraint is violated. 1765 // Ignore all suggested relevance scores if this constraint is violated.
1736 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 1766 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
1737 { { "a", true, true }, 1767 { { "a", true, true },
1738 { "b", true, false }, 1768 { "b", true, false },
1739 { "k a", false, true }, 1769 { "k a", false, false },
1740 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1770 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1741 std::string() }, 1771 std::string() },
1742 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," 1772 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
1743 "\"google:verbatimrelevance\":0}]", 1773 "\"google:verbatimrelevance\":0}]",
1744 { { "a", true, true }, 1774 { { "a", true, true },
1745 { "b", true, false }, 1775 { "b", true, false },
1746 { "k a", false, true }, 1776 { "k a", false, false },
1747 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1777 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1748 std::string() }, 1778 std::string() },
1749 { "[\"a\",[\"http://b.com\"],[],[]," 1779 { "[\"a\",[\"http://b.com\"],[],[],"
1750 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1780 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1751 "\"google:suggestrelevance\":[9999]}]", 1781 "\"google:suggestrelevance\":[9999]}]",
1752 { { "a", true, true }, 1782 { { "a", true, true },
1753 { "b.com", false, false }, 1783 { "b.com", false, false },
1754 { "k a", false, true }, 1784 { "k a", false, false },
1755 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1785 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1756 std::string() }, 1786 std::string() },
1757 { "[\"a\",[\"http://b.com\"],[],[]," 1787 { "[\"a\",[\"http://b.com\"],[],[],"
1758 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1788 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1759 "\"google:suggestrelevance\":[9999]," 1789 "\"google:suggestrelevance\":[9999],"
1760 "\"google:verbatimrelevance\":0}]", 1790 "\"google:verbatimrelevance\":0}]",
1761 { { "a", true, true }, 1791 { { "a", true, true },
1762 { "b.com", false, false }, 1792 { "b.com", false, false },
1763 { "k a", false, true }, 1793 { "k a", false, false },
1764 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1794 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1765 std::string() }, 1795 std::string() },
1766 1796
1767 // Ensure that the top result is ranked as highly as calculated verbatim. 1797 // Ensure that the top result is ranked as highly as calculated verbatim.
1768 // Ignore the suggested verbatim relevance if this constraint is violated. 1798 // Ignore the suggested verbatim relevance if this constraint is violated.
1769 // Note that keyword suggestions by default (not in suggested relevance 1799 // Note that keyword suggestions by default (not in suggested relevance
1770 // mode) score more highly than the default verbatim. 1800 // mode) score more highly than the default verbatim.
1771 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 1801 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
1772 { { "a", true, true }, 1802 { { "a", true, true },
1773 { "a1", true, true }, 1803 { "a1", true, true },
1774 { "k a", false, true }, 1804 { "k a", false, false },
1775 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1805 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1776 std::string() }, 1806 std::string() },
1777 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 1807 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]",
1778 { { "a", true, true }, 1808 { { "a", true, true },
1779 { "a1", true, true }, 1809 { "a1", true, true },
1780 { "k a", false, true }, 1810 { "k a", false, false },
1781 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1811 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1782 std::string() }, 1812 std::string() },
1783 // Continuing the same category of tests, but make sure we keep the 1813 // Continuing the same category of tests, but make sure we keep the
1784 // suggested relevance scores even as we discard the verbatim relevance 1814 // suggested relevance scores even as we discard the verbatim relevance
1785 // scores. 1815 // scores.
1786 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 1816 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1],"
1787 "\"google:verbatimrelevance\":0}]", 1817 "\"google:verbatimrelevance\":0}]",
1788 { { "a", true, true }, 1818 { { "a", true, true },
1789 { "k a", false, true }, 1819 { "k a", false, false },
1790 { "a1", true, true }, 1820 { "a1", true, true },
1791 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1821 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1792 std::string() }, 1822 std::string() },
1793 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 1823 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2],"
1794 "\"google:verbatimrelevance\":0}]", 1824 "\"google:verbatimrelevance\":0}]",
1795 { { "a", true, true }, 1825 { { "a", true, true },
1796 { "k a", false, true }, 1826 { "k a", false, false },
1797 { "a2", true, true }, 1827 { "a2", true, true },
1798 { "a1", true, true }, 1828 { "a1", true, true },
1799 kEmptyMatch, kEmptyMatch }, 1829 kEmptyMatch, kEmptyMatch },
1800 std::string() }, 1830 std::string() },
1801 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 1831 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3],"
1802 "\"google:verbatimrelevance\":2}]", 1832 "\"google:verbatimrelevance\":2}]",
1803 { { "a", true, true }, 1833 { { "a", true, true },
1804 { "k a", false, true }, 1834 { "k a", false, false },
1805 { "a2", true, true }, 1835 { "a2", true, true },
1806 { "a1", true, true }, 1836 { "a1", true, true },
1807 kEmptyMatch, kEmptyMatch }, 1837 kEmptyMatch, kEmptyMatch },
1808 std::string() }, 1838 std::string() },
1809 1839
1810 // Ensure that all suggestions are considered, regardless of order. 1840 // Ensure that all suggestions are considered, regardless of order.
1811 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 1841 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
1812 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1842 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
1813 { { "a", true, true }, 1843 { { "a", true, true },
1814 { "k a", false, true }, 1844 { "k a", false, false },
1815 { "h", true, false }, 1845 { "h", true, false },
1816 { "g", true, false }, 1846 { "g", true, false },
1817 { "f", true, false }, 1847 { "f", true, false },
1818 { "e", true, false } }, 1848 { "e", true, false } },
1819 std::string() }, 1849 std::string() },
1820 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 1850 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
1821 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 1851 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
1822 "\"http://h.com\"],[],[]," 1852 "\"http://h.com\"],[],[],"
1823 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 1853 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
1824 "\"NAVIGATION\", \"NAVIGATION\"," 1854 "\"NAVIGATION\", \"NAVIGATION\","
1825 "\"NAVIGATION\", \"NAVIGATION\"," 1855 "\"NAVIGATION\", \"NAVIGATION\","
1826 "\"NAVIGATION\"]," 1856 "\"NAVIGATION\"],"
1827 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 1857 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
1828 { { "a", true, true }, 1858 { { "a", true, true },
1829 { "k a", false, true }, 1859 { "k a", false, false },
1830 { "h.com", false, false }, 1860 { "h.com", false, false },
1831 { "g.com", false, false }, 1861 { "g.com", false, false },
1832 { "f.com", false, false }, 1862 { "f.com", false, false },
1833 { "e.com", false, false } }, 1863 { "e.com", false, false } },
1834 std::string() }, 1864 std::string() },
1835 1865
1836 // Ensure that incorrectly sized suggestion relevance lists are ignored. 1866 // Ensure that incorrectly sized suggestion relevance lists are ignored.
1837 // Note that keyword suggestions by default (not in suggested relevance 1867 // Note that keyword suggestions by default (not in suggested relevance
1838 // mode) score more highly than the default verbatim. 1868 // mode) score more highly than the default verbatim.
1839 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 1869 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
1840 { { "a", true, true }, 1870 { { "a", true, true },
1841 { "a1", true, true }, 1871 { "a1", true, true },
1842 { "a2", true, true }, 1872 { "a2", true, true },
1843 { "k a", false, true }, 1873 { "k a", false, false },
1844 kEmptyMatch, kEmptyMatch }, 1874 kEmptyMatch, kEmptyMatch },
1845 std::string() }, 1875 std::string() },
1846 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 1876 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
1847 { { "a", true, true }, 1877 { { "a", true, true },
1848 { "a1", true, true }, 1878 { "a1", true, true },
1849 { "k a", false, true }, 1879 { "k a", false, false },
1850 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1880 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1851 std::string() }, 1881 std::string() },
1852 // In this case, ignoring the suggested relevance scores means we keep 1882 // In this case, ignoring the suggested relevance scores means we keep
1853 // only one navsuggest result. 1883 // only one navsuggest result.
1854 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1884 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1855 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1885 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1856 "\"google:suggestrelevance\":[1]}]", 1886 "\"google:suggestrelevance\":[1]}]",
1857 { { "a", true, true }, 1887 { { "a", true, true },
1858 { "a1.com", false, true }, 1888 { "a1.com", false, false },
1859 { "k a", false, true }, 1889 { "k a", false, false },
1860 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1890 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1861 std::string() }, 1891 std::string() },
1862 { "[\"a\",[\"http://a1.com\"],[],[]," 1892 { "[\"a\",[\"http://a1.com\"],[],[],"
1863 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1893 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1864 "\"google:suggestrelevance\":[9999, 1]}]", 1894 "\"google:suggestrelevance\":[9999, 1]}]",
1865 { { "a", true, true }, 1895 { { "a", true, true },
1866 { "a1.com", false, true }, 1896 { "a1.com", false, false },
1867 { "k a", false, true }, 1897 { "k a", false, false },
1868 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1898 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1869 std::string() }, 1899 std::string() },
1870 1900
1871 // Ensure that all 'verbatim' results are merged with their maximum score. 1901 // Ensure that all 'verbatim' results are merged with their maximum score.
1872 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1902 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1873 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 1903 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
1874 { { "a2", true, true }, 1904 { { "a2", true, true },
1875 { "a", true, true }, 1905 { "a", true, true },
1876 { "a1", true, true }, 1906 { "a1", true, true },
1877 { "k a", false, true }, 1907 { "k a", false, false },
1878 kEmptyMatch, kEmptyMatch }, 1908 kEmptyMatch, kEmptyMatch },
1879 "2" }, 1909 "2" },
1880 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 1910 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
1881 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 1911 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
1882 "\"google:verbatimrelevance\":0}]", 1912 "\"google:verbatimrelevance\":0}]",
1883 { { "a2", true, true }, 1913 { { "a2", true, true },
1884 { "a", true, true }, 1914 { "a", true, true },
1885 { "a1", true, true }, 1915 { "a1", true, true },
1886 { "k a", false, true }, 1916 { "k a", false, false },
1887 kEmptyMatch, kEmptyMatch }, 1917 kEmptyMatch, kEmptyMatch },
1888 "2" }, 1918 "2" },
1889 1919
1890 // Ensure that verbatim is always generated without other suggestions. 1920 // Ensure that verbatim is always generated without other suggestions.
1891 // TODO(mpearson): Ensure the value of verbatimrelevance is respected 1921 // TODO(mpearson): Ensure the value of verbatimrelevance is respected
1892 // (except when suggested relevances are ignored). 1922 // (except when suggested relevances are ignored).
1893 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 1923 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
1894 { { "a", true, true }, 1924 { { "a", true, true },
1895 { "k a", false, true }, 1925 { "k a", false, false },
1896 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1926 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1897 std::string() }, 1927 std::string() },
1898 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 1928 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
1899 { { "a", true, true }, 1929 { { "a", true, true },
1900 { "k a", false, true }, 1930 { "k a", false, false },
1901 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1931 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
1902 std::string() }, 1932 std::string() },
1903 1933
1904 // Check that navsuggestions will be demoted below queries. 1934 // Check that navsuggestions will be demoted below queries.
1905 // (Navsuggestions are not allowed to appear first.) In the process, 1935 // (Navsuggestions are not allowed to appear first.) In the process,
1906 // make sure the navsuggestions still remain in the same order. 1936 // make sure the navsuggestions still remain in the same order.
1907 // First, check the situation where navsuggest scores more than verbatim 1937 // First, check the situation where navsuggest scores more than verbatim
1908 // and there are no query suggestions. 1938 // and there are no query suggestions.
1909 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1939 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1910 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1940 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1911 "\"google:verbatimrelevance\":9990," 1941 "\"google:verbatimrelevance\":9990,"
1912 "\"google:suggestrelevance\":[9998, 9999]}]", 1942 "\"google:suggestrelevance\":[9998, 9999]}]",
1913 { { "a", true, true }, 1943 { { "a", true, true },
1914 { "a2.com", false, true }, 1944 { "a2.com", false, false },
1915 { "a1.com", false, true }, 1945 { "a1.com", false, false },
1916 { "k a", false, true }, 1946 { "k a", false, false },
1917 kEmptyMatch, kEmptyMatch }, 1947 kEmptyMatch, kEmptyMatch },
1918 std::string() }, 1948 std::string() },
1919 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 1949 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
1920 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 1950 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
1921 "\"google:verbatimrelevance\":9990," 1951 "\"google:verbatimrelevance\":9990,"
1922 "\"google:suggestrelevance\":[9999, 9998]}]", 1952 "\"google:suggestrelevance\":[9999, 9998]}]",
1923 { { "a", true, true }, 1953 { { "a", true, true },
1924 { "a1.com", false, true }, 1954 { "a1.com", false, false },
1925 { "a2.com", false, true }, 1955 { "a2.com", false, false },
1926 { "k a", false, true }, 1956 { "k a", false, false },
1927 kEmptyMatch, kEmptyMatch }, 1957 kEmptyMatch, kEmptyMatch },
1928 std::string() }, 1958 std::string() },
1929 { "[\"a\",[\"https://a/\"],[],[]," 1959 { "[\"a\",[\"https://a/\"],[],[],"
1930 "{\"google:suggesttype\":[\"NAVIGATION\"]," 1960 "{\"google:suggesttype\":[\"NAVIGATION\"],"
1931 "\"google:suggestrelevance\":[9999]}]", 1961 "\"google:suggestrelevance\":[9999]}]",
1932 { { "a", true, true }, 1962 { { "a", true, true },
1933 { "https://a", false, true }, 1963 { "https://a", false, false },
1934 { "k a", false, true }, 1964 { "k a", false, false },
1935 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 1965 kEmptyMatch, kEmptyMatch, kEmptyMatch },
1936 std::string() }, 1966 std::string() },
1937 // Check when navsuggest scores more than verbatim and there is query 1967 // Check when navsuggest scores more than verbatim and there is query
1938 // suggestion but it scores lower. 1968 // suggestion but it scores lower.
1939 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1969 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1940 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1970 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1941 "\"google:verbatimrelevance\":9990," 1971 "\"google:verbatimrelevance\":9990,"
1942 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", 1972 "\"google:suggestrelevance\":[9998, 9999, 1300]}]",
1943 { { "a", true, true }, 1973 { { "a", true, true },
1944 { "a2.com", false, true }, 1974 { "a2.com", false, false },
1945 { "a1.com", false, true }, 1975 { "a1.com", false, false },
1946 { "a3", true, true }, 1976 { "a3", true, true },
1947 { "k a", false, true }, 1977 { "k a", false, false },
1948 kEmptyMatch }, 1978 kEmptyMatch },
1949 std::string() }, 1979 std::string() },
1950 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1980 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1951 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1981 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1952 "\"google:verbatimrelevance\":9990," 1982 "\"google:verbatimrelevance\":9990,"
1953 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", 1983 "\"google:suggestrelevance\":[9999, 9998, 1300]}]",
1954 { { "a", true, true }, 1984 { { "a", true, true },
1955 { "a1.com", false, true }, 1985 { "a1.com", false, false },
1956 { "a2.com", false, true }, 1986 { "a2.com", false, false },
1957 { "a3", true, true }, 1987 { "a3", true, true },
1958 { "k a", false, true }, 1988 { "k a", false, false },
1959 kEmptyMatch }, 1989 kEmptyMatch },
1960 std::string() }, 1990 std::string() },
1961 // Check when navsuggest scores more than a query suggestion. There is 1991 // Check when navsuggest scores more than a query suggestion. There is
1962 // a verbatim but it scores lower. 1992 // a verbatim but it scores lower.
1963 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 1993 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1964 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 1994 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1965 "\"google:verbatimrelevance\":9990," 1995 "\"google:verbatimrelevance\":9990,"
1966 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 1996 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1967 { { "a3", true, true }, 1997 { { "a3", true, true },
1968 { "a2.com", false, true }, 1998 { "a2.com", false, false },
1969 { "a1.com", false, true }, 1999 { "a1.com", false, false },
1970 { "a", true, true }, 2000 { "a", true, true },
1971 { "k a", false, true }, 2001 { "k a", false, false },
1972 kEmptyMatch }, 2002 kEmptyMatch },
1973 "3" }, 2003 "3" },
1974 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2004 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1975 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2005 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1976 "\"google:verbatimrelevance\":9990," 2006 "\"google:verbatimrelevance\":9990,"
1977 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 2007 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1978 { { "a3", true, true }, 2008 { { "a3", true, true },
1979 { "a1.com", false, true }, 2009 { "a1.com", false, false },
1980 { "a2.com", false, true }, 2010 { "a2.com", false, false },
1981 { "a", true, true }, 2011 { "a", true, true },
1982 { "k a", false, true }, 2012 { "k a", false, false },
1983 kEmptyMatch }, 2013 kEmptyMatch },
1984 "3" }, 2014 "3" },
1985 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2015 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1986 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2016 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1987 "\"google:verbatimrelevance\":0," 2017 "\"google:verbatimrelevance\":0,"
1988 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 2018 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
1989 { { "a3", true, true }, 2019 { { "a3", true, true },
1990 { "a2.com", false, true }, 2020 { "a2.com", false, false },
1991 { "a1.com", false, true }, 2021 { "a1.com", false, false },
1992 { "k a", false, true }, 2022 { "k a", false, false },
1993 kEmptyMatch, kEmptyMatch }, 2023 kEmptyMatch, kEmptyMatch },
1994 "3" }, 2024 "3" },
1995 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2025 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
1996 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2026 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
1997 "\"google:verbatimrelevance\":0," 2027 "\"google:verbatimrelevance\":0,"
1998 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 2028 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
1999 { { "a3", true, true }, 2029 { { "a3", true, true },
2000 { "a1.com", false, true }, 2030 { "a1.com", false, false },
2001 { "a2.com", false, true }, 2031 { "a2.com", false, false },
2002 { "k a", false, true }, 2032 { "k a", false, false },
2003 kEmptyMatch, kEmptyMatch }, 2033 kEmptyMatch, kEmptyMatch },
2004 "3" }, 2034 "3" },
2005 // Check when there is neither verbatim nor a query suggestion that, 2035 // Check when there is neither verbatim nor a query suggestion that,
2006 // because we can't demote navsuggestions below a query suggestion, 2036 // because we can't demote navsuggestions below a query suggestion,
2007 // we abandon suggested relevance scores entirely. One consequence is 2037 // we abandon suggested relevance scores entirely. One consequence is
2008 // that this means we restore the keyword verbatim match. Note 2038 // that this means we restore the keyword verbatim match. Note
2009 // that in this case of abandoning suggested relevance scores, we still 2039 // that in this case of abandoning suggested relevance scores, we still
2010 // keep the navsuggestions in the same order, but we revert to only allowing 2040 // keep the navsuggestions in the same order, but we revert to only allowing
2011 // one navigation to appear because the scores are completely local. 2041 // one navigation to appear because the scores are completely local.
2012 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 2042 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
2013 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 2043 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2014 "\"google:verbatimrelevance\":0," 2044 "\"google:verbatimrelevance\":0,"
2015 "\"google:suggestrelevance\":[9998, 9999]}]", 2045 "\"google:suggestrelevance\":[9998, 9999]}]",
2016 { { "a", true, true }, 2046 { { "a", true, true },
2017 { "a2.com", false, true }, 2047 { "a2.com", false, false },
2018 { "k a", false, true }, 2048 { "k a", false, false },
2019 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2049 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2020 std::string() }, 2050 std::string() },
2021 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 2051 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
2022 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 2052 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2023 "\"google:verbatimrelevance\":0," 2053 "\"google:verbatimrelevance\":0,"
2024 "\"google:suggestrelevance\":[9999, 9998]}]", 2054 "\"google:suggestrelevance\":[9999, 9998]}]",
2025 { { "a", true, true }, 2055 { { "a", true, true },
2026 { "a1.com", false, true }, 2056 { "a1.com", false, false },
2027 { "k a", false, true }, 2057 { "k a", false, false },
2028 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2058 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2029 std::string() }, 2059 std::string() },
2030 // More checks that everything works when it's not necessary to demote. 2060 // More checks that everything works when it's not necessary to demote.
2031 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2061 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2032 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2062 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2033 "\"google:verbatimrelevance\":9990," 2063 "\"google:verbatimrelevance\":9990,"
2034 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", 2064 "\"google:suggestrelevance\":[9997, 9998, 9999]}]",
2035 { { "a3", true, true }, 2065 { { "a3", true, true },
2036 { "a2.com", false, true }, 2066 { "a2.com", false, false },
2037 { "a1.com", false, true }, 2067 { "a1.com", false, false },
2038 { "a", true, true }, 2068 { "a", true, true },
2039 { "k a", false, true }, 2069 { "k a", false, false },
2040 kEmptyMatch }, 2070 kEmptyMatch },
2041 "3" }, 2071 "3" },
2042 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2072 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2043 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2073 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2044 "\"google:verbatimrelevance\":9990," 2074 "\"google:verbatimrelevance\":9990,"
2045 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", 2075 "\"google:suggestrelevance\":[9998, 9997, 9999]}]",
2046 { { "a3", true, true }, 2076 { { "a3", true, true },
2047 { "a1.com", false, true }, 2077 { "a1.com", false, false },
2048 { "a2.com", false, true }, 2078 { "a2.com", false, false },
2049 { "a", true, true }, 2079 { "a", true, true },
2050 { "k a", false, true }, 2080 { "k a", false, false },
2051 kEmptyMatch }, 2081 kEmptyMatch },
2052 "3" }, 2082 "3" },
2053 }; 2083 };
2054 2084
2055 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 2085 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
2056 QueryForInput(ASCIIToUTF16("k a"), false, true); 2086 QueryForInput(ASCIIToUTF16("k a"), false, true);
2057 2087
2058 // Set up a default fetcher with no results. 2088 // Set up a default fetcher with no results.
2059 net::TestURLFetcher* default_fetcher = 2089 net::TestURLFetcher* default_fetcher =
2060 test_factory_.GetFetcherByID( 2090 test_factory_.GetFetcherByID(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 struct { 2147 struct {
2118 const std::string json; 2148 const std::string json;
2119 const KeywordFetcherMatch matches[6]; 2149 const KeywordFetcherMatch matches[6];
2120 const std::string inline_autocompletion; 2150 const std::string inline_autocompletion;
2121 } cases[] = { 2151 } cases[] = {
2122 // Ensure that suggest relevance scores reorder matches and that 2152 // Ensure that suggest relevance scores reorder matches and that
2123 // the keyword verbatim (lacking a suggested verbatim score) beats 2153 // the keyword verbatim (lacking a suggested verbatim score) beats
2124 // the default provider verbatim. 2154 // the default provider verbatim.
2125 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", 2155 { "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]",
2126 { { "a", true, true }, 2156 { { "a", true, true },
2127 { "k a", false, true }, 2157 { "k a", false, false },
2128 { "c", true, false }, 2158 { "c", true, false },
2129 { "b", true, false }, 2159 { "b", true, false },
2130 kEmptyMatch, kEmptyMatch }, 2160 kEmptyMatch, kEmptyMatch },
2131 std::string() }, 2161 std::string() },
2132 // Again, check that relevance scores reorder matches, just this 2162 // Again, check that relevance scores reorder matches, just this
2133 // time with navigation matches. This also checks that with 2163 // time with navigation matches. This also checks that with
2134 // suggested relevance scores we allow multiple navsuggest results. 2164 // suggested relevance scores we allow multiple navsuggest results.
2135 // It's odd that navsuggest results that come from a keyword 2165 // Note that navsuggest results that come from a keyword provider
2136 // provider are marked as not a keyword result. I think this 2166 // are marked as not a keyword result. (They don't go to a
2137 // comes from them not going to a keyword search engine. 2167 // keyword search engine.)
2138 // TODO(mpearson): Investigate the implications (if any) of
2139 // tagging these results appropriately. If so, do it because it
2140 // makes more sense.
2141 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[]," 2168 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"d\"],[],[],"
2142 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2169 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2143 "\"google:suggestrelevance\":[1301, 1302, 1303]}]", 2170 "\"google:suggestrelevance\":[1301, 1302, 1303]}]",
2144 { { "a", true, true }, 2171 { { "a", true, true },
2145 { "d", true, false }, 2172 { "d", true, false },
2146 { "c.com", false, false }, 2173 { "c.com", false, false },
2147 { "b.com", false, false }, 2174 { "b.com", false, false },
2148 { "k a", false, true }, 2175 { "k a", false, false },
2149 kEmptyMatch }, 2176 kEmptyMatch },
2150 std::string() }, 2177 std::string() },
2151 2178
2152 // Without suggested relevance scores, we should only allow one 2179 // Without suggested relevance scores, we should only allow one
2153 // navsuggest result to be be displayed. 2180 // navsuggest result to be be displayed.
2154 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," 2181 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[],"
2155 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", 2182 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]",
2156 { { "a", true, true }, 2183 { { "a", true, true },
2157 { "b.com", false, false }, 2184 { "b.com", false, false },
2158 { "k a", false, true }, 2185 { "k a", false, false },
2159 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2186 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2160 std::string() }, 2187 std::string() },
2161 2188
2162 // Ensure that verbatimrelevance scores reorder or suppress verbatim. 2189 // Ensure that verbatimrelevance scores reorder or suppress verbatim.
2163 // Negative values will have no effect; the calculated value will be used. 2190 // Negative values will have no effect; the calculated value will be used.
2164 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," 2191 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999,"
2165 "\"google:suggestrelevance\":[9998]}]", 2192 "\"google:suggestrelevance\":[9998]}]",
2166 { { "a", true, true }, 2193 { { "a", true, true },
2167 { "a1", true, true }, 2194 { "a1", true, true },
2168 { "k a", false, true }, 2195 { "k a", false, false },
2169 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2196 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2170 std::string() }, 2197 std::string() },
2171 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," 2198 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998,"
2172 "\"google:suggestrelevance\":[9999]}]", 2199 "\"google:suggestrelevance\":[9999]}]",
2173 { { "a1", true, true }, 2200 { { "a1", true, true },
2174 { "a", true, true }, 2201 { "a", true, true },
2175 { "k a", false, true }, 2202 { "k a", false, false },
2176 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2203 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2177 "1" }, 2204 "1" },
2178 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," 2205 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0,"
2179 "\"google:suggestrelevance\":[9999]}]", 2206 "\"google:suggestrelevance\":[9999]}]",
2180 { { "a1", true, true }, 2207 { { "a1", true, true },
2181 { "k a", false, true }, 2208 { "k a", false, false },
2182 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2209 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
2183 "1" }, 2210 "1" },
2184 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," 2211 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1,"
2185 "\"google:suggestrelevance\":[9999]}]", 2212 "\"google:suggestrelevance\":[9999]}]",
2186 { { "a1", true, true }, 2213 { { "a1", true, true },
2187 { "a", true, true }, 2214 { "a", true, true },
2188 { "k a", false, true }, 2215 { "k a", false, false },
2189 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2216 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2190 "1" }, 2217 "1" },
2191 { "[\"a\",[\"http://a.com\"],[],[]," 2218 { "[\"a\",[\"http://a.com\"],[],[],"
2192 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2219 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2193 "\"google:verbatimrelevance\":9999," 2220 "\"google:verbatimrelevance\":9999,"
2194 "\"google:suggestrelevance\":[9998]}]", 2221 "\"google:suggestrelevance\":[9998]}]",
2195 { { "a", true, true }, 2222 { { "a", true, true },
2196 { "a.com", false, true }, 2223 { "a.com", false, false },
2197 { "k a", false, true }, 2224 { "k a", false, false },
2198 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2225 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2199 std::string() }, 2226 std::string() },
2200 2227
2201 // Ensure that both types of relevance scores reorder matches together. 2228 // Ensure that both types of relevance scores reorder matches together.
2202 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," 2229 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997],"
2203 "\"google:verbatimrelevance\":9998}]", 2230 "\"google:verbatimrelevance\":9998}]",
2204 { { "a1", true, true }, 2231 { { "a1", true, true },
2205 { "a", true, true }, 2232 { "a", true, true },
2206 { "a2", true, true }, 2233 { "a2", true, true },
2207 { "k a", false, true }, 2234 { "k a", false, false },
2208 kEmptyMatch, kEmptyMatch }, 2235 kEmptyMatch, kEmptyMatch },
2209 "1" }, 2236 "1" },
2210 2237
2211 // Check that non-inlinable matches may be ranked as the highest result 2238 // Check that non-inlinable matches may be ranked as the highest result
2212 // if there is at least one inlineable match. 2239 // if there is at least one inlineable match.
2213 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", 2240 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]",
2214 { { "b", true, false }, 2241 { { "b", true, false },
2215 { "a", true, true }, 2242 { "a", true, true },
2216 { "k a", false, true }, 2243 { "k a", false, false },
2217 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2244 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2218 std::string() }, 2245 std::string() },
2219 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
2220 "\"google:verbatimrelevance\":0}]",
2221 { { "b", true, false },
2222 { "k a", false, true },
2223 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
2224 std::string() },
2225 { "[\"a\",[\"http://b.com\"],[],[]," 2246 { "[\"a\",[\"http://b.com\"],[],[],"
2226 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2247 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2227 "\"google:suggestrelevance\":[9999]}]", 2248 "\"google:suggestrelevance\":[9999]}]",
2228 { { "b.com", false, false }, 2249 { { "b.com", false, false },
2229 { "a", true, true }, 2250 { "a", true, true },
2230 { "k a", false, true }, 2251 { "k a", false, false },
2252 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2253 std::string() },
2254 // On the other hand, if there is no inlineable match, restore
2255 // the keyword verbatim score.
2256 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999],"
2257 "\"google:verbatimrelevance\":0}]",
2258 { { "b", true, false },
2259 { "a", true, true },
2260 { "k a", false, false },
2231 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2261 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2232 std::string() }, 2262 std::string() },
2233 { "[\"a\",[\"http://b.com\"],[],[]," 2263 { "[\"a\",[\"http://b.com\"],[],[],"
2234 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2264 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2235 "\"google:suggestrelevance\":[9999]," 2265 "\"google:suggestrelevance\":[9999],"
2236 "\"google:verbatimrelevance\":0}]", 2266 "\"google:verbatimrelevance\":0}]",
2237 { { "b.com", false, false }, 2267 { { "b.com", false, false },
2238 { "k a", false, true }, 2268 { "a", true, true },
2239 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2269 { "k a", false, false },
2270 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2240 std::string() }, 2271 std::string() },
2241 2272
2242 // The top result does not have to score as highly as calculated 2273 // The top result does not have to score as highly as calculated
2243 // verbatim. i.e., there are no minimum score restrictions in 2274 // verbatim. i.e., there are no minimum score restrictions in
2244 // this provider. 2275 // this provider.
2245 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]", 2276 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0}]",
2246 { { "a1", true, true }, 2277 { { "a1", true, true },
2247 { "k a", false, true }, 2278 { "k a", false, false },
2248 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2279 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
2249 "1" }, 2280 "1" },
2250 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]", 2281 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":1}]",
2251 { { "a1", true, true }, 2282 { { "a1", true, true },
2252 { "k a", false, true }, 2283 { "k a", false, false },
2253 { "a", true, true }, 2284 { "a", true, true },
2254 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2285 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2255 "1" }, 2286 "1" },
2256 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," 2287 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1],"
2257 "\"google:verbatimrelevance\":0}]", 2288 "\"google:verbatimrelevance\":0}]",
2258 { { "k a", false, true }, 2289 { { "k a", false, false },
2259 { "a1", true, true }, 2290 { "a1", true, true },
2260 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2291 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
2261 std::string() }, 2292 "1" },
2262 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," 2293 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2],"
2263 "\"google:verbatimrelevance\":0}]", 2294 "\"google:verbatimrelevance\":0}]",
2264 { 2295 {
2265 { "k a", false, true }, 2296 { "k a", false, false },
2266 { "a2", true, true }, 2297 { "a2", true, true },
2267 { "a1", true, true }, 2298 { "a1", true, true },
2268 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2299 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2269 std::string() }, 2300 "2" },
2270 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," 2301 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3],"
2271 "\"google:verbatimrelevance\":2}]", 2302 "\"google:verbatimrelevance\":2}]",
2272 { { "k a", false, true }, 2303 { { "k a", false, false },
2273 { "a2", true, true }, 2304 { "a2", true, true },
2274 { "a", true, true }, 2305 { "a", true, true },
2275 { "a1", true, true }, 2306 { "a1", true, true },
2276 kEmptyMatch, kEmptyMatch }, 2307 kEmptyMatch, kEmptyMatch },
2277 std::string() }, 2308 "2" },
2278 2309
2279 // Ensure that all suggestions are considered, regardless of order. 2310 // Ensure that all suggestions are considered, regardless of order.
2280 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," 2311 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[],"
2281 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 2312 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
2282 { { "a", true, true }, 2313 { { "a", true, true },
2283 { "k a", false, true }, 2314 { "k a", false, false },
2284 { "h", true, false }, 2315 { "h", true, false },
2285 { "g", true, false }, 2316 { "g", true, false },
2286 { "f", true, false }, 2317 { "f", true, false },
2287 { "e", true, false } }, 2318 { "e", true, false } },
2288 std::string() }, 2319 std::string() },
2289 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," 2320 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\","
2290 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," 2321 "\"http://e.com\", \"http://f.com\", \"http://g.com\","
2291 "\"http://h.com\"],[],[]," 2322 "\"http://h.com\"],[],[],"
2292 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," 2323 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\","
2293 "\"NAVIGATION\", \"NAVIGATION\"," 2324 "\"NAVIGATION\", \"NAVIGATION\","
2294 "\"NAVIGATION\", \"NAVIGATION\"," 2325 "\"NAVIGATION\", \"NAVIGATION\","
2295 "\"NAVIGATION\"]," 2326 "\"NAVIGATION\"],"
2296 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", 2327 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]",
2297 { { "a", true, true }, 2328 { { "a", true, true },
2298 { "k a", false, true }, 2329 { "k a", false, false },
2299 { "h.com", false, false }, 2330 { "h.com", false, false },
2300 { "g.com", false, false }, 2331 { "g.com", false, false },
2301 { "f.com", false, false }, 2332 { "f.com", false, false },
2302 { "e.com", false, false } }, 2333 { "e.com", false, false } },
2303 std::string() }, 2334 std::string() },
2304 2335
2305 // Ensure that incorrectly sized suggestion relevance lists are ignored. 2336 // Ensure that incorrectly sized suggestion relevance lists are ignored.
2306 // Note that keyword suggestions by default (not in suggested relevance 2337 // Note that keyword suggestions by default (not in suggested relevance
2307 // mode) score more highly than the default verbatim. 2338 // mode) score more highly than the default verbatim.
2308 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", 2339 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]",
2309 { { "a", true, true }, 2340 { { "a", true, true },
2310 { "a1", true, true }, 2341 { "a1", true, true },
2311 { "a2", true, true }, 2342 { "a2", true, true },
2312 { "k a", false, true }, 2343 { "k a", false, false },
2313 kEmptyMatch, kEmptyMatch }, 2344 kEmptyMatch, kEmptyMatch },
2314 std::string() }, 2345 std::string() },
2315 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", 2346 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]",
2316 { { "a", true, true }, 2347 { { "a", true, true },
2317 { "a1", true, true }, 2348 { "a1", true, true },
2318 { "k a", false, true }, 2349 { "k a", false, false },
2319 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2350 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2320 std::string() }, 2351 std::string() },
2321 // In this case, ignoring the suggested relevance scores means we keep 2352 // In this case, ignoring the suggested relevance scores means we keep
2322 // only one navsuggest result. 2353 // only one navsuggest result.
2323 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 2354 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
2324 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 2355 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2325 "\"google:suggestrelevance\":[1]}]", 2356 "\"google:suggestrelevance\":[1]}]",
2326 { { "a", true, true }, 2357 { { "a", true, true },
2327 { "a1.com", false, true }, 2358 { "a1.com", false, false },
2328 { "k a", false, true }, 2359 { "k a", false, false },
2329 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2360 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2330 std::string() }, 2361 std::string() },
2331 { "[\"a\",[\"http://a1.com\"],[],[]," 2362 { "[\"a\",[\"http://a1.com\"],[],[],"
2332 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2363 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2333 "\"google:suggestrelevance\":[9999, 1]}]", 2364 "\"google:suggestrelevance\":[9999, 1]}]",
2334 { { "a", true, true }, 2365 { { "a", true, true },
2335 { "a1.com", false, true }, 2366 { "a1.com", false, false },
2336 { "k a", false, true }, 2367 { "k a", false, false },
2337 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2368 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2338 std::string() }, 2369 std::string() },
2339 2370
2340 // Ensure that all 'verbatim' results are merged with their maximum score. 2371 // Ensure that all 'verbatim' results are merged with their maximum score.
2341 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 2372 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
2342 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", 2373 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]",
2343 { { "a2", true, true }, 2374 { { "a2", true, true },
2344 { "a", true, true }, 2375 { "a", true, true },
2345 { "a1", true, true }, 2376 { "a1", true, true },
2346 { "k a", false, true }, 2377 { "k a", false, false },
2347 kEmptyMatch, kEmptyMatch }, 2378 kEmptyMatch, kEmptyMatch },
2348 "2" }, 2379 "2" },
2349 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," 2380 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[],"
2350 "{\"google:suggestrelevance\":[9998, 9997, 9999]," 2381 "{\"google:suggestrelevance\":[9998, 9997, 9999],"
2351 "\"google:verbatimrelevance\":0}]", 2382 "\"google:verbatimrelevance\":0}]",
2352 { { "a2", true, true }, 2383 { { "a2", true, true },
2353 { "a", true, true }, 2384 { "a", true, true },
2354 { "a1", true, true }, 2385 { "a1", true, true },
2355 { "k a", false, true }, 2386 { "k a", false, false },
2356 kEmptyMatch, kEmptyMatch }, 2387 kEmptyMatch, kEmptyMatch },
2357 "2" }, 2388 "2" },
2358 2389
2359 // Ensure that verbatim is always generated without other suggestions. 2390 // Ensure that verbatim is always generated without other suggestions.
2360 // TODO(mpearson): Ensure the value of verbatimrelevance is respected 2391 // TODO(mpearson): Ensure the value of verbatimrelevance is respected
2361 // (except when suggested relevances are ignored). 2392 // (except when suggested relevances are ignored).
2362 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", 2393 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]",
2363 { { "k a", false, true }, 2394 { { "k a", false, false },
2364 { "a", true, true }, 2395 { "a", true, true },
2365 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2396 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
2366 std::string() }, 2397 std::string() },
2367 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", 2398 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]",
2368 { { "a", true, true }, 2399 { { "a", true, true },
2369 { "k a", false, true }, 2400 { "k a", false, false },
2370 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2401 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch },
2371 std::string() }, 2402 std::string() },
2372 2403
2373 // Check that navsuggestions will be demoted below queries. 2404 // In reorder mode, navsuggestions will not need to be demoted (because
2374 // (Navsuggestions are not allowed to appear first.) In the process, 2405 // they are marked as not allowed to be default match and will be
2375 // make sure the navsuggestions still remain in the same order. 2406 // reordered as necessary).
2376 // First, check the situation where navsuggest scores more than verbatim
2377 // and there are no query suggestions.
2378 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 2407 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
2379 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 2408 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2380 "\"google:verbatimrelevance\":9990," 2409 "\"google:verbatimrelevance\":9990,"
2381 "\"google:suggestrelevance\":[9998, 9999]}]", 2410 "\"google:suggestrelevance\":[9998, 9999]}]",
2382 { { "a", true, true }, 2411 { { "a2.com", false, false },
2383 { "a2.com", false, true }, 2412 { "a1.com", false, false },
2384 { "a1.com", false, true }, 2413 { "a", true, true },
2385 { "k a", false, true }, 2414 { "k a", false, false },
2386 kEmptyMatch, kEmptyMatch }, 2415 kEmptyMatch, kEmptyMatch },
2387 std::string() }, 2416 std::string() },
2388 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 2417 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
2389 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 2418 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2390 "\"google:verbatimrelevance\":9990," 2419 "\"google:verbatimrelevance\":9990,"
2391 "\"google:suggestrelevance\":[9999, 9998]}]", 2420 "\"google:suggestrelevance\":[9999, 9998]}]",
2392 { { "a", true, true }, 2421 { { "a1.com", false, false },
2393 { "a1.com", false, true }, 2422 { "a2.com", false, false },
2394 { "a2.com", false, true }, 2423 { "a", true, true },
2395 { "k a", false, true }, 2424 { "k a", false, false },
2396 kEmptyMatch, kEmptyMatch }, 2425 kEmptyMatch, kEmptyMatch },
2397 std::string() }, 2426 std::string() },
2398 { "[\"a\",[\"https://a/\"],[],[]," 2427 { "[\"a\",[\"https://a/\"],[],[],"
2399 "{\"google:suggesttype\":[\"NAVIGATION\"]," 2428 "{\"google:suggesttype\":[\"NAVIGATION\"],"
2400 "\"google:suggestrelevance\":[9999]}]", 2429 "\"google:suggestrelevance\":[9999]}]",
2401 { { "a", true, true }, 2430 { { "https://a", false, false },
2402 { "https://a", false, true }, 2431 { "a", true, true },
2403 { "k a", false, true }, 2432 { "k a", false, false },
2404 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2433 kEmptyMatch, kEmptyMatch, kEmptyMatch },
2405 std::string() }, 2434 std::string() },
2406 // Check when navsuggest scores more than verbatim and there is query 2435 // Check when navsuggest scores more than verbatim and there is query
2407 // suggestion but it scores lower. 2436 // suggestion but it scores lower.
2408 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2437 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2409 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2438 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2410 "\"google:verbatimrelevance\":9990," 2439 "\"google:verbatimrelevance\":9990,"
2411 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", 2440 "\"google:suggestrelevance\":[9998, 9999, 1300]}]",
2412 { { "a", true, true }, 2441 { { "a2.com", false, false },
2413 { "a2.com", false, true }, 2442 { "a1.com", false, false },
2414 { "a1.com", false, true }, 2443 { "a", true, true },
2415 { "a3", true, true }, 2444 { "a3", true, true },
2416 { "k a", false, true }, 2445 { "k a", false, false },
2417 kEmptyMatch }, 2446 kEmptyMatch },
2418 std::string() }, 2447 std::string() },
2419 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2448 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2420 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2449 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2421 "\"google:verbatimrelevance\":9990," 2450 "\"google:verbatimrelevance\":9990,"
2422 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", 2451 "\"google:suggestrelevance\":[9999, 9998, 1300]}]",
2423 { { "a", true, true }, 2452 { { "a1.com", false, false },
2424 { "a1.com", false, true }, 2453 { "a2.com", false, false },
2425 { "a2.com", false, true }, 2454 { "a", true, true },
2426 { "a3", true, true }, 2455 { "a3", true, true },
2427 { "k a", false, true }, 2456 { "k a", false, false },
2428 kEmptyMatch }, 2457 kEmptyMatch },
2429 std::string() }, 2458 std::string() },
2430 // Check when navsuggest scores more than a query suggestion. There is 2459 // Check when navsuggest scores more than a query suggestion. There is
2431 // a verbatim but it scores lower. 2460 // a verbatim but it scores lower.
2432 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2461 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2433 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2462 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2434 "\"google:verbatimrelevance\":9990," 2463 "\"google:verbatimrelevance\":9990,"
2435 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 2464 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
2436 { { "a3", true, true }, 2465 { { "a2.com", false, false },
2437 { "a2.com", false, true }, 2466 { "a1.com", false, false },
2438 { "a1.com", false, true }, 2467 { "a3", true, true },
2439 { "a", true, true }, 2468 { "a", true, true },
2440 { "k a", false, true }, 2469 { "k a", false, false },
2441 kEmptyMatch }, 2470 kEmptyMatch },
2442 "3" }, 2471 "3" },
2443 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2472 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2444 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2473 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2445 "\"google:verbatimrelevance\":9990," 2474 "\"google:verbatimrelevance\":9990,"
2446 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 2475 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
2447 { { "a3", true, true }, 2476 { { "a1.com", false, false },
2448 { "a1.com", false, true }, 2477 { "a2.com", false, false },
2449 { "a2.com", false, true }, 2478 { "a3", true, true },
2450 { "a", true, true }, 2479 { "a", true, true },
2451 { "k a", false, true }, 2480 { "k a", false, false },
2452 kEmptyMatch }, 2481 kEmptyMatch },
2453 "3" }, 2482 "3" },
2454 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2483 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2455 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2484 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2456 "\"google:verbatimrelevance\":0," 2485 "\"google:verbatimrelevance\":0,"
2457 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", 2486 "\"google:suggestrelevance\":[9998, 9999, 9997]}]",
2458 { { "a3", true, true }, 2487 { { "a2.com", false, false },
2459 { "a2.com", false, true }, 2488 { "a1.com", false, false },
2460 { "a1.com", false, true }, 2489 { "a3", true, true },
2461 { "k a", false, true }, 2490 { "k a", false, false },
2462 kEmptyMatch, kEmptyMatch }, 2491 kEmptyMatch, kEmptyMatch },
2463 "3" }, 2492 "3" },
2464 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2493 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2465 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2494 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2466 "\"google:verbatimrelevance\":0," 2495 "\"google:verbatimrelevance\":0,"
2467 "\"google:suggestrelevance\":[9999, 9998, 9997]}]", 2496 "\"google:suggestrelevance\":[9999, 9998, 9997]}]",
2468 { { "a3", true, true }, 2497 { { "a1.com", false, false },
2469 { "a1.com", false, true }, 2498 { "a2.com", false, false },
2470 { "a2.com", false, true }, 2499 { "a3", true, true },
2471 { "k a", false, true }, 2500 { "k a", false, false },
2472 kEmptyMatch, kEmptyMatch }, 2501 kEmptyMatch, kEmptyMatch },
2473 "3" }, 2502 "3" },
2474 // Check when there is neither verbatim nor a query suggestion that, 2503 // Check when there is neither verbatim nor a query suggestion that,
2475 // because we can't demote navsuggestions below a query suggestion, 2504 // because we can't demote navsuggestions below a query suggestion,
2476 // we abandon suggested relevance scores entirely. One consequence is 2505 // we restore the keyword verbatim score.
2477 // that this means we restore the keyword verbatim match. Note
2478 // that in this case of abandoning suggested relevance scores, we still
2479 // keep the navsuggestions in the same order, but we revert to only allowing
2480 // one navigation to appear because the scores are completely local.
2481 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 2506 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
2482 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 2507 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2483 "\"google:verbatimrelevance\":0," 2508 "\"google:verbatimrelevance\":0,"
2484 "\"google:suggestrelevance\":[9998, 9999]}]", 2509 "\"google:suggestrelevance\":[9998, 9999]}]",
2485 { { "a", true, true }, 2510 { { "a2.com", false, false },
2486 { "a2.com", false, true }, 2511 { "a1.com", false, false },
2487 { "k a", false, true }, 2512 { "a", true, true },
2488 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2513 { "k a", false, false },
2514 kEmptyMatch, kEmptyMatch },
2489 std::string() }, 2515 std::string() },
2490 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," 2516 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[],"
2491 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," 2517 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"],"
2492 "\"google:verbatimrelevance\":0," 2518 "\"google:verbatimrelevance\":0,"
2493 "\"google:suggestrelevance\":[9999, 9998]}]", 2519 "\"google:suggestrelevance\":[9999, 9998]}]",
2494 { { "a", true, true }, 2520 { { "a1.com", false, false },
2495 { "a1.com", false, true }, 2521 { "a2.com", false, false },
2496 { "k a", false, true }, 2522 { "a", true, true },
2497 kEmptyMatch, kEmptyMatch, kEmptyMatch }, 2523 { "k a", false, false },
2524 kEmptyMatch, kEmptyMatch },
2498 std::string() }, 2525 std::string() },
2499 // More checks that everything works when it's not necessary to demote. 2526 // More checks that everything works when it's not necessary to demote.
2500 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2527 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2501 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2528 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2502 "\"google:verbatimrelevance\":9990," 2529 "\"google:verbatimrelevance\":9990,"
2503 "\"google:suggestrelevance\":[9997, 9998, 9999]}]", 2530 "\"google:suggestrelevance\":[9997, 9998, 9999]}]",
2504 { { "a3", true, true }, 2531 { { "a3", true, true },
2505 { "a2.com", false, true }, 2532 { "a2.com", false, false },
2506 { "a1.com", false, true }, 2533 { "a1.com", false, false },
2507 { "a", true, true }, 2534 { "a", true, true },
2508 { "k a", false, true }, 2535 { "k a", false, false },
2509 kEmptyMatch }, 2536 kEmptyMatch },
2510 "3" }, 2537 "3" },
2511 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," 2538 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[],"
2512 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," 2539 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"],"
2513 "\"google:verbatimrelevance\":9990," 2540 "\"google:verbatimrelevance\":9990,"
2514 "\"google:suggestrelevance\":[9998, 9997, 9999]}]", 2541 "\"google:suggestrelevance\":[9998, 9997, 9999]}]",
2515 { { "a3", true, true }, 2542 { { "a3", true, true },
2516 { "a1.com", false, true }, 2543 { "a1.com", false, false },
2517 { "a2.com", false, true }, 2544 { "a2.com", false, false },
2518 { "a", true, true }, 2545 { "a", true, true },
2519 { "k a", false, true }, 2546 { "k a", false, false },
2520 kEmptyMatch }, 2547 kEmptyMatch },
2521 "3" }, 2548 "3" },
2522 }; 2549 };
2523 2550
2524 std::map<std::string, std::string> params; 2551 std::map<std::string, std::string> params;
2525 params[std::string(OmniboxFieldTrial::kReorderForLegalDefaultMatchRule) + 2552 params[std::string(OmniboxFieldTrial::kReorderForLegalDefaultMatchRule) +
2526 ":*:*"] = OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled; 2553 ":*:*"] = OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled;
2527 ASSERT_TRUE(chrome_variations::AssociateVariationParams( 2554 ASSERT_TRUE(chrome_variations::AssociateVariationParams(
2528 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params)); 2555 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params));
2529 base::FieldTrialList::CreateFieldTrial( 2556 base::FieldTrialList::CreateFieldTrial(
(...skipping 17 matching lines...) Expand all
2547 SearchProvider::kKeywordProviderURLFetcherID); 2574 SearchProvider::kKeywordProviderURLFetcherID);
2548 ASSERT_TRUE(keyword_fetcher); 2575 ASSERT_TRUE(keyword_fetcher);
2549 keyword_fetcher->set_response_code(200); 2576 keyword_fetcher->set_response_code(200);
2550 keyword_fetcher->SetResponseString(cases[i].json); 2577 keyword_fetcher->SetResponseString(cases[i].json);
2551 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); 2578 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher);
2552 keyword_fetcher = NULL; 2579 keyword_fetcher = NULL;
2553 RunTillProviderDone(); 2580 RunTillProviderDone();
2554 2581
2555 const std::string description = "for input with json=" + cases[i].json; 2582 const std::string description = "for input with json=" + cases[i].json;
2556 const ACMatches& matches = provider_->matches(); 2583 const ACMatches& matches = provider_->matches();
2557 // The top match must inline and score as highly as calculated verbatim.
2558 ASSERT_FALSE(matches.empty()); 2584 ASSERT_FALSE(matches.empty());
2585 // Find the first match that's allowed to be the default match and check
2586 // its inline_autocompletion.
2587 ACMatches::const_iterator it = FindDefaultMatch(matches);
2588 ASSERT_NE(matches.end(), it);
2559 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), 2589 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion),
2560 matches[0].inline_autocompletion) << description; 2590 it->inline_autocompletion) << description;
2561 2591
2562 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); 2592 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches));
2563 size_t j = 0; 2593 size_t j = 0;
2564 // Ensure that the returned matches equal the expectations. 2594 // Ensure that the returned matches equal the expectations.
2565 for (; j < matches.size(); ++j) { 2595 for (; j < matches.size(); ++j) {
2566 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), 2596 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents),
2567 matches[j].contents) << description; 2597 matches[j].contents) << description;
2568 EXPECT_EQ(cases[i].matches[j].from_keyword, 2598 EXPECT_EQ(cases[i].matches[j].from_keyword,
2569 matches[j].keyword == ASCIIToUTF16("k")) << description; 2599 matches[j].keyword == ASCIIToUTF16("k")) << description;
2570 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, 2600 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match,
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
3943 AutocompleteInput::OTHER, &profile_)); 3973 AutocompleteInput::OTHER, &profile_));
3944 encrypted_types.Remove(syncer::SESSIONS); 3974 encrypted_types.Remove(syncer::SESSIONS);
3945 service->OnEncryptedTypesChanged(encrypted_types, false); 3975 service->OnEncryptedTypesChanged(encrypted_types, false);
3946 3976
3947 // Check that there were no side effects from previous tests. 3977 // Check that there were no side effects from previous tests.
3948 EXPECT_TRUE(SearchProvider::CanSendURL( 3978 EXPECT_TRUE(SearchProvider::CanSendURL(
3949 GURL("http://www.google.com/search"), 3979 GURL("http://www.google.com/search"),
3950 GURL("https://www.google.com/complete/search"), &google_template_url, 3980 GURL("https://www.google.com/complete/search"), &google_template_url,
3951 AutocompleteInput::OTHER, &profile_)); 3981 AutocompleteInput::OTHER, &profile_));
3952 } 3982 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698