OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/autocomplete/bookmark_provider.h" | 5 #include "chrome/browser/autocomplete/bookmark_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // This ensures that empty titles yield empty classifications. | 260 // This ensures that empty titles yield empty classifications. |
261 {"emptytitle", 1, {}}, | 261 {"emptytitle", 1, {}}, |
262 }; | 262 }; |
263 | 263 |
264 for (size_t i = 0; i < arraysize(query_data); ++i) { | 264 for (size_t i = 0; i < arraysize(query_data); ++i) { |
265 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 265 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
266 base::string16::npos, std::string(), GURL(), | 266 base::string16::npos, std::string(), GURL(), |
267 metrics::OmniboxEventProto::INVALID_SPEC, false, | 267 metrics::OmniboxEventProto::INVALID_SPEC, false, |
268 false, false, true, | 268 false, false, true, |
269 ChromeAutocompleteSchemeClassifier(profile_.get())); | 269 ChromeAutocompleteSchemeClassifier(profile_.get())); |
270 provider_->Start(input, false); | 270 provider_->Start(input, false, false); |
271 const ACMatches& matches(provider_->matches()); | 271 const ACMatches& matches(provider_->matches()); |
272 // Validate number of results is as expected. | 272 // Validate number of results is as expected. |
273 EXPECT_LE(matches.size(), query_data[i].match_count) | 273 EXPECT_LE(matches.size(), query_data[i].match_count) |
274 << "One or more of the following matches were unexpected:\n" | 274 << "One or more of the following matches were unexpected:\n" |
275 << MatchesAsString16(matches) | 275 << MatchesAsString16(matches) |
276 << "For query '" << query_data[i].query << "'."; | 276 << "For query '" << query_data[i].query << "'."; |
277 EXPECT_GE(matches.size(), query_data[i].match_count) | 277 EXPECT_GE(matches.size(), query_data[i].match_count) |
278 << "One or more expected matches are missing. Matches found:\n" | 278 << "One or more expected matches are missing. Matches found:\n" |
279 << MatchesAsString16(matches) | 279 << MatchesAsString16(matches) |
280 << "for query '" << query_data[i].query << "'."; | 280 << "for query '" << query_data[i].query << "'."; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 "worming burns #10", // boosted but longer title | 341 "worming burns #10", // boosted but longer title |
342 "burning worms #2"}}, // not boosted | 342 "burning worms #2"}}, // not boosted |
343 }; | 343 }; |
344 | 344 |
345 for (size_t i = 0; i < arraysize(query_data); ++i) { | 345 for (size_t i = 0; i < arraysize(query_data); ++i) { |
346 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 346 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
347 base::string16::npos, std::string(), GURL(), | 347 base::string16::npos, std::string(), GURL(), |
348 metrics::OmniboxEventProto::INVALID_SPEC, false, | 348 metrics::OmniboxEventProto::INVALID_SPEC, false, |
349 false, false, true, | 349 false, false, true, |
350 ChromeAutocompleteSchemeClassifier(profile_.get())); | 350 ChromeAutocompleteSchemeClassifier(profile_.get())); |
351 provider_->Start(input, false); | 351 provider_->Start(input, false, false); |
352 const ACMatches& matches(provider_->matches()); | 352 const ACMatches& matches(provider_->matches()); |
353 // Validate number and content of results is as expected. | 353 // Validate number and content of results is as expected. |
354 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); | 354 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); |
355 ++j) { | 355 ++j) { |
356 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '" | 356 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '" |
357 << base::UTF16ToUTF8(matches[j].description) << "' for query: '" | 357 << base::UTF16ToUTF8(matches[j].description) << "' for query: '" |
358 << query_data[i].query << "'."; | 358 << query_data[i].query << "'."; |
359 if (j >= query_data[i].match_count) | 359 if (j >= query_data[i].match_count) |
360 continue; | 360 continue; |
361 EXPECT_LT(j, matches.size()) << " Missing match '" | 361 EXPECT_LT(j, matches.size()) << " Missing match '" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 { "versi", "chrome://version", "0:1,9:3,14:1" } | 441 { "versi", "chrome://version", "0:1,9:3,14:1" } |
442 }; | 442 }; |
443 | 443 |
444 for (size_t i = 0; i < arraysize(query_data); ++i) { | 444 for (size_t i = 0; i < arraysize(query_data); ++i) { |
445 std::string description = "for query=" + query_data[i].query; | 445 std::string description = "for query=" + query_data[i].query; |
446 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 446 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
447 base::string16::npos, std::string(), GURL(), | 447 base::string16::npos, std::string(), GURL(), |
448 metrics::OmniboxEventProto::INVALID_SPEC, false, | 448 metrics::OmniboxEventProto::INVALID_SPEC, false, |
449 false, false, true, | 449 false, false, true, |
450 ChromeAutocompleteSchemeClassifier(profile_.get())); | 450 ChromeAutocompleteSchemeClassifier(profile_.get())); |
451 provider_->Start(input, false); | 451 provider_->Start(input, false, false); |
452 const ACMatches& matches(provider_->matches()); | 452 const ACMatches& matches(provider_->matches()); |
453 ASSERT_EQ(1U, matches.size()) << description; | 453 ASSERT_EQ(1U, matches.size()) << description; |
454 const AutocompleteMatch& match = matches[0]; | 454 const AutocompleteMatch& match = matches[0]; |
455 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents), | 455 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents), |
456 match.contents) << description; | 456 match.contents) << description; |
457 std::vector<std::string> class_strings; | 457 std::vector<std::string> class_strings; |
458 base::SplitString( | 458 base::SplitString( |
459 query_data[i].expected_contents_class, ',', &class_strings); | 459 query_data[i].expected_contents_class, ',', &class_strings); |
460 ASSERT_EQ(class_strings.size(), match.contents_class.size()) | 460 ASSERT_EQ(class_strings.size(), match.contents_class.size()) |
461 << description; | 461 << description; |
462 for (size_t i = 0; i < class_strings.size(); ++i) { | 462 for (size_t i = 0; i < class_strings.size(); ++i) { |
463 std::vector<std::string> chunks; | 463 std::vector<std::string> chunks; |
464 base::SplitString(class_strings[i], ':', &chunks); | 464 base::SplitString(class_strings[i], ':', &chunks); |
465 ASSERT_EQ(2U, chunks.size()) << description; | 465 ASSERT_EQ(2U, chunks.size()) << description; |
466 size_t offset; | 466 size_t offset; |
467 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; | 467 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; |
468 EXPECT_EQ(offset, match.contents_class[i].offset) << description; | 468 EXPECT_EQ(offset, match.contents_class[i].offset) << description; |
469 int style; | 469 int style; |
470 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; | 470 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; |
471 EXPECT_EQ(style, match.contents_class[i].style) << description; | 471 EXPECT_EQ(style, match.contents_class[i].style) << description; |
472 } | 472 } |
473 } | 473 } |
474 } | 474 } |
| 475 |
| 476 TEST_F(BookmarkProviderTest, DoesNotProvideMatchesOnFocus) { |
| 477 AutocompleteInput input(base::ASCIIToUTF16("foo"), |
| 478 base::string16::npos, std::string(), GURL(), |
| 479 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 480 false, false, true, |
| 481 ChromeAutocompleteSchemeClassifier(profile_.get())); |
| 482 provider_->Start(input, false, true); |
| 483 EXPECT_TRUE(provider_->matches().empty()); |
| 484 } |
OLD | NEW |