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" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 BookmarkMatch::MatchPositions expected_url_matches; | 361 BookmarkMatch::MatchPositions expected_url_matches; |
362 ExtractMatchPositions(data[i].expected_url_match_positions, | 362 ExtractMatchPositions(data[i].expected_url_match_positions, |
363 &expected_url_matches); | 363 &expected_url_matches); |
364 ExpectMatchPositions(matches[0].url_match_positions, expected_url_matches); | 364 ExpectMatchPositions(matches[0].url_match_positions, expected_url_matches); |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 // Makes sure index is updated when a node is removed. | 368 // Makes sure index is updated when a node is removed. |
369 TEST_F(BookmarkIndexTest, Remove) { | 369 TEST_F(BookmarkIndexTest, Remove) { |
370 const char* titles[] = { "a", "b" }; | 370 const char* titles[] = { "a", "b" }; |
371 const char* urls[] = { kAboutBlankURL, kAboutBlankURL }; | 371 const char* urls[] = {kAboutBlankURL, kAboutBlankURL}; |
372 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles)); | 372 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles)); |
373 | 373 |
374 // Remove the node and make sure we don't get back any results. | 374 // Remove the node and make sure we don't get back any results. |
375 model_->Remove(model_->other_node(), 0); | 375 model_->Remove(model_->other_node(), 0); |
376 ExpectMatches("A", NULL, 0U); | 376 ExpectMatches("A", NULL, 0U); |
377 } | 377 } |
378 | 378 |
379 // Makes sure index is updated when a node's title is changed. | 379 // Makes sure index is updated when a node's title is changed. |
380 TEST_F(BookmarkIndexTest, ChangeTitle) { | 380 TEST_F(BookmarkIndexTest, ChangeTitle) { |
381 const char* titles[] = { "a", "b" }; | 381 const char* titles[] = { "a", "b" }; |
382 const char* urls[] = { kAboutBlankURL, kAboutBlankURL }; | 382 const char* urls[] = {kAboutBlankURL, kAboutBlankURL}; |
383 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles)); | 383 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles)); |
384 | 384 |
385 // Remove the node and make sure we don't get back any results. | 385 // Remove the node and make sure we don't get back any results. |
386 const char* expected[] = { "blah" }; | 386 const char* expected[] = { "blah" }; |
387 model_->SetTitle(model_->other_node()->GetChild(0), ASCIIToUTF16("blah")); | 387 model_->SetTitle(model_->other_node()->GetChild(0), ASCIIToUTF16("blah")); |
388 ExpectMatches("BlAh", expected, ARRAYSIZE_UNSAFE(expected)); | 388 ExpectMatches("BlAh", expected, ARRAYSIZE_UNSAFE(expected)); |
389 } | 389 } |
390 | 390 |
391 // Makes sure no more than max queries is returned. | 391 // Makes sure no more than max queries is returned. |
392 TEST_F(BookmarkIndexTest, HonorMax) { | 392 TEST_F(BookmarkIndexTest, HonorMax) { |
393 const char* titles[] = { "abcd", "abcde" }; | 393 const char* titles[] = { "abcd", "abcde" }; |
394 const char* urls[] = { kAboutBlankURL, kAboutBlankURL }; | 394 const char* urls[] = {kAboutBlankURL, kAboutBlankURL}; |
395 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles)); | 395 AddBookmarks(titles, urls, ARRAYSIZE_UNSAFE(titles)); |
396 | 396 |
397 std::vector<BookmarkMatch> matches; | 397 std::vector<BookmarkMatch> matches; |
398 model_->GetBookmarksMatching(ASCIIToUTF16("ABc"), 1, &matches); | 398 model_->GetBookmarksMatching(ASCIIToUTF16("ABc"), 1, &matches); |
399 EXPECT_EQ(1U, matches.size()); | 399 EXPECT_EQ(1U, matches.size()); |
400 } | 400 } |
401 | 401 |
402 // Makes sure if the lower case string of a bookmark title is more characters | 402 // Makes sure if the lower case string of a bookmark title is more characters |
403 // than the upper case string no match positions are returned. | 403 // than the upper case string no match positions are returned. |
404 TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) { | 404 TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) { |
(...skipping 51 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 |