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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/bookmarks/browser/bookmark_match.h" | 15 #include "components/bookmarks/browser/bookmark_match.h" |
16 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
17 #include "components/bookmarks/test/bookmark_test_helpers.h" | 17 #include "components/bookmarks/test/bookmark_test_helpers.h" |
18 #include "components/bookmarks/test/test_bookmark_client.h" | 18 #include "components/bookmarks/test/test_bookmark_client.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 using base::ASCIIToUTF16; | 21 using base::ASCIIToUTF16; |
22 using base::UTF8ToUTF16; | 22 using base::UTF8ToUTF16; |
23 | 23 |
24 namespace bookmarks { | 24 namespace bookmarks { |
25 namespace { | 25 namespace { |
26 | 26 |
27 const char kAboutBlankURL[] = "about:blank"; | 27 const char kAboutBlankURL[] = "about:blank"; |
28 | 28 |
29 class BookmarkClientMock : public test::TestBookmarkClient { | 29 class BookmarkClientMock : public TestBookmarkClient { |
30 public: | 30 public: |
31 BookmarkClientMock(const std::map<GURL, int>& typed_count_map) | 31 BookmarkClientMock(const std::map<GURL, int>& typed_count_map) |
32 : typed_count_map_(typed_count_map) {} | 32 : typed_count_map_(typed_count_map) {} |
33 | 33 |
34 virtual bool SupportsTypedCountForNodes() OVERRIDE { return true; } | 34 virtual bool SupportsTypedCountForNodes() OVERRIDE { return true; } |
35 | 35 |
36 virtual void GetTypedCountForNodes( | 36 virtual void GetTypedCountForNodes( |
37 const NodeSet& nodes, | 37 const NodeSet& nodes, |
38 NodeTypedCountPairs* node_typed_count_pairs) OVERRIDE { | 38 NodeTypedCountPairs* node_typed_count_pairs) OVERRIDE { |
39 for (NodeSet::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { | 39 for (NodeSet::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 const BookmarkMatch::MatchPositions& actual_positions, | 125 const BookmarkMatch::MatchPositions& actual_positions, |
126 const BookmarkMatch::MatchPositions& expected_positions) { | 126 const BookmarkMatch::MatchPositions& expected_positions) { |
127 ASSERT_EQ(expected_positions.size(), actual_positions.size()); | 127 ASSERT_EQ(expected_positions.size(), actual_positions.size()); |
128 for (size_t i = 0; i < expected_positions.size(); ++i) { | 128 for (size_t i = 0; i < expected_positions.size(); ++i) { |
129 EXPECT_EQ(expected_positions[i].first, actual_positions[i].first); | 129 EXPECT_EQ(expected_positions[i].first, actual_positions[i].first); |
130 EXPECT_EQ(expected_positions[i].second, actual_positions[i].second); | 130 EXPECT_EQ(expected_positions[i].second, actual_positions[i].second); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 protected: | 134 protected: |
135 test::TestBookmarkClient client_; | 135 TestBookmarkClient client_; |
136 scoped_ptr<BookmarkModel> model_; | 136 scoped_ptr<BookmarkModel> model_; |
137 | 137 |
138 private: | 138 private: |
139 DISALLOW_COPY_AND_ASSIGN(BookmarkIndexTest); | 139 DISALLOW_COPY_AND_ASSIGN(BookmarkIndexTest); |
140 }; | 140 }; |
141 | 141 |
142 // Various permutations with differing input, queries and output that exercises | 142 // Various permutations with differing input, queries and output that exercises |
143 // all query paths. | 143 // all query paths. |
144 TEST_F(BookmarkIndexTest, GetBookmarksMatching) { | 144 TEST_F(BookmarkIndexTest, GetBookmarksMatching) { |
145 struct TestData { | 145 struct TestData { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 // Select top two matches. | 456 // Select top two matches. |
457 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); | 457 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); |
458 | 458 |
459 ASSERT_EQ(2, static_cast<int>(matches.size())); | 459 ASSERT_EQ(2, static_cast<int>(matches.size())); |
460 EXPECT_EQ(data[0].url, matches[0].node->url()); | 460 EXPECT_EQ(data[0].url, matches[0].node->url()); |
461 EXPECT_EQ(data[3].url, matches[1].node->url()); | 461 EXPECT_EQ(data[3].url, matches[1].node->url()); |
462 } | 462 } |
463 | 463 |
464 } // namespace | 464 } // namespace |
465 } // namespace bookmarks | 465 } // namespace bookmarks |
OLD | NEW |