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

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: rebased 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 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 3065 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
3052 ui::AXNodeData node_data_protected; 3066 ui::AXNodeData node_data_protected;
3053 node_data_protected.state = 0; 3067 node_data_protected.state = 0;
3054 textfield_->GetAccessibleNodeData(&node_data_protected); 3068 textfield_->GetAccessibleNodeData(&node_data_protected);
3055 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); 3069 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role);
3056 EXPECT_EQ(ASCIIToUTF16("********"), 3070 EXPECT_EQ(ASCIIToUTF16("********"),
3057 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); 3071 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE));
3058 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 3072 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
3059 } 3073 }
3060 3074
3075 // Tests to see if the context menu is updated along with the textfield's
3076 // caret bounds.
3077 TEST_F(TextfieldTest, ContextMenuUpdate) {
3078 InitTextfield();
3079 EXPECT_TRUE(textfield_->context_menu_controller());
3080
3081 ui::MenuModel* context_menu = GetContextMenuModel();
3082 EXPECT_TRUE(context_menu);
3083
3084 // Select all the text and get the new context menu.
3085 textfield_->SelectAll(false);
3086 ui::MenuModel* new_context_menu = GetContextMenuModel();
3087 EXPECT_TRUE(new_context_menu);
3088
3089 // Check if the new context menu is different.
3090 EXPECT_NE(&context_menu, &new_context_menu);
3091 }
3092
3093 #if defined(OS_MACOSX)
3094 // Tests to see if the BiDi submenu items are updated correctly when the
3095 // textfield's text direction is changed.
3096 TEST_F(TextfieldTest, TextServicesContextMenuTextDirectionTest) {
3097 InitTextfield();
3098 EXPECT_TRUE(textfield_->context_menu_controller());
3099
3100 EXPECT_TRUE(GetContextMenuModel());
3101
3102 textfield_->ChangeTextDirectionAndLayoutAlignment(
3103 base::i18n::TextDirection::LEFT_TO_RIGHT);
3104 test_api_->UpdateContextMenu();
3105 ViewsTextServicesContextMenu* text_services_menu =
3106 test_api_->text_services_context_menu();
3107
3108 EXPECT_FALSE(text_services_menu->IsTextDirectionCheckedForTesting(
3109 base::i18n::TextDirection::UNKNOWN_DIRECTION));
3110 EXPECT_TRUE(text_services_menu->IsTextDirectionCheckedForTesting(
3111 base::i18n::TextDirection::LEFT_TO_RIGHT));
3112 EXPECT_FALSE(text_services_menu->IsTextDirectionCheckedForTesting(
3113 base::i18n::TextDirection::RIGHT_TO_LEFT));
3114
3115 textfield_->ChangeTextDirectionAndLayoutAlignment(
3116 base::i18n::TextDirection::RIGHT_TO_LEFT);
3117 test_api_->UpdateContextMenu();
3118 text_services_menu = test_api_->text_services_context_menu();
3119
3120 EXPECT_FALSE(text_services_menu->IsTextDirectionCheckedForTesting(
3121 base::i18n::TextDirection::UNKNOWN_DIRECTION));
3122 EXPECT_FALSE(text_services_menu->IsTextDirectionCheckedForTesting(
3123 base::i18n::TextDirection::LEFT_TO_RIGHT));
3124 EXPECT_TRUE(text_services_menu->IsTextDirectionCheckedForTesting(
3125 base::i18n::TextDirection::RIGHT_TO_LEFT));
3126 }
3127 #endif // defined(OS_MACOSX)
3128
3061 } // namespace views 3129 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield_test_api.h ('k') | ui/views/controls/views_text_services_context_menu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698