OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmarks/browser/bookmark_index.h" | 5 #include "components/bookmarks/browser/bookmark_index.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void ExpectMatches(const std::string& query, | 93 void ExpectMatches(const std::string& query, |
94 query_parser::MatchingAlgorithm matching_algorithm, | 94 query_parser::MatchingAlgorithm matching_algorithm, |
95 const std::vector<std::string>& expected_titles) { | 95 const std::vector<std::string>& expected_titles) { |
96 std::vector<BookmarkMatch> matches; | 96 std::vector<BookmarkMatch> matches; |
97 model_->GetBookmarksMatching(ASCIIToUTF16(query), 1000, matching_algorithm, | 97 model_->GetBookmarksMatching(ASCIIToUTF16(query), 1000, matching_algorithm, |
98 &matches); | 98 &matches); |
99 ASSERT_EQ(expected_titles.size(), matches.size()); | 99 ASSERT_EQ(expected_titles.size(), matches.size()); |
100 for (size_t i = 0; i < expected_titles.size(); ++i) { | 100 for (size_t i = 0; i < expected_titles.size(); ++i) { |
101 bool found = false; | 101 bool found = false; |
102 for (size_t j = 0; j < matches.size(); ++j) { | 102 for (size_t j = 0; j < matches.size(); ++j) { |
103 if (ASCIIToUTF16(expected_titles[i]) == matches[j].node->GetTitle()) { | 103 const base::string16& title = matches[j].node->GetTitledUrlNodeTitle(); |
| 104 if (ASCIIToUTF16(expected_titles[i]) == title) { |
104 matches.erase(matches.begin() + j); | 105 matches.erase(matches.begin() + j); |
105 found = true; | 106 found = true; |
106 break; | 107 break; |
107 } | 108 } |
108 } | 109 } |
109 ASSERT_TRUE(found); | 110 ASSERT_TRUE(found); |
110 } | 111 } |
111 } | 112 } |
112 | 113 |
113 void ExtractMatchPositions(const std::string& string, | 114 void ExtractMatchPositions(const std::string& string, |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 526 |
526 std::map<GURL, int> typed_count_map; | 527 std::map<GURL, int> typed_count_map; |
527 for (size_t i = 0; i < arraysize(data); ++i) | 528 for (size_t i = 0; i < arraysize(data); ++i) |
528 typed_count_map.insert(std::make_pair(data[i].url, data[i].typed_count)); | 529 typed_count_map.insert(std::make_pair(data[i].url, data[i].typed_count)); |
529 | 530 |
530 std::unique_ptr<BookmarkModel> model = | 531 std::unique_ptr<BookmarkModel> model = |
531 TestBookmarkClient::CreateModelWithClient( | 532 TestBookmarkClient::CreateModelWithClient( |
532 base::MakeUnique<BookmarkClientMock>(typed_count_map)); | 533 base::MakeUnique<BookmarkClientMock>(typed_count_map)); |
533 | 534 |
534 for (size_t i = 0; i < arraysize(data); ++i) | 535 for (size_t i = 0; i < arraysize(data); ++i) |
535 // Populate the BookmarkIndex. | 536 // Populate the bookmark index. |
536 model->AddURL( | 537 model->AddURL( |
537 model->other_node(), i, UTF8ToUTF16(data[i].title), data[i].url); | 538 model->other_node(), i, UTF8ToUTF16(data[i].title), data[i].url); |
538 | 539 |
539 // Populate match nodes. | 540 // Populate match nodes. |
540 std::vector<BookmarkMatch> matches; | 541 std::vector<BookmarkMatch> matches; |
541 model->GetBookmarksMatching(ASCIIToUTF16("google"), 4, &matches); | 542 model->GetBookmarksMatching(ASCIIToUTF16("google"), 4, &matches); |
542 | 543 |
543 // The resulting order should be: | 544 // The resulting order should be: |
544 // 1. Google (google.com) 100 | 545 // 1. Google (google.com) 100 |
545 // 2. Google Reader (google.com/reader) 80 | 546 // 2. Google Reader (google.com/reader) 80 |
546 // 3. Google Docs (docs.google.com) 50 | 547 // 3. Google Docs (docs.google.com) 50 |
547 // 4. Google Maps (maps.google.com) 40 | 548 // 4. Google Maps (maps.google.com) 40 |
548 ASSERT_EQ(4U, matches.size()); | 549 ASSERT_EQ(4U, matches.size()); |
549 EXPECT_EQ(data[0].url, matches[0].node->url()); | 550 EXPECT_EQ(data[0].url, matches[0].node->GetTitledUrlNodeUrl()); |
550 EXPECT_EQ(data[3].url, matches[1].node->url()); | 551 EXPECT_EQ(data[3].url, matches[1].node->GetTitledUrlNodeUrl()); |
551 EXPECT_EQ(data[2].url, matches[2].node->url()); | 552 EXPECT_EQ(data[2].url, matches[2].node->GetTitledUrlNodeUrl()); |
552 EXPECT_EQ(data[1].url, matches[3].node->url()); | 553 EXPECT_EQ(data[1].url, matches[3].node->GetTitledUrlNodeUrl()); |
553 | 554 |
554 matches.clear(); | 555 matches.clear(); |
555 // Select top two matches. | 556 // Select top two matches. |
556 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); | 557 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); |
557 | 558 |
558 ASSERT_EQ(2U, matches.size()); | 559 ASSERT_EQ(2U, matches.size()); |
559 EXPECT_EQ(data[0].url, matches[0].node->url()); | 560 EXPECT_EQ(data[0].url, matches[0].node->GetTitledUrlNodeUrl()); |
560 EXPECT_EQ(data[3].url, matches[1].node->url()); | 561 EXPECT_EQ(data[3].url, matches[1].node->GetTitledUrlNodeUrl()); |
561 } | 562 } |
562 | 563 |
563 } // namespace | 564 } // namespace |
564 } // namespace bookmarks | 565 } // namespace bookmarks |
OLD | NEW |