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

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

Issue 1865063004: views: support vertical-drag-to-end on textfields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor some textfield unittests 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 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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 #include "ui/events/event.h" 26 #include "ui/events/event.h"
27 #include "ui/events/event_processor.h" 27 #include "ui/events/event_processor.h"
28 #include "ui/events/event_utils.h" 28 #include "ui/events/event_utils.h"
29 #include "ui/events/keycodes/keyboard_codes.h" 29 #include "ui/events/keycodes/keyboard_codes.h"
30 #include "ui/gfx/render_text.h" 30 #include "ui/gfx/render_text.h"
31 #include "ui/strings/grit/ui_strings.h" 31 #include "ui/strings/grit/ui_strings.h"
32 #include "ui/views/controls/textfield/textfield_controller.h" 32 #include "ui/views/controls/textfield/textfield_controller.h"
33 #include "ui/views/controls/textfield/textfield_model.h" 33 #include "ui/views/controls/textfield/textfield_model.h"
34 #include "ui/views/controls/textfield/textfield_test_api.h" 34 #include "ui/views/controls/textfield/textfield_test_api.h"
35 #include "ui/views/focus/focus_manager.h" 35 #include "ui/views/focus/focus_manager.h"
36 #include "ui/views/style/platform_style.h"
36 #include "ui/views/test/test_views_delegate.h" 37 #include "ui/views/test/test_views_delegate.h"
37 #include "ui/views/test/views_test_base.h" 38 #include "ui/views/test/views_test_base.h"
38 #include "ui/views/test/widget_test.h" 39 #include "ui/views/test/widget_test.h"
39 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
40 #include "url/gurl.h" 41 #include "url/gurl.h"
41 42
42 #if defined(OS_WIN) 43 #if defined(OS_WIN)
43 #include "base/win/windows_version.h" 44 #include "base/win/windows_version.h"
44 #endif 45 #endif
45 46
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); 641 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */));
641 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); 642 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */));
642 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); 643 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */));
643 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), 644 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(),
644 menu->IsEnabledAt(4 /* PASTE */)); 645 menu->IsEnabledAt(4 /* PASTE */));
645 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); 646 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */));
646 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); 647 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */));
647 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); 648 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */));
648 } 649 }
649 650
651 void PressLeftMouseButton() {
652 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_,
653 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
654 ui::EF_LEFT_MOUSE_BUTTON);
655 textfield_->OnMousePressed(click);
656 }
657
658 void ReleaseLeftMouseButton() {
659 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, mouse_position_,
660 mouse_position_, ui::EventTimeForNow(),
661 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
662 textfield_->OnMouseReleased(release);
663 }
664
665 void ClickLeftMouseButton() {
666 PressLeftMouseButton();
667 ReleaseLeftMouseButton();
668 }
669
670 void DragMouseTo(const gfx::Point& where) {
671 mouse_position_ = where;
672 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, where, where,
673 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
674 textfield_->OnMouseDragged(drag);
675 }
676
677 // Textfield does not listen to OnMouseMoved, so this function does not send
678 // an event when it updates the cursor position.
679 void MoveMouseTo(const gfx::Point& where) { mouse_position_ = where; }
680
650 // We need widget to populate wrapper class. 681 // We need widget to populate wrapper class.
651 Widget* widget_; 682 Widget* widget_;
652 683
653 TestTextfield* textfield_; 684 TestTextfield* textfield_;
654 scoped_ptr<TextfieldTestApi> test_api_; 685 scoped_ptr<TextfieldTestApi> test_api_;
655 TextfieldModel* model_; 686 TextfieldModel* model_;
656 687
657 // The string from Controller::ContentsChanged callback. 688 // The string from Controller::ContentsChanged callback.
658 base::string16 last_contents_; 689 base::string16 last_contents_;
659 690
660 // For testing input method related behaviors. 691 // For testing input method related behaviors.
661 MockInputMethod* input_method_; 692 MockInputMethod* input_method_;
662 693
663 // Indicates how many times OnBeforeUserAction() is called. 694 // Indicates how many times OnBeforeUserAction() is called.
664 int on_before_user_action_; 695 int on_before_user_action_;
665 696
666 // Indicates how many times OnAfterUserAction() is called. 697 // Indicates how many times OnAfterUserAction() is called.
667 int on_after_user_action_; 698 int on_after_user_action_;
668 699
669 private: 700 private:
670 ui::ClipboardType copied_to_clipboard_; 701 ui::ClipboardType copied_to_clipboard_;
671 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; 702 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_;
672 703
704 // Mouse position, for synthetic mouse events.
705 gfx::Point mouse_position_;
706
673 #if defined(OS_MACOSX) && !defined(USE_AURA) 707 #if defined(OS_MACOSX) && !defined(USE_AURA)
674 scoped_ptr<ui::test::EventGenerator> event_generator_; 708 scoped_ptr<ui::test::EventGenerator> event_generator_;
675 #endif 709 #endif
676 710
677 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); 711 DISALLOW_COPY_AND_ASSIGN(TextfieldTest);
678 }; 712 };
679 713
680 TEST_F(TextfieldTest, ModelChangesTest) { 714 TEST_F(TextfieldTest, ModelChangesTest) {
681 InitTextfield(); 715 InitTextfield();
682 716
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 widget_->GetFocusManager()->AdvanceFocus(true); 1114 widget_->GetFocusManager()->AdvanceFocus(true);
1081 EXPECT_EQ(3, GetFocusedView()->id()); 1115 EXPECT_EQ(3, GetFocusedView()->id());
1082 1116
1083 // Request focus should still work. 1117 // Request focus should still work.
1084 textfield_->RequestFocus(); 1118 textfield_->RequestFocus();
1085 EXPECT_EQ(1, GetFocusedView()->id()); 1119 EXPECT_EQ(1, GetFocusedView()->id());
1086 1120
1087 // Test if clicking on textfield view sets the focus. 1121 // Test if clicking on textfield view sets the focus.
1088 widget_->GetFocusManager()->AdvanceFocus(true); 1122 widget_->GetFocusManager()->AdvanceFocus(true);
1089 EXPECT_EQ(3, GetFocusedView()->id()); 1123 EXPECT_EQ(3, GetFocusedView()->id());
1090 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 1124 MoveMouseTo(gfx::Point());
1091 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1125 ClickLeftMouseButton();
1092 ui::EF_LEFT_MOUSE_BUTTON); 1126 // ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
tapted 2016/04/15 00:35:08 (delete commented stuff)
Elly Fong-Jones 2016/04/15 14:47:46 Done.
1093 textfield_->OnMousePressed(click); 1127 // ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1128 // ui::EF_LEFT_MOUSE_BUTTON);
1129 // textfield_->OnMousePressed(click);
1094 EXPECT_EQ(1, GetFocusedView()->id()); 1130 EXPECT_EQ(1, GetFocusedView()->id());
1095 1131
1096 // Tab/Shift+Tab should also cycle focus, not insert a tab character. 1132 // Tab/Shift+Tab should also cycle focus, not insert a tab character.
1097 SendKeyEvent(ui::VKEY_TAB, false, false); 1133 SendKeyEvent(ui::VKEY_TAB, false, false);
1098 EXPECT_EQ(2, GetFocusedView()->id()); 1134 EXPECT_EQ(2, GetFocusedView()->id());
1099 SendKeyEvent(ui::VKEY_TAB, false, false); 1135 SendKeyEvent(ui::VKEY_TAB, false, false);
1100 EXPECT_EQ(3, GetFocusedView()->id()); 1136 EXPECT_EQ(3, GetFocusedView()->id());
1101 // Cycle back to the first textfield. 1137 // Cycle back to the first textfield.
1102 SendKeyEvent(ui::VKEY_TAB, false, false); 1138 SendKeyEvent(ui::VKEY_TAB, false, false);
1103 EXPECT_EQ(1, GetFocusedView()->id()); 1139 EXPECT_EQ(1, GetFocusedView()->id());
(...skipping 28 matching lines...) Expand all
1132 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1168 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1133 1169
1134 // Exercise the "paste enabled?" check in the verifier. 1170 // Exercise the "paste enabled?" check in the verifier.
1135 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); 1171 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test");
1136 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1172 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1137 } 1173 }
1138 1174
1139 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { 1175 TEST_F(TextfieldTest, DoubleAndTripleClickTest) {
1140 InitTextfield(); 1176 InitTextfield();
1141 textfield_->SetText(ASCIIToUTF16("hello world")); 1177 textfield_->SetText(ASCIIToUTF16("hello world"));
1142 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
1143 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1144 ui::EF_LEFT_MOUSE_BUTTON);
1145 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
1146 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1147 ui::EF_LEFT_MOUSE_BUTTON);
1148 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
1149 ui::EventTimeForNow(),
1150 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
1151 ui::EF_LEFT_MOUSE_BUTTON);
1152 1178
1153 // Test for double click. 1179 // Test for double click.
1154 textfield_->OnMousePressed(click); 1180 MoveMouseTo(gfx::Point());
1155 textfield_->OnMouseReleased(release); 1181 ClickLeftMouseButton();
1156 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1182 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1157 textfield_->OnMousePressed(double_click); 1183 ClickLeftMouseButton();
tapted 2016/04/15 00:35:08 This needs to pass in a parameter to do a double-c
Elly Fong-Jones 2016/04/15 14:47:46 I added overloaded versions of ClickLeftMouseButto
1158 textfield_->OnMouseReleased(release);
1159 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1184 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1160 1185
1161 // Test for triple click. 1186 // Test for triple click.
1162 textfield_->OnMousePressed(click); 1187 ClickLeftMouseButton();
1163 textfield_->OnMouseReleased(release);
1164 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); 1188 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText());
1165 1189
1166 // Another click should reset back to double click. 1190 // Another click should reset back to double click.
1167 textfield_->OnMousePressed(click); 1191 ClickLeftMouseButton();
1168 textfield_->OnMouseReleased(release);
1169 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1192 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1170 } 1193 }
1171 1194
1172 TEST_F(TextfieldTest, DragToSelect) { 1195 TEST_F(TextfieldTest, DragToSelect) {
1173 InitTextfield(); 1196 InitTextfield();
1174 textfield_->SetText(ASCIIToUTF16("hello world")); 1197 textfield_->SetText(ASCIIToUTF16("hello world"));
1175 const int kStart = GetCursorPositionX(5); 1198 const int kStart = GetCursorPositionX(5);
1176 const int kEnd = 500; 1199 const int kEnd = 500;
1177 gfx::Point start_point(kStart, 0); 1200 gfx::Point start_point(kStart, 0);
1178 gfx::Point end_point(kEnd, 0); 1201 gfx::Point end_point(kEnd, 0);
1179 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, 1202
1180 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1203 MoveMouseTo(start_point);
1181 ui::EF_LEFT_MOUSE_BUTTON); 1204 PressLeftMouseButton();
1182 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point,
1183 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1184 ui::EF_LEFT_MOUSE_BUTTON);
1185 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(),
1186 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1187 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point,
1188 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1189 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point,
1190 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1191 ui::EF_LEFT_MOUSE_BUTTON);
1192 textfield_->OnMousePressed(click_a);
1193 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1205 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1206
1194 // Check that dragging left selects the beginning of the string. 1207 // Check that dragging left selects the beginning of the string.
1195 textfield_->OnMouseDragged(drag_left); 1208 DragMouseTo(gfx::Point());
1196 base::string16 text_left = textfield_->GetSelectedText(); 1209 base::string16 text_left = textfield_->GetSelectedText();
1197 EXPECT_STR_EQ("hello", text_left); 1210 EXPECT_STR_EQ("hello", text_left);
1211
1198 // Check that dragging right selects the rest of the string. 1212 // Check that dragging right selects the rest of the string.
1199 textfield_->OnMouseDragged(drag_right); 1213 DragMouseTo(end_point);
1200 base::string16 text_right = textfield_->GetSelectedText(); 1214 base::string16 text_right = textfield_->GetSelectedText();
1201 EXPECT_STR_EQ(" world", text_right); 1215 EXPECT_STR_EQ(" world", text_right);
1216
1202 // Check that releasing in the same location does not alter the selection. 1217 // Check that releasing in the same location does not alter the selection.
1203 textfield_->OnMouseReleased(release); 1218 ReleaseLeftMouseButton();
1204 EXPECT_EQ(text_right, textfield_->GetSelectedText()); 1219 EXPECT_EQ(text_right, textfield_->GetSelectedText());
1220
1205 // Check that dragging from beyond the text length works too. 1221 // Check that dragging from beyond the text length works too.
1206 textfield_->OnMousePressed(click_b); 1222 MoveMouseTo(end_point);
1207 textfield_->OnMouseDragged(drag_left); 1223 PressLeftMouseButton();
1208 textfield_->OnMouseReleased(release); 1224 DragMouseTo(gfx::Point());
1225 ReleaseLeftMouseButton();
1209 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); 1226 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText());
1210 } 1227 }
1211 1228
1229 // This test checks that dragging above the textfield selects to the beginning
1230 // and dragging below the textfield selects to the end, but only on platforms
1231 // where that is the expected behavior.
1232 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) {
1233 InitTextfield();
1234 textfield_->SetText(ASCIIToUTF16("hello world"));
1235 const base::string16 expected_up = base::ASCIIToUTF16(
1236 PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? "hello" : "lo");
1237 const base::string16 expected_down = base::ASCIIToUTF16(
1238 PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? " world" : " w");
1239 const int kStartX = GetCursorPositionX(5);
1240 const int kDownX = GetCursorPositionX(7);
1241 const int kUpX = GetCursorPositionX(3);
1242 gfx::Point start_point(kStartX, 0);
1243 gfx::Point down_point(kDownX, 500);
1244 gfx::Point up_point(kUpX, -500);
1245
1246 MoveMouseTo(start_point);
1247 PressLeftMouseButton();
1248 DragMouseTo(up_point);
1249 ReleaseLeftMouseButton();
1250 EXPECT_EQ(textfield_->GetSelectedText(), expected_up);
1251
1252 MoveMouseTo(start_point);
1253 PressLeftMouseButton();
1254 DragMouseTo(down_point);
1255 ReleaseLeftMouseButton();
1256 EXPECT_EQ(textfield_->GetSelectedText(), expected_down);
1257 }
1258
1212 #if defined(OS_WIN) 1259 #if defined(OS_WIN)
1213 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { 1260 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) {
1214 InitTextfield(); 1261 InitTextfield();
1215 textfield_->SetText(ASCIIToUTF16("hello world")); 1262 textfield_->SetText(ASCIIToUTF16("hello world"));
1216 1263
1217 ui::OSExchangeData data; 1264 ui::OSExchangeData data;
1218 base::string16 string(ASCIIToUTF16("string ")); 1265 base::string16 string(ASCIIToUTF16("string "));
1219 data.SetString(string); 1266 data.SetString(string);
1220 int formats = 0; 1267 int formats = 0;
1221 std::set<ui::Clipboard::FormatType> format_types; 1268 std::set<ui::Clipboard::FormatType> format_types;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 // Ensure that textfields without selections do not support drag operations. 1331 // Ensure that textfields without selections do not support drag operations.
1285 textfield_->ClearSelection(); 1332 textfield_->ClearSelection();
1286 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1333 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1287 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1334 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1288 textfield_->SelectRange(kStringRange); 1335 textfield_->SelectRange(kStringRange);
1289 // Ensure that password textfields do not support drag operations. 1336 // Ensure that password textfields do not support drag operations.
1290 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 1337 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1291 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1338 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1292 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1339 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1293 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); 1340 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
1341 MoveMouseTo(kStringPoint);
1342 PressLeftMouseButton();
1294 // Ensure that textfields only initiate drag operations inside the selection. 1343 // Ensure that textfields only initiate drag operations inside the selection.
1295 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, 1344 // ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint,
tapted 2016/04/15 00:35:08 (remove)
Elly Fong-Jones 2016/04/15 14:47:45 Done.
1296 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1345 // kStringPoint,
1297 ui::EF_LEFT_MOUSE_BUTTON); 1346 // ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1298 textfield_->OnMousePressed(press_event); 1347 // ui::EF_LEFT_MOUSE_BUTTON);
1348 // textfield_->OnMousePressed(press_event);
1299 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1349 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1300 textfield_->GetDragOperationsForView(NULL, gfx::Point())); 1350 textfield_->GetDragOperationsForView(NULL, gfx::Point()));
1301 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), 1351 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(),
1302 gfx::Point())); 1352 gfx::Point()));
1303 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, 1353 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY,
1304 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1354 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1305 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 1355 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
1306 gfx::Point())); 1356 gfx::Point()));
1307 // Ensure that textfields support local moves. 1357 // Ensure that textfields support local moves.
1308 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1358 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1309 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); 1359 textfield_->GetDragOperationsForView(textfield_, kStringPoint));
1310 } 1360 }
1311 1361
1312 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { 1362 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
1313 InitTextfield(); 1363 InitTextfield();
1314 textfield_->SetText(ASCIIToUTF16("hello world")); 1364 textfield_->SetText(ASCIIToUTF16("hello world"));
1315 1365
1316 base::string16 string; 1366 base::string16 string;
1317 ui::OSExchangeData data; 1367 ui::OSExchangeData data;
1318 int formats = 0; 1368 int formats = 0;
1319 int operations = 0; 1369 int operations = 0;
1320 std::set<ui::Clipboard::FormatType> format_types; 1370 std::set<ui::Clipboard::FormatType> format_types;
1321 1371
1322 // Start dragging "ello". 1372 // Start dragging "ello".
1323 textfield_->SelectRange(gfx::Range(1, 5)); 1373 textfield_->SelectRange(gfx::Range(1, 5));
1324 gfx::Point point(GetCursorPositionX(3), 0); 1374 gfx::Point point(GetCursorPositionX(3), 0);
1325 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1375 MoveMouseTo(point);
1326 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1376 PressLeftMouseButton();
1327 ui::EF_LEFT_MOUSE_BUTTON); 1377 // ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
tapted 2016/04/15 00:35:08 (remove)
Elly Fong-Jones 2016/04/15 14:47:46 Done.
1328 textfield_->OnMousePressed(click_a); 1378 // ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1329 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), 1379 // ui::EF_LEFT_MOUSE_BUTTON);
1330 gfx::Point())); 1380 // textfield_->OnMousePressed(click_a);
1331 operations = textfield_->GetDragOperationsForView(textfield_, 1381 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point()));
tapted 2016/04/15 00:35:08 The third argument for CanStartDragForView is the
Elly Fong-Jones 2016/04/15 14:47:46 point is more correct so point it is.
1332 click_a.location()); 1382 operations = textfield_->GetDragOperationsForView(textfield_, point);
1333 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1383 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1334 operations); 1384 operations);
1335 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); 1385 textfield_->WriteDragDataForView(NULL, point, &data);
tapted 2016/04/15 00:35:08 nit: nullptr
Elly Fong-Jones 2016/04/15 14:47:46 Done.
1336 EXPECT_TRUE(data.GetString(&string)); 1386 EXPECT_TRUE(data.GetString(&string));
1337 EXPECT_EQ(textfield_->GetSelectedText(), string); 1387 EXPECT_EQ(textfield_->GetSelectedText(), string);
1338 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1388 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1339 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1389 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1340 EXPECT_TRUE(format_types.empty()); 1390 EXPECT_TRUE(format_types.empty());
1341 1391
1342 // Drop "ello" after "w". 1392 // Drop "ello" after "w".
1343 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); 1393 const gfx::Point kDropPoint(GetCursorPositionX(7), 0);
1344 EXPECT_TRUE(textfield_->CanDrop(data)); 1394 EXPECT_TRUE(textfield_->CanDrop(data));
1345 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); 1395 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations);
(...skipping 23 matching lines...) Expand all
1369 1419
1370 base::string16 string; 1420 base::string16 string;
1371 ui::OSExchangeData data; 1421 ui::OSExchangeData data;
1372 int formats = 0; 1422 int formats = 0;
1373 int operations = 0; 1423 int operations = 0;
1374 std::set<ui::Clipboard::FormatType> format_types; 1424 std::set<ui::Clipboard::FormatType> format_types;
1375 1425
1376 // Start dragging " worl". 1426 // Start dragging " worl".
1377 textfield_->SelectRange(gfx::Range(5, 10)); 1427 textfield_->SelectRange(gfx::Range(5, 10));
1378 gfx::Point point(GetCursorPositionX(7), 0); 1428 gfx::Point point(GetCursorPositionX(7), 0);
1379 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1429 MoveMouseTo(point);
1380 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1430 PressLeftMouseButton();
1381 ui::EF_LEFT_MOUSE_BUTTON); 1431 // ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
tapted 2016/04/15 00:35:08 (remove)
Elly Fong-Jones 2016/04/15 14:47:46 Done.
1382 textfield_->OnMousePressed(click_a); 1432 // ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1383 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), 1433 // ui::EF_LEFT_MOUSE_BUTTON);
1384 gfx::Point())); 1434 // textfield_->OnMousePressed(click_a);
1385 operations = textfield_->GetDragOperationsForView(textfield_, 1435 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point()));
1386 click_a.location()); 1436 operations = textfield_->GetDragOperationsForView(textfield_, point);
1387 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1437 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1388 operations); 1438 operations);
1389 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); 1439 textfield_->WriteDragDataForView(NULL, point, &data);
tapted 2016/04/15 00:35:08 nit: nullptr
Elly Fong-Jones 2016/04/15 14:47:46 Done.
1390 EXPECT_TRUE(data.GetString(&string)); 1440 EXPECT_TRUE(data.GetString(&string));
1391 EXPECT_EQ(textfield_->GetSelectedText(), string); 1441 EXPECT_EQ(textfield_->GetSelectedText(), string);
1392 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1442 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1393 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1443 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1394 EXPECT_TRUE(format_types.empty()); 1444 EXPECT_TRUE(format_types.empty());
1395 1445
1396 // Drop " worl" after "h". 1446 // Drop " worl" after "h".
1397 EXPECT_TRUE(textfield_->CanDrop(data)); 1447 EXPECT_TRUE(textfield_->CanDrop(data));
1398 gfx::Point drop_point(GetCursorPositionX(1), 0); 1448 gfx::Point drop_point(GetCursorPositionX(1), 0);
1399 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); 1449 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations);
(...skipping 17 matching lines...) Expand all
1417 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1467 EXPECT_STR_EQ("h worlellod", textfield_->text());
1418 } 1468 }
1419 1469
1420 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1470 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1421 InitTextfield(); 1471 InitTextfield();
1422 textfield_->SetText(ASCIIToUTF16("hello world")); 1472 textfield_->SetText(ASCIIToUTF16("hello world"));
1423 1473
1424 // Start dragging "worl". 1474 // Start dragging "worl".
1425 textfield_->SelectRange(gfx::Range(6, 10)); 1475 textfield_->SelectRange(gfx::Range(6, 10));
1426 gfx::Point point(GetCursorPositionX(8), 0); 1476 gfx::Point point(GetCursorPositionX(8), 0);
1427 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, 1477 MoveMouseTo(point);
1428 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1478 PressLeftMouseButton();
1429 ui::EF_LEFT_MOUSE_BUTTON);
1430 textfield_->OnMousePressed(click);
1431 ui::OSExchangeData data; 1479 ui::OSExchangeData data;
1432 textfield_->WriteDragDataForView(NULL, click.location(), &data); 1480 textfield_->WriteDragDataForView(NULL, point, &data);
tapted 2016/04/15 00:35:08 nit: nullptr
Elly Fong-Jones 2016/04/15 14:47:45 Done.
1433 EXPECT_TRUE(textfield_->CanDrop(data)); 1481 EXPECT_TRUE(textfield_->CanDrop(data));
1434 // Drag the text over somewhere valid, outside the current selection. 1482 // Drag the text over somewhere valid, outside the current selection.
1435 gfx::Point drop_point(GetCursorPositionX(2), 0); 1483 gfx::Point drop_point(GetCursorPositionX(2), 0);
1436 ui::DropTargetEvent drop(data, drop_point, drop_point, 1484 ui::DropTargetEvent drop(data, drop_point, drop_point,
1437 ui::DragDropTypes::DRAG_MOVE); 1485 ui::DragDropTypes::DRAG_MOVE);
1438 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); 1486 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop));
1439 // "Cancel" the drag, via move and release over the selection, and OnDragDone. 1487 // "Cancel" the drag, via move and release over the selection, and OnDragDone.
1440 gfx::Point drag_point(GetCursorPositionX(9), 0); 1488 gfx::Point drag_point(GetCursorPositionX(9), 0);
1441 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, 1489 DragMouseTo(drag_point);
1442 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1490 ReleaseLeftMouseButton();
1443 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point,
1444 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1445 ui::EF_LEFT_MOUSE_BUTTON);
1446 textfield_->OnMouseDragged(drag);
1447 textfield_->OnMouseReleased(release);
1448 textfield_->OnDragDone();
1449 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); 1491 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text());
1450 } 1492 }
1451 1493
1452 TEST_F(TextfieldTest, ReadOnlyTest) { 1494 TEST_F(TextfieldTest, ReadOnlyTest) {
1453 InitTextfield(); 1495 InitTextfield();
1454 textfield_->SetText(ASCIIToUTF16("read only")); 1496 textfield_->SetText(ASCIIToUTF16("read only"));
1455 textfield_->SetReadOnly(true); 1497 textfield_->SetReadOnly(true);
1456 EXPECT_TRUE(textfield_->enabled()); 1498 EXPECT_TRUE(textfield_->enabled());
1457 EXPECT_TRUE(textfield_->IsFocusable()); 1499 EXPECT_TRUE(textfield_->IsFocusable());
1458 1500
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 2254
2213 textfield_->SelectRange(gfx::Range(5, 5)); 2255 textfield_->SelectRange(gfx::Range(5, 5));
2214 const gfx::Rect middle_cursor = GetCursorBounds(); 2256 const gfx::Rect middle_cursor = GetCursorBounds();
2215 textfield_->SelectRange(gfx::Range(0, 0)); 2257 textfield_->SelectRange(gfx::Range(0, 0));
2216 const gfx::Point beginning = GetCursorBounds().origin(); 2258 const gfx::Point beginning = GetCursorBounds().origin();
2217 2259
2218 // Double click, but do not release the left button. 2260 // Double click, but do not release the left button.
2219 MouseClick(middle_cursor, 0); 2261 MouseClick(middle_cursor, 0);
2220 const gfx::Point middle(middle_cursor.x(), 2262 const gfx::Point middle(middle_cursor.x(),
2221 middle_cursor.y() + middle_cursor.height() / 2); 2263 middle_cursor.y() + middle_cursor.height() / 2);
2222 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, 2264 MoveMouseTo(middle);
2223 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2265 PressLeftMouseButton();
2224 ui::EF_LEFT_MOUSE_BUTTON);
2225 textfield_->OnMousePressed(press_event);
2226 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); 2266 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange());
2227 2267
2228 // Drag the mouse to the beginning of the textfield. 2268 // Drag the mouse to the beginning of the textfield.
2229 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, 2269 DragMouseTo(beginning);
2230 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
2231 textfield_->OnMouseDragged(drag_event);
2232 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 2270 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
2233 } 2271 }
2234 2272
2235 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 2273 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2236 // flaky: http://crbug.com/396477 2274 // flaky: http://crbug.com/396477
2237 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) { 2275 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) {
2238 InitTextfield(); 2276 InitTextfield();
2239 textfield_->SetText(ASCIIToUTF16("0123")); 2277 textfield_->SetText(ASCIIToUTF16("0123"));
2240 gfx::Point point_1(GetCursorPositionX(1), 0); 2278 gfx::Point point_1(GetCursorPositionX(1), 0);
2241 gfx::Point point_2(GetCursorPositionX(2), 0); 2279 gfx::Point point_2(GetCursorPositionX(2), 0);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 2621
2584 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2622 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2585 ui::AXViewState state_protected; 2623 ui::AXViewState state_protected;
2586 textfield_->GetAccessibleState(&state_protected); 2624 textfield_->GetAccessibleState(&state_protected);
2587 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2625 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2588 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2626 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2589 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2627 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2590 } 2628 }
2591 2629
2592 } // namespace views 2630 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698