Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Side by Side Diff: chrome/browser/bookmarks/bookmark_index_unittest.cc

Issue 165455: Autocomplete suggestions for bookmark TitleMatch's does not order matching bo... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/bookmarks/bookmark_index.cc ('k') | chrome/browser/bookmarks/bookmark_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/message_loop.h"
8 #include "base/string_util.h" 9 #include "base/string_util.h"
9 #include "chrome/browser/bookmarks/bookmark_index.h" 10 #include "chrome/browser/bookmarks/bookmark_index.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/history/history_database.h"
13 #include "chrome/browser/history/in_memory_database.h"
11 #include "chrome/browser/history/query_parser.h" 14 #include "chrome/browser/history/query_parser.h"
15 #include "chrome/test/testing_profile.h"
12 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
13 17
14 class BookmarkIndexTest : public testing::Test { 18 class BookmarkIndexTest : public testing::Test {
15 public: 19 public:
16 BookmarkIndexTest() : model_(new BookmarkModel(NULL)) {} 20 BookmarkIndexTest() : model_(new BookmarkModel(NULL)) {}
17 21
18 void AddBookmarksWithTitles(const wchar_t** titles, size_t count) { 22 void AddBookmarksWithTitles(const wchar_t** titles, size_t count) {
19 std::vector<std::wstring> title_vector; 23 std::vector<std::wstring> title_vector;
20 for (size_t i = 0; i < count; ++i) 24 for (size_t i = 0; i < count; ++i)
21 title_vector.push_back(titles[i]); 25 title_vector.push_back(titles[i]);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 model_->GetBookmarksWithTitlesMatching(query, 1000, &matches); 79 model_->GetBookmarksWithTitlesMatching(query, 1000, &matches);
76 ASSERT_EQ(1U, matches.size()); 80 ASSERT_EQ(1U, matches.size());
77 const bookmark_utils::TitleMatch& match = matches[0]; 81 const bookmark_utils::TitleMatch& match = matches[0];
78 ASSERT_EQ(expected_positions.size(), match.match_positions.size()); 82 ASSERT_EQ(expected_positions.size(), match.match_positions.size());
79 for (size_t i = 0; i < expected_positions.size(); ++i) { 83 for (size_t i = 0; i < expected_positions.size(); ++i) {
80 EXPECT_EQ(expected_positions[i].first, match.match_positions[i].first); 84 EXPECT_EQ(expected_positions[i].first, match.match_positions[i].first);
81 EXPECT_EQ(expected_positions[i].second, match.match_positions[i].second); 85 EXPECT_EQ(expected_positions[i].second, match.match_positions[i].second);
82 } 86 }
83 } 87 }
84 88
85
86 protected: 89 protected:
87 scoped_ptr<BookmarkModel> model_; 90 scoped_ptr<BookmarkModel> model_;
88 91
89 private: 92 private:
90 DISALLOW_COPY_AND_ASSIGN(BookmarkIndexTest); 93 DISALLOW_COPY_AND_ASSIGN(BookmarkIndexTest);
91 }; 94 };
92 95
93 // Various permutations with differing input, queries and output that exercises 96 // Various permutations with differing input, queries and output that exercises
94 // all query paths. 97 // all query paths.
95 TEST_F(BookmarkIndexTest, Tests) { 98 TEST_F(BookmarkIndexTest, Tests) {
(...skipping 17 matching lines...) Expand all
113 // Exact and prefix match. 116 // Exact and prefix match.
114 { L"ab cdef ghij;ab;cde;cdef;ghi;cdef ab;ghij ab", 117 { L"ab cdef ghij;ab;cde;cdef;ghi;cdef ab;ghij ab",
115 L"ab cde ghi", 118 L"ab cde ghi",
116 L"ab cdef ghij"}, 119 L"ab cdef ghij"},
117 120
118 // Title with term multiple times. 121 // Title with term multiple times.
119 { L"ab ab", L"ab", L"ab ab"}, 122 { L"ab ab", L"ab", L"ab ab"},
120 123
121 // Make sure quotes don't do a prefix match. 124 // Make sure quotes don't do a prefix match.
122 { L"think", L"\"thi\"", L""}, 125 { L"think", L"\"thi\"", L""},
123
124 }; 126 };
125 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 127 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
126 std::vector<std::wstring> titles; 128 std::vector<std::wstring> titles;
127 SplitString(data[i].input, L';', &titles); 129 SplitString(data[i].input, L';', &titles);
128 AddBookmarksWithTitles(titles); 130 AddBookmarksWithTitles(titles);
129 131
130 std::vector<std::wstring> expected; 132 std::vector<std::wstring> expected;
131 if (!data[i].expected.empty()) 133 if (!data[i].expected.empty())
132 SplitString(data[i].expected, L';', &expected); 134 SplitString(data[i].expected, L';', &expected);
133 135
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) { 200 TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) {
199 const BookmarkNode* n1 = model_->AddURL(model_->other_node(), 0, L"\u0130 i", 201 const BookmarkNode* n1 = model_->AddURL(model_->other_node(), 0, L"\u0130 i",
200 GURL("http://www.google.com")); 202 GURL("http://www.google.com"));
201 203
202 std::vector<bookmark_utils::TitleMatch> matches; 204 std::vector<bookmark_utils::TitleMatch> matches;
203 model_->GetBookmarksWithTitlesMatching(L"i", 100, &matches); 205 model_->GetBookmarksWithTitlesMatching(L"i", 100, &matches);
204 ASSERT_EQ(1U, matches.size()); 206 ASSERT_EQ(1U, matches.size());
205 EXPECT_TRUE(matches[0].node == n1); 207 EXPECT_TRUE(matches[0].node == n1);
206 EXPECT_TRUE(matches[0].match_positions.empty()); 208 EXPECT_TRUE(matches[0].match_positions.empty());
207 } 209 }
210
211 TEST_F(BookmarkIndexTest, GetResultsSortedByTypedCount) {
212 // This ensures MessageLoop::current() will exist, which is needed by
213 // TestingProfile::BlockUntilHistoryProcessesPendingRequests().
214 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
215
216 TestingProfile profile;
217 profile.CreateHistoryService(true);
218 profile.BlockUntilHistoryProcessesPendingRequests();
219 profile.CreateBookmarkModel(true);
220 profile.BlockUntilBookmarkModelLoaded();
221
222 BookmarkModel* model = profile.GetBookmarkModel();
223
224 HistoryService* const history_service =
225 profile.GetHistoryService(Profile::EXPLICIT_ACCESS);
226
227 history::URLDatabase* url_db = history_service->in_memory_database();
228
229 struct TestData {
230 const GURL url;
231 const std::wstring title;
232 const int typed_count;
233 } data[] = {
234 { GURL("http://www.google.com/"), L"Google", 100 },
235 { GURL("http://maps.google.com/"), L"Google Maps", 40 },
236 { GURL("http://docs.google.com/"), L"Google Docs", 50 },
237 { GURL("http://reader.google.com/"), L"Google Reader", 80 },
238 };
239
240 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
241 history::URLRow info(data[i].url);
242 info.set_title(data[i].title);
243 info.set_typed_count(data[i].typed_count);
244 // Populate the InMemoryDatabase....
245 url_db->AddURL(info);
246 // Populate the BookmarkIndex.
247 model->AddURL(model->other_node(), i, data[i].title, data[i].url);
248 }
249
250 // Check that the InMemoryDatabase stored the URLs properly.
251 history::URLRow result1;
252 url_db->GetRowForURL(data[0].url, &result1);
253 EXPECT_EQ(data[0].title, result1.title());
254
255 history::URLRow result2;
256 url_db->GetRowForURL(data[1].url, &result2);
257 EXPECT_EQ(data[1].title, result2.title());
258
259 history::URLRow result3;
260 url_db->GetRowForURL(data[2].url, &result3);
261 EXPECT_EQ(data[2].title, result3.title());
262
263 history::URLRow result4;
264 url_db->GetRowForURL(data[3].url, &result4);
265 EXPECT_EQ(data[3].title, result4.title());
266
267 // Populate match nodes.
268 std::vector<bookmark_utils::TitleMatch> matches;
269 model->GetBookmarksWithTitlesMatching(L"google", 4, &matches);
270
271 // The resulting order should be:
272 // 1. Google (google.com) 100
273 // 2. Google Reader (google.com/reader) 80
274 // 3. Google Docs (docs.google.com) 50
275 // 4. Google Maps (maps.google.com) 40
276 EXPECT_EQ(4, static_cast<int>(matches.size()));
277 EXPECT_EQ(data[0].url, matches[0].node->GetURL());
278 EXPECT_EQ(data[3].url, matches[1].node->GetURL());
279 EXPECT_EQ(data[2].url, matches[2].node->GetURL());
280 EXPECT_EQ(data[1].url, matches[3].node->GetURL());
281
282 matches.clear();
283 // Select top two matches.
284 model->GetBookmarksWithTitlesMatching(L"google", 2, &matches);
285
286 EXPECT_EQ(2, static_cast<int>(matches.size()));
287 EXPECT_EQ(data[0].url, matches[0].node->GetURL());
288 EXPECT_EQ(data[3].url, matches[1].node->GetURL());
289 }
290
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_index.cc ('k') | chrome/browser/bookmarks/bookmark_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698