Index: ui/views/controls/combobox/combobox_unittest.cc |
diff --git a/ui/views/controls/combobox/combobox_unittest.cc b/ui/views/controls/combobox/combobox_unittest.cc |
index 7cdaa56308c1447a34f3f30def031c999b57d767..3e316dedef4ba4eb3d8a0b53f0de443e0b66e738 100644 |
--- a/ui/views/controls/combobox/combobox_unittest.cc |
+++ b/ui/views/controls/combobox/combobox_unittest.cc |
@@ -18,6 +18,7 @@ |
#include "ui/events/event_utils.h" |
#include "ui/events/keycodes/dom/dom_code.h" |
#include "ui/events/keycodes/keyboard_codes.h" |
+#include "ui/events/test/event_generator.h" |
#include "ui/views/controls/combobox/combobox_listener.h" |
#include "ui/views/test/combobox_test_api.h" |
#include "ui/views/test/views_test_base.h" |
@@ -206,7 +207,8 @@ class ComboboxTest : public ViewsTestBase { |
combobox_->set_id(1); |
widget_ = new Widget; |
- Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
+ Widget::InitParams params = |
+ CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
karandeepb
2017/01/11 08:16:20
Did not look into it, but tests fail with the Even
tapted
2017/01/11 14:54:20
I think popups have can_activate = false by defaul
karandeepb
2017/01/13 03:13:38
Acknowledged.
|
params.bounds = gfx::Rect(200, 200, 200, 200); |
widget_->Init(params); |
View* container = new View(); |
@@ -216,19 +218,19 @@ class ComboboxTest : public ViewsTestBase { |
combobox_->RequestFocus(); |
combobox_->SizeToPreferredSize(); |
+ |
+ event_generator_.reset( |
tapted
2017/01/11 14:54:20
event_generator_ = base::MakeUnique<..EventGenerat
karandeepb
2017/01/13 03:13:38
Done.
|
+ new ui::test::EventGenerator(widget_->GetNativeWindow())); |
+ event_generator_->set_target(ui::test::EventGenerator::Target::WINDOW); |
} |
protected: |
- void SendKeyEvent(ui::KeyboardCode key_code) { |
- SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED); |
+ void PressKey(ui::KeyboardCode key_code) { |
+ event_generator_->PressKey(key_code, ui::EF_NONE); |
} |
- void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) { |
- ui::KeyEvent event(type, key_code, ui::EF_NONE); |
- FocusManager* focus_manager = widget_->GetFocusManager(); |
- widget_->OnKeyEvent(&event); |
- if (!event.handled() && focus_manager) |
- focus_manager->OnKeyEvent(event); |
+ void ReleaseKey(ui::KeyboardCode key_code) { |
+ event_generator_->ReleaseKey(key_code, ui::EF_NONE); |
} |
View* GetFocusedView() { |
@@ -269,28 +271,30 @@ class ComboboxTest : public ViewsTestBase { |
// The current menu show count. |
int menu_show_count_; |
+ std::unique_ptr<ui::test::EventGenerator> event_generator_; |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(ComboboxTest); |
}; |
TEST_F(ComboboxTest, KeyTest) { |
InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
- SendKeyEvent(ui::VKEY_END); |
+ PressKey(ui::VKEY_END); |
EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); |
- SendKeyEvent(ui::VKEY_HOME); |
+ PressKey(ui::VKEY_HOME); |
EXPECT_EQ(combobox_->selected_index(), 0); |
- SendKeyEvent(ui::VKEY_DOWN); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(combobox_->selected_index(), 2); |
- SendKeyEvent(ui::VKEY_RIGHT); |
+ PressKey(ui::VKEY_RIGHT); |
EXPECT_EQ(combobox_->selected_index(), 2); |
- SendKeyEvent(ui::VKEY_LEFT); |
+ PressKey(ui::VKEY_LEFT); |
EXPECT_EQ(combobox_->selected_index(), 2); |
- SendKeyEvent(ui::VKEY_UP); |
+ PressKey(ui::VKEY_UP); |
EXPECT_EQ(combobox_->selected_index(), 1); |
- SendKeyEvent(ui::VKEY_PRIOR); |
+ PressKey(ui::VKEY_PRIOR); |
EXPECT_EQ(combobox_->selected_index(), 0); |
- SendKeyEvent(ui::VKEY_NEXT); |
+ PressKey(ui::VKEY_NEXT); |
EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); |
} |
@@ -304,7 +308,8 @@ TEST_F(ComboboxTest, DisabilityTest) { |
combobox_->SetEnabled(false); |
widget_ = new Widget; |
- Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
+ Widget::InitParams params = |
+ CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
params.bounds = gfx::Rect(100, 100, 100, 100); |
widget_->Init(params); |
View* container = new View(); |
@@ -320,17 +325,17 @@ TEST_F(ComboboxTest, SkipSeparatorSimple) { |
separators.insert(2); |
InitCombobox(&separators, Combobox::STYLE_NORMAL); |
EXPECT_EQ(0, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(1, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(3, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_UP); |
+ PressKey(ui::VKEY_UP); |
EXPECT_EQ(1, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_HOME); |
+ PressKey(ui::VKEY_HOME); |
EXPECT_EQ(0, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_PRIOR); |
+ PressKey(ui::VKEY_PRIOR); |
EXPECT_EQ(0, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_END); |
+ PressKey(ui::VKEY_END); |
EXPECT_EQ(9, combobox_->selected_index()); |
} |
@@ -341,17 +346,17 @@ TEST_F(ComboboxTest, SkipSeparatorBeginning) { |
separators.insert(0); |
InitCombobox(&separators, Combobox::STYLE_NORMAL); |
EXPECT_EQ(1, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(2, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(3, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_UP); |
+ PressKey(ui::VKEY_UP); |
EXPECT_EQ(2, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_HOME); |
+ PressKey(ui::VKEY_HOME); |
EXPECT_EQ(1, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_PRIOR); |
+ PressKey(ui::VKEY_PRIOR); |
EXPECT_EQ(1, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_END); |
+ PressKey(ui::VKEY_END); |
EXPECT_EQ(9, combobox_->selected_index()); |
} |
@@ -362,11 +367,11 @@ TEST_F(ComboboxTest, SkipSeparatorEnd) { |
separators.insert(TestComboboxModel::kItemCount - 1); |
InitCombobox(&separators, Combobox::STYLE_NORMAL); |
combobox_->SetSelectedIndex(8); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(8, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_UP); |
+ PressKey(ui::VKEY_UP); |
EXPECT_EQ(7, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_END); |
+ PressKey(ui::VKEY_END); |
EXPECT_EQ(8, combobox_->selected_index()); |
} |
@@ -380,17 +385,17 @@ TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { |
separators.insert(2); |
InitCombobox(&separators, Combobox::STYLE_NORMAL); |
EXPECT_EQ(3, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(4, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_UP); |
+ PressKey(ui::VKEY_UP); |
EXPECT_EQ(3, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_NEXT); |
+ PressKey(ui::VKEY_NEXT); |
EXPECT_EQ(9, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_HOME); |
+ PressKey(ui::VKEY_HOME); |
EXPECT_EQ(3, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_END); |
+ PressKey(ui::VKEY_END); |
EXPECT_EQ(9, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_PRIOR); |
+ PressKey(ui::VKEY_PRIOR); |
EXPECT_EQ(3, combobox_->selected_index()); |
} |
@@ -404,9 +409,9 @@ TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { |
separators.insert(6); |
InitCombobox(&separators, Combobox::STYLE_NORMAL); |
combobox_->SetSelectedIndex(3); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(7, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_UP); |
+ PressKey(ui::VKEY_UP); |
EXPECT_EQ(3, combobox_->selected_index()); |
} |
@@ -420,17 +425,17 @@ TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { |
separators.insert(9); |
InitCombobox(&separators, Combobox::STYLE_NORMAL); |
combobox_->SetSelectedIndex(6); |
- SendKeyEvent(ui::VKEY_DOWN); |
+ PressKey(ui::VKEY_DOWN); |
EXPECT_EQ(6, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_UP); |
+ PressKey(ui::VKEY_UP); |
EXPECT_EQ(5, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_HOME); |
+ PressKey(ui::VKEY_HOME); |
EXPECT_EQ(0, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_NEXT); |
+ PressKey(ui::VKEY_NEXT); |
EXPECT_EQ(6, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_PRIOR); |
+ PressKey(ui::VKEY_PRIOR); |
EXPECT_EQ(0, combobox_->selected_index()); |
- SendKeyEvent(ui::VKEY_END); |
+ PressKey(ui::VKEY_END); |
EXPECT_EQ(6, combobox_->selected_index()); |
} |
@@ -542,7 +547,7 @@ TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
combobox_->set_listener(&listener); |
// With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. |
- SendKeyEvent(ui::VKEY_RETURN); |
+ PressKey(ui::VKEY_RETURN); |
EXPECT_EQ(1, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
} |
@@ -554,7 +559,7 @@ TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { |
combobox_->set_listener(&listener); |
// With STYLE_ACTION, the click event is notified and the menu is not shown. |
- SendKeyEvent(ui::VKEY_RETURN); |
+ PressKey(ui::VKEY_RETURN); |
EXPECT_EQ(0, menu_show_count()); |
EXPECT_TRUE(listener.on_perform_action_called()); |
EXPECT_EQ(0, listener.perform_action_index()); |
@@ -567,11 +572,11 @@ TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { |
combobox_->set_listener(&listener); |
// With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. |
- SendKeyEvent(ui::VKEY_SPACE); |
+ PressKey(ui::VKEY_SPACE); |
EXPECT_EQ(1, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
- SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); |
+ ReleaseKey(ui::VKEY_SPACE); |
EXPECT_EQ(1, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
} |
@@ -584,11 +589,11 @@ TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { |
// With STYLE_ACTION, the click event is notified after releasing and the menu |
// is not shown. |
- SendKeyEvent(ui::VKEY_SPACE); |
+ PressKey(ui::VKEY_SPACE); |
EXPECT_EQ(0, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
- SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); |
+ ReleaseKey(ui::VKEY_SPACE); |
EXPECT_EQ(0, menu_show_count()); |
EXPECT_TRUE(listener.on_perform_action_called()); |
EXPECT_EQ(0, listener.perform_action_index()); |