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 165165b73e759c5ca8ef33805532859057797f9c..7cdaa56308c1447a34f3f30def031c999b57d767 100644 |
--- a/ui/views/controls/combobox/combobox_unittest.cc |
+++ b/ui/views/controls/combobox/combobox_unittest.cc |
@@ -185,7 +185,7 @@ class TestComboboxListener : public views::ComboboxListener { |
class ComboboxTest : public ViewsTestBase { |
public: |
- ComboboxTest() : widget_(NULL), combobox_(NULL) {} |
+ ComboboxTest() : widget_(NULL), combobox_(NULL), menu_show_count_(0) {} |
tapted
2017/01/11 15:11:53
nit: move these to inline initializers, like
wid
karandeepb
2017/01/11 23:58:31
Done.
|
void TearDown() override { |
if (widget_) |
@@ -202,6 +202,7 @@ class ComboboxTest : public ViewsTestBase { |
ASSERT_FALSE(combobox_); |
combobox_ = new TestCombobox(model_.get(), style); |
test_api_.reset(new ComboboxTestApi(combobox_)); |
+ test_api_->InstallTestMenuRunner(&menu_show_count_); |
combobox_->set_id(1); |
widget_ = new Widget; |
@@ -253,6 +254,8 @@ class ComboboxTest : public ViewsTestBase { |
PerformMouseRelease(point); |
} |
+ int menu_show_count() const { return menu_show_count_; } |
tapted
2017/01/11 15:11:53
is this needed - it's OK for a test harness to hav
karandeepb
2017/01/11 23:58:31
Oh yeah I should have declared menu_show_count_ pr
|
+ |
// We need widget to populate wrapper class. |
Widget* widget_; |
@@ -263,6 +266,9 @@ class ComboboxTest : public ViewsTestBase { |
// Combobox does not take ownership of the model, hence it needs to be scoped. |
std::unique_ptr<TestComboboxModel> model_; |
+ // The current menu show count. |
+ int menu_show_count_; |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(ComboboxTest); |
}; |
@@ -503,17 +509,14 @@ TEST_F(ComboboxTest, Click) { |
TestComboboxListener listener; |
combobox_->set_listener(&listener); |
- |
combobox_->Layout(); |
- int menu_show_count = 0; |
- test_api_->InstallTestMenuRunner(&menu_show_count); |
// Click the left side. The menu is shown. |
- EXPECT_EQ(0, menu_show_count); |
+ EXPECT_EQ(0, menu_show_count()); |
PerformClick(gfx::Point(combobox_->x() + 1, |
combobox_->y() + combobox_->height() / 2)); |
EXPECT_FALSE(listener.on_perform_action_called()); |
- EXPECT_EQ(1, menu_show_count); |
+ EXPECT_EQ(1, menu_show_count()); |
} |
TEST_F(ComboboxTest, ClickButDisabled) { |
@@ -526,12 +529,10 @@ TEST_F(ComboboxTest, ClickButDisabled) { |
combobox_->SetEnabled(false); |
// Click the left side, but nothing happens since the combobox is disabled. |
- int menu_show_count = 0; |
- test_api_->InstallTestMenuRunner(&menu_show_count); |
PerformClick(gfx::Point(combobox_->x() + 1, |
combobox_->y() + combobox_->height() / 2)); |
EXPECT_FALSE(listener.on_perform_action_called()); |
- EXPECT_EQ(0, menu_show_count); |
+ EXPECT_EQ(0, menu_show_count()); |
} |
TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
@@ -540,8 +541,9 @@ TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
TestComboboxListener listener; |
combobox_->set_listener(&listener); |
- // With STYLE_NORMAL, the click event is ignored. |
+ // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. |
SendKeyEvent(ui::VKEY_RETURN); |
+ EXPECT_EQ(1, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
} |
@@ -551,8 +553,9 @@ TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { |
TestComboboxListener listener; |
combobox_->set_listener(&listener); |
- // With STYLE_ACTION, the click event is notified. |
+ // With STYLE_ACTION, the click event is notified and the menu is not shown. |
SendKeyEvent(ui::VKEY_RETURN); |
+ EXPECT_EQ(0, menu_show_count()); |
EXPECT_TRUE(listener.on_perform_action_called()); |
EXPECT_EQ(0, listener.perform_action_index()); |
} |
@@ -563,10 +566,13 @@ TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { |
TestComboboxListener listener; |
combobox_->set_listener(&listener); |
- // With STYLE_NORMAL, the click event is ignored. |
+ // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. |
SendKeyEvent(ui::VKEY_SPACE); |
+ EXPECT_EQ(1, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
+ |
SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); |
+ EXPECT_EQ(1, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
} |
@@ -576,10 +582,14 @@ TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { |
TestComboboxListener listener; |
combobox_->set_listener(&listener); |
- // With STYLE_ACTION, the click event is notified after releasing. |
+ // With STYLE_ACTION, the click event is notified after releasing and the menu |
+ // is not shown. |
SendKeyEvent(ui::VKEY_SPACE); |
+ EXPECT_EQ(0, menu_show_count()); |
EXPECT_FALSE(listener.on_perform_action_called()); |
+ |
SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); |
+ EXPECT_EQ(0, menu_show_count()); |
EXPECT_TRUE(listener.on_perform_action_called()); |
EXPECT_EQ(0, listener.perform_action_index()); |
} |
@@ -593,12 +603,10 @@ TEST_F(ComboboxTest, NotifyOnClickWithMouse) { |
combobox_->Layout(); |
// Click the right side (arrow button). The menu is shown. |
- int menu_show_count = 0; |
- test_api_->InstallTestMenuRunner(&menu_show_count); |
const gfx::Point right_point(combobox_->x() + combobox_->width() - 1, |
combobox_->y() + combobox_->height() / 2); |
- EXPECT_EQ(0, menu_show_count); |
+ EXPECT_EQ(0, menu_show_count()); |
// On Mac, actions occur on mouse down. Otherwise mouse up. |
#if defined(OS_MACOSX) |
@@ -608,43 +616,43 @@ TEST_F(ComboboxTest, NotifyOnClickWithMouse) { |
#endif |
PerformMousePress(right_point); |
- EXPECT_EQ(kActOnMouseDown, menu_show_count); |
+ EXPECT_EQ(kActOnMouseDown, menu_show_count()); |
PerformMouseRelease(right_point); |
- EXPECT_EQ(1, menu_show_count); |
+ EXPECT_EQ(1, menu_show_count()); |
// Click the left side (text button). The click event is notified. |
const gfx::Point left_point( |
gfx::Point(combobox_->x() + 1, combobox_->y() + combobox_->height() / 2)); |
- test_api_->InstallTestMenuRunner(&menu_show_count); |
PerformMousePress(left_point); |
PerformMouseRelease(left_point); |
- EXPECT_EQ(1, menu_show_count); // Unchanged. |
+ EXPECT_EQ(1, menu_show_count()); // Unchanged. |
EXPECT_EQ(0, listener.perform_action_index()); |
} |
TEST_F(ComboboxTest, ConsumingPressKeyEvents) { |
InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
- int menu_show_count = 0; |
- test_api_->InstallTestMenuRunner(&menu_show_count); |
EXPECT_TRUE(combobox_->OnKeyPressed( |
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); |
- EXPECT_EQ(1, menu_show_count); |
+ EXPECT_EQ(1, menu_show_count()); |
EXPECT_TRUE(combobox_->OnKeyPressed( |
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); |
- EXPECT_EQ(2, menu_show_count); |
+ EXPECT_EQ(2, menu_show_count()); |
} |
TEST_F(ComboboxTest, ConsumingKeyPressEventsActionStyle) { |
// When the combobox's style is STYLE_ACTION, pressing events of a space key |
- // or an enter key will be consumed. |
+ // or an enter key will be consumed and the menu is not shown. |
InitCombobox(nullptr, Combobox::STYLE_ACTION); |
+ |
EXPECT_TRUE(combobox_->OnKeyPressed( |
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); |
+ EXPECT_EQ(0, menu_show_count()); |
EXPECT_TRUE(combobox_->OnKeyPressed( |
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); |
+ EXPECT_EQ(0, menu_show_count()); |
} |
TEST_F(ComboboxTest, ContentWidth) { |