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

Side by Side Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 2164483006: [MacViews] Implemented text context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed tapted's comments and added a test Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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
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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 641 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
641 ui::EventTimeForNow(), 642 ui::EventTimeForNow(),
642 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, 643 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT,
643 ui::EF_LEFT_MOUSE_BUTTON); 644 ui::EF_LEFT_MOUSE_BUTTON);
644 textfield_->OnMouseReleased(release); 645 textfield_->OnMouseReleased(release);
645 } 646 }
646 647
647 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, 648 void VerifyTextfieldContextMenuContents(bool textfield_has_selection,
648 bool can_undo, 649 bool can_undo,
649 ui::MenuModel* menu) { 650 ui::MenuModel* menu) {
650 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); 651 int menu_index = 0;
651 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); 652 #if defined(OS_MACOSX)
652 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); 653 // On Mac, the Look Up item should appear at the top of the menu if the
653 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); 654 // textfield has a selection.
655 if (textfield_has_selection) {
656 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* LOOK UP */));
657 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */));
658 }
659 #endif
660
661 EXPECT_EQ(can_undo, menu->IsEnabledAt(menu_index++ /* UNDO */));
662 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */));
663 EXPECT_EQ(textfield_has_selection,
664 menu->IsEnabledAt(menu_index++ /* CUT */));
665 EXPECT_EQ(textfield_has_selection,
666 menu->IsEnabledAt(menu_index++ /* COPY */));
654 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), 667 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(),
655 menu->IsEnabledAt(4 /* PASTE */)); 668 menu->IsEnabledAt(menu_index++ /* PASTE */));
656 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); 669 EXPECT_EQ(textfield_has_selection,
657 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); 670 menu->IsEnabledAt(menu_index++ /* DELETE */));
658 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); 671 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* Separator */));
672 EXPECT_TRUE(menu->IsEnabledAt(menu_index++ /* SELECT ALL */));
659 } 673 }
660 674
661 void PressMouseButton(ui::EventFlags mouse_button_flags, int extra_flags) { 675 void PressMouseButton(ui::EventFlags mouse_button_flags, int extra_flags) {
662 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_, 676 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_,
663 ui::EventTimeForNow(), mouse_button_flags, 677 ui::EventTimeForNow(), mouse_button_flags,
664 mouse_button_flags | extra_flags); 678 mouse_button_flags | extra_flags);
665 textfield_->OnMousePressed(press); 679 textfield_->OnMousePressed(press);
666 } 680 }
667 681
668 void ReleaseMouseButton(ui::EventFlags mouse_button_flags) { 682 void ReleaseMouseButton(ui::EventFlags mouse_button_flags) {
(...skipping 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 3052 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
3039 ui::AXNodeData node_data_protected; 3053 ui::AXNodeData node_data_protected;
3040 node_data_protected.state = 0; 3054 node_data_protected.state = 0;
3041 textfield_->GetAccessibleNodeData(&node_data_protected); 3055 textfield_->GetAccessibleNodeData(&node_data_protected);
3042 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); 3056 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role);
3043 EXPECT_EQ(ASCIIToUTF16("********"), 3057 EXPECT_EQ(ASCIIToUTF16("********"),
3044 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); 3058 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE));
3045 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 3059 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
3046 } 3060 }
3047 3061
3062 // Tests to see if the context menu is updated along with the textfield's
3063 // caret bounds.
3064 TEST_F(TextfieldTest, ContextMenuUpdate) {
3065 InitTextfield();
3066 EXPECT_TRUE(textfield_->context_menu_controller());
3067
3068 ui::MenuModel* context_menu = GetContextMenuModel();
3069 EXPECT_TRUE(context_menu);
3070
3071 // Select all the text and get the new context menu.
3072 textfield_->SelectAll(false);
3073 ui::MenuModel* new_context_menu = GetContextMenuModel();
3074 EXPECT_TRUE(new_context_menu);
3075
3076 // Check if the new context menu is different.
3077 EXPECT_NE(&context_menu, &new_context_menu);
3078 }
3079
3080 #if defined(OS_MACOSX)
3081
3082 // Tests to see if the BiDi submenu items are updated correctly when the
3083 // textfield's text direction is changed.
3084 TEST_F(TextfieldTest, TextServicesContextMenuTextDirectionTest) {
3085 using base::i18n::TextDirection;
3086
3087 InitTextfield();
3088 EXPECT_TRUE(textfield_->context_menu_controller());
3089
3090 EXPECT_TRUE(GetContextMenuModel());
3091
3092 textfield_->ChangeTextDirectionAndLayoutAlignment(
3093 TextDirection::LEFT_TO_RIGHT);
3094 test_api_->UpdateContextMenu();
3095 ViewsTextServicesContextMenu* text_services_menu =
3096 test_api_->text_services_context_menu();
3097
3098 EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked(
3099 TextDirection::UNKNOWN_DIRECTION));
3100 EXPECT_TRUE(text_services_menu->IsTextDirectionItemChecked(
3101 TextDirection::LEFT_TO_RIGHT));
3102 EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked(
3103 TextDirection::RIGHT_TO_LEFT));
3104
3105 textfield_->ChangeTextDirectionAndLayoutAlignment(
3106 TextDirection::RIGHT_TO_LEFT);
3107 test_api_->UpdateContextMenu();
3108 text_services_menu = test_api_->text_services_context_menu();
3109
3110 EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked(
3111 TextDirection::UNKNOWN_DIRECTION));
3112 EXPECT_FALSE(text_services_menu->IsTextDirectionItemChecked(
3113 TextDirection::LEFT_TO_RIGHT));
3114 EXPECT_TRUE(text_services_menu->IsTextDirectionItemChecked(
3115 TextDirection::RIGHT_TO_LEFT));
3116 }
3117 #endif
msw 2017/01/26 20:59:16 nit: add a comment: "#endif // OS_MACOSX" and add
spqchan 2017/02/01 00:32:38 Done.
3118
3048 } // namespace views 3119 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698