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

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

Issue 1372253002: gfx: Make conversions from gfx::Point to PointF explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointfconvert-gfx: . Created 5 years, 2 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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 return test_api_->GetRenderText()->GetCursorBounds(sel, true); 601 return test_api_->GetRenderText()->GetCursorBounds(sel, true);
602 } 602 }
603 603
604 gfx::Rect GetDisplayRect() { 604 gfx::Rect GetDisplayRect() {
605 return test_api_->GetRenderText()->display_rect(); 605 return test_api_->GetRenderText()->display_rect();
606 } 606 }
607 607
608 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and 608 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and
609 // y-axis is in the middle of |bound|'s vertical range. 609 // y-axis is in the middle of |bound|'s vertical range.
610 void MouseClick(const gfx::Rect bound, int x_offset) { 610 void MouseClick(const gfx::Rect bound, int x_offset) {
611 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); 611 gfx::PointF point(bound.x() + x_offset, bound.y() + bound.height() / 2);
612 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, 612 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point,
613 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 613 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
614 ui::EF_LEFT_MOUSE_BUTTON); 614 ui::EF_LEFT_MOUSE_BUTTON);
615 textfield_->OnMousePressed(click); 615 textfield_->OnMousePressed(click);
616 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, 616 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point,
617 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 617 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
618 ui::EF_LEFT_MOUSE_BUTTON); 618 ui::EF_LEFT_MOUSE_BUTTON);
619 textfield_->OnMouseReleased(release); 619 textfield_->OnMouseReleased(release);
620 } 620 }
621 621
622 // This is to avoid double/triple click. 622 // This is to avoid double/triple click.
623 void NonClientMouseClick() { 623 void NonClientMouseClick() {
624 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 624 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::PointF(), gfx::PointF(),
625 ui::EventTimeForNow(), 625 ui::EventTimeForNow(),
626 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, 626 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT,
627 ui::EF_LEFT_MOUSE_BUTTON); 627 ui::EF_LEFT_MOUSE_BUTTON);
628 textfield_->OnMousePressed(click); 628 textfield_->OnMousePressed(click);
629 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 629 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::PointF(), gfx::PointF(),
630 ui::EventTimeForNow(), 630 ui::EventTimeForNow(),
631 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, 631 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT,
632 ui::EF_LEFT_MOUSE_BUTTON); 632 ui::EF_LEFT_MOUSE_BUTTON);
633 textfield_->OnMouseReleased(release); 633 textfield_->OnMouseReleased(release);
634 } 634 }
635 635
636 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, 636 void VerifyTextfieldContextMenuContents(bool textfield_has_selection,
637 bool can_undo, 637 bool can_undo,
638 ui::MenuModel* menu) { 638 ui::MenuModel* menu) {
639 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); 639 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */));
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 widget_->GetFocusManager()->AdvanceFocus(true); 1080 widget_->GetFocusManager()->AdvanceFocus(true);
1081 EXPECT_EQ(3, GetFocusedView()->id()); 1081 EXPECT_EQ(3, GetFocusedView()->id());
1082 1082
1083 // Request focus should still work. 1083 // Request focus should still work.
1084 textfield_->RequestFocus(); 1084 textfield_->RequestFocus();
1085 EXPECT_EQ(1, GetFocusedView()->id()); 1085 EXPECT_EQ(1, GetFocusedView()->id());
1086 1086
1087 // Test if clicking on textfield view sets the focus. 1087 // Test if clicking on textfield view sets the focus.
1088 widget_->GetFocusManager()->AdvanceFocus(true); 1088 widget_->GetFocusManager()->AdvanceFocus(true);
1089 EXPECT_EQ(3, GetFocusedView()->id()); 1089 EXPECT_EQ(3, GetFocusedView()->id());
1090 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 1090 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::PointF(), gfx::PointF(),
1091 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1091 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1092 ui::EF_LEFT_MOUSE_BUTTON); 1092 ui::EF_LEFT_MOUSE_BUTTON);
1093 textfield_->OnMousePressed(click); 1093 textfield_->OnMousePressed(click);
1094 EXPECT_EQ(1, GetFocusedView()->id()); 1094 EXPECT_EQ(1, GetFocusedView()->id());
1095 1095
1096 // Tab/Shift+Tab should also cycle focus, not insert a tab character. 1096 // Tab/Shift+Tab should also cycle focus, not insert a tab character.
1097 SendKeyEvent(ui::VKEY_TAB, false, false); 1097 SendKeyEvent(ui::VKEY_TAB, false, false);
1098 EXPECT_EQ(2, GetFocusedView()->id()); 1098 EXPECT_EQ(2, GetFocusedView()->id());
1099 SendKeyEvent(ui::VKEY_TAB, false, false); 1099 SendKeyEvent(ui::VKEY_TAB, false, false);
1100 EXPECT_EQ(3, GetFocusedView()->id()); 1100 EXPECT_EQ(3, GetFocusedView()->id());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1132 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1133 1133
1134 // Exercise the "paste enabled?" check in the verifier. 1134 // Exercise the "paste enabled?" check in the verifier.
1135 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); 1135 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test");
1136 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1136 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1137 } 1137 }
1138 1138
1139 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { 1139 TEST_F(TextfieldTest, DoubleAndTripleClickTest) {
1140 InitTextfield(); 1140 InitTextfield();
1141 textfield_->SetText(ASCIIToUTF16("hello world")); 1141 textfield_->SetText(ASCIIToUTF16("hello world"));
1142 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 1142 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::PointF(), gfx::PointF(),
1143 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1143 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1144 ui::EF_LEFT_MOUSE_BUTTON); 1144 ui::EF_LEFT_MOUSE_BUTTON);
1145 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 1145 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::PointF(), gfx::PointF(),
1146 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1146 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1147 ui::EF_LEFT_MOUSE_BUTTON); 1147 ui::EF_LEFT_MOUSE_BUTTON);
1148 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 1148 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::PointF(),
1149 ui::EventTimeForNow(), 1149 gfx::PointF(), ui::EventTimeForNow(),
1150 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, 1150 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
1151 ui::EF_LEFT_MOUSE_BUTTON); 1151 ui::EF_LEFT_MOUSE_BUTTON);
1152 1152
1153 // Test for double click. 1153 // Test for double click.
1154 textfield_->OnMousePressed(click); 1154 textfield_->OnMousePressed(click);
1155 textfield_->OnMouseReleased(release); 1155 textfield_->OnMouseReleased(release);
1156 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1156 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1157 textfield_->OnMousePressed(double_click); 1157 textfield_->OnMousePressed(double_click);
1158 textfield_->OnMouseReleased(release); 1158 textfield_->OnMouseReleased(release);
1159 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1159 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1160 1160
1161 // Test for triple click. 1161 // Test for triple click.
1162 textfield_->OnMousePressed(click); 1162 textfield_->OnMousePressed(click);
1163 textfield_->OnMouseReleased(release); 1163 textfield_->OnMouseReleased(release);
1164 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); 1164 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText());
1165 1165
1166 // Another click should reset back to double click. 1166 // Another click should reset back to double click.
1167 textfield_->OnMousePressed(click); 1167 textfield_->OnMousePressed(click);
1168 textfield_->OnMouseReleased(release); 1168 textfield_->OnMouseReleased(release);
1169 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1169 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1170 } 1170 }
1171 1171
1172 TEST_F(TextfieldTest, DragToSelect) { 1172 TEST_F(TextfieldTest, DragToSelect) {
1173 InitTextfield(); 1173 InitTextfield();
1174 textfield_->SetText(ASCIIToUTF16("hello world")); 1174 textfield_->SetText(ASCIIToUTF16("hello world"));
1175 const int kStart = GetCursorPositionX(5); 1175 const float kStart = GetCursorPositionX(5);
1176 const int kEnd = 500; 1176 const float kEnd = 500.f;
1177 gfx::Point start_point(kStart, 0); 1177 gfx::PointF start_point(kStart, 0.f);
1178 gfx::Point end_point(kEnd, 0); 1178 gfx::PointF end_point(kEnd, 0.f);
1179 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, 1179 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point,
1180 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1180 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1181 ui::EF_LEFT_MOUSE_BUTTON); 1181 ui::EF_LEFT_MOUSE_BUTTON);
1182 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, 1182 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point,
1183 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1183 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1184 ui::EF_LEFT_MOUSE_BUTTON); 1184 ui::EF_LEFT_MOUSE_BUTTON);
1185 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), 1185 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::PointF(), gfx::PointF(),
1186 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1186 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1187 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, 1187 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point,
1188 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1188 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1189 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, 1189 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point,
1190 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1190 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1191 ui::EF_LEFT_MOUSE_BUTTON); 1191 ui::EF_LEFT_MOUSE_BUTTON);
1192 textfield_->OnMousePressed(click_a); 1192 textfield_->OnMousePressed(click_a);
1193 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1193 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1194 // Check that dragging left selects the beginning of the string. 1194 // Check that dragging left selects the beginning of the string.
1195 textfield_->OnMouseDragged(drag_left); 1195 textfield_->OnMouseDragged(drag_left);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 textfield_->ClearSelection(); 1285 textfield_->ClearSelection();
1286 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1286 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1287 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1287 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1288 textfield_->SelectRange(kStringRange); 1288 textfield_->SelectRange(kStringRange);
1289 // Ensure that password textfields do not support drag operations. 1289 // Ensure that password textfields do not support drag operations.
1290 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 1290 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1291 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1291 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1292 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1292 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1293 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); 1293 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
1294 // Ensure that textfields only initiate drag operations inside the selection. 1294 // Ensure that textfields only initiate drag operations inside the selection.
1295 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, 1295 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, gfx::PointF(kStringPoint),
1296 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1296 gfx::PointF(kStringPoint), ui::EventTimeForNow(),
1297 ui::EF_LEFT_MOUSE_BUTTON,
1297 ui::EF_LEFT_MOUSE_BUTTON); 1298 ui::EF_LEFT_MOUSE_BUTTON);
1298 textfield_->OnMousePressed(press_event); 1299 textfield_->OnMousePressed(press_event);
1299 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1300 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1300 textfield_->GetDragOperationsForView(NULL, gfx::Point())); 1301 textfield_->GetDragOperationsForView(NULL, gfx::Point()));
1301 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), 1302 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(),
1302 gfx::Point())); 1303 gfx::Point()));
1303 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, 1304 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY,
1304 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1305 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1305 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 1306 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
1306 gfx::Point())); 1307 gfx::Point()));
1307 // Ensure that textfields support local moves. 1308 // Ensure that textfields support local moves.
1308 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1309 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1309 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); 1310 textfield_->GetDragOperationsForView(textfield_, kStringPoint));
1310 } 1311 }
1311 1312
1312 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { 1313 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
1313 InitTextfield(); 1314 InitTextfield();
1314 textfield_->SetText(ASCIIToUTF16("hello world")); 1315 textfield_->SetText(ASCIIToUTF16("hello world"));
1315 1316
1316 base::string16 string; 1317 base::string16 string;
1317 ui::OSExchangeData data; 1318 ui::OSExchangeData data;
1318 int formats = 0; 1319 int formats = 0;
1319 int operations = 0; 1320 int operations = 0;
1320 std::set<OSExchangeData::CustomFormat> custom_formats; 1321 std::set<OSExchangeData::CustomFormat> custom_formats;
1321 1322
1322 // Start dragging "ello". 1323 // Start dragging "ello".
1323 textfield_->SelectRange(gfx::Range(1, 5)); 1324 textfield_->SelectRange(gfx::Range(1, 5));
1324 gfx::Point point(GetCursorPositionX(3), 0); 1325 gfx::PointF point(GetCursorPositionX(3), 0.f);
1325 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1326 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
1326 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1327 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1327 ui::EF_LEFT_MOUSE_BUTTON); 1328 ui::EF_LEFT_MOUSE_BUTTON);
1328 textfield_->OnMousePressed(click_a); 1329 textfield_->OnMousePressed(click_a);
1329 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), 1330 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(),
1330 gfx::Point())); 1331 gfx::Point()));
1331 operations = textfield_->GetDragOperationsForView(textfield_, 1332 operations = textfield_->GetDragOperationsForView(textfield_,
1332 click_a.location()); 1333 click_a.location());
1333 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1334 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1334 operations); 1335 operations);
1335 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); 1336 textfield_->WriteDragDataForView(NULL, click_a.location(), &data);
1336 EXPECT_TRUE(data.GetString(&string)); 1337 EXPECT_TRUE(data.GetString(&string));
1337 EXPECT_EQ(textfield_->GetSelectedText(), string); 1338 EXPECT_EQ(textfield_->GetSelectedText(), string);
1338 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); 1339 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats));
1339 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1340 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1340 EXPECT_TRUE(custom_formats.empty()); 1341 EXPECT_TRUE(custom_formats.empty());
1341 1342
1342 // Drop "ello" after "w". 1343 // Drop "ello" after "w".
1343 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); 1344 const gfx::PointF kDropPoint(GetCursorPositionX(7), 0.f);
1344 EXPECT_TRUE(textfield_->CanDrop(data)); 1345 EXPECT_TRUE(textfield_->CanDrop(data));
1345 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); 1346 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations);
1346 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1347 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1347 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1348 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1348 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1349 EXPECT_STR_EQ("h welloorld", textfield_->text());
1349 textfield_->OnDragDone(); 1350 textfield_->OnDragDone();
1350 1351
1351 // Undo/Redo the drag&drop change. 1352 // Undo/Redo the drag&drop change.
1352 SendKeyEvent(ui::VKEY_Z, false, true); 1353 SendKeyEvent(ui::VKEY_Z, false, true);
1353 EXPECT_STR_EQ("hello world", textfield_->text()); 1354 EXPECT_STR_EQ("hello world", textfield_->text());
(...skipping 14 matching lines...) Expand all
1368 textfield_->SetText(ASCIIToUTF16("hello world")); 1369 textfield_->SetText(ASCIIToUTF16("hello world"));
1369 1370
1370 base::string16 string; 1371 base::string16 string;
1371 ui::OSExchangeData data; 1372 ui::OSExchangeData data;
1372 int formats = 0; 1373 int formats = 0;
1373 int operations = 0; 1374 int operations = 0;
1374 std::set<OSExchangeData::CustomFormat> custom_formats; 1375 std::set<OSExchangeData::CustomFormat> custom_formats;
1375 1376
1376 // Start dragging " worl". 1377 // Start dragging " worl".
1377 textfield_->SelectRange(gfx::Range(5, 10)); 1378 textfield_->SelectRange(gfx::Range(5, 10));
1378 gfx::Point point(GetCursorPositionX(7), 0); 1379 gfx::PointF point(GetCursorPositionX(7), 0);
1379 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1380 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
1380 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1381 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1381 ui::EF_LEFT_MOUSE_BUTTON); 1382 ui::EF_LEFT_MOUSE_BUTTON);
1382 textfield_->OnMousePressed(click_a); 1383 textfield_->OnMousePressed(click_a);
1383 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), 1384 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(),
1384 gfx::Point())); 1385 gfx::Point()));
1385 operations = textfield_->GetDragOperationsForView(textfield_, 1386 operations = textfield_->GetDragOperationsForView(textfield_,
1386 click_a.location()); 1387 click_a.location());
1387 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1388 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1388 operations); 1389 operations);
1389 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); 1390 textfield_->WriteDragDataForView(NULL, click_a.location(), &data);
1390 EXPECT_TRUE(data.GetString(&string)); 1391 EXPECT_TRUE(data.GetString(&string));
1391 EXPECT_EQ(textfield_->GetSelectedText(), string); 1392 EXPECT_EQ(textfield_->GetSelectedText(), string);
1392 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); 1393 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats));
1393 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1394 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1394 EXPECT_TRUE(custom_formats.empty()); 1395 EXPECT_TRUE(custom_formats.empty());
1395 1396
1396 // Drop " worl" after "h". 1397 // Drop " worl" after "h".
1397 EXPECT_TRUE(textfield_->CanDrop(data)); 1398 EXPECT_TRUE(textfield_->CanDrop(data));
1398 gfx::Point drop_point(GetCursorPositionX(1), 0); 1399 gfx::PointF drop_point(GetCursorPositionX(1), 0);
1399 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); 1400 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations);
1400 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1401 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1401 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1402 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1402 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1403 EXPECT_STR_EQ("h worlellod", textfield_->text());
1403 textfield_->OnDragDone(); 1404 textfield_->OnDragDone();
1404 1405
1405 // Undo/Redo the drag&drop change. 1406 // Undo/Redo the drag&drop change.
1406 SendKeyEvent(ui::VKEY_Z, false, true); 1407 SendKeyEvent(ui::VKEY_Z, false, true);
1407 EXPECT_STR_EQ("hello world", textfield_->text()); 1408 EXPECT_STR_EQ("hello world", textfield_->text());
1408 SendKeyEvent(ui::VKEY_Z, false, true); 1409 SendKeyEvent(ui::VKEY_Z, false, true);
1409 EXPECT_STR_EQ("", textfield_->text()); 1410 EXPECT_STR_EQ("", textfield_->text());
1410 SendKeyEvent(ui::VKEY_Z, false, true); 1411 SendKeyEvent(ui::VKEY_Z, false, true);
1411 EXPECT_STR_EQ("", textfield_->text()); 1412 EXPECT_STR_EQ("", textfield_->text());
1412 SendKeyEvent(ui::VKEY_Z, true, true); 1413 SendKeyEvent(ui::VKEY_Z, true, true);
1413 EXPECT_STR_EQ("hello world", textfield_->text()); 1414 EXPECT_STR_EQ("hello world", textfield_->text());
1414 SendKeyEvent(ui::VKEY_Z, true, true); 1415 SendKeyEvent(ui::VKEY_Z, true, true);
1415 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1416 EXPECT_STR_EQ("h worlellod", textfield_->text());
1416 SendKeyEvent(ui::VKEY_Z, true, true); 1417 SendKeyEvent(ui::VKEY_Z, true, true);
1417 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1418 EXPECT_STR_EQ("h worlellod", textfield_->text());
1418 } 1419 }
1419 1420
1420 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1421 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1421 InitTextfield(); 1422 InitTextfield();
1422 textfield_->SetText(ASCIIToUTF16("hello world")); 1423 textfield_->SetText(ASCIIToUTF16("hello world"));
1423 1424
1424 // Start dragging "worl". 1425 // Start dragging "worl".
1425 textfield_->SelectRange(gfx::Range(6, 10)); 1426 textfield_->SelectRange(gfx::Range(6, 10));
1426 gfx::Point point(GetCursorPositionX(8), 0); 1427 gfx::PointF point(GetCursorPositionX(8), 0);
1427 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, 1428 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point,
1428 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1429 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1429 ui::EF_LEFT_MOUSE_BUTTON); 1430 ui::EF_LEFT_MOUSE_BUTTON);
1430 textfield_->OnMousePressed(click); 1431 textfield_->OnMousePressed(click);
1431 ui::OSExchangeData data; 1432 ui::OSExchangeData data;
1432 textfield_->WriteDragDataForView(NULL, click.location(), &data); 1433 textfield_->WriteDragDataForView(NULL, click.location(), &data);
1433 EXPECT_TRUE(textfield_->CanDrop(data)); 1434 EXPECT_TRUE(textfield_->CanDrop(data));
1434 // Drag the text over somewhere valid, outside the current selection. 1435 // Drag the text over somewhere valid, outside the current selection.
1435 gfx::Point drop_point(GetCursorPositionX(2), 0); 1436 gfx::PointF drop_point(GetCursorPositionX(2), 0.f);
1436 ui::DropTargetEvent drop(data, drop_point, drop_point, 1437 ui::DropTargetEvent drop(data, drop_point, drop_point,
1437 ui::DragDropTypes::DRAG_MOVE); 1438 ui::DragDropTypes::DRAG_MOVE);
1438 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); 1439 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop));
1439 // "Cancel" the drag, via move and release over the selection, and OnDragDone. 1440 // "Cancel" the drag, via move and release over the selection, and OnDragDone.
1440 gfx::Point drag_point(GetCursorPositionX(9), 0); 1441 gfx::PointF drag_point(GetCursorPositionX(9), 0.f);
1441 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, 1442 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point,
1442 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1443 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1443 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, 1444 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point,
1444 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1445 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1445 ui::EF_LEFT_MOUSE_BUTTON); 1446 ui::EF_LEFT_MOUSE_BUTTON);
1446 textfield_->OnMouseDragged(drag); 1447 textfield_->OnMouseDragged(drag);
1447 textfield_->OnMouseReleased(release); 1448 textfield_->OnMouseReleased(release);
1448 textfield_->OnDragDone(); 1449 textfield_->OnDragDone();
1449 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); 1450 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text());
1450 } 1451 }
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 // The word we select by double clicking should remain selected regardless of 2207 // The word we select by double clicking should remain selected regardless of
2207 // where we drag the mouse afterwards without releasing the left button. 2208 // where we drag the mouse afterwards without releasing the left button.
2208 TEST_F(TextfieldTest, KeepInitiallySelectedWord) { 2209 TEST_F(TextfieldTest, KeepInitiallySelectedWord) {
2209 InitTextfield(); 2210 InitTextfield();
2210 2211
2211 textfield_->SetText(ASCIIToUTF16("abc def ghi")); 2212 textfield_->SetText(ASCIIToUTF16("abc def ghi"));
2212 2213
2213 textfield_->SelectRange(gfx::Range(5, 5)); 2214 textfield_->SelectRange(gfx::Range(5, 5));
2214 const gfx::Rect middle_cursor = GetCursorBounds(); 2215 const gfx::Rect middle_cursor = GetCursorBounds();
2215 textfield_->SelectRange(gfx::Range(0, 0)); 2216 textfield_->SelectRange(gfx::Range(0, 0));
2216 const gfx::Point beginning = GetCursorBounds().origin(); 2217 const auto beginning = gfx::PointF(GetCursorBounds().origin());
2217 2218
2218 // Double click, but do not release the left button. 2219 // Double click, but do not release the left button.
2219 MouseClick(middle_cursor, 0); 2220 MouseClick(middle_cursor, 0);
2220 const gfx::Point middle(middle_cursor.x(), 2221 const gfx::PointF middle(middle_cursor.x(),
2221 middle_cursor.y() + middle_cursor.height() / 2); 2222 middle_cursor.y() + middle_cursor.height() / 2);
2222 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, 2223 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle,
2223 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2224 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2224 ui::EF_LEFT_MOUSE_BUTTON); 2225 ui::EF_LEFT_MOUSE_BUTTON);
2225 textfield_->OnMousePressed(press_event); 2226 textfield_->OnMousePressed(press_event);
2226 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); 2227 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange());
2227 2228
2228 // Drag the mouse to the beginning of the textfield. 2229 // Drag the mouse to the beginning of the textfield.
2229 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, 2230 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning,
2230 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 2231 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
2231 textfield_->OnMouseDragged(drag_event); 2232 textfield_->OnMouseDragged(drag_event);
2232 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 2233 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
2233 } 2234 }
2234 2235
2235 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 2236 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2236 // flaky: http://crbug.com/396477 2237 // flaky: http://crbug.com/396477
2237 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) { 2238 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) {
2238 InitTextfield(); 2239 InitTextfield();
2239 textfield_->SetText(ASCIIToUTF16("0123")); 2240 textfield_->SetText(ASCIIToUTF16("0123"));
2240 gfx::Point point_1(GetCursorPositionX(1), 0); 2241 gfx::PointF point_1(GetCursorPositionX(1), 0.f);
2241 gfx::Point point_2(GetCursorPositionX(2), 0); 2242 gfx::PointF point_2(GetCursorPositionX(2), 0.f);
2242 gfx::Point point_3(GetCursorPositionX(3), 0); 2243 gfx::PointF point_3(GetCursorPositionX(3), 0.f);
2243 gfx::Point point_4(GetCursorPositionX(4), 0); 2244 gfx::PointF point_4(GetCursorPositionX(4), 0.f);
2244 2245
2245 // Text selected by the mouse should be placed on the selection clipboard. 2246 // Text selected by the mouse should be placed on the selection clipboard.
2246 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, 2247 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1,
2247 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2248 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2248 ui::EF_LEFT_MOUSE_BUTTON); 2249 ui::EF_LEFT_MOUSE_BUTTON);
2249 textfield_->OnMousePressed(press); 2250 textfield_->OnMousePressed(press);
2250 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3, 2251 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3,
2251 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2252 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2252 ui::EF_LEFT_MOUSE_BUTTON); 2253 ui::EF_LEFT_MOUSE_BUTTON);
2253 textfield_->OnMouseDragged(drag); 2254 textfield_->OnMouseDragged(drag);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 // Middle clicking in the selection should clear the clipboard and selection. 2332 // Middle clicking in the selection should clear the clipboard and selection.
2332 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); 2333 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo");
2333 textfield_->SelectRange(gfx::Range(2, 6)); 2334 textfield_->SelectRange(gfx::Range(2, 6));
2334 textfield_->OnMousePressed(middle); 2335 textfield_->OnMousePressed(middle);
2335 EXPECT_STR_EQ("012301230123", textfield_->text()); 2336 EXPECT_STR_EQ("012301230123", textfield_->text());
2336 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); 2337 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange());
2337 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); 2338 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
2338 2339
2339 // Double and triple clicking should update the clipboard contents. 2340 // Double and triple clicking should update the clipboard contents.
2340 textfield_->SetText(ASCIIToUTF16("ab cd ef")); 2341 textfield_->SetText(ASCIIToUTF16("ab cd ef"));
2341 gfx::Point word(GetCursorPositionX(4), 0); 2342 gfx::PointF word(GetCursorPositionX(4), 0.f);
2342 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, 2343 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word,
2343 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2344 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2344 ui::EF_LEFT_MOUSE_BUTTON); 2345 ui::EF_LEFT_MOUSE_BUTTON);
2345 textfield_->OnMousePressed(press_word); 2346 textfield_->OnMousePressed(press_word);
2346 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, 2347 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word,
2347 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2348 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2348 ui::EF_LEFT_MOUSE_BUTTON); 2349 ui::EF_LEFT_MOUSE_BUTTON);
2349 textfield_->OnMouseReleased(release_word); 2350 textfield_->OnMouseReleased(release_word);
2350 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word, 2351 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word,
2351 ui::EventTimeForNow(), 2352 ui::EventTimeForNow(),
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2591 2592
2592 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2593 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2593 ui::AXViewState state_protected; 2594 ui::AXViewState state_protected;
2594 textfield_->GetAccessibleState(&state_protected); 2595 textfield_->GetAccessibleState(&state_protected);
2595 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2596 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2596 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2597 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2597 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2598 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2598 } 2599 }
2599 2600
2600 } // namespace views 2601 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698