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

Side by Side Diff: ui/views/controls/combobox/native_combobox_views_unittest.cc

Issue 9875001: views: Rename Combobox "selected getter/setter" accessors to something more accurate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: combo box -> combobox Created 8 years, 8 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
OLDNEW
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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "ui/base/keycodes/keyboard_codes.h" 6 #include "ui/base/keycodes/keyboard_codes.h"
7 #include "ui/base/models/combobox_model.h" 7 #include "ui/base/models/combobox_model.h"
8 #include "ui/views/controls/combobox/combobox.h" 8 #include "ui/views/controls/combobox/combobox.h"
9 #include "ui/views/controls/combobox/native_combobox_views.h" 9 #include "ui/views/controls/combobox/native_combobox_views.h"
10 #include "ui/views/ime/mock_input_method.h" 10 #include "ui/views/ime/mock_input_method.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 key_received_ = key_handled_ = false; 43 key_received_ = key_handled_ = false;
44 } 44 }
45 45
46 private: 46 private:
47 bool key_handled_; 47 bool key_handled_;
48 bool key_received_; 48 bool key_received_;
49 49
50 DISALLOW_COPY_AND_ASSIGN(TestCombobox); 50 DISALLOW_COPY_AND_ASSIGN(TestCombobox);
51 }; 51 };
52 52
53 // A concrete class is needed to test the combo box. 53 // A concrete class is needed to test the combobox.
54 class TestComboboxModel : public ui::ComboboxModel { 54 class TestComboboxModel : public ui::ComboboxModel {
55 public: 55 public:
56 TestComboboxModel() {} 56 TestComboboxModel() {}
57 virtual ~TestComboboxModel() {} 57 virtual ~TestComboboxModel() {}
58 58
59 // Overridden from ui::ComboboxModel: 59 // Overridden from ui::ComboboxModel:
60 virtual int GetItemCount() const OVERRIDE { 60 virtual int GetItemCount() const OVERRIDE {
61 return 4; 61 return 4;
62 } 62 }
63 virtual string16 GetItemAt(int index) OVERRIDE { 63 virtual string16 GetItemAt(int index) OVERRIDE {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // Combobox does not take ownership of the model, hence it needs to be scoped. 145 // Combobox does not take ownership of the model, hence it needs to be scoped.
146 scoped_ptr<TestComboboxModel> model_; 146 scoped_ptr<TestComboboxModel> model_;
147 147
148 // For testing input method related behaviors. 148 // For testing input method related behaviors.
149 MockInputMethod* input_method_; 149 MockInputMethod* input_method_;
150 }; 150 };
151 151
152 TEST_F(NativeComboboxViewsTest, KeyTest) { 152 TEST_F(NativeComboboxViewsTest, KeyTest) {
153 InitCombobox(); 153 InitCombobox();
154 SendKeyEvent(ui::VKEY_END); 154 SendKeyEvent(ui::VKEY_END);
155 EXPECT_EQ(combobox_->selected_item() + 1, model_->GetItemCount()); 155 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount());
156 SendKeyEvent(ui::VKEY_HOME); 156 SendKeyEvent(ui::VKEY_HOME);
157 EXPECT_EQ(combobox_->selected_item(), 0); 157 EXPECT_EQ(combobox_->selected_index(), 0);
158 SendKeyEvent(ui::VKEY_DOWN); 158 SendKeyEvent(ui::VKEY_DOWN);
159 SendKeyEvent(ui::VKEY_DOWN); 159 SendKeyEvent(ui::VKEY_DOWN);
160 EXPECT_EQ(combobox_->selected_item(), 2); 160 EXPECT_EQ(combobox_->selected_index(), 2);
161 SendKeyEvent(ui::VKEY_RIGHT); 161 SendKeyEvent(ui::VKEY_RIGHT);
162 EXPECT_EQ(combobox_->selected_item(), 2); 162 EXPECT_EQ(combobox_->selected_index(), 2);
163 SendKeyEvent(ui::VKEY_LEFT); 163 SendKeyEvent(ui::VKEY_LEFT);
164 EXPECT_EQ(combobox_->selected_item(), 2); 164 EXPECT_EQ(combobox_->selected_index(), 2);
165 } 165 }
166 166
167 // Check that if a combobox is disabled before it has a native wrapper, then the 167 // Check that if a combobox is disabled before it has a native wrapper, then the
168 // native wrapper inherits the disabled state when it gets created. 168 // native wrapper inherits the disabled state when it gets created.
169 TEST_F(NativeComboboxViewsTest, DisabilityTest) { 169 TEST_F(NativeComboboxViewsTest, DisabilityTest) {
170 model_.reset(new TestComboboxModel()); 170 model_.reset(new TestComboboxModel());
171 171
172 ASSERT_FALSE(combobox_); 172 ASSERT_FALSE(combobox_);
173 combobox_ = new TestCombobox(model_.get()); 173 combobox_ = new TestCombobox(model_.get());
174 combobox_->SetEnabled(false); 174 combobox_->SetEnabled(false);
175 ASSERT_FALSE(combobox_->GetNativeWrapperForTesting()); 175 ASSERT_FALSE(combobox_->GetNativeWrapperForTesting());
176 176
177 widget_ = new Widget; 177 widget_ = new Widget;
178 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 178 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
179 params.bounds = gfx::Rect(100, 100, 100, 100); 179 params.bounds = gfx::Rect(100, 100, 100, 100);
180 widget_->Init(params); 180 widget_->Init(params);
181 View* container = new View(); 181 View* container = new View();
182 widget_->SetContentsView(container); 182 widget_->SetContentsView(container);
183 container->AddChildView(combobox_); 183 container->AddChildView(combobox_);
184 184
185 combobox_view_ = static_cast<NativeComboboxViews*>( 185 combobox_view_ = static_cast<NativeComboboxViews*>(
186 combobox_->GetNativeWrapperForTesting()); 186 combobox_->GetNativeWrapperForTesting());
187 ASSERT_TRUE(combobox_view_); 187 ASSERT_TRUE(combobox_view_);
188 ASSERT_FALSE(combobox_view_->enabled()); 188 ASSERT_FALSE(combobox_view_->enabled());
189 } 189 }
190 190
191 } // namespace views 191 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/native_combobox_views.cc ('k') | ui/views/controls/combobox/native_combobox_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698