OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "ui/events/event_processor.h" | 35 #include "ui/events/event_processor.h" |
36 #include "ui/events/event_utils.h" | 36 #include "ui/events/event_utils.h" |
37 #include "ui/events/keycodes/keyboard_codes.h" | 37 #include "ui/events/keycodes/keyboard_codes.h" |
38 #include "ui/events/test/event_generator.h" | 38 #include "ui/events/test/event_generator.h" |
39 #include "ui/events/test/keyboard_layout.h" | 39 #include "ui/events/test/keyboard_layout.h" |
40 #include "ui/gfx/render_text.h" | 40 #include "ui/gfx/render_text.h" |
41 #include "ui/strings/grit/ui_strings.h" | 41 #include "ui/strings/grit/ui_strings.h" |
42 #include "ui/views/controls/textfield/textfield_controller.h" | 42 #include "ui/views/controls/textfield/textfield_controller.h" |
43 #include "ui/views/controls/textfield/textfield_model.h" | 43 #include "ui/views/controls/textfield/textfield_model.h" |
44 #include "ui/views/controls/textfield/textfield_test_api.h" | 44 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 45 #include "ui/views/controls/views_text_services_context_menu.h" |
45 #include "ui/views/focus/focus_manager.h" | 46 #include "ui/views/focus/focus_manager.h" |
46 #include "ui/views/style/platform_style.h" | 47 #include "ui/views/style/platform_style.h" |
47 #include "ui/views/test/test_views_delegate.h" | 48 #include "ui/views/test/test_views_delegate.h" |
48 #include "ui/views/test/views_test_base.h" | 49 #include "ui/views/test/views_test_base.h" |
49 #include "ui/views/test/widget_test.h" | 50 #include "ui/views/test/widget_test.h" |
50 #include "ui/views/widget/widget.h" | 51 #include "ui/views/widget/widget.h" |
51 #include "url/gurl.h" | 52 #include "url/gurl.h" |
52 | 53 |
53 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
54 #include "base/win/windows_version.h" | 55 #include "base/win/windows_version.h" |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 637 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
637 ui::EventTimeForNow(), | 638 ui::EventTimeForNow(), |
638 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 639 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
639 ui::EF_LEFT_MOUSE_BUTTON); | 640 ui::EF_LEFT_MOUSE_BUTTON); |
640 textfield_->OnMouseReleased(release); | 641 textfield_->OnMouseReleased(release); |
641 } | 642 } |
642 | 643 |
643 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 644 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
644 bool can_undo, | 645 bool can_undo, |
645 ui::MenuModel* menu) { | 646 ui::MenuModel* menu) { |
646 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); | 647 int menu_index = 0; |
647 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); | 648 #if defined(OS_MACOSX) |
648 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); | 649 // On Mac, the Look Up item should appear at the top of the menu if the |
649 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); | 650 // textfield has a selection. |
| 651 if (textfield_has_selection) { |
| 652 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* LOOK UP */)); |
| 653 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */)); |
| 654 } |
| 655 #endif |
| 656 |
| 657 EXPECT_EQ(can_undo, menu->IsEnabledAt(menu_index++ /* UNDO */)); |
| 658 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */)); |
| 659 EXPECT_EQ(textfield_has_selection, |
| 660 menu->IsEnabledAt(menu_index++ /* CUT */)); |
| 661 EXPECT_EQ(textfield_has_selection, |
| 662 menu->IsEnabledAt(menu_index++ /* COPY */)); |
650 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), | 663 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), |
651 menu->IsEnabledAt(4 /* PASTE */)); | 664 menu->IsEnabledAt(menu_index++ /* PASTE */)); |
652 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 665 EXPECT_EQ(textfield_has_selection, |
653 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); | 666 menu->IsEnabledAt(menu_index++ /* DELETE */)); |
654 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); | 667 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */)); |
| 668 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* SELECT ALL */)); |
655 } | 669 } |
656 | 670 |
657 void PressLeftMouseButton(int extra_flags) { | 671 void PressLeftMouseButton(int extra_flags) { |
658 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_, | 672 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_, |
659 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 673 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
660 ui::EF_LEFT_MOUSE_BUTTON | extra_flags); | 674 ui::EF_LEFT_MOUSE_BUTTON | extra_flags); |
661 textfield_->OnMousePressed(click); | 675 textfield_->OnMousePressed(click); |
662 } | 676 } |
663 | 677 |
664 void PressLeftMouseButton() { | 678 void PressLeftMouseButton() { |
(...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3002 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 3016 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
3003 ui::AXNodeData node_data_protected; | 3017 ui::AXNodeData node_data_protected; |
3004 node_data_protected.state = 0; | 3018 node_data_protected.state = 0; |
3005 textfield_->GetAccessibleNodeData(&node_data_protected); | 3019 textfield_->GetAccessibleNodeData(&node_data_protected); |
3006 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); | 3020 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); |
3007 EXPECT_EQ(ASCIIToUTF16("********"), | 3021 EXPECT_EQ(ASCIIToUTF16("********"), |
3008 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); | 3022 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); |
3009 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 3023 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
3010 } | 3024 } |
3011 | 3025 |
| 3026 #if defined(OS_MACOSX) |
| 3027 TEST_F(TextfieldTest, TextServicesContextMenuTextDirectionTest) { |
| 3028 using base::i18n::TextDirection; |
| 3029 |
| 3030 InitTextfield(); |
| 3031 EXPECT_TRUE(textfield_->context_menu_controller()); |
| 3032 |
| 3033 EXPECT_TRUE(GetContextMenuModel()); |
| 3034 |
| 3035 textfield_->ChangeTextDirectionAndLayoutAlignment( |
| 3036 TextDirection::LEFT_TO_RIGHT); |
| 3037 test_api_->UpdateContextMenu(); |
| 3038 ViewsTextServicesContextMenu* text_services_menu = |
| 3039 test_api_->text_services_context_menu(); |
| 3040 |
| 3041 EXPECT_FALSE(text_services_menu->IsCommandIdChecked( |
| 3042 IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); |
| 3043 EXPECT_TRUE(text_services_menu->IsCommandIdChecked( |
| 3044 IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); |
| 3045 EXPECT_FALSE(text_services_menu->IsCommandIdChecked( |
| 3046 IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); |
| 3047 |
| 3048 textfield_->ChangeTextDirectionAndLayoutAlignment( |
| 3049 TextDirection::RIGHT_TO_LEFT); |
| 3050 test_api_->UpdateContextMenu(); |
| 3051 text_services_menu = test_api_->text_services_context_menu(); |
| 3052 |
| 3053 EXPECT_FALSE(text_services_menu->IsCommandIdChecked( |
| 3054 IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); |
| 3055 EXPECT_FALSE(text_services_menu->IsCommandIdChecked( |
| 3056 IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); |
| 3057 EXPECT_TRUE(text_services_menu->IsCommandIdChecked( |
| 3058 IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); |
| 3059 } |
| 3060 #endif |
| 3061 |
3012 } // namespace views | 3062 } // namespace views |
OLD | NEW |