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

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

Issue 1177503003: Remove the 2-level input method system & InputMethodBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased & removed views::View::GetTextInputClient & removed GetFocusedTextInputClient. Created 5 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "ui/views/controls/combobox/combobox.h" 5 #include "ui/views/controls/combobox/combobox.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/base/ime/input_method_factory.h"
11 #include "ui/base/ime/text_input_client.h" 12 #include "ui/base/ime/text_input_client.h"
12 #include "ui/base/models/combobox_model.h" 13 #include "ui/base/models/combobox_model.h"
13 #include "ui/events/event.h" 14 #include "ui/events/event.h"
14 #include "ui/events/event_constants.h" 15 #include "ui/events/event_constants.h"
15 #include "ui/events/event_utils.h" 16 #include "ui/events/event_utils.h"
16 #include "ui/events/keycodes/keyboard_codes.h" 17 #include "ui/events/keycodes/keyboard_codes.h"
17 #include "ui/views/controls/combobox/combobox_listener.h" 18 #include "ui/views/controls/combobox/combobox_listener.h"
18 #include "ui/views/controls/menu/menu_runner.h" 19 #include "ui/views/controls/menu/menu_runner.h"
19 #include "ui/views/controls/menu/menu_runner_handler.h" 20 #include "ui/views/controls/menu/menu_runner_handler.h"
20 #include "ui/views/ime/mock_input_method.h"
21 #include "ui/views/test/menu_runner_test_api.h" 21 #include "ui/views/test/menu_runner_test_api.h"
22 #include "ui/views/test/views_test_base.h" 22 #include "ui/views/test/views_test_base.h"
23 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
24 24
25 using base::ASCIIToUTF16; 25 using base::ASCIIToUTF16;
26 26
27 namespace views { 27 namespace views {
28 28
29 namespace { 29 namespace {
30 30
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 private: 194 private:
195 DISALLOW_COPY_AND_ASSIGN(TestComboboxListener); 195 DISALLOW_COPY_AND_ASSIGN(TestComboboxListener);
196 }; 196 };
197 197
198 } // namespace 198 } // namespace
199 199
200 class ComboboxTest : public ViewsTestBase { 200 class ComboboxTest : public ViewsTestBase {
201 public: 201 public:
202 ComboboxTest() : widget_(NULL), combobox_(NULL) {} 202 ComboboxTest() : widget_(NULL), combobox_(NULL) {}
203 203
204 void SetUp() override {
205 ui::SetUpInputMethodFactoryForTesting();
206 ViewsTestBase::SetUp();
207 }
208
204 void TearDown() override { 209 void TearDown() override {
205 if (widget_) 210 if (widget_)
206 widget_->Close(); 211 widget_->Close();
207 ViewsTestBase::TearDown(); 212 ViewsTestBase::TearDown();
208 } 213 }
209 214
210 void InitCombobox(const std::set<int>* separators) { 215 void InitCombobox(const std::set<int>* separators) {
211 model_.reset(new TestComboboxModel()); 216 model_.reset(new TestComboboxModel());
212 217
213 if (separators) 218 if (separators)
214 model_->SetSeparators(*separators); 219 model_->SetSeparators(*separators);
215 220
216 ASSERT_FALSE(combobox_); 221 ASSERT_FALSE(combobox_);
217 combobox_ = new TestCombobox(model_.get()); 222 combobox_ = new TestCombobox(model_.get());
218 combobox_->set_id(1); 223 combobox_->set_id(1);
219 224
220 widget_ = new Widget; 225 widget_ = new Widget;
221 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 226 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
222 params.bounds = gfx::Rect(200, 200, 200, 200); 227 params.bounds = gfx::Rect(200, 200, 200, 200);
223 widget_->Init(params); 228 widget_->Init(params);
224 View* container = new View(); 229 View* container = new View();
225 widget_->SetContentsView(container); 230 widget_->SetContentsView(container);
226 container->AddChildView(combobox_); 231 container->AddChildView(combobox_);
227 232
228 widget_->ReplaceInputMethod(new MockInputMethod);
229
230 // Assumes the Widget is always focused.
231 widget_->GetInputMethod()->OnFocus();
232
233 combobox_->RequestFocus(); 233 combobox_->RequestFocus();
234 combobox_->SizeToPreferredSize(); 234 combobox_->SizeToPreferredSize();
235 } 235 }
236 236
237 protected: 237 protected:
238 void SendKeyEvent(ui::KeyboardCode key_code) { 238 void SendKeyEvent(ui::KeyboardCode key_code) {
239 SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED); 239 SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED);
240 } 240 }
241 241
242 void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) { 242 void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) {
243 ui::KeyEvent event(type, key_code, ui::EF_NONE); 243 ui::KeyEvent event(type, key_code, ui::EF_NONE);
244 widget_->GetInputMethod()->DispatchKeyEvent(event); 244 FocusManager* focus_manager = widget_->GetFocusManager();
245 widget_->OnKeyEvent(&event);
246 if (!event.handled() && focus_manager)
247 focus_manager->OnKeyEvent(event);
245 } 248 }
246 249
247 View* GetFocusedView() { 250 View* GetFocusedView() {
248 return widget_->GetFocusManager()->GetFocusedView(); 251 return widget_->GetFocusManager()->GetFocusedView();
249 } 252 }
250 253
251 void PerformClick(const gfx::Point& point) { 254 void PerformClick(const gfx::Point& point) {
252 ui::MouseEvent pressed_event = ui::MouseEvent( 255 ui::MouseEvent pressed_event = ui::MouseEvent(
253 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), 256 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(),
254 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 257 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 EXPECT_EQ(short_item_width, combobox.content_size_.width()); 667 EXPECT_EQ(short_item_width, combobox.content_size_.width());
665 } 668 }
666 669
667 TEST_F(ComboboxTest, TypingPrefixNotifiesListener) { 670 TEST_F(ComboboxTest, TypingPrefixNotifiesListener) {
668 InitCombobox(NULL); 671 InitCombobox(NULL);
669 672
670 TestComboboxListener listener; 673 TestComboboxListener listener;
671 combobox_->set_listener(&listener); 674 combobox_->set_listener(&listener);
672 675
673 // Type the first character of the second menu item ("JELLY"). 676 // Type the first character of the second menu item ("JELLY").
674 combobox_->GetTextInputClient()->InsertChar('J', ui::EF_NONE); 677 combobox_->GetTextInputClient()->InsertChar('J', ui::EF_NONE);
yukawa 2015/06/16 02:45:03 Can this be rewritten with InputMethod::GetTextInp
Shu Chen 2015/06/16 05:15:26 Done.
675 EXPECT_EQ(1, listener.actions_performed()); 678 EXPECT_EQ(1, listener.actions_performed());
676 EXPECT_EQ(1, listener.perform_action_index()); 679 EXPECT_EQ(1, listener.perform_action_index());
677 680
678 // Type the second character of "JELLY", item shouldn't change and 681 // Type the second character of "JELLY", item shouldn't change and
679 // OnPerformAction() shouldn't be re-called. 682 // OnPerformAction() shouldn't be re-called.
680 combobox_->GetTextInputClient()->InsertChar('E', ui::EF_NONE); 683 combobox_->GetTextInputClient()->InsertChar('E', ui::EF_NONE);
681 EXPECT_EQ(1, listener.actions_performed()); 684 EXPECT_EQ(1, listener.actions_performed());
682 EXPECT_EQ(1, listener.perform_action_index()); 685 EXPECT_EQ(1, listener.perform_action_index());
683 686
684 // Clears the typed text. 687 // Clears the typed text.
685 combobox_->OnBlur(); 688 combobox_->OnBlur();
686 689
687 // Type the first character of "PEANUT BUTTER", which should change the 690 // Type the first character of "PEANUT BUTTER", which should change the
688 // selected index and perform an action. 691 // selected index and perform an action.
689 combobox_->GetTextInputClient()->InsertChar('P', ui::EF_NONE); 692 combobox_->GetTextInputClient()->InsertChar('P', ui::EF_NONE);
yukawa 2015/06/16 02:45:03 Is this a realistic scenario? Can Combobox receiv
Shu Chen 2015/06/16 05:15:26 I think combobox_->RequestFocus() should be added
690 EXPECT_EQ(2, listener.actions_performed()); 693 EXPECT_EQ(2, listener.actions_performed());
691 EXPECT_EQ(2, listener.perform_action_index()); 694 EXPECT_EQ(2, listener.perform_action_index());
692 } 695 }
693 696
694 } // namespace views 697 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698