| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 {"frank", 1, {{{0, 5}, {8, 13}, {16, 21}, {0, 0}}}}, | 254 {"frank", 1, {{{0, 5}, {8, 13}, {16, 21}, {0, 0}}}}, |
| 255 {"frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, | 255 {"frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, |
| 256 {"frankly frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, | 256 {"frankly frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, |
| 257 {"foobar foo", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, | 257 {"foobar foo", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, |
| 258 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, | 258 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { | 261 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { |
| 262 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 262 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 263 base::string16::npos, base::string16(), GURL(), | 263 base::string16::npos, base::string16(), GURL(), |
| 264 AutocompleteInput::INVALID_SPEC, false, false, | 264 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 265 false, true); | 265 false, false, true); |
| 266 provider_->Start(input, false); | 266 provider_->Start(input, false); |
| 267 const ACMatches& matches(provider_->matches()); | 267 const ACMatches& matches(provider_->matches()); |
| 268 // Validate number of results is as expected. | 268 // Validate number of results is as expected. |
| 269 EXPECT_LE(matches.size(), query_data[i].match_count) | 269 EXPECT_LE(matches.size(), query_data[i].match_count) |
| 270 << "One or more of the following matches were unexpected:\n" | 270 << "One or more of the following matches were unexpected:\n" |
| 271 << MatchesAsString16(matches) | 271 << MatchesAsString16(matches) |
| 272 << "For query '" << query_data[i].query << "'."; | 272 << "For query '" << query_data[i].query << "'."; |
| 273 EXPECT_GE(matches.size(), query_data[i].match_count) | 273 EXPECT_GE(matches.size(), query_data[i].match_count) |
| 274 << "One or more expected matches are missing. Matches found:\n" | 274 << "One or more expected matches are missing. Matches found:\n" |
| 275 << MatchesAsString16(matches) | 275 << MatchesAsString16(matches) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // Ranking of prefix matches with URL boost. Note that a query of | 331 // Ranking of prefix matches with URL boost. Note that a query of |
| 332 // "worm burn" will have the same results. | 332 // "worm burn" will have the same results. |
| 333 {"burn worm", 3, {"burning worms #2", // boosted | 333 {"burn worm", 3, {"burning worms #2", // boosted |
| 334 "worming burns #20", // boosted | 334 "worming burns #20", // boosted |
| 335 "burning worms #1"}}, // not boosted but shorter | 335 "burning worms #1"}}, // not boosted but shorter |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { | 338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { |
| 339 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 339 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 340 base::string16::npos, base::string16(), GURL(), | 340 base::string16::npos, base::string16(), GURL(), |
| 341 AutocompleteInput::INVALID_SPEC, false, false, | 341 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 342 false, true); | 342 false, false, true); |
| 343 provider_->Start(input, false); | 343 provider_->Start(input, false); |
| 344 const ACMatches& matches(provider_->matches()); | 344 const ACMatches& matches(provider_->matches()); |
| 345 // Validate number and content of results is as expected. | 345 // Validate number and content of results is as expected. |
| 346 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); | 346 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); |
| 347 ++j) { | 347 ++j) { |
| 348 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '" | 348 EXPECT_LT(j, query_data[i].match_count) << " Unexpected match '" |
| 349 << base::UTF16ToUTF8(matches[j].description) << "' for query: '" | 349 << base::UTF16ToUTF8(matches[j].description) << "' for query: '" |
| 350 << query_data[i].query << "'."; | 350 << query_data[i].query << "'."; |
| 351 if (j >= query_data[i].match_count) | 351 if (j >= query_data[i].match_count) |
| 352 continue; | 352 continue; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // need to be in the bookmarks list because BookmarkProvider's | 387 // need to be in the bookmarks list because BookmarkProvider's |
| 388 // TitleMatchToACMatch() has an assertion that verifies the URL is | 388 // TitleMatchToACMatch() has an assertion that verifies the URL is |
| 389 // actually bookmarked. | 389 // actually bookmarked. |
| 390 }; | 390 }; |
| 391 | 391 |
| 392 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { | 392 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { |
| 393 const std::string description = "for query=" + query_data[i].query + | 393 const std::string description = "for query=" + query_data[i].query + |
| 394 " and url=" + query_data[i].url; | 394 " and url=" + query_data[i].url; |
| 395 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 395 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 396 base::string16::npos, base::string16(), GURL(), | 396 base::string16::npos, base::string16(), GURL(), |
| 397 AutocompleteInput::INVALID_SPEC, false, false, | 397 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 398 false, true); | 398 false, false, true); |
| 399 const base::string16 fixed_up_input( | 399 const base::string16 fixed_up_input( |
| 400 provider_->FixupUserInput(input).second); | 400 provider_->FixupUserInput(input).second); |
| 401 BookmarkNode node(GURL(query_data[i].url)); | 401 BookmarkNode node(GURL(query_data[i].url)); |
| 402 node.SetTitle(base::ASCIIToUTF16(query_data[i].url)); | 402 node.SetTitle(base::ASCIIToUTF16(query_data[i].url)); |
| 403 BookmarkMatch bookmark_match; | 403 BookmarkMatch bookmark_match; |
| 404 bookmark_match.node = &node; | 404 bookmark_match.node = &node; |
| 405 const AutocompleteMatch& ac_match = provider_->BookmarkMatchToACMatch( | 405 const AutocompleteMatch& ac_match = provider_->BookmarkMatchToACMatch( |
| 406 input, fixed_up_input, bookmark_match); | 406 input, fixed_up_input, bookmark_match); |
| 407 EXPECT_EQ(query_data[i].allowed_to_be_default_match, | 407 EXPECT_EQ(query_data[i].allowed_to_be_default_match, |
| 408 ac_match.allowed_to_be_default_match) << description; | 408 ac_match.allowed_to_be_default_match) << description; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 433 }; | 433 }; |
| 434 | 434 |
| 435 // Reload the bookmarks index with |index_urls| == true. | 435 // Reload the bookmarks index with |index_urls| == true. |
| 436 model_ = client_.CreateModel(true); | 436 model_ = client_.CreateModel(true); |
| 437 SetUp(); | 437 SetUp(); |
| 438 | 438 |
| 439 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { | 439 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { |
| 440 std::string description = "for query=" + query_data[i].query; | 440 std::string description = "for query=" + query_data[i].query; |
| 441 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), | 441 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), |
| 442 base::string16::npos, base::string16(), GURL(), | 442 base::string16::npos, base::string16(), GURL(), |
| 443 AutocompleteInput::INVALID_SPEC, false, false, | 443 metrics::OmniboxEventProto::INVALID_SPEC, false, |
| 444 false, true); | 444 false, false, true); |
| 445 provider_->Start(input, false); | 445 provider_->Start(input, false); |
| 446 const ACMatches& matches(provider_->matches()); | 446 const ACMatches& matches(provider_->matches()); |
| 447 ASSERT_EQ(1U, matches.size()) << description; | 447 ASSERT_EQ(1U, matches.size()) << description; |
| 448 const AutocompleteMatch& match = matches[0]; | 448 const AutocompleteMatch& match = matches[0]; |
| 449 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents), | 449 EXPECT_EQ(base::ASCIIToUTF16(query_data[i].expected_contents), |
| 450 match.contents) << description; | 450 match.contents) << description; |
| 451 std::vector<std::string> class_strings; | 451 std::vector<std::string> class_strings; |
| 452 base::SplitString( | 452 base::SplitString( |
| 453 query_data[i].expected_contents_class, ',', &class_strings); | 453 query_data[i].expected_contents_class, ',', &class_strings); |
| 454 ASSERT_EQ(class_strings.size(), match.contents_class.size()) | 454 ASSERT_EQ(class_strings.size(), match.contents_class.size()) |
| 455 << description; | 455 << description; |
| 456 for (size_t i = 0; i < class_strings.size(); ++i) { | 456 for (size_t i = 0; i < class_strings.size(); ++i) { |
| 457 std::vector<std::string> chunks; | 457 std::vector<std::string> chunks; |
| 458 base::SplitString(class_strings[i], ':', &chunks); | 458 base::SplitString(class_strings[i], ':', &chunks); |
| 459 ASSERT_EQ(2U, chunks.size()) << description; | 459 ASSERT_EQ(2U, chunks.size()) << description; |
| 460 size_t offset; | 460 size_t offset; |
| 461 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; | 461 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; |
| 462 EXPECT_EQ(offset, match.contents_class[i].offset) << description; | 462 EXPECT_EQ(offset, match.contents_class[i].offset) << description; |
| 463 int style; | 463 int style; |
| 464 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; | 464 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; |
| 465 EXPECT_EQ(style, match.contents_class[i].style) << description; | 465 EXPECT_EQ(style, match.contents_class[i].style) << description; |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 } | 468 } |
| OLD | NEW |