| 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 "components/omnibox/browser/bookmark_provider.h" | 5 #include "components/omnibox/browser/bookmark_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, | 272 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, |
| 273 // This ensures that leading whitespace in the title is not removed. | 273 // This ensures that leading whitespace in the title is not removed. |
| 274 {"hello", 1, {{{1, 6}, {9, 14}, {0, 0}}}}, | 274 {"hello", 1, {{{1, 6}, {9, 14}, {0, 0}}}}, |
| 275 // This ensures that empty titles yield empty classifications. | 275 // This ensures that empty titles yield empty classifications. |
| 276 {"emptytitle", 1, {}}, | 276 {"emptytitle", 1, {}}, |
| 277 }; | 277 }; |
| 278 | 278 |
| 279 for (size_t i = 0; i < arraysize(query_data); ++i) { | 279 for (size_t i = 0; i < arraysize(query_data); ++i) { |
| 280 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 280 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 281 base::string16::npos, std::string(), GURL(), | 281 base::string16::npos, std::string(), GURL(), |
| 282 base::string16(), |
| 282 metrics::OmniboxEventProto::INVALID_SPEC, false, | 283 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 283 false, false, true, false, TestSchemeClassifier()); | 284 false, false, true, false, TestSchemeClassifier()); |
| 284 provider_->Start(input, false); | 285 provider_->Start(input, false); |
| 285 const ACMatches& matches(provider_->matches()); | 286 const ACMatches& matches(provider_->matches()); |
| 286 // Validate number of results is as expected. | 287 // Validate number of results is as expected. |
| 287 EXPECT_LE(matches.size(), query_data[i].match_count) | 288 EXPECT_LE(matches.size(), query_data[i].match_count) |
| 288 << "One or more of the following matches were unexpected:\n" | 289 << "One or more of the following matches were unexpected:\n" |
| 289 << MatchesAsString16(matches) | 290 << MatchesAsString16(matches) |
| 290 << "For query '" << query_data[i].query << "'."; | 291 << "For query '" << query_data[i].query << "'."; |
| 291 EXPECT_GE(matches.size(), query_data[i].match_count) | 292 EXPECT_GE(matches.size(), query_data[i].match_count) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 "burning worms #2"}}, // not boosted | 353 "burning worms #2"}}, // not boosted |
| 353 // A query of "worm burn" will have the same results. | 354 // A query of "worm burn" will have the same results. |
| 354 {"worm burn", 3, {"burning worms #1", // boosted | 355 {"worm burn", 3, {"burning worms #1", // boosted |
| 355 "worming burns #10", // boosted but longer title | 356 "worming burns #10", // boosted but longer title |
| 356 "burning worms #2"}}, // not boosted | 357 "burning worms #2"}}, // not boosted |
| 357 }; | 358 }; |
| 358 | 359 |
| 359 for (size_t i = 0; i < arraysize(query_data); ++i) { | 360 for (size_t i = 0; i < arraysize(query_data); ++i) { |
| 360 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 361 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 361 base::string16::npos, std::string(), GURL(), | 362 base::string16::npos, std::string(), GURL(), |
| 363 base::string16(), |
| 362 metrics::OmniboxEventProto::INVALID_SPEC, false, | 364 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 363 false, false, true, false, TestSchemeClassifier()); | 365 false, false, true, false, TestSchemeClassifier()); |
| 364 provider_->Start(input, false); | 366 provider_->Start(input, false); |
| 365 const ACMatches& matches(provider_->matches()); | 367 const ACMatches& matches(provider_->matches()); |
| 366 // Validate number and content of results is as expected. | 368 // Validate number and content of results is as expected. |
| 367 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); | 369 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); |
| 368 ++j) { | 370 ++j) { |
| 369 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '" | 371 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '" |
| 370 << base::UTF16ToUTF8(matches[j].description) << "' for query: '" | 372 << base::UTF16ToUTF8(matches[j].description) << "' for query: '" |
| 371 << query_data[i].query << "'."; | 373 << query_data[i].query << "'."; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 // need to be in the bookmarks list because BookmarkProvider's | 410 // need to be in the bookmarks list because BookmarkProvider's |
| 409 // TitleMatchToACMatch() has an assertion that verifies the URL is | 411 // TitleMatchToACMatch() has an assertion that verifies the URL is |
| 410 // actually bookmarked. | 412 // actually bookmarked. |
| 411 }; | 413 }; |
| 412 | 414 |
| 413 for (size_t i = 0; i < arraysize(query_data); ++i) { | 415 for (size_t i = 0; i < arraysize(query_data); ++i) { |
| 414 const std::string description = "for query=" + query_data[i].query + | 416 const std::string description = "for query=" + query_data[i].query + |
| 415 " and url=" + query_data[i].url; | 417 " and url=" + query_data[i].url; |
| 416 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 418 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 417 base::string16::npos, std::string(), GURL(), | 419 base::string16::npos, std::string(), GURL(), |
| 420 base::string16(), |
| 418 metrics::OmniboxEventProto::INVALID_SPEC, false, | 421 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 419 false, false, true, false, TestSchemeClassifier()); | 422 false, false, true, false, TestSchemeClassifier()); |
| 420 const base::string16 fixed_up_input( | 423 const base::string16 fixed_up_input( |
| 421 provider_->FixupUserInput(input).second); | 424 provider_->FixupUserInput(input).second); |
| 422 BookmarkNode node(GURL(query_data[i].url)); | 425 BookmarkNode node(GURL(query_data[i].url)); |
| 423 node.SetTitle(base::ASCIIToUTF16(query_data[i].url)); | 426 node.SetTitle(base::ASCIIToUTF16(query_data[i].url)); |
| 424 TitledUrlMatch bookmark_match; | 427 TitledUrlMatch bookmark_match; |
| 425 bookmark_match.node = &node; | 428 bookmark_match.node = &node; |
| 426 int relevance = provider_->CalculateBookmarkMatchRelevance(bookmark_match); | 429 int relevance = provider_->CalculateBookmarkMatchRelevance(bookmark_match); |
| 427 const AutocompleteMatch& ac_match = TitledUrlMatchToAutocompleteMatch( | 430 const AutocompleteMatch& ac_match = TitledUrlMatchToAutocompleteMatch( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 452 { "dom http", "http://www.domain.com/http/", | 455 { "dom http", "http://www.domain.com/http/", |
| 453 "0:3,4:1,11:3,14:1,22:3,26:1" }, | 456 "0:3,4:1,11:3,14:1,22:3,26:1" }, |
| 454 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" }, | 457 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" }, |
| 455 { "versi", "chrome://version", "0:1,9:3,14:1" } | 458 { "versi", "chrome://version", "0:1,9:3,14:1" } |
| 456 }; | 459 }; |
| 457 | 460 |
| 458 for (size_t i = 0; i < arraysize(query_data); ++i) { | 461 for (size_t i = 0; i < arraysize(query_data); ++i) { |
| 459 std::string description = "for query=" + query_data[i].query; | 462 std::string description = "for query=" + query_data[i].query; |
| 460 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 463 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 461 base::string16::npos, std::string(), GURL(), | 464 base::string16::npos, std::string(), GURL(), |
| 465 base::string16(), |
| 462 metrics::OmniboxEventProto::INVALID_SPEC, false, | 466 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 463 false, false, true, false, TestSchemeClassifier()); | 467 false, false, true, false, TestSchemeClassifier()); |
| 464 provider_->Start(input, false); | 468 provider_->Start(input, false); |
| 465 const ACMatches& matches(provider_->matches()); | 469 const ACMatches& matches(provider_->matches()); |
| 466 ASSERT_EQ(1U, matches.size()) << description; | 470 ASSERT_EQ(1U, matches.size()) << description; |
| 467 const AutocompleteMatch& match = matches[0]; | 471 const AutocompleteMatch& match = matches[0]; |
| 468 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents), | 472 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents), |
| 469 match.contents) << description; | 473 match.contents) << description; |
| 470 std::vector<std::string> class_strings = base::SplitString( | 474 std::vector<std::string> class_strings = base::SplitString( |
| 471 query_data[i].expected_contents_class, ",", | 475 query_data[i].expected_contents_class, ",", |
| 472 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 476 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 473 ASSERT_EQ(class_strings.size(), match.contents_class.size()) | 477 ASSERT_EQ(class_strings.size(), match.contents_class.size()) |
| 474 << description; | 478 << description; |
| 475 for (size_t i = 0; i < class_strings.size(); ++i) { | 479 for (size_t i = 0; i < class_strings.size(); ++i) { |
| 476 std::vector<std::string> chunks = base::SplitString( | 480 std::vector<std::string> chunks = base::SplitString( |
| 477 class_strings[i], ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 481 class_strings[i], ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 478 ASSERT_EQ(2U, chunks.size()) << description; | 482 ASSERT_EQ(2U, chunks.size()) << description; |
| 479 size_t offset; | 483 size_t offset; |
| 480 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; | 484 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; |
| 481 EXPECT_EQ(offset, match.contents_class[i].offset) << description; | 485 EXPECT_EQ(offset, match.contents_class[i].offset) << description; |
| 482 int style; | 486 int style; |
| 483 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; | 487 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; |
| 484 EXPECT_EQ(style, match.contents_class[i].style) << description; | 488 EXPECT_EQ(style, match.contents_class[i].style) << description; |
| 485 } | 489 } |
| 486 } | 490 } |
| 487 } | 491 } |
| 488 | 492 |
| 489 TEST_F(BookmarkProviderTest, DoesNotProvideMatchesOnFocus) { | 493 TEST_F(BookmarkProviderTest, DoesNotProvideMatchesOnFocus) { |
| 490 AutocompleteInput input(base::ASCIIToUTF16("foo"), base::string16::npos, | 494 AutocompleteInput input(base::ASCIIToUTF16("foo"), base::string16::npos, |
| 491 std::string(), GURL(), | 495 std::string(), GURL(), base::string16(), |
| 492 metrics::OmniboxEventProto::INVALID_SPEC, false, | 496 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 493 false, false, true, true, TestSchemeClassifier()); | 497 false, false, true, true, TestSchemeClassifier()); |
| 494 provider_->Start(input, false); | 498 provider_->Start(input, false); |
| 495 EXPECT_TRUE(provider_->matches().empty()); | 499 EXPECT_TRUE(provider_->matches().empty()); |
| 496 } | 500 } |
| OLD | NEW |