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

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

Issue 184663002: Omnibox: Make URLs of Bookmarks Searchable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ALL_MATCHES (in response to recent changes) Created 6 years, 8 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.h » ('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) 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/bookmarks/bookmark_index.h" 5 #include "chrome/browser/bookmarks/bookmark_index.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.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 "chrome/browser/bookmarks/bookmark_model.h" 15 #include "chrome/browser/bookmarks/bookmark_model.h"
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
17 #include "chrome/browser/bookmarks/bookmark_test_helpers.h" 17 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
18 #include "chrome/browser/history/history_service.h" 18 #include "chrome/browser/history/history_service.h"
19 #include "chrome/browser/history/history_service_factory.h" 19 #include "chrome/browser/history/history_service_factory.h"
20 #include "chrome/browser/history/url_database.h" 20 #include "chrome/browser/history/url_database.h"
21 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
22 #include "components/bookmarks/core/browser/bookmark_title_match.h" 22 #include "components/bookmarks/core/browser/bookmark_match.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 23 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 using base::ASCIIToUTF16; 26 using base::ASCIIToUTF16;
27 27
28 class BookmarkIndexTest : public testing::Test { 28 class BookmarkIndexTest : public testing::Test {
29 public: 29 public:
30 BookmarkIndexTest() : model_(new BookmarkModel(NULL)) {} 30 BookmarkIndexTest() : model_(new BookmarkModel(NULL, false)) {
31
32 void AddBookmarksWithTitles(const char** titles, size_t count) {
33 std::vector<std::string> title_vector;
34 for (size_t i = 0; i < count; ++i)
35 title_vector.push_back(titles[i]);
36 AddBookmarksWithTitles(title_vector);
37 } 31 }
38 32
39 void AddBookmarksWithTitles(const std::vector<std::string>& titles) { 33 typedef std::pair<std::string, std::string> TitleAndURL;
40 GURL url("about:blank"); 34
41 for (size_t i = 0; i < titles.size(); ++i) 35 void AddBookmarks(const char** titles, const char** urls, size_t count) {
36 // The pair is (title, url).
37 std::vector<TitleAndURL> bookmarks;
38 for (size_t i = 0; i < count; ++i) {
39 TitleAndURL bookmark(titles[i], urls[i]);
40 bookmarks.push_back(bookmark);
41 }
42 AddBookmarks(bookmarks);
43 }
44
45 void AddBookmarks(const std::vector<TitleAndURL> bookmarks) {
46 for (size_t i = 0; i < bookmarks.size(); ++i) {
42 model_->AddURL(model_->other_node(), static_cast<int>(i), 47 model_->AddURL(model_->other_node(), static_cast<int>(i),
43 ASCIIToUTF16(titles[i]), url); 48 ASCIIToUTF16(bookmarks[i].first),
49 GURL(bookmarks[i].second));
50 }
44 } 51 }
45 52
46 void ExpectMatches(const std::string& query, 53 void ExpectMatches(const std::string& query,
47 const char** expected_titles, 54 const char** expected_titles,
48 size_t expected_count) { 55 size_t expected_count) {
49 std::vector<std::string> title_vector; 56 std::vector<std::string> title_vector;
50 for (size_t i = 0; i < expected_count; ++i) 57 for (size_t i = 0; i < expected_count; ++i)
51 title_vector.push_back(expected_titles[i]); 58 title_vector.push_back(expected_titles[i]);
52 ExpectMatches(query, title_vector); 59 ExpectMatches(query, title_vector);
53 } 60 }
54 61
55 void ExpectMatches(const std::string& query, 62 void ExpectMatches(const std::string& query,
56 const std::vector<std::string>& expected_titles) { 63 const std::vector<std::string>& expected_titles) {
57 std::vector<BookmarkTitleMatch> matches; 64 std::vector<BookmarkMatch> matches;
58 model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16(query), 1000, &matches); 65 model_->GetBookmarksMatching(ASCIIToUTF16(query), 1000, &matches);
59 ASSERT_EQ(expected_titles.size(), matches.size()); 66 ASSERT_EQ(expected_titles.size(), matches.size());
60 for (size_t i = 0; i < expected_titles.size(); ++i) { 67 for (size_t i = 0; i < expected_titles.size(); ++i) {
61 bool found = false; 68 bool found = false;
62 for (size_t j = 0; j < matches.size(); ++j) { 69 for (size_t j = 0; j < matches.size(); ++j) {
63 if (ASCIIToUTF16(expected_titles[i]) == matches[j].node->GetTitle()) { 70 if (ASCIIToUTF16(expected_titles[i]) == matches[j].node->GetTitle()) {
64 matches.erase(matches.begin() + j); 71 matches.erase(matches.begin() + j);
65 found = true; 72 found = true;
66 break; 73 break;
67 } 74 }
68 } 75 }
69 ASSERT_TRUE(found); 76 ASSERT_TRUE(found);
70 } 77 }
71 } 78 }
72 79
73 void ExtractMatchPositions(const std::string& string, 80 void ExtractMatchPositions(const std::string& string,
74 BookmarkTitleMatch::MatchPositions* matches) { 81 BookmarkMatch::MatchPositions* matches) {
75 std::vector<std::string> match_strings; 82 std::vector<std::string> match_strings;
76 base::SplitString(string, ':', &match_strings); 83 base::SplitString(string, ':', &match_strings);
77 for (size_t i = 0; i < match_strings.size(); ++i) { 84 for (size_t i = 0; i < match_strings.size(); ++i) {
78 std::vector<std::string> chunks; 85 std::vector<std::string> chunks;
79 base::SplitString(match_strings[i], ',', &chunks); 86 base::SplitString(match_strings[i], ',', &chunks);
80 ASSERT_EQ(2U, chunks.size()); 87 ASSERT_EQ(2U, chunks.size());
81 matches->push_back(BookmarkTitleMatch::MatchPosition()); 88 matches->push_back(BookmarkMatch::MatchPosition());
82 int chunks0, chunks1; 89 int chunks0, chunks1;
83 base::StringToInt(chunks[0], &chunks0); 90 base::StringToInt(chunks[0], &chunks0);
84 base::StringToInt(chunks[1], &chunks1); 91 base::StringToInt(chunks[1], &chunks1);
85 matches->back().first = chunks0; 92 matches->back().first = chunks0;
86 matches->back().second = chunks1; 93 matches->back().second = chunks1;
87 } 94 }
88 } 95 }
89 96
90 void ExpectMatchPositions( 97 void ExpectMatchPositions(
91 const std::string& query, 98 const BookmarkMatch::MatchPositions& actual_positions,
92 const BookmarkTitleMatch::MatchPositions& expected_positions) { 99 const BookmarkMatch::MatchPositions& expected_positions) {
93 std::vector<BookmarkTitleMatch> matches; 100 ASSERT_EQ(expected_positions.size(), actual_positions.size());
94 model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16(query), 1000, &matches);
95 ASSERT_EQ(1U, matches.size());
96 const BookmarkTitleMatch& match = matches[0];
97 ASSERT_EQ(expected_positions.size(), match.match_positions.size());
98 for (size_t i = 0; i < expected_positions.size(); ++i) { 101 for (size_t i = 0; i < expected_positions.size(); ++i) {
99 EXPECT_EQ(expected_positions[i].first, match.match_positions[i].first); 102 EXPECT_EQ(expected_positions[i].first, actual_positions[i].first);
100 EXPECT_EQ(expected_positions[i].second, match.match_positions[i].second); 103 EXPECT_EQ(expected_positions[i].second, actual_positions[i].second);
101 } 104 }
102 } 105 }
103 106
104 protected: 107 protected:
105 scoped_ptr<BookmarkModel> model_; 108 scoped_ptr<BookmarkModel> model_;
106 109
107 private: 110 private:
108 DISALLOW_COPY_AND_ASSIGN(BookmarkIndexTest); 111 DISALLOW_COPY_AND_ASSIGN(BookmarkIndexTest);
109 }; 112 };
110 113
111 // Various permutations with differing input, queries and output that exercises 114 // Various permutations with differing input, queries and output that exercises
112 // all query paths. 115 // all query paths.
113 TEST_F(BookmarkIndexTest, Tests) { 116 TEST_F(BookmarkIndexTest, GetBookmarksMatching) {
114 struct TestData { 117 struct TestData {
115 const std::string input; 118 const std::string titles;
116 const std::string query; 119 const std::string query;
117 const std::string expected; 120 const std::string expected;
118 } data[] = { 121 } data[] = {
119 // Trivial test case of only one term, exact match. 122 // Trivial test case of only one term, exact match.
120 { "a;b", "A", "a" }, 123 { "a;b", "A", "a" },
121 124
122 // Prefix match, one term. 125 // Prefix match, one term.
123 { "abcd;abc;b", "abc", "abcd;abc" }, 126 { "abcd;abc;b", "abc", "abcd;abc" },
124 127
125 // Prefix match, multiple terms. 128 // Prefix match, multiple terms.
(...skipping 11 matching lines...) Expand all
137 { "ab ab", "ab", "ab ab"}, 140 { "ab ab", "ab", "ab ab"},
138 141
139 // Make sure quotes don't do a prefix match. 142 // Make sure quotes don't do a prefix match.
140 { "think", "\"thi\"", ""}, 143 { "think", "\"thi\"", ""},
141 144
142 // Prefix matches against multiple candidates. 145 // Prefix matches against multiple candidates.
143 { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4"}, 146 { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4"},
144 }; 147 };
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 148 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
146 std::vector<std::string> titles; 149 std::vector<std::string> titles;
147 base::SplitString(data[i].input, ';', &titles); 150 base::SplitString(data[i].titles, ';', &titles);
148 AddBookmarksWithTitles(titles); 151 std::vector<TitleAndURL> bookmarks;
152 for (size_t j = 0; j < titles.size(); ++j) {
153 TitleAndURL bookmark(titles[j], "about:blank");
154 bookmarks.push_back(bookmark);
155 }
156 AddBookmarks(bookmarks);
149 157
150 std::vector<std::string> expected; 158 std::vector<std::string> expected;
151 if (!data[i].expected.empty()) 159 if (!data[i].expected.empty())
152 base::SplitString(data[i].expected, ';', &expected); 160 base::SplitString(data[i].expected, ';', &expected);
153 161
154 ExpectMatches(data[i].query, expected); 162 ExpectMatches(data[i].query, expected);
155 163
156 model_.reset(new BookmarkModel(NULL)); 164 model_.reset(new BookmarkModel(NULL, false));
157 } 165 }
158 } 166 }
159 167
160 TEST_F(BookmarkIndexTest, TestNormalization) { 168 // Analogous to GetBookmarksMatching, this test tests various permutations
169 // of title, URL, and input to see if the title/URL matches the input as
170 // expected.
171 TEST_F(BookmarkIndexTest, GetBookmarksMatchingWithURLs) {
172 struct TestData {
173 const std::string query;
174 const std::string title;
175 const std::string url;
176 const bool should_be_retrieved;
177 } data[] = {
178 // Test single-word inputs. Include both exact matches and prefix matches.
179 { "foo", "Foo", "http://www.bar.com/", true },
180 { "foo", "Foodie", "http://www.bar.com/", true },
181 { "foo", "Bar", "http://www.foo.com/", true },
182 { "foo", "Bar", "http://www.foodie.com/", true },
183 { "foo", "Foo", "http://www.foo.com/", true },
184 { "foo", "Bar", "http://www.bar.com/", false },
185 { "foo", "Bar", "http://www.bar.com/blah/foo/blah-again/ ", true },
186 { "foo", "Bar", "http://www.bar.com/blah/foodie/blah-again/ ", true },
187 { "foo", "Bar", "http://www.bar.com/blah-foo/blah-again/ ", true },
188 { "foo", "Bar", "http://www.bar.com/blah-foodie/blah-again/ ", true },
189 { "foo", "Bar", "http://www.bar.com/blahafoo/blah-again/ ", false },
190
191 // Test multi-word inputs.
192 { "foo bar", "Foo Bar", "http://baz.com/", true },
193 { "foo bar", "Foodie Bar", "http://baz.com/", true },
194 { "bar foo", "Foo Bar", "http://baz.com/", true },
195 { "bar foo", "Foodie Barly", "http://baz.com/", true },
196 { "foo bar", "Foo Baz", "http://baz.com/", false },
197 { "foo bar", "Foo Baz", "http://bar.com/", true },
198 { "foo bar", "Foo Baz", "http://barly.com/", true },
199 { "foo bar", "Foodie Baz", "http://barly.com/", true },
200 { "bar foo", "Foo Baz", "http://bar.com/", true },
201 { "bar foo", "Foo Baz", "http://barly.com/", true },
202 { "foo bar", "Baz Bar", "http://blah.com/foo", true },
203 { "foo bar", "Baz Barly", "http://blah.com/foodie", true },
204 { "foo bar", "Baz Bur", "http://blah.com/foo/bar", true },
205 { "foo bar", "Baz Bur", "http://blah.com/food/barly", true },
206 { "foo bar", "Baz Bur", "http://bar.com/blah/foo", true },
207 { "foo bar", "Baz Bur", "http://barly.com/blah/food", true },
208 { "foo bar", "Baz Bur", "http://bar.com/blah/flub", false },
209 { "foo bar", "Baz Bur", "http://foo.com/blah/flub", false }
210 };
211
212 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
213 model_.reset(new BookmarkModel(NULL, true));
214 std::vector<TitleAndURL> bookmarks;
215 bookmarks.push_back(TitleAndURL(data[i].title, data[i].url));
216 AddBookmarks(bookmarks);
217
218 std::vector<std::string> expected;
219 if (data[i].should_be_retrieved)
220 expected.push_back(data[i].title);
221
222 ExpectMatches(data[i].query, expected);
223 }
224 }
225
226 TEST_F(BookmarkIndexTest, Normalization) {
161 struct TestData { 227 struct TestData {
162 const char* title; 228 const char* title;
163 const char* query; 229 const char* query;
164 } data[] = { 230 } data[] = {
165 { "fooa\xcc\x88-test", "foo\xc3\xa4-test" }, 231 { "fooa\xcc\x88-test", "foo\xc3\xa4-test" },
166 { "fooa\xcc\x88-test", "fooa\xcc\x88-test" }, 232 { "fooa\xcc\x88-test", "fooa\xcc\x88-test" },
167 { "fooa\xcc\x88-test", "foo\xc3\xa4" }, 233 { "fooa\xcc\x88-test", "foo\xc3\xa4" },
168 { "fooa\xcc\x88-test", "fooa\xcc\x88" }, 234 { "fooa\xcc\x88-test", "fooa\xcc\x88" },
169 { "fooa\xcc\x88-test", "foo" }, 235 { "fooa\xcc\x88-test", "foo" },
170 { "foo\xc3\xa4-test", "foo\xc3\xa4-test" }, 236 { "foo\xc3\xa4-test", "foo\xc3\xa4-test" },
171 { "foo\xc3\xa4-test", "fooa\xcc\x88-test" }, 237 { "foo\xc3\xa4-test", "fooa\xcc\x88-test" },
172 { "foo\xc3\xa4-test", "foo\xc3\xa4" }, 238 { "foo\xc3\xa4-test", "foo\xc3\xa4" },
173 { "foo\xc3\xa4-test", "fooa\xcc\x88" }, 239 { "foo\xc3\xa4-test", "fooa\xcc\x88" },
174 { "foo\xc3\xa4-test", "foo" }, 240 { "foo\xc3\xa4-test", "foo" },
175 { "foo", "foo" } 241 { "foo", "foo" }
176 }; 242 };
177 243
178 GURL url("about:blank"); 244 GURL url("about:blank");
179 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 245 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
180 model_->AddURL(model_->other_node(), 0, base::UTF8ToUTF16(data[i].title), 246 model_->AddURL(model_->other_node(), 0, base::UTF8ToUTF16(data[i].title),
181 url); 247 url);
182 std::vector<BookmarkTitleMatch> matches; 248 std::vector<BookmarkMatch> matches;
183 model_->GetBookmarksWithTitlesMatching( 249 model_->GetBookmarksMatching(
184 base::UTF8ToUTF16(data[i].query), 10, &matches); 250 base::UTF8ToUTF16(data[i].query), 10, &matches);
185 EXPECT_EQ(1u, matches.size()); 251 EXPECT_EQ(1u, matches.size());
186 model_.reset(new BookmarkModel(NULL)); 252 model_.reset(new BookmarkModel(NULL, false));
187 } 253 }
188 } 254 }
189 255
190 // Makes sure match positions are updated appropriately. 256 // Makes sure match positions are updated appropriately for title matches.
191 TEST_F(BookmarkIndexTest, MatchPositions) { 257 TEST_F(BookmarkIndexTest, MatchPositionsTitles) {
192 struct TestData { 258 struct TestData {
193 const std::string title; 259 const std::string title;
194 const std::string query; 260 const std::string query;
195 const std::string expected; 261 const std::string expected_title_match_positions;
196 } data[] = { 262 } data[] = {
197 // Trivial test case of only one term, exact match. 263 // Trivial test case of only one term, exact match.
198 { "a", "A", "0,1" }, 264 { "a", "A", "0,1" },
199 { "foo bar", "bar", "4,7" }, 265 { "foo bar", "bar", "4,7" },
200 { "fooey bark", "bar foo", "0,3:6,9"}, 266 { "fooey bark", "bar foo", "0,3:6,9" },
201 // Non-trivial tests. 267 // Non-trivial tests.
202 { "foobar foo", "foobar foo", "0,6:7,10" }, 268 { "foobar foo", "foobar foo", "0,6:7,10" },
203 { "foobar foo", "foo foobar", "0,6:7,10" }, 269 { "foobar foo", "foo foobar", "0,6:7,10" },
204 { "foobar foobar", "foobar foo", "0,6:7,13" }, 270 { "foobar foobar", "foobar foo", "0,6:7,13" },
205 { "foobar foobar", "foo foobar", "0,6:7,13" }, 271 { "foobar foobar", "foo foobar", "0,6:7,13" },
206 }; 272 };
207 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 273 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
208 std::vector<std::string> titles; 274 std::vector<TitleAndURL> bookmarks;
209 titles.push_back(data[i].title); 275 TitleAndURL bookmark(data[i].title, "about:blank");
210 AddBookmarksWithTitles(titles); 276 bookmarks.push_back(bookmark);
277 AddBookmarks(bookmarks);
211 278
212 BookmarkTitleMatch::MatchPositions expected_matches; 279 std::vector<BookmarkMatch> matches;
213 ExtractMatchPositions(data[i].expected, &expected_matches); 280 model_->GetBookmarksMatching(ASCIIToUTF16(data[i].query), 1000, &matches);
214 ExpectMatchPositions(data[i].query, expected_matches); 281 ASSERT_EQ(1U, matches.size());
215 282
216 model_.reset(new BookmarkModel(NULL)); 283 BookmarkMatch::MatchPositions expected_title_matches;
284 ExtractMatchPositions(data[i].expected_title_match_positions,
285 &expected_title_matches);
286 ExpectMatchPositions(matches[0].title_match_positions,
287 expected_title_matches);
288
289 model_.reset(new BookmarkModel(NULL, false));
290 }
291 }
292
293 // Makes sure match positions are updated appropriately for URL matches.
294 TEST_F(BookmarkIndexTest, MatchPositionsURLs) {
295 struct TestData {
296 const std::string query;
297 const std::string url;
298 const std::string expected_url_match_positions;
299 } data[] = {
300 { "foo", "http://www.foo.com/", "11,14" },
301 { "foo", "http://www.foodie.com/", "11,14" },
302 { "foo", "http://www.foofoo.com/", "11,14" },
303 { "www", "http://www.foo.com/", "7,10" },
304 { "foo", "http://www.foodie.com/blah/foo/fi", "11,14:27,30" },
305 { "foo", "http://www.blah.com/blah/foo/fi", "25,28" },
306 { "foo www", "http://www.foodie.com/blah/foo/fi", "7,10:11,14:27,30" },
307 { "www foo", "http://www.foodie.com/blah/foo/fi", "7,10:11,14:27,30" },
308 { "www bla", "http://www.foodie.com/blah/foo/fi", "7,10:22,25" },
309 { "http", "http://www.foo.com/", "0,4" },
310 { "http www", "http://www.foo.com/", "0,4:7,10" },
311 { "http foo", "http://www.foo.com/", "0,4:11,14" },
312 { "http foo", "http://www.bar.com/baz/foodie/hi", "0,4:23,26" }
313 };
314
315 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
316 model_.reset(new BookmarkModel(NULL, true));
317 std::vector<TitleAndURL> bookmarks;
318 TitleAndURL bookmark("123456", data[i].url);
319 bookmarks.push_back(bookmark);
320 AddBookmarks(bookmarks);
321
322 std::vector<BookmarkMatch> matches;
323 model_->GetBookmarksMatching(ASCIIToUTF16(data[i].query), 1000, &matches);
324 ASSERT_EQ(1U, matches.size()) << data[i].url << data[i].query;
325
326 BookmarkMatch::MatchPositions expected_url_matches;
327 ExtractMatchPositions(data[i].expected_url_match_positions,
328 &expected_url_matches);
329 ExpectMatchPositions(matches[0].url_match_positions, expected_url_matches);
217 } 330 }
218 } 331 }
219 332
220 // Makes sure index is updated when a node is removed. 333 // Makes sure index is updated when a node is removed.
221 TEST_F(BookmarkIndexTest, Remove) { 334 TEST_F(BookmarkIndexTest, Remove) {
222 const char* input[] = { "a", "b" }; 335 const char* titles[] = { "a", "b" };
223 AddBookmarksWithTitles(input, ARRAYSIZE_UNSAFE(input)); 336 const char* urls[] = { "about:blank", "about:blank" };
337 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles));
224 338
225 // Remove the node and make sure we don't get back any results. 339 // Remove the node and make sure we don't get back any results.
226 model_->Remove(model_->other_node(), 0); 340 model_->Remove(model_->other_node(), 0);
227 ExpectMatches("A", NULL, 0U); 341 ExpectMatches("A", NULL, 0U);
228 } 342 }
229 343
230 // Makes sure index is updated when a node's title is changed. 344 // Makes sure index is updated when a node's title is changed.
231 TEST_F(BookmarkIndexTest, ChangeTitle) { 345 TEST_F(BookmarkIndexTest, ChangeTitle) {
232 const char* input[] = { "a", "b" }; 346 const char* titles[] = { "a", "b" };
233 AddBookmarksWithTitles(input, ARRAYSIZE_UNSAFE(input)); 347 const char* urls[] = { "about:blank", "about:blank" };
348 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles));
234 349
235 // Remove the node and make sure we don't get back any results. 350 // Remove the node and make sure we don't get back any results.
236 const char* expected[] = { "blah" }; 351 const char* expected[] = { "blah" };
237 model_->SetTitle(model_->other_node()->GetChild(0), ASCIIToUTF16("blah")); 352 model_->SetTitle(model_->other_node()->GetChild(0), ASCIIToUTF16("blah"));
238 ExpectMatches("BlAh", expected, ARRAYSIZE_UNSAFE(expected)); 353 ExpectMatches("BlAh", expected, ARRAYSIZE_UNSAFE(expected));
239 } 354 }
240 355
241 // Makes sure no more than max queries is returned. 356 // Makes sure no more than max queries is returned.
242 TEST_F(BookmarkIndexTest, HonorMax) { 357 TEST_F(BookmarkIndexTest, HonorMax) {
243 const char* input[] = { "abcd", "abcde" }; 358 const char* titles[] = { "abcd", "abcde" };
244 AddBookmarksWithTitles(input, ARRAYSIZE_UNSAFE(input)); 359 const char* urls[] = { "about:blank", "about:blank" };
360 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles));
245 361
246 std::vector<BookmarkTitleMatch> matches; 362 std::vector<BookmarkMatch> matches;
247 model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16("ABc"), 1, &matches); 363 model_->GetBookmarksMatching(ASCIIToUTF16("ABc"), 1, &matches);
248 EXPECT_EQ(1U, matches.size()); 364 EXPECT_EQ(1U, matches.size());
249 } 365 }
250 366
251 // Makes sure if the lower case string of a bookmark title is more characters 367 // Makes sure if the lower case string of a bookmark title is more characters
252 // than the upper case string no match positions are returned. 368 // than the upper case string no match positions are returned.
253 TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) { 369 TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) {
254 const BookmarkNode* n1 = model_->AddURL(model_->other_node(), 0, 370 const BookmarkNode* n1 = model_->AddURL(model_->other_node(), 0,
255 base::WideToUTF16(L"\u0130 i"), 371 base::WideToUTF16(L"\u0130 i"),
256 GURL("http://www.google.com")); 372 GURL("http://www.google.com"));
257 373
258 std::vector<BookmarkTitleMatch> matches; 374 std::vector<BookmarkMatch> matches;
259 model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16("i"), 100, &matches); 375 model_->GetBookmarksMatching(ASCIIToUTF16("i"), 100, &matches);
260 ASSERT_EQ(1U, matches.size()); 376 ASSERT_EQ(1U, matches.size());
261 EXPECT_TRUE(matches[0].node == n1); 377 EXPECT_TRUE(matches[0].node == n1);
262 EXPECT_TRUE(matches[0].match_positions.empty()); 378 EXPECT_TRUE(matches[0].title_match_positions.empty());
263 } 379 }
264 380
265 TEST_F(BookmarkIndexTest, GetResultsSortedByTypedCount) { 381 TEST_F(BookmarkIndexTest, GetResultsSortedByTypedCount) {
266 // This ensures MessageLoop::current() will exist, which is needed by 382 // This ensures MessageLoop::current() will exist, which is needed by
267 // TestingProfile::BlockUntilHistoryProcessesPendingRequests(). 383 // TestingProfile::BlockUntilHistoryProcessesPendingRequests().
268 content::TestBrowserThreadBundle thread_bundle; 384 content::TestBrowserThreadBundle thread_bundle;
269 385
270 TestingProfile profile; 386 TestingProfile profile;
271 ASSERT_TRUE(profile.CreateHistoryService(true, false)); 387 ASSERT_TRUE(profile.CreateHistoryService(true, false));
272 profile.BlockUntilHistoryProcessesPendingRequests(); 388 profile.BlockUntilHistoryProcessesPendingRequests();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 429
314 history::URLRow result3; 430 history::URLRow result3;
315 url_db->GetRowForURL(data[2].url, &result3); 431 url_db->GetRowForURL(data[2].url, &result3);
316 EXPECT_EQ(data[2].title, base::UTF16ToUTF8(result3.title())); 432 EXPECT_EQ(data[2].title, base::UTF16ToUTF8(result3.title()));
317 433
318 history::URLRow result4; 434 history::URLRow result4;
319 url_db->GetRowForURL(data[3].url, &result4); 435 url_db->GetRowForURL(data[3].url, &result4);
320 EXPECT_EQ(data[3].title, base::UTF16ToUTF8(result4.title())); 436 EXPECT_EQ(data[3].title, base::UTF16ToUTF8(result4.title()));
321 437
322 // Populate match nodes. 438 // Populate match nodes.
323 std::vector<BookmarkTitleMatch> matches; 439 std::vector<BookmarkMatch> matches;
324 model->GetBookmarksWithTitlesMatching(ASCIIToUTF16("google"), 4, &matches); 440 model->GetBookmarksMatching(ASCIIToUTF16("google"), 4, &matches);
325 441
326 // The resulting order should be: 442 // The resulting order should be:
327 // 1. Google (google.com) 100 443 // 1. Google (google.com) 100
328 // 2. Google Reader (google.com/reader) 80 444 // 2. Google Reader (google.com/reader) 80
329 // 3. Google Docs (docs.google.com) 50 445 // 3. Google Docs (docs.google.com) 50
330 // 4. Google Maps (maps.google.com) 40 446 // 4. Google Maps (maps.google.com) 40
331 EXPECT_EQ(4, static_cast<int>(matches.size())); 447 EXPECT_EQ(4, static_cast<int>(matches.size()));
332 EXPECT_EQ(data[0].url, matches[0].node->url()); 448 EXPECT_EQ(data[0].url, matches[0].node->url());
333 EXPECT_EQ(data[3].url, matches[1].node->url()); 449 EXPECT_EQ(data[3].url, matches[1].node->url());
334 EXPECT_EQ(data[2].url, matches[2].node->url()); 450 EXPECT_EQ(data[2].url, matches[2].node->url());
335 EXPECT_EQ(data[1].url, matches[3].node->url()); 451 EXPECT_EQ(data[1].url, matches[3].node->url());
336 452
337 matches.clear(); 453 matches.clear();
338 // Select top two matches. 454 // Select top two matches.
339 model->GetBookmarksWithTitlesMatching(ASCIIToUTF16("google"), 2, &matches); 455 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches);
340 456
341 EXPECT_EQ(2, static_cast<int>(matches.size())); 457 EXPECT_EQ(2, static_cast<int>(matches.size()));
342 EXPECT_EQ(data[0].url, matches[0].node->url()); 458 EXPECT_EQ(data[0].url, matches[0].node->url());
343 EXPECT_EQ(data[3].url, matches[1].node->url()); 459 EXPECT_EQ(data[3].url, matches[1].node->url());
344 } 460 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_index.cc ('k') | chrome/browser/bookmarks/bookmark_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698