Chromium Code Reviews| Index: ui/views/controls/textfield/textfield_unittest.cc |
| diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc |
| index 858e7d51f2517f9eb67c6988f9f4a44735e3b1df..b7a598d1f9421e1211ca3fab7a4dd3e6592855b6 100644 |
| --- a/ui/views/controls/textfield/textfield_unittest.cc |
| +++ b/ui/views/controls/textfield/textfield_unittest.cc |
| @@ -42,6 +42,7 @@ |
| #include "ui/views/controls/textfield/textfield_controller.h" |
| #include "ui/views/controls/textfield/textfield_model.h" |
| #include "ui/views/controls/textfield/textfield_test_api.h" |
| +#include "ui/views/controls/views_text_services_context_menu.h" |
| #include "ui/views/focus/focus_manager.h" |
| #include "ui/views/style/platform_style.h" |
| #include "ui/views/test/test_views_delegate.h" |
| @@ -647,15 +648,28 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController { |
| void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
| bool can_undo, |
| ui::MenuModel* menu) { |
| - EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); |
| - EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); |
| - EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); |
| - EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); |
| + int menu_index = 0; |
| +#if defined(OS_MACOSX) |
| + // On Mac, the Look Up item should appear at the top of the menu if the |
| + // textfield has a selection. |
| + if (textfield_has_selection) { |
| + EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* LOOK UP */)); |
| + EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */)); |
| + } |
| +#endif |
| + |
| + EXPECT_EQ(can_undo, menu->IsEnabledAt(menu_index++ /* UNDO */)); |
| + EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */)); |
| + EXPECT_EQ(textfield_has_selection, |
| + menu->IsEnabledAt(menu_index++ /* CUT */)); |
| + EXPECT_EQ(textfield_has_selection, |
| + menu->IsEnabledAt(menu_index++ /* COPY */)); |
| EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), |
| - menu->IsEnabledAt(4 /* PASTE */)); |
| - EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
| - EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); |
| - EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); |
| + menu->IsEnabledAt(menu_index++ /* PASTE */)); |
| + EXPECT_EQ(textfield_has_selection, |
| + menu->IsEnabledAt(menu_index++ /* DELETE */)); |
| + EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */)); |
| + EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* SELECT ALL */)); |
| } |
| void PressMouseButton(ui::EventFlags mouse_button_flags, int extra_flags) { |
| @@ -3045,4 +3059,40 @@ TEST_F(TextfieldTest, AccessiblePasswordTest) { |
| EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| } |
| +#if defined(OS_MACOSX) |
| +TEST_F(TextfieldTest, TextServicesContextMenuTextDirectionTest) { |
|
tapted
2017/01/13 21:37:33
nit: add a comment explaining the test
spqchan
2017/01/26 18:27:01
Done.
|
| + using base::i18n::TextDirection; |
| + |
| + InitTextfield(); |
| + EXPECT_TRUE(textfield_->context_menu_controller()); |
| + |
| + EXPECT_TRUE(GetContextMenuModel()); |
| + |
| + textfield_->ChangeTextDirectionAndLayoutAlignment( |
| + TextDirection::LEFT_TO_RIGHT); |
| + test_api_->UpdateContextMenu(); |
|
tapted
2017/01/13 21:37:33
can we add a test that verifies the context menu r
spqchan
2017/01/26 18:27:01
Done.
|
| + ViewsTextServicesContextMenu* text_services_menu = |
| + test_api_->text_services_context_menu(); |
| + |
| + EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked( |
| + TextDirection::UNKNOWN_DIRECTION)); |
| + EXPECT_TRUE(text_services_menu->IsTextDirectionItemChecked( |
| + TextDirection::LEFT_TO_RIGHT)); |
| + EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked( |
| + TextDirection::RIGHT_TO_LEFT)); |
| + |
| + textfield_->ChangeTextDirectionAndLayoutAlignment( |
| + TextDirection::RIGHT_TO_LEFT); |
| + test_api_->UpdateContextMenu(); |
| + text_services_menu = test_api_->text_services_context_menu(); |
| + |
| + EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked( |
| + TextDirection::UNKNOWN_DIRECTION)); |
| + EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked( |
| + TextDirection::LEFT_TO_RIGHT)); |
| + EXPECT_TRUE(text_services_menu->IsTextDirectionItemChecked( |
| + TextDirection::RIGHT_TO_LEFT)); |
| +} |
| +#endif |
| + |
| } // namespace views |