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

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

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cache arrow images Created 4 years, 8 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 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 1e65e015fbf47d550e27ccab0485c80bcb6974e3..1d3ae74370a1ce38d7dd1a380035cd7af0d6ac02 100644
--- a/ui/views/controls/combobox/combobox_unittest.cc
+++ b/ui/views/controls/combobox/combobox_unittest.cc
@@ -36,9 +36,9 @@ namespace {
class TestCombobox : public Combobox {
public:
explicit TestCombobox(ui::ComboboxModel* model)
- : Combobox(model),
- key_handled_(false),
- key_received_(false) {}
+ : TestCombobox(model, Combobox::STYLE_NORMAL) {}
tapted 2016/04/26 05:05:58 In this case I think things are better without the
Elly Fong-Jones 2016/04/26 17:41:26 Done.
+ TestCombobox(ui::ComboboxModel* model, Combobox::Style style)
+ : Combobox(model, style), key_handled_(false), key_received_(false) {}
bool OnKeyPressed(const ui::KeyEvent& e) override {
key_received_ = true;
@@ -196,13 +196,17 @@ class ComboboxTest : public ViewsTestBase {
}
void InitCombobox(const std::set<int>* separators) {
+ InitCombobox(separators, Combobox::STYLE_NORMAL);
+ }
+
+ void InitCombobox(const std::set<int>* separators, Combobox::Style style) {
model_.reset(new TestComboboxModel());
if (separators)
model_->SetSeparators(*separators);
ASSERT_FALSE(combobox_);
- combobox_ = new TestCombobox(model_.get());
+ combobox_ = new TestCombobox(model_.get(), style);
test_api_.reset(new ComboboxTestApi(combobox_));
combobox_->set_id(1);
@@ -447,9 +451,11 @@ TEST_F(ComboboxTest, SelectValue) {
EXPECT_EQ(1, combobox_->selected_index());
EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("BANANAS")));
EXPECT_EQ(1, combobox_->selected_index());
+}
+TEST_F(ComboboxTest, SelectValueActionStyle) {
// With the action style, the selected index is always 0.
- combobox_->SetStyle(Combobox::STYLE_ACTION);
+ InitCombobox(NULL, Combobox::STYLE_ACTION);
tapted 2016/04/26 05:05:58 nit: since it's changing, any added code should be
Elly Fong-Jones 2016/04/26 17:41:26 Done.
EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("PEANUT BUTTER")));
EXPECT_EQ(0, combobox_->selected_index());
EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("JELLY")));
@@ -459,10 +465,8 @@ TEST_F(ComboboxTest, SelectValue) {
}
TEST_F(ComboboxTest, SelectIndexActionStyle) {
- InitCombobox(NULL);
-
// With the action style, the selected index is always 0.
- combobox_->SetStyle(Combobox::STYLE_ACTION);
+ InitCombobox(NULL, Combobox::STYLE_ACTION);
combobox_->SetSelectedIndex(1);
EXPECT_EQ(0, combobox_->selected_index());
combobox_->SetSelectedIndex(2);
@@ -483,10 +487,9 @@ TEST_F(ComboboxTest, ListenerHandlesDelete) {
// With STYLE_ACTION
// |combobox| will be deleted on change.
- combobox = new TestCombobox(&model);
+ combobox = new TestCombobox(&model, Combobox::STYLE_ACTION);
evil_listener.reset(new EvilListener());
combobox->set_listener(evil_listener.get());
- combobox->SetStyle(Combobox::STYLE_ACTION);
ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2));
EXPECT_TRUE(evil_listener->deleted());
}
@@ -536,9 +539,15 @@ TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) {
// With STYLE_NORMAL, the click event is ignored.
SendKeyEvent(ui::VKEY_RETURN);
EXPECT_FALSE(listener.on_perform_action_called());
+}
+
+TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) {
+ InitCombobox(NULL, Combobox::STYLE_ACTION);
+
+ TestComboboxListener listener;
+ combobox_->set_listener(&listener);
// With STYLE_ACTION, the click event is notified.
- combobox_->SetStyle(Combobox::STYLE_ACTION);
SendKeyEvent(ui::VKEY_RETURN);
EXPECT_TRUE(listener.on_perform_action_called());
EXPECT_EQ(0, listener.perform_action_index());
@@ -555,9 +564,15 @@ TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) {
EXPECT_FALSE(listener.on_perform_action_called());
SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED);
EXPECT_FALSE(listener.on_perform_action_called());
+}
+
+TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) {
+ InitCombobox(NULL, Combobox::STYLE_ACTION);
+
+ TestComboboxListener listener;
+ combobox_->set_listener(&listener);
// With STYLE_ACTION, the click event is notified after releasing.
- combobox_->SetStyle(Combobox::STYLE_ACTION);
SendKeyEvent(ui::VKEY_SPACE);
EXPECT_FALSE(listener.on_perform_action_called());
SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED);
@@ -566,12 +581,11 @@ TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) {
}
TEST_F(ComboboxTest, NotifyOnClickWithMouse) {
- InitCombobox(NULL);
+ InitCombobox(NULL, Combobox::STYLE_ACTION);
TestComboboxListener listener;
combobox_->set_listener(&listener);
- combobox_->SetStyle(Combobox::STYLE_ACTION);
combobox_->Layout();
// Click the right side (arrow button). The menu is shown.
@@ -599,10 +613,12 @@ TEST_F(ComboboxTest, ConsumingPressKeyEvents) {
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE)));
EXPECT_FALSE(combobox_->OnKeyPressed(
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE)));
+}
+TEST_F(ComboboxTest, ConsumingPressKeyEventsActionStyle) {
+ InitCombobox(NULL, Combobox::STYLE_ACTION);
// When the combobox's style is STYLE_ACTION, pressing events of a space key
// or an enter key will be consumed.
- combobox_->SetStyle(Combobox::STYLE_ACTION);
EXPECT_TRUE(combobox_->OnKeyPressed(
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE)));
EXPECT_TRUE(combobox_->OnKeyPressed(
@@ -613,7 +629,9 @@ TEST_F(ComboboxTest, ContentWidth) {
std::vector<std::string> values;
VectorComboboxModel model(&values);
TestCombobox combobox(&model);
+ TestCombobox action_combobox(&model, Combobox::STYLE_ACTION);
ComboboxTestApi test_api(&combobox);
+ ComboboxTestApi action_test_api(&action_combobox);
std::string long_item = "this is the long item";
std::string short_item = "s";
@@ -621,11 +639,13 @@ TEST_F(ComboboxTest, ContentWidth) {
values.resize(1);
values[0] = long_item;
combobox.ModelChanged();
+ action_combobox.ModelChanged();
const int long_item_width = test_api.content_size().width();
values[0] = short_item;
combobox.ModelChanged();
+ action_combobox.ModelChanged();
const int short_item_width = test_api.content_size().width();
@@ -633,15 +653,14 @@ TEST_F(ComboboxTest, ContentWidth) {
values[0] = short_item;
values[1] = long_item;
combobox.ModelChanged();
+ action_combobox.ModelChanged();
// When the style is STYLE_NORMAL, the width will fit with the longest item.
- combobox.SetStyle(Combobox::STYLE_NORMAL);
EXPECT_EQ(long_item_width, test_api.content_size().width());
// When the style is STYLE_ACTION, the width will fit with the selected item's
// width.
- combobox.SetStyle(Combobox::STYLE_ACTION);
- EXPECT_EQ(short_item_width, test_api.content_size().width());
+ EXPECT_EQ(short_item_width, action_test_api.content_size().width());
}
// Test that model updates preserve the selected index, so long as it is in
@@ -760,7 +779,26 @@ TEST_F(ComboboxTest, MenuModel) {
// Check that with STYLE_ACTION, the first item (only) is not shown.
tapted 2016/04/26 05:05:58 this comment should move be above the next test ca
Elly Fong-Jones 2016/04/26 17:41:26 Done.
EXPECT_TRUE(menu_model->IsVisibleAt(0));
- combobox_->SetStyle(Combobox::STYLE_ACTION);
+}
+
+TEST_F(ComboboxTest, MenuModelActionStyle) {
+ const int kSeparatorIndex = 3;
+ std::set<int> separators;
+ separators.insert(kSeparatorIndex);
+ InitCombobox(&separators, Combobox::STYLE_ACTION);
+
+ ui::MenuModel* menu_model = test_api_->menu_model();
+
+ EXPECT_EQ(TestComboboxModel::kItemCount, menu_model->GetItemCount());
+ EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR,
+ menu_model->GetTypeAt(kSeparatorIndex));
+
+ EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0));
+ EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1));
+
+ EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0));
+ EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1));
+
EXPECT_FALSE(menu_model->IsVisibleAt(0));
EXPECT_TRUE(menu_model->IsVisibleAt(1));
}

Powered by Google App Engine
This is Rietveld 408576698