| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // Tell the SearchProvider the default suggest query is done. | 430 // Tell the SearchProvider the default suggest query is done. |
| 431 default_fetcher->set_response_code(200); | 431 default_fetcher->set_response_code(200); |
| 432 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); | 432 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
| 433 } | 433 } |
| 434 | 434 |
| 435 void SearchProviderTest::ForcedQueryTestHelper( | 435 void SearchProviderTest::ForcedQueryTestHelper( |
| 436 const std::string& input, | 436 const std::string& input, |
| 437 const std::string& json, | 437 const std::string& json, |
| 438 const std::string expected_matches[3], | 438 const std::string expected_matches[3], |
| 439 const std::string& error_description) { | 439 const std::string& error_description) { |
| 440 QueryForInput(ASCIIToUTF16(input), false, false); | 440 // Send the query twice in order to bypass checks about whether a single |
| 441 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 441 // new reply can change the inline autocompletion. |
| 442 SearchProvider::kDefaultProviderURLFetcherID); | 442 for (size_t i = 0; i < 2; i++) { |
| 443 ASSERT_TRUE(fetcher); | 443 QueryForInput(ASCIIToUTF16(input), false, false); |
| 444 fetcher->set_response_code(200); | 444 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| 445 fetcher->SetResponseString(json); | 445 SearchProvider::kDefaultProviderURLFetcherID); |
| 446 fetcher->delegate()->OnURLFetchComplete(fetcher); | 446 ASSERT_TRUE(fetcher); |
| 447 RunTillProviderDone(); | 447 fetcher->set_response_code(200); |
| 448 fetcher->SetResponseString(json); |
| 449 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 450 RunTillProviderDone(); |
| 451 } |
| 448 | 452 |
| 449 const ACMatches& matches = provider_->matches(); | 453 const ACMatches& matches = provider_->matches(); |
| 450 ASSERT_LE(matches.size(), 3u); | 454 ASSERT_LE(matches.size(), 3u); |
| 451 size_t i = 0; | 455 size_t i = 0; |
| 452 // Ensure that the returned matches equal the expectations. | 456 // Ensure that the returned matches equal the expectations. |
| 453 for (; i < matches.size(); ++i) { | 457 for (; i < matches.size(); ++i) { |
| 454 EXPECT_EQ(ASCIIToUTF16(expected_matches[i]), matches[i].contents) << | 458 EXPECT_EQ(ASCIIToUTF16(expected_matches[i]), matches[i].contents) << |
| 455 error_description; | 459 error_description; |
| 456 } | 460 } |
| 457 // Ensure that no expected matches are missing. | 461 // Ensure that no expected matches are missing. |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1123 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1120 fetcher = NULL; | 1124 fetcher = NULL; |
| 1121 | 1125 |
| 1122 // Run till the history results complete. | 1126 // Run till the history results complete. |
| 1123 RunTillProviderDone(); | 1127 RunTillProviderDone(); |
| 1124 | 1128 |
| 1125 // Make sure the only match is 'a.com' and it doesn't have a template_url. | 1129 // Make sure the only match is 'a.com' and it doesn't have a template_url. |
| 1126 AutocompleteMatch nav_match; | 1130 AutocompleteMatch nav_match; |
| 1127 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); | 1131 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); |
| 1128 EXPECT_TRUE(nav_match.keyword.empty()); | 1132 EXPECT_TRUE(nav_match.keyword.empty()); |
| 1129 EXPECT_TRUE(nav_match.allowed_to_be_default_match); | 1133 EXPECT_FALSE(nav_match.allowed_to_be_default_match); |
| 1130 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match)); | 1134 EXPECT_FALSE(FindMatchWithDestination(GURL("http://a.com/b"), &nav_match)); |
| 1131 } | 1135 } |
| 1132 | 1136 |
| 1133 // Verifies that the most relevant suggest results are added properly. | 1137 // Verifies that the most relevant suggest results are added properly. |
| 1134 TEST_F(SearchProviderTest, SuggestRelevance) { | 1138 TEST_F(SearchProviderTest, SuggestRelevance) { |
| 1135 QueryForInput(ASCIIToUTF16("a"), false, false); | 1139 QueryForInput(ASCIIToUTF16("a"), false, false); |
| 1136 | 1140 |
| 1137 // Make sure the default provider's suggest service was queried. | 1141 // Make sure the default provider's suggest service was queried. |
| 1138 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 1142 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| 1139 SearchProvider::kDefaultProviderURLFetcherID); | 1143 SearchProvider::kDefaultProviderURLFetcherID); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1152 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4; | 1156 AutocompleteMatch verbatim, match_a1, match_a2, match_a3, match_a4; |
| 1153 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim)); | 1157 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a"), &verbatim)); |
| 1154 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1)); | 1158 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a1"), &match_a1)); |
| 1155 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2)); | 1159 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a2"), &match_a2)); |
| 1156 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3)); | 1160 EXPECT_TRUE(FindMatchWithContents(ASCIIToUTF16("a3"), &match_a3)); |
| 1157 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4)); | 1161 EXPECT_FALSE(FindMatchWithContents(ASCIIToUTF16("a4"), &match_a4)); |
| 1158 EXPECT_GT(verbatim.relevance, match_a1.relevance); | 1162 EXPECT_GT(verbatim.relevance, match_a1.relevance); |
| 1159 EXPECT_GT(match_a1.relevance, match_a2.relevance); | 1163 EXPECT_GT(match_a1.relevance, match_a2.relevance); |
| 1160 EXPECT_GT(match_a2.relevance, match_a3.relevance); | 1164 EXPECT_GT(match_a2.relevance, match_a3.relevance); |
| 1161 EXPECT_TRUE(verbatim.allowed_to_be_default_match); | 1165 EXPECT_TRUE(verbatim.allowed_to_be_default_match); |
| 1162 EXPECT_TRUE(match_a1.allowed_to_be_default_match); | 1166 EXPECT_FALSE(match_a1.allowed_to_be_default_match); |
| 1163 EXPECT_TRUE(match_a2.allowed_to_be_default_match); | 1167 EXPECT_FALSE(match_a2.allowed_to_be_default_match); |
| 1164 EXPECT_TRUE(match_a3.allowed_to_be_default_match); | 1168 EXPECT_FALSE(match_a3.allowed_to_be_default_match); |
| 1165 } | 1169 } |
| 1166 | 1170 |
| 1167 // Verifies that the default provider abandons suggested relevance scores | 1171 // Verifies that the default provider abandons suggested relevance scores |
| 1168 // when in keyword mode. This should happen regardless of whether the | 1172 // when in keyword mode. This should happen regardless of whether the |
| 1169 // keyword provider returns suggested relevance scores. | 1173 // keyword provider returns suggested relevance scores. |
| 1170 TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) { | 1174 TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) { |
| 1171 struct { | 1175 struct { |
| 1172 const std::string default_provider_json; | 1176 const std::string default_provider_json; |
| 1173 const std::string keyword_provider_json; | 1177 const std::string keyword_provider_json; |
| 1174 const std::string matches[5]; | 1178 const std::string matches[5]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1187 "{\"google:verbatimrelevance\":9700," | 1191 "{\"google:verbatimrelevance\":9700," |
| 1188 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 1192 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 1189 "\"google:suggestrelevance\":[9900, 9800]}]", | 1193 "\"google:suggestrelevance\":[9900, 9800]}]", |
| 1190 "[\"a\",[\"akeyword-query\"],[],[],{\"google:suggesttype\":[\"QUERY\"]," | 1194 "[\"a\",[\"akeyword-query\"],[],[],{\"google:suggesttype\":[\"QUERY\"]," |
| 1191 "\"google:verbatimrelevance\":9500," | 1195 "\"google:verbatimrelevance\":9500," |
| 1192 "\"google:suggestrelevance\":[9600]}]", | 1196 "\"google:suggestrelevance\":[9600]}]", |
| 1193 { "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } } | 1197 { "akeyword-query", "a", "k a", "adefault.com", "k adefault-query" } } |
| 1194 }; | 1198 }; |
| 1195 | 1199 |
| 1196 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1200 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1197 QueryForInput(ASCIIToUTF16("k a"), false, true); | 1201 // Send the query twice in order to bypass checks about whether a single |
| 1198 net::TestURLFetcher* default_fetcher = | 1202 // new reply can change the inline autocompletion. |
| 1199 test_factory_.GetFetcherByID( | 1203 for (size_t j = 0; j < 2; j++) { |
| 1200 SearchProvider::kDefaultProviderURLFetcherID); | 1204 QueryForInput(ASCIIToUTF16("k a"), false, true); |
| 1201 ASSERT_TRUE(default_fetcher); | 1205 net::TestURLFetcher* default_fetcher = |
| 1202 default_fetcher->set_response_code(200); | 1206 test_factory_.GetFetcherByID( |
| 1203 default_fetcher->SetResponseString(cases[i].default_provider_json); | 1207 SearchProvider::kDefaultProviderURLFetcherID); |
| 1204 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); | 1208 ASSERT_TRUE(default_fetcher); |
| 1205 net::TestURLFetcher* keyword_fetcher = | 1209 default_fetcher->set_response_code(200); |
| 1206 test_factory_.GetFetcherByID( | 1210 default_fetcher->SetResponseString(cases[i].default_provider_json); |
| 1207 SearchProvider::kKeywordProviderURLFetcherID); | 1211 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
| 1208 ASSERT_TRUE(keyword_fetcher); | 1212 net::TestURLFetcher* keyword_fetcher = |
| 1209 keyword_fetcher->set_response_code(200); | 1213 test_factory_.GetFetcherByID( |
| 1210 keyword_fetcher->SetResponseString(cases[i].keyword_provider_json); | 1214 SearchProvider::kKeywordProviderURLFetcherID); |
| 1211 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); | 1215 ASSERT_TRUE(keyword_fetcher); |
| 1212 RunTillProviderDone(); | 1216 keyword_fetcher->set_response_code(200); |
| 1217 keyword_fetcher->SetResponseString(cases[i].keyword_provider_json); |
| 1218 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); |
| 1219 RunTillProviderDone(); |
| 1220 } |
| 1213 | 1221 |
| 1214 const std::string description = "for input with default_provider_json=" + | 1222 const std::string description = "for input with default_provider_json=" + |
| 1215 cases[i].default_provider_json + " and keyword_provider_json=" + | 1223 cases[i].default_provider_json + " and keyword_provider_json=" + |
| 1216 cases[i].keyword_provider_json; | 1224 cases[i].keyword_provider_json; |
| 1217 const ACMatches& matches = provider_->matches(); | 1225 const ACMatches& matches = provider_->matches(); |
| 1218 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); | 1226 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); |
| 1219 size_t j = 0; | 1227 size_t j = 0; |
| 1220 // Ensure that the returned matches equal the expectations. | 1228 // Ensure that the returned matches equal the expectations. |
| 1221 for (; j < matches.size(); ++j) { | 1229 for (; j < matches.size(); ++j) { |
| 1222 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents) << | 1230 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j]), matches[j].contents) << |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," | 1268 { "[\"a\",[\"http://b.com\", \"http://c.com\"],[],[]," |
| 1261 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", | 1269 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]}]", |
| 1262 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch, | 1270 { { "a", true }, { "b.com", false }, kEmptyMatch, kEmptyMatch, |
| 1263 kEmptyMatch, kEmptyMatch }, | 1271 kEmptyMatch, kEmptyMatch }, |
| 1264 std::string() }, | 1272 std::string() }, |
| 1265 | 1273 |
| 1266 // Ensure that verbatimrelevance scores reorder or suppress verbatim. | 1274 // Ensure that verbatimrelevance scores reorder or suppress verbatim. |
| 1267 // Negative values will have no effect; the calculated value will be used. | 1275 // Negative values will have no effect; the calculated value will be used. |
| 1268 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," | 1276 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," |
| 1269 "\"google:suggestrelevance\":[9998]}]", | 1277 "\"google:suggestrelevance\":[9998]}]", |
| 1270 { { "a", true}, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1278 { { "a", true}, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1271 kEmptyMatch }, | 1279 kEmptyMatch }, |
| 1272 std::string() }, | 1280 std::string() }, |
| 1273 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," | 1281 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," |
| 1274 "\"google:suggestrelevance\":[9999]}]", | 1282 "\"google:suggestrelevance\":[9999]}]", |
| 1275 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1283 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1276 kEmptyMatch }, | 1284 kEmptyMatch }, |
| 1277 "1" }, | 1285 "1" }, |
| 1278 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," | 1286 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":0," |
| 1279 "\"google:suggestrelevance\":[9999]}]", | 1287 "\"google:suggestrelevance\":[9999]}]", |
| 1280 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1288 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1281 kEmptyMatch }, | 1289 kEmptyMatch }, |
| 1282 "1" }, | 1290 "1" }, |
| 1283 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," | 1291 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":-1," |
| 1284 "\"google:suggestrelevance\":[9999]}]", | 1292 "\"google:suggestrelevance\":[9999]}]", |
| 1285 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1293 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1286 kEmptyMatch }, | 1294 kEmptyMatch }, |
| 1287 "1" }, | 1295 "1" }, |
| 1288 { "[\"a\",[\"http://a.com\"],[],[]," | 1296 { "[\"a\",[\"http://a.com\"],[],[]," |
| 1289 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1297 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1290 "\"google:verbatimrelevance\":9999," | 1298 "\"google:verbatimrelevance\":9999," |
| 1291 "\"google:suggestrelevance\":[9998]}]", | 1299 "\"google:suggestrelevance\":[9998]}]", |
| 1292 { { "a", true }, { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1300 { { "a", true }, { "a.com", false }, kEmptyMatch, kEmptyMatch, |
| 1293 kEmptyMatch }, | 1301 kEmptyMatch, kEmptyMatch }, |
| 1294 std::string() }, | 1302 std::string() }, |
| 1295 { "[\"a\",[\"http://a.com\"],[],[]," | 1303 { "[\"a\",[\"http://a.com\"],[],[]," |
| 1296 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1304 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1297 "\"google:verbatimrelevance\":9998," | 1305 "\"google:verbatimrelevance\":9998," |
| 1298 "\"google:suggestrelevance\":[9999]}]", | 1306 "\"google:suggestrelevance\":[9999]}]", |
| 1299 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1307 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1300 kEmptyMatch }, | 1308 kEmptyMatch }, |
| 1301 ".com" }, | 1309 ".com" }, |
| 1302 { "[\"a\",[\"http://a.com\"],[],[]," | 1310 { "[\"a\",[\"http://a.com\"],[],[]," |
| 1303 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1311 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1304 "\"google:verbatimrelevance\":0," | 1312 "\"google:verbatimrelevance\":0," |
| 1305 "\"google:suggestrelevance\":[9999]}]", | 1313 "\"google:suggestrelevance\":[9999]}]", |
| 1306 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1314 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1307 kEmptyMatch }, | 1315 kEmptyMatch }, |
| 1308 ".com" }, | 1316 ".com" }, |
| 1309 { "[\"a\",[\"http://a.com\"],[],[]," | 1317 { "[\"a\",[\"http://a.com\"],[],[]," |
| 1310 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1318 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1311 "\"google:verbatimrelevance\":-1," | 1319 "\"google:verbatimrelevance\":-1," |
| 1312 "\"google:suggestrelevance\":[9999]}]", | 1320 "\"google:suggestrelevance\":[9999]}]", |
| 1313 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1321 { { "a.com", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1314 kEmptyMatch }, | 1322 kEmptyMatch }, |
| 1315 ".com" }, | 1323 ".com" }, |
| 1316 | 1324 |
| 1317 // Ensure that both types of relevance scores reorder matches together. | 1325 // Ensure that both types of relevance scores reorder matches together. |
| 1318 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," | 1326 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," |
| 1319 "\"google:verbatimrelevance\":9998}]", | 1327 "\"google:verbatimrelevance\":9998}]", |
| 1320 { { "a1", true }, { "a", true }, { "a2", true }, kEmptyMatch, kEmptyMatch, | 1328 { { "a1", true }, { "a", true }, { "a2", false }, kEmptyMatch, |
| 1321 kEmptyMatch }, | 1329 kEmptyMatch, kEmptyMatch }, |
| 1322 "1" }, | 1330 "1" }, |
| 1323 | 1331 |
| 1324 // Allow non-inlineable matches to be the highest-scoring match but, | 1332 // Allow non-inlineable matches to be the highest-scoring match but, |
| 1325 // if the result set lacks a single inlineable result, abandon suggested | 1333 // if the result set lacks a single inlineable result, abandon suggested |
| 1326 // relevance scores entirely. | 1334 // relevance scores entirely. |
| 1327 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", | 1335 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", |
| 1328 { { "b", false }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1336 { { "b", false }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1329 kEmptyMatch }, | 1337 kEmptyMatch }, |
| 1330 std::string() }, | 1338 std::string() }, |
| 1331 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," | 1339 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]," |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1356 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1364 { { "a1", true }, { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1357 kEmptyMatch }, | 1365 kEmptyMatch }, |
| 1358 "1" }, | 1366 "1" }, |
| 1359 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," | 1367 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[1]," |
| 1360 "\"google:verbatimrelevance\":0}]", | 1368 "\"google:verbatimrelevance\":0}]", |
| 1361 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1369 { { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1362 kEmptyMatch }, | 1370 kEmptyMatch }, |
| 1363 "1" }, | 1371 "1" }, |
| 1364 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," | 1372 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," |
| 1365 "\"google:verbatimrelevance\":0}]", | 1373 "\"google:verbatimrelevance\":0}]", |
| 1366 { { "a2", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1374 { { "a2", true }, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1367 kEmptyMatch }, | 1375 kEmptyMatch }, |
| 1368 "2" }, | 1376 "2" }, |
| 1369 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," | 1377 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," |
| 1370 "\"google:verbatimrelevance\":2}]", | 1378 "\"google:verbatimrelevance\":2}]", |
| 1371 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, | 1379 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch, |
| 1372 kEmptyMatch }, | 1380 kEmptyMatch, kEmptyMatch }, |
| 1373 "2" }, | 1381 "2" }, |
| 1374 { "[\"a\",[\"http://a.com\"],[],[]," | 1382 { "[\"a\",[\"http://a.com\"],[],[]," |
| 1375 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1383 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1376 "\"google:suggestrelevance\":[1]," | 1384 "\"google:suggestrelevance\":[1]," |
| 1377 "\"google:verbatimrelevance\":0}]", | 1385 "\"google:verbatimrelevance\":0}]", |
| 1378 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1386 { { "a.com", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1379 kEmptyMatch }, | 1387 kEmptyMatch }, |
| 1380 ".com" }, | 1388 ".com" }, |
| 1381 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1389 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1382 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1390 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1383 "\"google:suggestrelevance\":[1, 2]," | 1391 "\"google:suggestrelevance\":[1, 2]," |
| 1384 "\"google:verbatimrelevance\":0}]", | 1392 "\"google:verbatimrelevance\":0}]", |
| 1385 { { "a2.com", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, | 1393 { { "a2.com", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch, |
| 1386 kEmptyMatch, kEmptyMatch }, | 1394 kEmptyMatch, kEmptyMatch }, |
| 1387 "2.com" }, | 1395 "2.com" }, |
| 1388 | 1396 |
| 1389 // Ensure that all suggestions are considered, regardless of order. | 1397 // Ensure that all suggestions are considered, regardless of order. |
| 1390 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," | 1398 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," |
| 1391 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1399 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
| 1392 { { "a", true }, { "h", false }, { "g", false }, { "f", false }, | 1400 { { "a", true }, { "h", false }, { "g", false }, { "f", false }, |
| 1393 { "e", false }, { "d", false } }, | 1401 { "e", false }, { "d", false } }, |
| 1394 std::string() }, | 1402 std::string() }, |
| 1395 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," | 1403 { "[\"a\",[\"http://b.com\", \"http://c.com\", \"http://d.com\"," |
| 1396 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," | 1404 "\"http://e.com\", \"http://f.com\", \"http://g.com\"," |
| 1397 "\"http://h.com\"],[],[]," | 1405 "\"http://h.com\"],[],[]," |
| 1398 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," | 1406 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"," |
| 1399 "\"NAVIGATION\", \"NAVIGATION\"," | 1407 "\"NAVIGATION\", \"NAVIGATION\"," |
| 1400 "\"NAVIGATION\", \"NAVIGATION\"," | 1408 "\"NAVIGATION\", \"NAVIGATION\"," |
| 1401 "\"NAVIGATION\"]," | 1409 "\"NAVIGATION\"]," |
| 1402 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1410 "\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
| 1403 { { "a", true }, { "h.com", false }, { "g.com", false }, | 1411 { { "a", true }, { "h.com", false }, { "g.com", false }, |
| 1404 { "f.com", false }, { "e.com", false }, { "d.com", false } }, | 1412 { "f.com", false }, { "e.com", false }, { "d.com", false } }, |
| 1405 std::string() }, | 1413 std::string() }, |
| 1406 | 1414 |
| 1407 // Ensure that incorrectly sized suggestion relevance lists are ignored. | 1415 // Ensure that incorrectly sized suggestion relevance lists are ignored. |
| 1408 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", | 1416 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", |
| 1409 { { "a", true }, { "a1", true }, { "a2", true }, kEmptyMatch, kEmptyMatch, | 1417 { { "a", true }, { "a1", false }, { "a2", false }, kEmptyMatch, |
| 1410 kEmptyMatch }, | 1418 kEmptyMatch, kEmptyMatch }, |
| 1411 std::string() }, | 1419 std::string() }, |
| 1412 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", | 1420 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", |
| 1413 { { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1421 { { "a", true }, { "a1", false }, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1414 kEmptyMatch }, | 1422 kEmptyMatch }, |
| 1415 std::string() }, | 1423 std::string() }, |
| 1416 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1424 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1417 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1425 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1418 "\"google:suggestrelevance\":[1]}]", | 1426 "\"google:suggestrelevance\":[1]}]", |
| 1419 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, | 1427 { { "a", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch, |
| 1420 kEmptyMatch, kEmptyMatch }, | 1428 kEmptyMatch, kEmptyMatch }, |
| 1421 std::string() }, | 1429 std::string() }, |
| 1422 { "[\"a\",[\"http://a1.com\"],[],[]," | 1430 { "[\"a\",[\"http://a1.com\"],[],[]," |
| 1423 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1431 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1424 "\"google:suggestrelevance\":[9999, 1]}]", | 1432 "\"google:suggestrelevance\":[9999, 1]}]", |
| 1425 { { "a", true }, { "a1.com", true }, kEmptyMatch, kEmptyMatch, | 1433 { { "a", true }, { "a1.com", false }, kEmptyMatch, kEmptyMatch, |
| 1426 kEmptyMatch, kEmptyMatch }, | 1434 kEmptyMatch, kEmptyMatch }, |
| 1427 std::string() }, | 1435 std::string() }, |
| 1428 | 1436 |
| 1429 // Ensure that all 'verbatim' results are merged with their maximum score. | 1437 // Ensure that all 'verbatim' results are merged with their maximum score. |
| 1430 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1438 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
| 1431 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", | 1439 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", |
| 1432 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, | 1440 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch, |
| 1433 kEmptyMatch }, | 1441 kEmptyMatch, kEmptyMatch }, |
| 1434 "2" }, | 1442 "2" }, |
| 1435 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1443 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
| 1436 "{\"google:suggestrelevance\":[9998, 9997, 9999]," | 1444 "{\"google:suggestrelevance\":[9998, 9997, 9999]," |
| 1437 "\"google:verbatimrelevance\":0}]", | 1445 "\"google:verbatimrelevance\":0}]", |
| 1438 { { "a2", true }, { "a", true }, { "a1", true }, kEmptyMatch, kEmptyMatch, | 1446 { { "a2", true }, { "a", true }, { "a1", false }, kEmptyMatch, |
| 1439 kEmptyMatch }, | 1447 kEmptyMatch, kEmptyMatch }, |
| 1440 "2" }, | 1448 "2" }, |
| 1441 | 1449 |
| 1442 // Ensure that verbatim is always generated without other suggestions. | 1450 // Ensure that verbatim is always generated without other suggestions. |
| 1443 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). | 1451 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). |
| 1444 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", | 1452 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", |
| 1445 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1453 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1446 kEmptyMatch }, | 1454 kEmptyMatch }, |
| 1447 std::string() }, | 1455 std::string() }, |
| 1448 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", | 1456 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", |
| 1449 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, | 1457 { { "a", true }, kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch, |
| 1450 kEmptyMatch }, | 1458 kEmptyMatch }, |
| 1451 std::string() }, | 1459 std::string() }, |
| 1452 }; | 1460 }; |
| 1453 | 1461 |
| 1454 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1462 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1455 QueryForInput(ASCIIToUTF16("a"), false, false); | 1463 // Send the query twice in order to bypass checks about whether a single |
| 1456 net::TestURLFetcher* fetcher = | 1464 // new reply can change the inline autocompletion. |
| 1457 test_factory_.GetFetcherByID( | 1465 for (size_t j = 0; j < 2; j++) { |
| 1458 SearchProvider::kDefaultProviderURLFetcherID); | 1466 QueryForInput(ASCIIToUTF16("a"), false, false); |
| 1459 ASSERT_TRUE(fetcher); | 1467 net::TestURLFetcher* fetcher = |
| 1460 fetcher->set_response_code(200); | 1468 test_factory_.GetFetcherByID( |
| 1461 fetcher->SetResponseString(cases[i].json); | 1469 SearchProvider::kDefaultProviderURLFetcherID); |
| 1462 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1470 ASSERT_TRUE(fetcher); |
| 1463 RunTillProviderDone(); | 1471 fetcher->set_response_code(200); |
| 1472 fetcher->SetResponseString(cases[i].json); |
| 1473 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1474 RunTillProviderDone(); |
| 1475 } |
| 1464 | 1476 |
| 1465 const std::string description = "for input with json=" + cases[i].json; | 1477 const std::string description = "for input with json=" + cases[i].json; |
| 1466 const ACMatches& matches = provider_->matches(); | 1478 const ACMatches& matches = provider_->matches(); |
| 1467 ASSERT_FALSE(matches.empty()); | 1479 ASSERT_FALSE(matches.empty()); |
| 1468 // Find the first match that's allowed to be the default match and check | 1480 // Find the first match that's allowed to be the default match and check |
| 1469 // its inline_autocompletion. | 1481 // its inline_autocompletion. |
| 1470 ACMatches::const_iterator it = FindDefaultMatch(matches); | 1482 ACMatches::const_iterator it = FindDefaultMatch(matches); |
| 1471 ASSERT_NE(matches.end(), it); | 1483 ASSERT_NE(matches.end(), it); |
| 1472 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 1484 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 1473 it->inline_autocompletion) << description; | 1485 it->inline_autocompletion) << description; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 { "b.com", false, false }, | 1555 { "b.com", false, false }, |
| 1544 { "k a", false, false }, | 1556 { "k a", false, false }, |
| 1545 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1557 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1546 std::string() }, | 1558 std::string() }, |
| 1547 | 1559 |
| 1548 // Ensure that verbatimrelevance scores reorder or suppress verbatim. | 1560 // Ensure that verbatimrelevance scores reorder or suppress verbatim. |
| 1549 // Negative values will have no effect; the calculated value will be used. | 1561 // Negative values will have no effect; the calculated value will be used. |
| 1550 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," | 1562 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9999," |
| 1551 "\"google:suggestrelevance\":[9998]}]", | 1563 "\"google:suggestrelevance\":[9998]}]", |
| 1552 { { "a", true, true }, | 1564 { { "a", true, true }, |
| 1553 { "a1", true, true }, | 1565 { "a1", true, false }, |
| 1554 { "k a", false, false }, | 1566 { "k a", false, false }, |
| 1555 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1567 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1556 std::string() }, | 1568 std::string() }, |
| 1557 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," | 1569 { "[\"a\",[\"a1\"],[],[],{\"google:verbatimrelevance\":9998," |
| 1558 "\"google:suggestrelevance\":[9999]}]", | 1570 "\"google:suggestrelevance\":[9999]}]", |
| 1559 { { "a1", true, true }, | 1571 { { "a1", true, true }, |
| 1560 { "a", true, true }, | 1572 { "a", true, true }, |
| 1561 { "k a", false, false }, | 1573 { "k a", false, false }, |
| 1562 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1574 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1563 "1" }, | 1575 "1" }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1582 { "a.com", false, false }, | 1594 { "a.com", false, false }, |
| 1583 { "k a", false, false }, | 1595 { "k a", false, false }, |
| 1584 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1596 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1585 std::string() }, | 1597 std::string() }, |
| 1586 | 1598 |
| 1587 // Ensure that both types of relevance scores reorder matches together. | 1599 // Ensure that both types of relevance scores reorder matches together. |
| 1588 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," | 1600 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[9999, 9997]," |
| 1589 "\"google:verbatimrelevance\":9998}]", | 1601 "\"google:verbatimrelevance\":9998}]", |
| 1590 { { "a1", true, true }, | 1602 { { "a1", true, true }, |
| 1591 { "a", true, true }, | 1603 { "a", true, true }, |
| 1592 { "a2", true, true }, | 1604 { "a2", true, false }, |
| 1593 { "k a", false, false }, | 1605 { "k a", false, false }, |
| 1594 kEmptyMatch, kEmptyMatch }, | 1606 kEmptyMatch, kEmptyMatch }, |
| 1595 "1" }, | 1607 "1" }, |
| 1596 | 1608 |
| 1597 // Check that non-inlinable matches may be ranked as the highest result | 1609 // Check that non-inlinable matches may be ranked as the highest result |
| 1598 // if there is at least one inlineable match. | 1610 // if there is at least one inlineable match. |
| 1599 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", | 1611 { "[\"a\",[\"b\"],[],[],{\"google:suggestrelevance\":[9999]}]", |
| 1600 { { "b", true, false }, | 1612 { { "b", true, false }, |
| 1601 { "a", true, true }, | 1613 { "a", true, true }, |
| 1602 { "k a", false, false }, | 1614 { "k a", false, false }, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1647 "\"google:verbatimrelevance\":0}]", | 1659 "\"google:verbatimrelevance\":0}]", |
| 1648 { { "k a", false, false }, | 1660 { { "k a", false, false }, |
| 1649 { "a1", true, true }, | 1661 { "a1", true, true }, |
| 1650 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1662 kEmptyMatch, kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1651 "1" }, | 1663 "1" }, |
| 1652 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," | 1664 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 2]," |
| 1653 "\"google:verbatimrelevance\":0}]", | 1665 "\"google:verbatimrelevance\":0}]", |
| 1654 { | 1666 { |
| 1655 { "k a", false, false }, | 1667 { "k a", false, false }, |
| 1656 { "a2", true, true }, | 1668 { "a2", true, true }, |
| 1657 { "a1", true, true }, | 1669 { "a1", true, false }, |
| 1658 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1670 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1659 "2" }, | 1671 "2" }, |
| 1660 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," | 1672 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1, 3]," |
| 1661 "\"google:verbatimrelevance\":2}]", | 1673 "\"google:verbatimrelevance\":2}]", |
| 1662 { { "k a", false, false }, | 1674 { { "k a", false, false }, |
| 1663 { "a2", true, true }, | 1675 { "a2", true, true }, |
| 1664 { "a", true, true }, | 1676 { "a", true, true }, |
| 1665 { "a1", true, true }, | 1677 { "a1", true, false }, |
| 1666 kEmptyMatch, kEmptyMatch }, | 1678 kEmptyMatch, kEmptyMatch }, |
| 1667 "2" }, | 1679 "2" }, |
| 1668 | 1680 |
| 1669 // Ensure that all suggestions are considered, regardless of order. | 1681 // Ensure that all suggestions are considered, regardless of order. |
| 1670 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," | 1682 { "[\"a\",[\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"],[],[]," |
| 1671 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", | 1683 "{\"google:suggestrelevance\":[1, 2, 3, 4, 5, 6, 7]}]", |
| 1672 { { "a", true, true }, | 1684 { { "a", true, true }, |
| 1673 { "k a", false, false }, | 1685 { "k a", false, false }, |
| 1674 { "h", true, false }, | 1686 { "h", true, false }, |
| 1675 { "g", true, false }, | 1687 { "g", true, false }, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1690 { "g.com", false, false }, | 1702 { "g.com", false, false }, |
| 1691 { "f.com", false, false }, | 1703 { "f.com", false, false }, |
| 1692 { "e.com", false, false } }, | 1704 { "e.com", false, false } }, |
| 1693 std::string() }, | 1705 std::string() }, |
| 1694 | 1706 |
| 1695 // Ensure that incorrectly sized suggestion relevance lists are ignored. | 1707 // Ensure that incorrectly sized suggestion relevance lists are ignored. |
| 1696 // Note that keyword suggestions by default (not in suggested relevance | 1708 // Note that keyword suggestions by default (not in suggested relevance |
| 1697 // mode) score more highly than the default verbatim. | 1709 // mode) score more highly than the default verbatim. |
| 1698 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", | 1710 { "[\"a\",[\"a1\", \"a2\"],[],[],{\"google:suggestrelevance\":[1]}]", |
| 1699 { { "a", true, true }, | 1711 { { "a", true, true }, |
| 1700 { "a1", true, true }, | 1712 { "a1", true, false }, |
| 1701 { "a2", true, true }, | 1713 { "a2", true, false }, |
| 1702 { "k a", false, false }, | 1714 { "k a", false, false }, |
| 1703 kEmptyMatch, kEmptyMatch }, | 1715 kEmptyMatch, kEmptyMatch }, |
| 1704 std::string() }, | 1716 std::string() }, |
| 1705 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", | 1717 { "[\"a\",[\"a1\"],[],[],{\"google:suggestrelevance\":[9999, 1]}]", |
| 1706 { { "a", true, true }, | 1718 { { "a", true, true }, |
| 1707 { "a1", true, true }, | 1719 { "a1", true, false }, |
| 1708 { "k a", false, false }, | 1720 { "k a", false, false }, |
| 1709 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1721 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1710 std::string() }, | 1722 std::string() }, |
| 1711 // In this case, ignoring the suggested relevance scores means we keep | 1723 // In this case, ignoring the suggested relevance scores means we keep |
| 1712 // only one navsuggest result. | 1724 // only one navsuggest result. |
| 1713 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," | 1725 { "[\"a\",[\"http://a1.com\", \"http://a2.com\"],[],[]," |
| 1714 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," | 1726 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 1715 "\"google:suggestrelevance\":[1]}]", | 1727 "\"google:suggestrelevance\":[1]}]", |
| 1716 { { "a", true, true }, | 1728 { { "a", true, true }, |
| 1717 { "a1.com", false, false }, | 1729 { "a1.com", false, false }, |
| 1718 { "k a", false, false }, | 1730 { "k a", false, false }, |
| 1719 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1731 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1720 std::string() }, | 1732 std::string() }, |
| 1721 { "[\"a\",[\"http://a1.com\"],[],[]," | 1733 { "[\"a\",[\"http://a1.com\"],[],[]," |
| 1722 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1734 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 1723 "\"google:suggestrelevance\":[9999, 1]}]", | 1735 "\"google:suggestrelevance\":[9999, 1]}]", |
| 1724 { { "a", true, true }, | 1736 { { "a", true, true }, |
| 1725 { "a1.com", false, false }, | 1737 { "a1.com", false, false }, |
| 1726 { "k a", false, false }, | 1738 { "k a", false, false }, |
| 1727 kEmptyMatch, kEmptyMatch, kEmptyMatch }, | 1739 kEmptyMatch, kEmptyMatch, kEmptyMatch }, |
| 1728 std::string() }, | 1740 std::string() }, |
| 1729 | 1741 |
| 1730 // Ensure that all 'verbatim' results are merged with their maximum score. | 1742 // Ensure that all 'verbatim' results are merged with their maximum score. |
| 1731 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1743 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
| 1732 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", | 1744 "{\"google:suggestrelevance\":[9998, 9997, 9999]}]", |
| 1733 { { "a2", true, true }, | 1745 { { "a2", true, true }, |
| 1734 { "a", true, true }, | 1746 { "a", true, true }, |
| 1735 { "a1", true, true }, | 1747 { "a1", true, false }, |
| 1736 { "k a", false, false }, | 1748 { "k a", false, false }, |
| 1737 kEmptyMatch, kEmptyMatch }, | 1749 kEmptyMatch, kEmptyMatch }, |
| 1738 "2" }, | 1750 "2" }, |
| 1739 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," | 1751 { "[\"a\",[\"a\", \"a1\", \"a2\"],[],[]," |
| 1740 "{\"google:suggestrelevance\":[9998, 9997, 9999]," | 1752 "{\"google:suggestrelevance\":[9998, 9997, 9999]," |
| 1741 "\"google:verbatimrelevance\":0}]", | 1753 "\"google:verbatimrelevance\":0}]", |
| 1742 { { "a2", true, true }, | 1754 { { "a2", true, true }, |
| 1743 { "a", true, true }, | 1755 { "a", true, true }, |
| 1744 { "a1", true, true }, | 1756 { "a1", true, false }, |
| 1745 { "k a", false, false }, | 1757 { "k a", false, false }, |
| 1746 kEmptyMatch, kEmptyMatch }, | 1758 kEmptyMatch, kEmptyMatch }, |
| 1747 "2" }, | 1759 "2" }, |
| 1748 | 1760 |
| 1749 // Ensure that verbatim is always generated without other suggestions. | 1761 // Ensure that verbatim is always generated without other suggestions. |
| 1750 // TODO(mpearson): Ensure the value of verbatimrelevance is respected | 1762 // TODO(mpearson): Ensure the value of verbatimrelevance is respected |
| 1751 // (except when suggested relevances are ignored). | 1763 // (except when suggested relevances are ignored). |
| 1752 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", | 1764 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", |
| 1753 { { "k a", false, false }, | 1765 { { "k a", false, false }, |
| 1754 { "a", true, true }, | 1766 { "a", true, true }, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1793 std::string() }, | 1805 std::string() }, |
| 1794 // Check when navsuggest scores more than verbatim and there is query | 1806 // Check when navsuggest scores more than verbatim and there is query |
| 1795 // suggestion but it scores lower. | 1807 // suggestion but it scores lower. |
| 1796 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1808 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1797 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1809 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1798 "\"google:verbatimrelevance\":9990," | 1810 "\"google:verbatimrelevance\":9990," |
| 1799 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", | 1811 "\"google:suggestrelevance\":[9998, 9999, 1300]}]", |
| 1800 { { "a2.com", false, false }, | 1812 { { "a2.com", false, false }, |
| 1801 { "a1.com", false, false }, | 1813 { "a1.com", false, false }, |
| 1802 { "a", true, true }, | 1814 { "a", true, true }, |
| 1803 { "a3", true, true }, | 1815 { "a3", true, false }, |
| 1804 { "k a", false, false }, | 1816 { "k a", false, false }, |
| 1805 kEmptyMatch }, | 1817 kEmptyMatch }, |
| 1806 std::string() }, | 1818 std::string() }, |
| 1807 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1819 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1808 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1820 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1809 "\"google:verbatimrelevance\":9990," | 1821 "\"google:verbatimrelevance\":9990," |
| 1810 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", | 1822 "\"google:suggestrelevance\":[9999, 9998, 1300]}]", |
| 1811 { { "a1.com", false, false }, | 1823 { { "a1.com", false, false }, |
| 1812 { "a2.com", false, false }, | 1824 { "a2.com", false, false }, |
| 1813 { "a", true, true }, | 1825 { "a", true, true }, |
| 1814 { "a3", true, true }, | 1826 { "a3", true, false }, |
| 1815 { "k a", false, false }, | 1827 { "k a", false, false }, |
| 1816 kEmptyMatch }, | 1828 kEmptyMatch }, |
| 1817 std::string() }, | 1829 std::string() }, |
| 1818 // Check when navsuggest scores more than a query suggestion. There is | 1830 // Check when navsuggest scores more than a query suggestion. There is |
| 1819 // a verbatim but it scores lower. | 1831 // a verbatim but it scores lower. |
| 1820 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," | 1832 { "[\"a\",[\"http://a1.com\", \"http://a2.com\", \"a3\"],[],[]," |
| 1821 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," | 1833 "{\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\", \"QUERY\"]," |
| 1822 "\"google:verbatimrelevance\":9990," | 1834 "\"google:verbatimrelevance\":9990," |
| 1823 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", | 1835 "\"google:suggestrelevance\":[9998, 9999, 9997]}]", |
| 1824 { { "a2.com", false, false }, | 1836 { { "a2.com", false, false }, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1901 { { "a3", true, true }, | 1913 { { "a3", true, true }, |
| 1902 { "a1.com", false, false }, | 1914 { "a1.com", false, false }, |
| 1903 { "a2.com", false, false }, | 1915 { "a2.com", false, false }, |
| 1904 { "a", true, true }, | 1916 { "a", true, true }, |
| 1905 { "k a", false, false }, | 1917 { "k a", false, false }, |
| 1906 kEmptyMatch }, | 1918 kEmptyMatch }, |
| 1907 "3" }, | 1919 "3" }, |
| 1908 }; | 1920 }; |
| 1909 | 1921 |
| 1910 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1922 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1911 QueryForInput(ASCIIToUTF16("k a"), false, true); | 1923 // Send the query twice in order to bypass checks about whether a single |
| 1924 // new reply can change the inline autocompletion. |
| 1925 for (size_t j = 0; j < 2; j++) { |
| 1926 QueryForInput(ASCIIToUTF16("k a"), false, true); |
| 1912 | 1927 |
| 1913 // Set up a default fetcher with no results. | 1928 // Set up a default fetcher with no results. |
| 1914 net::TestURLFetcher* default_fetcher = | 1929 net::TestURLFetcher* default_fetcher = |
| 1915 test_factory_.GetFetcherByID( | 1930 test_factory_.GetFetcherByID( |
| 1916 SearchProvider::kDefaultProviderURLFetcherID); | 1931 SearchProvider::kDefaultProviderURLFetcherID); |
| 1917 ASSERT_TRUE(default_fetcher); | 1932 ASSERT_TRUE(default_fetcher); |
| 1918 default_fetcher->set_response_code(200); | 1933 default_fetcher->set_response_code(200); |
| 1919 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); | 1934 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
| 1920 default_fetcher = NULL; | 1935 default_fetcher = NULL; |
| 1921 | 1936 |
| 1922 // Set up a keyword fetcher with provided results. | 1937 // Set up a keyword fetcher with provided results. |
| 1923 net::TestURLFetcher* keyword_fetcher = | 1938 net::TestURLFetcher* keyword_fetcher = |
| 1924 test_factory_.GetFetcherByID( | 1939 test_factory_.GetFetcherByID( |
| 1925 SearchProvider::kKeywordProviderURLFetcherID); | 1940 SearchProvider::kKeywordProviderURLFetcherID); |
| 1926 ASSERT_TRUE(keyword_fetcher); | 1941 ASSERT_TRUE(keyword_fetcher); |
| 1927 keyword_fetcher->set_response_code(200); | 1942 keyword_fetcher->set_response_code(200); |
| 1928 keyword_fetcher->SetResponseString(cases[i].json); | 1943 keyword_fetcher->SetResponseString(cases[i].json); |
| 1929 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); | 1944 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); |
| 1930 keyword_fetcher = NULL; | 1945 keyword_fetcher = NULL; |
| 1931 RunTillProviderDone(); | 1946 RunTillProviderDone(); |
| 1947 } |
| 1932 | 1948 |
| 1933 const std::string description = "for input with json=" + cases[i].json; | 1949 const std::string description = "for input with json=" + cases[i].json; |
| 1934 const ACMatches& matches = provider_->matches(); | 1950 const ACMatches& matches = provider_->matches(); |
| 1935 ASSERT_FALSE(matches.empty()); | 1951 ASSERT_FALSE(matches.empty()); |
| 1936 // Find the first match that's allowed to be the default match and check | 1952 // Find the first match that's allowed to be the default match and check |
| 1937 // its inline_autocompletion. | 1953 // its inline_autocompletion. |
| 1938 ACMatches::const_iterator it = FindDefaultMatch(matches); | 1954 ACMatches::const_iterator it = FindDefaultMatch(matches); |
| 1939 ASSERT_NE(matches.end(), it); | 1955 ASSERT_NE(matches.end(), it); |
| 1940 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 1956 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 1941 it->inline_autocompletion) << description; | 1957 it->inline_autocompletion) << description; |
| 1942 | 1958 |
| 1943 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); | 1959 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); |
| 1944 size_t j = 0; | 1960 size_t j = 0; |
| 1945 // Ensure that the returned matches equal the expectations. | 1961 // Ensure that the returned matches equal the expectations. |
| 1946 for (; j < matches.size(); ++j) { | 1962 for (; j < matches.size(); ++j) { |
| 1947 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), | 1963 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), |
| 1948 matches[j].contents) << description; | 1964 matches[j].contents) << description; |
| 1949 EXPECT_EQ(cases[i].matches[j].from_keyword, | 1965 EXPECT_EQ(cases[i].matches[j].from_keyword, |
| 1950 matches[j].keyword == ASCIIToUTF16("k")) << description; | 1966 matches[j].keyword == ASCIIToUTF16("k")) << description; |
| 1951 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, | 1967 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, |
| 1952 matches[j].allowed_to_be_default_match) << description; | 1968 matches[j].allowed_to_be_default_match) << description; |
| 1953 } | 1969 } |
| 1954 // Ensure that no expected matches are missing. | 1970 // Ensure that no expected matches are missing. |
| 1955 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) | 1971 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) |
| 1956 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << | 1972 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << |
| 1957 "Case # " << i << " " << description; | 1973 "Case # " << i << " " << description; |
| 1958 } | 1974 } |
| 1959 } | 1975 } |
| 1960 | 1976 |
| 1977 TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) { |
| 1978 struct Match { |
| 1979 std::string contents; |
| 1980 bool allowed_to_be_default_match; |
| 1981 }; |
| 1982 const Match kEmptyMatch = { kNotApplicable, false }; |
| 1983 // This test sends two separate queries, each receiving different JSON |
| 1984 // replies, and checks that receiving the second reply doesn't cause |
| 1985 // an unexpected inline autcompletion. |
| 1986 struct { |
| 1987 const std::string first_json; |
| 1988 const std::string second_json; |
| 1989 const Match matches[4]; |
| 1990 } cases[] = { |
| 1991 // A simple test that verifies we inline autocomplete if the new top |
| 1992 // suggestion is the same as the old inline autocompleted suggestion. |
| 1993 { "[\"a\",[\"ab1\", \"ab2\"],[],[]," |
| 1994 "{\"google:verbatimrelevance\":1300," |
| 1995 "\"google:suggestrelevance\":[1302, 1301]}]", |
| 1996 "[\"ab\",[\"ab1\", \"ab2\"],[],[]," |
| 1997 "{\"google:verbatimrelevance\":1300," |
| 1998 "\"google:suggestrelevance\":[1302, 1301]}]", |
| 1999 { { "ab1", true }, { "ab2", false }, { "ab", true }, kEmptyMatch } }, |
| 2000 // Ditto, just for a navigation suggestion. |
| 2001 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[]," |
| 2002 "{\"google:verbatimrelevance\":1300," |
| 2003 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 2004 "\"google:suggestrelevance\":[1302, 1301]}]", |
| 2005 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[]," |
| 2006 "{\"google:verbatimrelevance\":1300," |
| 2007 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 2008 "\"google:suggestrelevance\":[1302, 1301]}]", |
| 2009 { { "ab1.com", true }, { "ab2.com", false }, { "ab", true }, |
| 2010 kEmptyMatch } }, |
| 2011 |
| 2012 // Without an original inline autcompletion, a new inline autcompletion |
| 2013 // should be rejected. |
| 2014 { "[\"a\",[\"ab1\", \"ab2\"],[],[]," |
| 2015 "{\"google:verbatimrelevance\":1300," |
| 2016 "\"google:suggestrelevance\":[900, 800]}]", |
| 2017 "[\"ab\",[\"ab1\", \"ab2\"],[],[]," |
| 2018 "{\"google:suggestrelevance\":[1302, 1301]," |
| 2019 "\"google:verbatimrelevance\":1300}]", |
| 2020 { { "ab1", false }, { "ab2", false }, { "ab", true }, kEmptyMatch } }, |
| 2021 { "[\"a\",[\"ab1\", \"ab2\"],[],[]," |
| 2022 "{\"google:verbatimrelevance\":1300," |
| 2023 "\"google:suggestrelevance\":[900, 800]}]", |
| 2024 "[\"ab\",[\"ab1\", \"ab2\"],[],[]," |
| 2025 "{\"google:verbatimrelevance\":1300," |
| 2026 "\"google:suggestrelevance\":[1301, 1302]}]", |
| 2027 { { "ab2", false }, { "ab1", false }, { "ab", true }, kEmptyMatch } }, |
| 2028 // Now, the same verifications but with the new inline autocompletion as a |
| 2029 // navsuggestion. The new autocompletion should still be rejected. |
| 2030 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[]," |
| 2031 "{\"google:verbatimrelevance\":1300," |
| 2032 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 2033 "\"google:suggestrelevance\":[900, 800]}]", |
| 2034 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[]," |
| 2035 "{\"google:verbatimrelevance\":1300," |
| 2036 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 2037 "\"google:suggestrelevance\":[1302, 1301]}]", |
| 2038 { { "ab1.com", false }, { "ab2.com", false }, { "ab", true }, |
| 2039 kEmptyMatch } }, |
| 2040 { "[\"a\",[\"ab1.com\", \"ab2.com\"],[],[]," |
| 2041 "{\"google:verbatimrelevance\":1300," |
| 2042 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 2043 "\"google:suggestrelevance\":[900, 800]}]", |
| 2044 "[\"ab\",[\"ab1.com\", \"ab2.com\"],[],[]," |
| 2045 "{\"google:verbatimrelevance\":1300," |
| 2046 "\"google:suggesttype\":[\"NAVIGATION\", \"NAVIGATION\"]," |
| 2047 "\"google:suggestrelevance\":[1301, 1302]}]", |
| 2048 { { "ab2.com", false }, { "ab1.com", false }, { "ab", true }, |
| 2049 kEmptyMatch } }, |
| 2050 }; |
| 2051 |
| 2052 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 2053 // First, send the query "a" and receive the provided JSON reply, |
| 2054 // |first_json|. |
| 2055 QueryForInput(ASCIIToUTF16("a"), false, false); |
| 2056 net::TestURLFetcher* first_fetcher = |
| 2057 test_factory_.GetFetcherByID( |
| 2058 SearchProvider::kDefaultProviderURLFetcherID); |
| 2059 ASSERT_TRUE(first_fetcher); |
| 2060 first_fetcher->set_response_code(200); |
| 2061 first_fetcher->SetResponseString(cases[i].first_json); |
| 2062 first_fetcher->delegate()->OnURLFetchComplete(first_fetcher); |
| 2063 RunTillProviderDone(); |
| 2064 |
| 2065 // Then, send the query "ab" and get the provided JSON reply, |
| 2066 // |second_json|. |
| 2067 QueryForInput(ASCIIToUTF16("ab"), false, false); |
| 2068 net::TestURLFetcher* second_fetcher = |
| 2069 test_factory_.GetFetcherByID( |
| 2070 SearchProvider::kDefaultProviderURLFetcherID); |
| 2071 ASSERT_TRUE(second_fetcher); |
| 2072 second_fetcher->set_response_code(200); |
| 2073 second_fetcher->SetResponseString(cases[i].second_json); |
| 2074 second_fetcher->delegate()->OnURLFetchComplete(second_fetcher); |
| 2075 RunTillProviderDone(); |
| 2076 |
| 2077 // Finally, check that we have the expected results. |
| 2078 const std::string description = "for input with first_json=" + |
| 2079 cases[i].first_json + " and second_json=" + cases[i].second_json; |
| 2080 const ACMatches& matches = provider_->matches(); |
| 2081 ASSERT_FALSE(matches.empty()); |
| 2082 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].matches)); |
| 2083 size_t j = 0; |
| 2084 // Ensure that the returned matches equal the expectations. |
| 2085 for (; j < matches.size(); ++j) { |
| 2086 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), |
| 2087 matches[j].contents) << description; |
| 2088 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, |
| 2089 matches[j].allowed_to_be_default_match) << description; |
| 2090 } |
| 2091 // Ensure that no expected matches are missing. |
| 2092 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) |
| 2093 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents) << |
| 2094 "Case # " << j << " " << description; |
| 2095 } |
| 2096 } |
| 2097 |
| 1961 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { | 2098 TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { |
| 1962 // We hardcode the string "term1" below, so ensure that the search term that | 2099 // We hardcode the string "term1" below, so ensure that the search term that |
| 1963 // got added to history already is that string. | 2100 // got added to history already is that string. |
| 1964 ASSERT_EQ(ASCIIToUTF16("term1"), term1_); | 2101 ASSERT_EQ(ASCIIToUTF16("term1"), term1_); |
| 1965 base::string16 term = term1_.substr(0, term1_.length() - 1); | 2102 base::string16 term = term1_.substr(0, term1_.length() - 1); |
| 1966 | 2103 |
| 1967 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2); | 2104 AddSearchToHistory(default_t_url_, term + ASCIIToUTF16("2"), 2); |
| 1968 profile_.BlockUntilHistoryProcessesPendingRequests(); | 2105 profile_.BlockUntilHistoryProcessesPendingRequests(); |
| 1969 | 2106 |
| 1970 struct { | 2107 struct { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2083 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2220 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2084 kEmptyMatch, kEmptyMatch } }, | 2221 kEmptyMatch, kEmptyMatch } }, |
| 2085 { "a.com", "[\"a.com\",[\"https://a.com\"],[],[]," | 2222 { "a.com", "[\"a.com\",[\"https://a.com\"],[],[]," |
| 2086 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 2223 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
| 2087 "\"google:suggestrelevance\":[9999]}]", | 2224 "\"google:suggestrelevance\":[9999]}]", |
| 2088 { { "https://a.com", AutocompleteMatchType::NAVSUGGEST, true }, | 2225 { { "https://a.com", AutocompleteMatchType::NAVSUGGEST, true }, |
| 2089 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2226 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2090 kEmptyMatch, kEmptyMatch } }, | 2227 kEmptyMatch, kEmptyMatch } }, |
| 2091 | 2228 |
| 2092 // Ensure topmost inlineable SUGGEST matches are NOT allowed for URL | 2229 // Ensure topmost inlineable SUGGEST matches are NOT allowed for URL |
| 2093 // input. SearchProvider disregards search and verbatim suggested | 2230 // input. |
| 2094 // relevances. | |
| 2095 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," | 2231 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," |
| 2096 "{\"google:suggestrelevance\":[9999]}]", | 2232 "{\"google:suggestrelevance\":[9999]}]", |
| 2097 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2233 { { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false }, |
| 2098 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, | 2234 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2099 kEmptyMatch, kEmptyMatch } }, | 2235 kEmptyMatch, kEmptyMatch } }, |
| 2100 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," | 2236 { "a.com", "[\"a.com\",[\"a.com info\"],[],[]," |
| 2101 "{\"google:suggestrelevance\":[9999]}]", | 2237 "{\"google:suggestrelevance\":[9999]}]", |
| 2102 { { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2238 { { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false }, |
| 2103 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, | 2239 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2104 kEmptyMatch, kEmptyMatch } }, | 2240 kEmptyMatch, kEmptyMatch } }, |
| 2105 | 2241 |
| 2106 // Ensure the fallback mechanism allows inlinable NAVIGATION matches. | 2242 // Ensure the fallback mechanism allows inlinable NAVIGATION matches. |
| 2107 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," | 2243 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," |
| 2108 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 2244 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 2109 "\"google:suggestrelevance\":[9999, 9998]}]", | 2245 "\"google:suggestrelevance\":[9999, 9998]}]", |
| 2110 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, | 2246 { { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, false }, |
| 2111 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2247 { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, |
| 2112 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, | 2248 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2113 kEmptyMatch } }, | 2249 kEmptyMatch } }, |
| 2250 // In this case, when we abandon relevance scores, we restore the |
| 2251 // |allowed_to_be_default_match| of the "a.com info" query. This doesn't |
| 2252 // violate any constraints because we know it's not going to be used. |
| 2114 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," | 2253 { "a.com", "[\"a.com\",[\"a.com info\", \"http://a.com/b\"],[],[]," |
| 2115 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 2254 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 2116 "\"google:suggestrelevance\":[9998, 9997]," | 2255 "\"google:suggestrelevance\":[9998, 9997]," |
| 2117 "\"google:verbatimrelevance\":9999}]", | 2256 "\"google:verbatimrelevance\":9999}]", |
| 2118 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, | 2257 { { "a.com/b", AutocompleteMatchType::NAVSUGGEST, true }, |
| 2119 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2258 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2120 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, | 2259 { "a.com info", AutocompleteMatchType::SEARCH_SUGGEST, true }, |
| 2121 kEmptyMatch } }, | 2260 kEmptyMatch } }, |
| 2122 | 2261 |
| 2123 // Ensure topmost non-inlineable SUGGEST matches are allowed for URL | 2262 // Ensure topmost non-inlineable SUGGEST matches are allowed for URL |
| 2124 // input assuming the top inlineable match is not a query (i.e., is a | 2263 // input assuming the top inlineable match is not a query (i.e., is a |
| 2125 // NAVSUGGEST). | 2264 // NAVSUGGEST). |
| 2126 { "a.com", "[\"a.com\",[\"info\"],[],[]," | 2265 { "a.com", "[\"a.com\",[\"info\"],[],[]," |
| 2127 "{\"google:suggestrelevance\":[9999]}]", | 2266 "{\"google:suggestrelevance\":[9999]}]", |
| 2128 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, | 2267 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, |
| 2129 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2268 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2130 kEmptyMatch, kEmptyMatch } }, | 2269 kEmptyMatch, kEmptyMatch } }, |
| 2131 { "a.com", "[\"a.com\",[\"info\"],[],[]," | 2270 { "a.com", "[\"a.com\",[\"info\"],[],[]," |
| 2132 "{\"google:suggestrelevance\":[9999]}]", | 2271 "{\"google:suggestrelevance\":[9999]}]", |
| 2133 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, | 2272 { { "info", AutocompleteMatchType::SEARCH_SUGGEST, false }, |
| 2134 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, | 2273 { "a.com", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, true }, |
| 2135 kEmptyMatch, kEmptyMatch } }, | 2274 kEmptyMatch, kEmptyMatch } }, |
| 2136 }; | 2275 }; |
| 2137 | 2276 |
| 2138 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 2277 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 2139 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 2278 // Send the query twice in order to bypass checks about whether a single |
| 2140 net::TestURLFetcher* fetcher = | 2279 // new reply can change the inline autocompletion. |
| 2141 test_factory_.GetFetcherByID( | 2280 for (size_t j = 0; j < 2; j++) { |
| 2142 SearchProvider::kDefaultProviderURLFetcherID); | 2281 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 2143 ASSERT_TRUE(fetcher); | 2282 net::TestURLFetcher* fetcher = |
| 2144 fetcher->set_response_code(200); | 2283 test_factory_.GetFetcherByID( |
| 2145 fetcher->SetResponseString(cases[i].json); | 2284 SearchProvider::kDefaultProviderURLFetcherID); |
| 2146 fetcher->delegate()->OnURLFetchComplete(fetcher); | 2285 ASSERT_TRUE(fetcher); |
| 2147 RunTillProviderDone(); | 2286 fetcher->set_response_code(200); |
| 2287 fetcher->SetResponseString(cases[i].json); |
| 2288 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 2289 RunTillProviderDone(); |
| 2290 } |
| 2148 | 2291 |
| 2292 const std::string description = "input=" + cases[i].input + " json=" + |
| 2293 cases[i].json; |
| 2149 size_t j = 0; | 2294 size_t j = 0; |
| 2150 const ACMatches& matches = provider_->matches(); | 2295 const ACMatches& matches = provider_->matches(); |
| 2151 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output)); | 2296 ASSERT_LE(matches.size(), ARRAYSIZE_UNSAFE(cases[i].output)) << |
| 2297 description; |
| 2152 // Ensure that the returned matches equal the expectations. | 2298 // Ensure that the returned matches equal the expectations. |
| 2153 for (; j < matches.size(); ++j) { | 2299 for (; j < matches.size(); ++j) { |
| 2154 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents), | 2300 EXPECT_EQ(ASCIIToUTF16(cases[i].output[j].match_contents), |
| 2155 matches[j].contents); | 2301 matches[j].contents) << description; |
| 2156 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type); | 2302 EXPECT_EQ(cases[i].output[j].match_type, matches[j].type) << description; |
| 2157 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match, | 2303 EXPECT_EQ(cases[i].output[j].allowed_to_be_default_match, |
| 2158 matches[j].allowed_to_be_default_match); | 2304 matches[j].allowed_to_be_default_match) << description; |
| 2159 } | 2305 } |
| 2160 // Ensure that no expected matches are missing. | 2306 // Ensure that no expected matches are missing. |
| 2161 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) { | 2307 for (; j < ARRAYSIZE_UNSAFE(cases[i].output); ++j) { |
| 2162 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents); | 2308 EXPECT_EQ(kNotApplicable, cases[i].output[j].match_contents) << |
| 2309 description; |
| 2163 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES, | 2310 EXPECT_EQ(AutocompleteMatchType::NUM_TYPES, |
| 2164 cases[i].output[j].match_type); | 2311 cases[i].output[j].match_type) << description; |
| 2165 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match); | 2312 EXPECT_FALSE(cases[i].output[j].allowed_to_be_default_match) << |
| 2313 description; |
| 2166 } | 2314 } |
| 2167 } | 2315 } |
| 2168 } | 2316 } |
| 2169 | 2317 |
| 2170 // A basic test that verifies the field trial triggered parsing logic. | 2318 // A basic test that verifies the field trial triggered parsing logic. |
| 2171 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { | 2319 TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { |
| 2172 QueryForInput(ASCIIToUTF16("foo"), false, false); | 2320 QueryForInput(ASCIIToUTF16("foo"), false, false); |
| 2173 | 2321 |
| 2174 // Make sure the default providers suggest service was queried. | 2322 // Make sure the default providers suggest service was queried. |
| 2175 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 2323 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3262 // Mismatching input will return empty prefetch data. | 3410 // Mismatching input will return empty prefetch data. |
| 3263 AutocompleteInput input2(base::ASCIIToUTF16("weather n"), | 3411 AutocompleteInput input2(base::ASCIIToUTF16("weather n"), |
| 3264 base::string16::npos, base::string16(), GURL(), | 3412 base::string16::npos, base::string16(), GURL(), |
| 3265 metrics::OmniboxEventProto::INVALID_SPEC, false, | 3413 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 3266 false, true, true, | 3414 false, true, true, |
| 3267 ChromeAutocompleteSchemeClassifier(&profile_)); | 3415 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 3268 provider_->DoAnswersQuery(input2); | 3416 provider_->DoAnswersQuery(input2); |
| 3269 EXPECT_TRUE(provider_->prefetch_data_.full_query_text.empty()); | 3417 EXPECT_TRUE(provider_->prefetch_data_.full_query_text.empty()); |
| 3270 EXPECT_TRUE(provider_->prefetch_data_.query_type.empty()); | 3418 EXPECT_TRUE(provider_->prefetch_data_.query_type.empty()); |
| 3271 } | 3419 } |
| OLD | NEW |