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

Side by Side Diff: chrome/browser/autocomplete/bookmark_provider_unittest.cc

Issue 10913262: Implement Bookmark Autocomplete Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #include "chrome/browser/autocomplete/bookmark_provider.h"
2
3 #include "base/memory/ref_counted.h"
4 #include "base/memory/scoped_ptr.h"
5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autocomplete/autocomplete_provider.h"
7 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 class BookmarkProviderTest : public testing::Test,
14 public AutocompleteProviderListener {
15 public:
16 BookmarkProviderTest() : model_(new BookmarkModel(NULL)) {}
17
18 // AutocompleteProviderListener: Not called.
19 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE {}
20
21 protected:
22 virtual void SetUp() OVERRIDE;
23 virtual void TearDown() OVERRIDE;
24
25 // Initializes test data.
26 void AddBookmarksWithTitles(const char** titles, size_t count);
27 void AddBookmarksWithTitles(const std::vector<std::string>& titles);
28
29 scoped_ptr<TestingProfile> profile_;
30 scoped_ptr<BookmarkModel> model_;
31 scoped_refptr<BookmarkProvider> provider_;
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(BookmarkProviderTest);
35 };
36
37 void BookmarkProviderTest::SetUp() {
38 profile_.reset(new TestingProfile());
39 DCHECK(profile_.get());
40 provider_ = new BookmarkProvider(this, profile_.get());
41 DCHECK(provider_);
42 provider_->set_bookmark_model_for_testing(model_.get());
43 }
44
45 void BookmarkProviderTest::TearDown() {
46 }
47
48 void BookmarkProviderTest::AddBookmarksWithTitles(const char** titles,
49 size_t count) {
50 std::vector<std::string> title_vector;
51 for (size_t i = 0; i < count; ++i)
52 title_vector.push_back(titles[i]);
53 AddBookmarksWithTitles(title_vector);
54 }
55
56 void BookmarkProviderTest::AddBookmarksWithTitles(
57 const std::vector<std::string>& titles) {
58 GURL url("about:blank");
59 for (size_t i = 0; i < titles.size(); ++i)
60 model_->AddURL(model_->other_node(), static_cast<int>(i),
61 ASCIIToUTF16(titles[i]), url);
62 }
63
64 TEST_F(BookmarkProviderTest, Positions) {
65 const char* test_data[] = {
66 "abc def",
67 "abcde",
68 };
69 AddBookmarksWithTitles(test_data, ARRAYSIZE_UNSAFE(test_data));
70
71 struct QueryData {
72 const std::string query;
73 const size_t match_count;
74 const size_t positions[3][2];
75 } query_data[] = {
76 // Trivial test case of only one term, exact match.
77 { "abc", 1, {{0,1},{2,3},{0,0}} },
78 { "foo bar", 0, {{0,1},{2,3},{0,0}} },
79 { "fooey bark", 0, {{0,1},{2,3},{0,0}} },
80 };
81
82 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) {
83 // WHAT???
84 AutocompleteInput input(ASCIIToUTF16(query_data[i].query),
85 ASCIIToUTF16("N/A"), false, false, false,
86 AutocompleteInput::ALL_MATCHES);
87 provider_->Start(input, false);
88 const ACMatches& matches(provider_->matches());
89 // Validate number of results is as expected.
90 EXPECT_EQ(query_data[i].match_count, matches.size());
91 // Validate positions within each result is as expected.
92 #if 0
93 ExpectClassificationsEqual(matches, { { 0, 1 }, { 3, 5} });
94 #endif
95 }
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698