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

Unified Diff: ui/views/controls/combobox/combobox_unittest.cc

Issue 59383003: Add the button style for combobox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky's review (3) Created 7 years 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 side-by-side diff with in-line comments
Download patch
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 3637c087b1db6a7dd602668317659201339920e1..3ca80a14f91d7297fc19a1a88ba6432b594d5d00 100644
--- a/ui/views/controls/combobox/combobox_unittest.cc
+++ b/ui/views/controls/combobox/combobox_unittest.cc
@@ -10,6 +10,7 @@
#include "ui/base/models/combobox_model.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
+#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/ime/mock_input_method.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
@@ -83,6 +84,29 @@ class TestComboboxModel : public ui::ComboboxModel {
DISALLOW_COPY_AND_ASSIGN(TestComboboxModel);
};
+class TestComboboxListener : public views::ComboboxListener {
+ public:
+ TestComboboxListener()
+ : on_selected_index_changed_(false),
+ on_combobox_text_button_clicked_called_(false) {
+ }
+ virtual ~TestComboboxListener() {}
+
+ virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE {
+ on_selected_index_changed_ = true;
+ }
+
+ virtual void OnComboboxTextButtonClicked(views::Combobox* combobox) OVERRIDE {
+ on_combobox_text_button_clicked_called_ = true;
+ }
+
+ bool on_selected_index_changed_;
sky 2013/12/05 16:46:32 private and add accessors/setters.
hajimehoshi 2013/12/06 12:27:04 Done.
+ bool on_combobox_text_button_clicked_called_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestComboboxListener);
+};
+
} // namespace
namespace views {
@@ -123,7 +147,11 @@ class ComboboxTest : public ViewsTestBase {
protected:
void SendKeyEvent(ui::KeyboardCode key_code) {
- ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, 0, false);
+ SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED);
+ }
+
+ void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) {
+ ui::KeyEvent event(type, key_code, 0, false);
input_method_->DispatchKeyEvent(event);
}
@@ -340,4 +368,27 @@ TEST_F(ComboboxTest, SelectValue) {
EXPECT_EQ(1, combobox_->selected_index());
}
+TEST_F(ComboboxTest, NotifyOnClick) {
sky 2013/12/05 16:46:32 Add coverage of mouse events too.
hajimehoshi 2013/12/06 12:27:04 Done. (Added a class ComboboxMenuRunner)
+ InitCombobox();
+
+ TestComboboxListener listener;
+ combobox_->set_listener(&listener);
+
+ // With STYLE_SHOW_DROP_DOWN_ON_CLICK, the click event is ignored.
+ SendKeyEvent(ui::VKEY_RETURN);
+ EXPECT_FALSE(listener.on_combobox_text_button_clicked_called_);
+
+ // With STYLE_NOTIFY_ON_CLICK, the click event is notified.
+ combobox_->SetStyle(Combobox::STYLE_NOTIFY_ON_CLICK);
+ SendKeyEvent(ui::VKEY_RETURN);
+ EXPECT_TRUE(listener.on_combobox_text_button_clicked_called_);
+
+ // With a space key, the click event is notified after releasing.
+ listener.on_combobox_text_button_clicked_called_ = false;
+ SendKeyEvent(ui::VKEY_SPACE);
+ EXPECT_FALSE(listener.on_combobox_text_button_clicked_called_);
+ SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED);
+ EXPECT_TRUE(listener.on_combobox_text_button_clicked_called_);
+}
+
} // namespace views
« ui/views/controls/combobox/combobox.cc ('K') | « ui/views/controls/combobox/combobox_listener.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698