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/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" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 &expected_title_matches); | 286 &expected_title_matches); |
287 ExpectMatchPositions(matches[0].title_match_positions, | 287 ExpectMatchPositions(matches[0].title_match_positions, |
288 expected_title_matches); | 288 expected_title_matches); |
289 | 289 |
290 model_ = client_.CreateModel(false); | 290 model_ = client_.CreateModel(false); |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 // Makes sure match positions are updated appropriately for URL matches. | 294 // Makes sure match positions are updated appropriately for URL matches. |
295 TEST_F(BookmarkIndexTest, MatchPositionsURLs) { | 295 TEST_F(BookmarkIndexTest, MatchPositionsURLs) { |
| 296 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 |
| 297 const std::string ja_wiki_url = "http://ja.wikipedia.org/wiki/%E7%AC%AC%E4" |
| 298 "%BA%8C%E6%AC%A1%E4%B8%96%E7%95%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7" |
| 299 ".E3.83.AB.E3.82.B5.E3.82.A4.E3.83.A6.E4.BD.93.E5.88.B6"; |
296 struct TestData { | 300 struct TestData { |
297 const std::string query; | 301 const std::string query; |
298 const std::string url; | 302 const std::string url; |
299 const std::string expected_url_match_positions; | 303 const std::string expected_url_match_positions; |
300 } data[] = { | 304 } data[] = { |
301 { "foo", "http://www.foo.com/", "11,14" }, | 305 { "foo", "http://www.foo.com/", "11,14" }, |
302 { "foo", "http://www.foodie.com/", "11,14" }, | 306 { "foo", "http://www.foodie.com/", "11,14" }, |
303 { "foo", "http://www.foofoo.com/", "11,14" }, | 307 { "foo", "http://www.foofoo.com/", "11,14" }, |
304 { "www", "http://www.foo.com/", "7,10" }, | 308 { "www", "http://www.foo.com/", "7,10" }, |
305 { "foo", "http://www.foodie.com/blah/foo/fi", "11,14:27,30" }, | 309 { "foo", "http://www.foodie.com/blah/foo/fi", "11,14:27,30" }, |
306 { "foo", "http://www.blah.com/blah/foo/fi", "25,28" }, | 310 { "foo", "http://www.blah.com/blah/foo/fi", "25,28" }, |
307 { "foo www", "http://www.foodie.com/blah/foo/fi", "7,10:11,14:27,30" }, | 311 { "foo www", "http://www.foodie.com/blah/foo/fi", "7,10:11,14:27,30" }, |
308 { "www foo", "http://www.foodie.com/blah/foo/fi", "7,10:11,14:27,30" }, | 312 { "www foo", "http://www.foodie.com/blah/foo/fi", "7,10:11,14:27,30" }, |
309 { "www bla", "http://www.foodie.com/blah/foo/fi", "7,10:22,25" }, | 313 { "www bla", "http://www.foodie.com/blah/foo/fi", "7,10:22,25" }, |
310 { "http", "http://www.foo.com/", "0,4" }, | 314 { "http", "http://www.foo.com/", "0,4" }, |
311 { "http www", "http://www.foo.com/", "0,4:7,10" }, | 315 { "http www", "http://www.foo.com/", "0,4:7,10" }, |
312 { "http foo", "http://www.foo.com/", "0,4:11,14" }, | 316 { "http foo", "http://www.foo.com/", "0,4:11,14" }, |
313 { "http foo", "http://www.bar.com/baz/foodie/hi", "0,4:23,26" } | 317 { "http foo", "http://www.bar.com/baz/foodie/hi", "0,4:23,26" }, |
| 318 { "第二次", ja_wiki_url, "29,56" }, |
| 319 { "ja 第二次", ja_wiki_url, "7,9:29,56" }, |
| 320 { "第二次 E3.8", ja_wiki_url, "29,56:94,98:103,107:" |
| 321 "112,116:121,125:" |
| 322 "130,134:139,143" } |
314 }; | 323 }; |
315 | 324 |
316 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 325 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
317 model_ = client_.CreateModel(true); | 326 model_ = client_.CreateModel(true); |
318 std::vector<TitleAndURL> bookmarks; | 327 std::vector<TitleAndURL> bookmarks; |
319 TitleAndURL bookmark("123456", data[i].url); | 328 TitleAndURL bookmark("123456", data[i].url); |
320 bookmarks.push_back(bookmark); | 329 bookmarks.push_back(bookmark); |
321 AddBookmarks(bookmarks); | 330 AddBookmarks(bookmarks); |
322 | 331 |
323 std::vector<BookmarkMatch> matches; | 332 std::vector<BookmarkMatch> matches; |
324 model_->GetBookmarksMatching(ASCIIToUTF16(data[i].query), 1000, &matches); | 333 model_->GetBookmarksMatching( |
| 334 base::UTF8ToUTF16(data[i].query), 1000, &matches); |
325 ASSERT_EQ(1U, matches.size()) << data[i].url << data[i].query; | 335 ASSERT_EQ(1U, matches.size()) << data[i].url << data[i].query; |
326 | 336 |
327 BookmarkMatch::MatchPositions expected_url_matches; | 337 BookmarkMatch::MatchPositions expected_url_matches; |
328 ExtractMatchPositions(data[i].expected_url_match_positions, | 338 ExtractMatchPositions(data[i].expected_url_match_positions, |
329 &expected_url_matches); | 339 &expected_url_matches); |
330 ExpectMatchPositions(matches[0].url_match_positions, expected_url_matches); | 340 ExpectMatchPositions(matches[0].url_match_positions, expected_url_matches); |
331 } | 341 } |
332 } | 342 } |
333 | 343 |
334 // Makes sure index is updated when a node is removed. | 344 // Makes sure index is updated when a node is removed. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 EXPECT_EQ(data[1].url, matches[3].node->url()); | 462 EXPECT_EQ(data[1].url, matches[3].node->url()); |
453 | 463 |
454 matches.clear(); | 464 matches.clear(); |
455 // Select top two matches. | 465 // Select top two matches. |
456 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); | 466 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); |
457 | 467 |
458 EXPECT_EQ(2, static_cast<int>(matches.size())); | 468 EXPECT_EQ(2, static_cast<int>(matches.size())); |
459 EXPECT_EQ(data[0].url, matches[0].node->url()); | 469 EXPECT_EQ(data[0].url, matches[0].node->url()); |
460 EXPECT_EQ(data[3].url, matches[1].node->url()); | 470 EXPECT_EQ(data[3].url, matches[1].node->url()); |
461 } | 471 } |
OLD | NEW |