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

Side by Side Diff: ui/views/controls/prefix_selector_unittest.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 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
« no previous file with comments | « ui/views/controls/prefix_selector.cc ('k') | ui/views/controls/progress_bar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ui/views/controls/prefix_selector.h"
6
7 #include <string>
8
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"
13
14 using base::ASCIIToUTF16;
15
16 namespace views {
17
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"));
25 }
26
27 virtual ~TestPrefixDelegate() {}
28
29 virtual int GetRowCount() override {
30 return static_cast<int>(rows_.size());
31 }
32
33 virtual int GetSelectedRow() override {
34 return selected_row_;
35 }
36
37 virtual void SetSelectedRow(int row) override {
38 selected_row_ = row;
39 }
40
41 virtual base::string16 GetTextForRow(int row) override {
42 return rows_[row];
43 }
44
45 private:
46 std::vector<base::string16> rows_;
47 int selected_row_;
48
49 DISALLOW_COPY_AND_ASSIGN(TestPrefixDelegate);
50 };
51
52 class PrefixSelectorTest : public ViewsTestBase {
53 public:
54 PrefixSelectorTest() {
55 selector_.reset(new PrefixSelector(&delegate_));
56 }
57
58 protected:
59 scoped_ptr<PrefixSelector> selector_;
60 TestPrefixDelegate delegate_;
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(PrefixSelectorTest);
64 };
65
66 TEST_F(PrefixSelectorTest, PrefixSelect) {
67 selector_->InsertText(ASCIIToUTF16("an"));
68 EXPECT_EQ(1, delegate_.GetSelectedRow());
69
70 // Invoke OnViewBlur() to reset time.
71 selector_->OnViewBlur();
72 selector_->InsertText(ASCIIToUTF16("a"));
73 EXPECT_EQ(0, delegate_.GetSelectedRow());
74
75 selector_->OnViewBlur();
76 selector_->InsertText(ASCIIToUTF16("g"));
77 EXPECT_EQ(3, delegate_.GetSelectedRow());
78
79 selector_->OnViewBlur();
80 selector_->InsertText(ASCIIToUTF16("b"));
81 selector_->InsertText(ASCIIToUTF16("a"));
82 EXPECT_EQ(2, delegate_.GetSelectedRow());
83
84 selector_->OnViewBlur();
85 selector_->InsertText(ASCIIToUTF16("\t"));
86 selector_->InsertText(ASCIIToUTF16("b"));
87 selector_->InsertText(ASCIIToUTF16("a"));
88 EXPECT_EQ(2, delegate_.GetSelectedRow());
89 }
90
91 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/prefix_selector.cc ('k') | ui/views/controls/progress_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698