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

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

Issue 404203003: Distinguish between keystroke and character events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsCharFromNative() for Mac build Created 6 years, 5 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"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 combobox_->RequestFocus(); 238 combobox_->RequestFocus();
239 combobox_->SizeToPreferredSize(); 239 combobox_->SizeToPreferredSize();
240 } 240 }
241 241
242 protected: 242 protected:
243 void SendKeyEvent(ui::KeyboardCode key_code) { 243 void SendKeyEvent(ui::KeyboardCode key_code) {
244 SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED); 244 SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED);
245 } 245 }
246 246
247 void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) { 247 void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) {
248 ui::KeyEvent event(type, key_code, 0, false); 248 ui::KeyEvent event(type, key_code, ui::EF_NONE);
249 widget_->GetInputMethod()->DispatchKeyEvent(event); 249 widget_->GetInputMethod()->DispatchKeyEvent(event);
250 } 250 }
251 251
252 View* GetFocusedView() { 252 View* GetFocusedView() {
253 return widget_->GetFocusManager()->GetFocusedView(); 253 return widget_->GetFocusManager()->GetFocusedView();
254 } 254 }
255 255
256 void PerformClick(const gfx::Point& point) { 256 void PerformClick(const gfx::Point& point) {
257 ui::MouseEvent pressed_event = ui::MouseEvent(ui::ET_MOUSE_PRESSED, point, 257 ui::MouseEvent pressed_event = ui::MouseEvent(ui::ET_MOUSE_PRESSED, point,
258 point, 258 point,
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 combobox_->y() + combobox_->height() / 2)); 617 combobox_->y() + combobox_->height() / 2));
618 EXPECT_TRUE(listener.on_perform_action_called()); 618 EXPECT_TRUE(listener.on_perform_action_called());
619 EXPECT_FALSE(test_menu_runner_handler->executed()); 619 EXPECT_FALSE(test_menu_runner_handler->executed());
620 EXPECT_EQ(0, listener.perform_action_index()); 620 EXPECT_EQ(0, listener.perform_action_index());
621 } 621 }
622 622
623 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { 623 TEST_F(ComboboxTest, ConsumingPressKeyEvents) {
624 InitCombobox(NULL); 624 InitCombobox(NULL);
625 625
626 EXPECT_FALSE(combobox_->OnKeyPressed( 626 EXPECT_FALSE(combobox_->OnKeyPressed(
627 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false))); 627 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE)));
628 EXPECT_FALSE(combobox_->OnKeyPressed( 628 EXPECT_FALSE(combobox_->OnKeyPressed(
629 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, 0, false))); 629 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE)));
630 630
631 // When the combobox's style is STYLE_ACTION, pressing events of a space key 631 // When the combobox's style is STYLE_ACTION, pressing events of a space key
632 // or an enter key will be consumed. 632 // or an enter key will be consumed.
633 combobox_->SetStyle(Combobox::STYLE_ACTION); 633 combobox_->SetStyle(Combobox::STYLE_ACTION);
634 EXPECT_TRUE(combobox_->OnKeyPressed( 634 EXPECT_TRUE(combobox_->OnKeyPressed(
635 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false))); 635 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE)));
636 EXPECT_TRUE(combobox_->OnKeyPressed( 636 EXPECT_TRUE(combobox_->OnKeyPressed(
637 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, 0, false))); 637 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE)));
638 } 638 }
639 639
640 TEST_F(ComboboxTest, ContentWidth) { 640 TEST_F(ComboboxTest, ContentWidth) {
641 std::vector<std::string> values; 641 std::vector<std::string> values;
642 VectorComboboxModel model(&values); 642 VectorComboboxModel model(&values);
643 TestCombobox combobox(&model); 643 TestCombobox combobox(&model);
644 644
645 std::string long_item = "this is the long item"; 645 std::string long_item = "this is the long item";
646 std::string short_item = "s"; 646 std::string short_item = "s";
647 647
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 combobox_->OnBlur(); 692 combobox_->OnBlur();
693 693
694 // Type the first character of "PEANUT BUTTER", which should change the 694 // Type the first character of "PEANUT BUTTER", which should change the
695 // selected index and perform an action. 695 // selected index and perform an action.
696 combobox_->GetTextInputClient()->InsertChar('P', ui::EF_NONE); 696 combobox_->GetTextInputClient()->InsertChar('P', ui::EF_NONE);
697 EXPECT_EQ(2, listener.actions_performed()); 697 EXPECT_EQ(2, listener.actions_performed());
698 EXPECT_EQ(2, listener.perform_action_index()); 698 EXPECT_EQ(2, listener.perform_action_index());
699 } 699 }
700 700
701 } // namespace views 701 } // namespace views
OLDNEW
« no previous file with comments | « ui/platform_window/x11/x11_window.cc ('k') | ui/views/controls/menu/menu_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698