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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void ExpectMatches(const std::string& query, | 44 void ExpectMatches(const std::string& query, |
45 const char** expected_titles, | 45 const char** expected_titles, |
46 size_t expected_count) { | 46 size_t expected_count) { |
47 std::vector<std::string> title_vector; | 47 std::vector<std::string> title_vector; |
48 for (size_t i = 0; i < expected_count; ++i) | 48 for (size_t i = 0; i < expected_count; ++i) |
49 title_vector.push_back(expected_titles[i]); | 49 title_vector.push_back(expected_titles[i]); |
50 ExpectMatches(query, title_vector); | 50 ExpectMatches(query, title_vector); |
51 } | 51 } |
52 | 52 |
53 void ExpectMatches(const std::string& query, | 53 void ExpectMatches(const std::string& query, |
54 const std::vector<std::string> expected_titles) { | 54 const std::vector<std::string>& expected_titles) { |
55 std::vector<bookmark_utils::TitleMatch> matches; | 55 std::vector<bookmark_utils::TitleMatch> matches; |
56 model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16(query), 1000, &matches); | 56 model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16(query), 1000, &matches); |
57 ASSERT_EQ(expected_titles.size(), matches.size()); | 57 ASSERT_EQ(expected_titles.size(), matches.size()); |
58 for (size_t i = 0; i < expected_titles.size(); ++i) { | 58 for (size_t i = 0; i < expected_titles.size(); ++i) { |
59 bool found = false; | 59 bool found = false; |
60 for (size_t j = 0; j < matches.size(); ++j) { | 60 for (size_t j = 0; j < matches.size(); ++j) { |
61 if (ASCIIToUTF16(expected_titles[i]) == matches[j].node->GetTitle()) { | 61 if (ASCIIToUTF16(expected_titles[i]) == matches[j].node->GetTitle()) { |
62 matches.erase(matches.begin() + j); | 62 matches.erase(matches.begin() + j); |
63 found = true; | 63 found = true; |
64 break; | 64 break; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 EXPECT_EQ(data[1].url, matches[3].node->url()); | 296 EXPECT_EQ(data[1].url, matches[3].node->url()); |
297 | 297 |
298 matches.clear(); | 298 matches.clear(); |
299 // Select top two matches. | 299 // Select top two matches. |
300 model->GetBookmarksWithTitlesMatching(ASCIIToUTF16("google"), 2, &matches); | 300 model->GetBookmarksWithTitlesMatching(ASCIIToUTF16("google"), 2, &matches); |
301 | 301 |
302 EXPECT_EQ(2, static_cast<int>(matches.size())); | 302 EXPECT_EQ(2, static_cast<int>(matches.size())); |
303 EXPECT_EQ(data[0].url, matches[0].node->url()); | 303 EXPECT_EQ(data[0].url, matches[0].node->url()); |
304 EXPECT_EQ(data[3].url, matches[1].node->url()); | 304 EXPECT_EQ(data[3].url, matches[1].node->url()); |
305 } | 305 } |
OLD | NEW |