[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / views / controls / prefix_selector_unittest.cc
blob031c0079aee4d23dde6707541db460166ff1e051
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/controls/prefix_selector.h"
7 #include <string>
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/views/controls/prefix_delegate.h"
12 #include "ui/views/test/views_test_base.h"
14 using base::ASCIIToUTF16;
16 namespace views {
18 class TestPrefixDelegate : public PrefixDelegate {
19 public:
20 TestPrefixDelegate() : selected_row_(0) {
21 rows_.push_back(ASCIIToUTF16("aardvark"));
22 rows_.push_back(ASCIIToUTF16("antelope"));
23 rows_.push_back(ASCIIToUTF16("badger"));
24 rows_.push_back(ASCIIToUTF16("gnu"));
27 virtual ~TestPrefixDelegate() {}
29 virtual int GetRowCount() OVERRIDE {
30 return static_cast<int>(rows_.size());
33 virtual int GetSelectedRow() OVERRIDE {
34 return selected_row_;
37 virtual void SetSelectedRow(int row) OVERRIDE {
38 selected_row_ = row;
41 virtual base::string16 GetTextForRow(int row) OVERRIDE {
42 return rows_[row];
45 private:
46 std::vector<base::string16> rows_;
47 int selected_row_;
49 DISALLOW_COPY_AND_ASSIGN(TestPrefixDelegate);
52 class PrefixSelectorTest : public ViewsTestBase {
53 public:
54 PrefixSelectorTest() {
55 selector_.reset(new PrefixSelector(&delegate_));
58 protected:
59 scoped_ptr<PrefixSelector> selector_;
60 TestPrefixDelegate delegate_;
62 private:
63 DISALLOW_COPY_AND_ASSIGN(PrefixSelectorTest);
66 TEST_F(PrefixSelectorTest, PrefixSelect) {
67 selector_->InsertText(ASCIIToUTF16("an"));
68 EXPECT_EQ(1, delegate_.GetSelectedRow());
70 // Invoke OnViewBlur() to reset time.
71 selector_->OnViewBlur();
72 selector_->InsertText(ASCIIToUTF16("a"));
73 EXPECT_EQ(0, delegate_.GetSelectedRow());
75 selector_->OnViewBlur();
76 selector_->InsertText(ASCIIToUTF16("g"));
77 EXPECT_EQ(3, delegate_.GetSelectedRow());
79 selector_->OnViewBlur();
80 selector_->InsertText(ASCIIToUTF16("b"));
81 selector_->InsertText(ASCIIToUTF16("a"));
82 EXPECT_EQ(2, delegate_.GetSelectedRow());
84 selector_->OnViewBlur();
85 selector_->InsertText(ASCIIToUTF16("\t"));
86 selector_->InsertText(ASCIIToUTF16("b"));
87 selector_->InsertText(ASCIIToUTF16("a"));
88 EXPECT_EQ(2, delegate_.GetSelectedRow());
91 } // namespace views