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