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

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

Issue 1260453006: ui: events: Add a class to hold common touch and stylus properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address build problems, add accessor and unit tests. Created 5 years, 4 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 } 590 }
591 591
592 gfx::Rect GetDisplayRect() { 592 gfx::Rect GetDisplayRect() {
593 return test_api_->GetRenderText()->display_rect(); 593 return test_api_->GetRenderText()->display_rect();
594 } 594 }
595 595
596 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and 596 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and
597 // y-axis is in the middle of |bound|'s vertical range. 597 // y-axis is in the middle of |bound|'s vertical range.
598 void MouseClick(const gfx::Rect bound, int x_offset) { 598 void MouseClick(const gfx::Rect bound, int x_offset) {
599 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); 599 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2);
600 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, 600 ui::MouseEvent click(
601 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 601 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(),
602 ui::EF_LEFT_MOUSE_BUTTON); 602 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
603 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
603 textfield_->OnMousePressed(click); 604 textfield_->OnMousePressed(click);
604 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, 605 ui::MouseEvent release(
605 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 606 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(),
606 ui::EF_LEFT_MOUSE_BUTTON); 607 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
608 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
607 textfield_->OnMouseReleased(release); 609 textfield_->OnMouseReleased(release);
608 } 610 }
609 611
610 // This is to avoid double/triple click. 612 // This is to avoid double/triple click.
611 void NonClientMouseClick() { 613 void NonClientMouseClick() {
612 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 614 ui::MouseEvent click(
613 ui::EventTimeForNow(), 615 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
614 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, 616 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT,
615 ui::EF_LEFT_MOUSE_BUTTON); 617 ui::EF_LEFT_MOUSE_BUTTON,
618 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
616 textfield_->OnMousePressed(click); 619 textfield_->OnMousePressed(click);
617 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 620 ui::MouseEvent release(
618 ui::EventTimeForNow(), 621 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
619 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, 622 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT,
620 ui::EF_LEFT_MOUSE_BUTTON); 623 ui::EF_LEFT_MOUSE_BUTTON,
624 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
621 textfield_->OnMouseReleased(release); 625 textfield_->OnMouseReleased(release);
622 } 626 }
623 627
624 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, 628 void VerifyTextfieldContextMenuContents(bool textfield_has_selection,
625 bool can_undo, 629 bool can_undo,
626 ui::MenuModel* menu) { 630 ui::MenuModel* menu) {
627 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); 631 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */));
628 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); 632 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */));
629 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); 633 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */));
630 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); 634 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */));
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 widget_->GetFocusManager()->AdvanceFocus(true); 1044 widget_->GetFocusManager()->AdvanceFocus(true);
1041 EXPECT_EQ(3, GetFocusedView()->id()); 1045 EXPECT_EQ(3, GetFocusedView()->id());
1042 1046
1043 // Request focus should still work. 1047 // Request focus should still work.
1044 textfield_->RequestFocus(); 1048 textfield_->RequestFocus();
1045 EXPECT_EQ(1, GetFocusedView()->id()); 1049 EXPECT_EQ(1, GetFocusedView()->id());
1046 1050
1047 // Test if clicking on textfield view sets the focus. 1051 // Test if clicking on textfield view sets the focus.
1048 widget_->GetFocusManager()->AdvanceFocus(true); 1052 widget_->GetFocusManager()->AdvanceFocus(true);
1049 EXPECT_EQ(3, GetFocusedView()->id()); 1053 EXPECT_EQ(3, GetFocusedView()->id());
1050 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 1054 ui::MouseEvent click(
1051 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1055 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
1052 ui::EF_LEFT_MOUSE_BUTTON); 1056 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1057 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1053 textfield_->OnMousePressed(click); 1058 textfield_->OnMousePressed(click);
1054 EXPECT_EQ(1, GetFocusedView()->id()); 1059 EXPECT_EQ(1, GetFocusedView()->id());
1055 1060
1056 // Tab/Shift+Tab should also cycle focus, not insert a tab character. 1061 // Tab/Shift+Tab should also cycle focus, not insert a tab character.
1057 SendKeyEvent(ui::VKEY_TAB, false, false); 1062 SendKeyEvent(ui::VKEY_TAB, false, false);
1058 EXPECT_EQ(2, GetFocusedView()->id()); 1063 EXPECT_EQ(2, GetFocusedView()->id());
1059 SendKeyEvent(ui::VKEY_TAB, false, false); 1064 SendKeyEvent(ui::VKEY_TAB, false, false);
1060 EXPECT_EQ(3, GetFocusedView()->id()); 1065 EXPECT_EQ(3, GetFocusedView()->id());
1061 // Cycle back to the first textfield. 1066 // Cycle back to the first textfield.
1062 SendKeyEvent(ui::VKEY_TAB, false, false); 1067 SendKeyEvent(ui::VKEY_TAB, false, false);
(...skipping 29 matching lines...) Expand all
1092 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1097 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1093 1098
1094 // Exercise the "paste enabled?" check in the verifier. 1099 // Exercise the "paste enabled?" check in the verifier.
1095 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); 1100 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test");
1096 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1101 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1097 } 1102 }
1098 1103
1099 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { 1104 TEST_F(TextfieldTest, DoubleAndTripleClickTest) {
1100 InitTextfield(); 1105 InitTextfield();
1101 textfield_->SetText(ASCIIToUTF16("hello world")); 1106 textfield_->SetText(ASCIIToUTF16("hello world"));
1102 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 1107 ui::MouseEvent click(
1103 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1108 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
1104 ui::EF_LEFT_MOUSE_BUTTON); 1109 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1105 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 1110 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1106 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1111 ui::MouseEvent release(
1107 ui::EF_LEFT_MOUSE_BUTTON); 1112 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
1108 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 1113 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1109 ui::EventTimeForNow(), 1114 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1110 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, 1115 ui::MouseEvent double_click(
1111 ui::EF_LEFT_MOUSE_BUTTON); 1116 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
1117 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
1118 ui::EF_LEFT_MOUSE_BUTTON,
1119 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1112 1120
1113 // Test for double click. 1121 // Test for double click.
1114 textfield_->OnMousePressed(click); 1122 textfield_->OnMousePressed(click);
1115 textfield_->OnMouseReleased(release); 1123 textfield_->OnMouseReleased(release);
1116 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1124 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1117 textfield_->OnMousePressed(double_click); 1125 textfield_->OnMousePressed(double_click);
1118 textfield_->OnMouseReleased(release); 1126 textfield_->OnMouseReleased(release);
1119 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1127 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1120 1128
1121 // Test for triple click. 1129 // Test for triple click.
1122 textfield_->OnMousePressed(click); 1130 textfield_->OnMousePressed(click);
1123 textfield_->OnMouseReleased(release); 1131 textfield_->OnMouseReleased(release);
1124 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); 1132 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText());
1125 1133
1126 // Another click should reset back to double click. 1134 // Another click should reset back to double click.
1127 textfield_->OnMousePressed(click); 1135 textfield_->OnMousePressed(click);
1128 textfield_->OnMouseReleased(release); 1136 textfield_->OnMouseReleased(release);
1129 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1137 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1130 } 1138 }
1131 1139
1132 TEST_F(TextfieldTest, DragToSelect) { 1140 TEST_F(TextfieldTest, DragToSelect) {
1133 InitTextfield(); 1141 InitTextfield();
1134 textfield_->SetText(ASCIIToUTF16("hello world")); 1142 textfield_->SetText(ASCIIToUTF16("hello world"));
1135 const int kStart = GetCursorPositionX(5); 1143 const int kStart = GetCursorPositionX(5);
1136 const int kEnd = 500; 1144 const int kEnd = 500;
1137 gfx::Point start_point(kStart, 0); 1145 gfx::Point start_point(kStart, 0);
1138 gfx::Point end_point(kEnd, 0); 1146 gfx::Point end_point(kEnd, 0);
1139 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, 1147 ui::MouseEvent click_a(
1140 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1148 ui::ET_MOUSE_PRESSED, start_point, start_point, ui::EventTimeForNow(),
1141 ui::EF_LEFT_MOUSE_BUTTON); 1149 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1142 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, 1150 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1143 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1151 ui::MouseEvent click_b(
1144 ui::EF_LEFT_MOUSE_BUTTON); 1152 ui::ET_MOUSE_PRESSED, end_point, end_point, ui::EventTimeForNow(),
1145 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), 1153 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1146 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1154 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1147 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, 1155 ui::MouseEvent drag_left(
1148 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1156 ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
1149 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, 1157 ui::EF_LEFT_MOUSE_BUTTON, 0,
1150 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1158 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1151 ui::EF_LEFT_MOUSE_BUTTON); 1159 ui::MouseEvent drag_right(
1160 ui::ET_MOUSE_DRAGGED, end_point, end_point, ui::EventTimeForNow(),
1161 ui::EF_LEFT_MOUSE_BUTTON, 0,
1162 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1163 ui::MouseEvent release(
1164 ui::ET_MOUSE_RELEASED, end_point, end_point, ui::EventTimeForNow(),
1165 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1166 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1152 textfield_->OnMousePressed(click_a); 1167 textfield_->OnMousePressed(click_a);
1153 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1168 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1154 // Check that dragging left selects the beginning of the string. 1169 // Check that dragging left selects the beginning of the string.
1155 textfield_->OnMouseDragged(drag_left); 1170 textfield_->OnMouseDragged(drag_left);
1156 base::string16 text_left = textfield_->GetSelectedText(); 1171 base::string16 text_left = textfield_->GetSelectedText();
1157 EXPECT_STR_EQ("hello", text_left); 1172 EXPECT_STR_EQ("hello", text_left);
1158 // Check that dragging right selects the rest of the string. 1173 // Check that dragging right selects the rest of the string.
1159 textfield_->OnMouseDragged(drag_right); 1174 textfield_->OnMouseDragged(drag_right);
1160 base::string16 text_right = textfield_->GetSelectedText(); 1175 base::string16 text_right = textfield_->GetSelectedText();
1161 EXPECT_STR_EQ(" world", text_right); 1176 EXPECT_STR_EQ(" world", text_right);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 textfield_->ClearSelection(); 1260 textfield_->ClearSelection();
1246 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1261 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1247 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1262 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1248 textfield_->SelectRange(kStringRange); 1263 textfield_->SelectRange(kStringRange);
1249 // Ensure that password textfields do not support drag operations. 1264 // Ensure that password textfields do not support drag operations.
1250 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 1265 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1251 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1266 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1252 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1267 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1253 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); 1268 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
1254 // Ensure that textfields only initiate drag operations inside the selection. 1269 // Ensure that textfields only initiate drag operations inside the selection.
1255 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, 1270 ui::MouseEvent press_event(
1256 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1271 ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, ui::EventTimeForNow(),
1257 ui::EF_LEFT_MOUSE_BUTTON); 1272 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1273 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1258 textfield_->OnMousePressed(press_event); 1274 textfield_->OnMousePressed(press_event);
1259 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1275 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1260 textfield_->GetDragOperationsForView(NULL, gfx::Point())); 1276 textfield_->GetDragOperationsForView(NULL, gfx::Point()));
1261 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), 1277 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(),
1262 gfx::Point())); 1278 gfx::Point()));
1263 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, 1279 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY,
1264 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1280 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1265 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 1281 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
1266 gfx::Point())); 1282 gfx::Point()));
1267 // Ensure that textfields support local moves. 1283 // Ensure that textfields support local moves.
1268 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1284 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1269 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); 1285 textfield_->GetDragOperationsForView(textfield_, kStringPoint));
1270 } 1286 }
1271 1287
1272 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { 1288 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
1273 InitTextfield(); 1289 InitTextfield();
1274 textfield_->SetText(ASCIIToUTF16("hello world")); 1290 textfield_->SetText(ASCIIToUTF16("hello world"));
1275 1291
1276 base::string16 string; 1292 base::string16 string;
1277 ui::OSExchangeData data; 1293 ui::OSExchangeData data;
1278 int formats = 0; 1294 int formats = 0;
1279 int operations = 0; 1295 int operations = 0;
1280 std::set<OSExchangeData::CustomFormat> custom_formats; 1296 std::set<OSExchangeData::CustomFormat> custom_formats;
1281 1297
1282 // Start dragging "ello". 1298 // Start dragging "ello".
1283 textfield_->SelectRange(gfx::Range(1, 5)); 1299 textfield_->SelectRange(gfx::Range(1, 5));
1284 gfx::Point point(GetCursorPositionX(3), 0); 1300 gfx::Point point(GetCursorPositionX(3), 0);
1285 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1301 ui::MouseEvent click_a(
1286 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1302 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(),
1287 ui::EF_LEFT_MOUSE_BUTTON); 1303 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1304 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1288 textfield_->OnMousePressed(click_a); 1305 textfield_->OnMousePressed(click_a);
1289 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), 1306 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(),
1290 gfx::Point())); 1307 gfx::Point()));
1291 operations = textfield_->GetDragOperationsForView(textfield_, 1308 operations = textfield_->GetDragOperationsForView(textfield_,
1292 click_a.location()); 1309 click_a.location());
1293 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1310 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1294 operations); 1311 operations);
1295 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); 1312 textfield_->WriteDragDataForView(NULL, click_a.location(), &data);
1296 EXPECT_TRUE(data.GetString(&string)); 1313 EXPECT_TRUE(data.GetString(&string));
1297 EXPECT_EQ(textfield_->GetSelectedText(), string); 1314 EXPECT_EQ(textfield_->GetSelectedText(), string);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 1346
1330 base::string16 string; 1347 base::string16 string;
1331 ui::OSExchangeData data; 1348 ui::OSExchangeData data;
1332 int formats = 0; 1349 int formats = 0;
1333 int operations = 0; 1350 int operations = 0;
1334 std::set<OSExchangeData::CustomFormat> custom_formats; 1351 std::set<OSExchangeData::CustomFormat> custom_formats;
1335 1352
1336 // Start dragging " worl". 1353 // Start dragging " worl".
1337 textfield_->SelectRange(gfx::Range(5, 10)); 1354 textfield_->SelectRange(gfx::Range(5, 10));
1338 gfx::Point point(GetCursorPositionX(7), 0); 1355 gfx::Point point(GetCursorPositionX(7), 0);
1339 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1356 ui::MouseEvent click_a(
1340 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1357 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(),
1341 ui::EF_LEFT_MOUSE_BUTTON); 1358 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1359 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1342 textfield_->OnMousePressed(click_a); 1360 textfield_->OnMousePressed(click_a);
1343 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), 1361 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(),
1344 gfx::Point())); 1362 gfx::Point()));
1345 operations = textfield_->GetDragOperationsForView(textfield_, 1363 operations = textfield_->GetDragOperationsForView(textfield_,
1346 click_a.location()); 1364 click_a.location());
1347 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1365 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1348 operations); 1366 operations);
1349 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); 1367 textfield_->WriteDragDataForView(NULL, click_a.location(), &data);
1350 EXPECT_TRUE(data.GetString(&string)); 1368 EXPECT_TRUE(data.GetString(&string));
1351 EXPECT_EQ(textfield_->GetSelectedText(), string); 1369 EXPECT_EQ(textfield_->GetSelectedText(), string);
(...skipping 25 matching lines...) Expand all
1377 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1395 EXPECT_STR_EQ("h worlellod", textfield_->text());
1378 } 1396 }
1379 1397
1380 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1398 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1381 InitTextfield(); 1399 InitTextfield();
1382 textfield_->SetText(ASCIIToUTF16("hello world")); 1400 textfield_->SetText(ASCIIToUTF16("hello world"));
1383 1401
1384 // Start dragging "worl". 1402 // Start dragging "worl".
1385 textfield_->SelectRange(gfx::Range(6, 10)); 1403 textfield_->SelectRange(gfx::Range(6, 10));
1386 gfx::Point point(GetCursorPositionX(8), 0); 1404 gfx::Point point(GetCursorPositionX(8), 0);
1387 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, 1405 ui::MouseEvent click(
1388 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1406 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(),
1389 ui::EF_LEFT_MOUSE_BUTTON); 1407 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1408 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1390 textfield_->OnMousePressed(click); 1409 textfield_->OnMousePressed(click);
1391 ui::OSExchangeData data; 1410 ui::OSExchangeData data;
1392 textfield_->WriteDragDataForView(NULL, click.location(), &data); 1411 textfield_->WriteDragDataForView(NULL, click.location(), &data);
1393 EXPECT_TRUE(textfield_->CanDrop(data)); 1412 EXPECT_TRUE(textfield_->CanDrop(data));
1394 // Drag the text over somewhere valid, outside the current selection. 1413 // Drag the text over somewhere valid, outside the current selection.
1395 gfx::Point drop_point(GetCursorPositionX(2), 0); 1414 gfx::Point drop_point(GetCursorPositionX(2), 0);
1396 ui::DropTargetEvent drop(data, drop_point, drop_point, 1415 ui::DropTargetEvent drop(data, drop_point, drop_point,
1397 ui::DragDropTypes::DRAG_MOVE); 1416 ui::DragDropTypes::DRAG_MOVE);
1398 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); 1417 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop));
1399 // "Cancel" the drag, via move and release over the selection, and OnDragDone. 1418 // "Cancel" the drag, via move and release over the selection, and OnDragDone.
1400 gfx::Point drag_point(GetCursorPositionX(9), 0); 1419 gfx::Point drag_point(GetCursorPositionX(9), 0);
1401 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, 1420 ui::MouseEvent drag(
1402 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 1421 ui::ET_MOUSE_DRAGGED, drag_point, drag_point, ui::EventTimeForNow(),
1403 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, 1422 ui::EF_LEFT_MOUSE_BUTTON, 0,
1404 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 1423 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1405 ui::EF_LEFT_MOUSE_BUTTON); 1424 ui::MouseEvent release(
1425 ui::ET_MOUSE_RELEASED, drag_point, drag_point, ui::EventTimeForNow(),
1426 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1427 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1406 textfield_->OnMouseDragged(drag); 1428 textfield_->OnMouseDragged(drag);
1407 textfield_->OnMouseReleased(release); 1429 textfield_->OnMouseReleased(release);
1408 textfield_->OnDragDone(); 1430 textfield_->OnDragDone();
1409 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); 1431 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text());
1410 } 1432 }
1411 1433
1412 TEST_F(TextfieldTest, ReadOnlyTest) { 1434 TEST_F(TextfieldTest, ReadOnlyTest) {
1413 InitTextfield(); 1435 InitTextfield();
1414 textfield_->SetText(ASCIIToUTF16("read only")); 1436 textfield_->SetText(ASCIIToUTF16("read only"));
1415 textfield_->SetReadOnly(true); 1437 textfield_->SetReadOnly(true);
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 2194
2173 textfield_->SelectRange(gfx::Range(5, 5)); 2195 textfield_->SelectRange(gfx::Range(5, 5));
2174 const gfx::Rect middle_cursor = GetCursorBounds(); 2196 const gfx::Rect middle_cursor = GetCursorBounds();
2175 textfield_->SelectRange(gfx::Range(0, 0)); 2197 textfield_->SelectRange(gfx::Range(0, 0));
2176 const gfx::Point beginning = GetCursorBounds().origin(); 2198 const gfx::Point beginning = GetCursorBounds().origin();
2177 2199
2178 // Double click, but do not release the left button. 2200 // Double click, but do not release the left button.
2179 MouseClick(middle_cursor, 0); 2201 MouseClick(middle_cursor, 0);
2180 const gfx::Point middle(middle_cursor.x(), 2202 const gfx::Point middle(middle_cursor.x(),
2181 middle_cursor.y() + middle_cursor.height() / 2); 2203 middle_cursor.y() + middle_cursor.height() / 2);
2182 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, 2204 ui::MouseEvent press_event(
2183 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2205 ui::ET_MOUSE_PRESSED, middle, middle, ui::EventTimeForNow(),
2184 ui::EF_LEFT_MOUSE_BUTTON); 2206 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2207 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2185 textfield_->OnMousePressed(press_event); 2208 textfield_->OnMousePressed(press_event);
2186 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); 2209 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange());
2187 2210
2188 // Drag the mouse to the beginning of the textfield. 2211 // Drag the mouse to the beginning of the textfield.
2189 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, 2212 ui::MouseEvent drag_event(
2190 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 2213 ui::ET_MOUSE_DRAGGED, beginning, beginning, ui::EventTimeForNow(),
2214 ui::EF_LEFT_MOUSE_BUTTON, 0,
2215 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2191 textfield_->OnMouseDragged(drag_event); 2216 textfield_->OnMouseDragged(drag_event);
2192 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 2217 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
2193 } 2218 }
2194 2219
2195 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 2220 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2196 // flaky: http://crbug.com/396477 2221 // flaky: http://crbug.com/396477
2197 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) { 2222 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) {
2198 InitTextfield(); 2223 InitTextfield();
2199 textfield_->SetText(ASCIIToUTF16("0123")); 2224 textfield_->SetText(ASCIIToUTF16("0123"));
2200 gfx::Point point_1(GetCursorPositionX(1), 0); 2225 gfx::Point point_1(GetCursorPositionX(1), 0);
2201 gfx::Point point_2(GetCursorPositionX(2), 0); 2226 gfx::Point point_2(GetCursorPositionX(2), 0);
2202 gfx::Point point_3(GetCursorPositionX(3), 0); 2227 gfx::Point point_3(GetCursorPositionX(3), 0);
2203 gfx::Point point_4(GetCursorPositionX(4), 0); 2228 gfx::Point point_4(GetCursorPositionX(4), 0);
2204 2229
2205 // Text selected by the mouse should be placed on the selection clipboard. 2230 // Text selected by the mouse should be placed on the selection clipboard.
2206 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, 2231 ui::MouseEvent press(
2207 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2232 ui::ET_MOUSE_PRESSED, point_1, point_1, ui::EventTimeForNow(),
2208 ui::EF_LEFT_MOUSE_BUTTON); 2233 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2234 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2209 textfield_->OnMousePressed(press); 2235 textfield_->OnMousePressed(press);
2210 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3, 2236 ui::MouseEvent drag(
2211 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2237 ui::ET_MOUSE_DRAGGED, point_3, point_3, ui::EventTimeForNow(),
2212 ui::EF_LEFT_MOUSE_BUTTON); 2238 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2239 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2213 textfield_->OnMouseDragged(drag); 2240 textfield_->OnMouseDragged(drag);
2214 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point_3, point_3, 2241 ui::MouseEvent release(
2215 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2242 ui::ET_MOUSE_RELEASED, point_3, point_3, ui::EventTimeForNow(),
2216 ui::EF_LEFT_MOUSE_BUTTON); 2243 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2244 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2217 textfield_->OnMouseReleased(release); 2245 textfield_->OnMouseReleased(release);
2218 EXPECT_EQ(gfx::Range(1, 3), textfield_->GetSelectedRange()); 2246 EXPECT_EQ(gfx::Range(1, 3), textfield_->GetSelectedRange());
2219 EXPECT_STR_EQ("12", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2247 EXPECT_STR_EQ("12", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2220 2248
2221 // Select-all should update the selection clipboard. 2249 // Select-all should update the selection clipboard.
2222 SendKeyEvent(ui::VKEY_A, false, true); 2250 SendKeyEvent(ui::VKEY_A, false, true);
2223 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange()); 2251 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange());
2224 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2252 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2225 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 2253 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
2226 2254
2227 // Shift-click selection modifications should update the clipboard. 2255 // Shift-click selection modifications should update the clipboard.
2228 NonClientMouseClick(); 2256 NonClientMouseClick();
2229 ui::MouseEvent press_2(ui::ET_MOUSE_PRESSED, point_2, point_2, 2257 ui::MouseEvent press_2(
2230 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2258 ui::ET_MOUSE_PRESSED, point_2, point_2, ui::EventTimeForNow(),
2231 ui::EF_LEFT_MOUSE_BUTTON); 2259 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2260 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2232 press_2.set_flags(press_2.flags() | ui::EF_SHIFT_DOWN); 2261 press_2.set_flags(press_2.flags() | ui::EF_SHIFT_DOWN);
2233 #if defined(USE_X11) 2262 #if defined(USE_X11)
2234 ui::UpdateX11EventForFlags(&press_2); 2263 ui::UpdateX11EventForFlags(&press_2);
2235 #endif 2264 #endif
2236 textfield_->OnMousePressed(press_2); 2265 textfield_->OnMousePressed(press_2);
2237 ui::MouseEvent release_2(ui::ET_MOUSE_RELEASED, point_2, point_2, 2266 ui::MouseEvent release_2(
2238 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2267 ui::ET_MOUSE_RELEASED, point_2, point_2, ui::EventTimeForNow(),
2239 ui::EF_LEFT_MOUSE_BUTTON); 2268 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2269 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2240 textfield_->OnMouseReleased(release_2); 2270 textfield_->OnMouseReleased(release_2);
2241 EXPECT_EQ(gfx::Range(0, 2), textfield_->GetSelectedRange()); 2271 EXPECT_EQ(gfx::Range(0, 2), textfield_->GetSelectedRange());
2242 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2272 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2243 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 2273 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
2244 2274
2245 // Shift-Left/Right should update the selection clipboard. 2275 // Shift-Left/Right should update the selection clipboard.
2246 SendKeyEvent(ui::VKEY_RIGHT, true, false); 2276 SendKeyEvent(ui::VKEY_RIGHT, true, false);
2247 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2277 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2248 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 2278 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
2249 SendKeyEvent(ui::VKEY_LEFT, true, false); 2279 SendKeyEvent(ui::VKEY_LEFT, true, false);
2250 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2280 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2251 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 2281 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
2252 SendKeyEvent(ui::VKEY_RIGHT, true, true); 2282 SendKeyEvent(ui::VKEY_RIGHT, true, true);
2253 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2283 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2254 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 2284 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
2255 2285
2256 // Moving the cursor without a selection should not change the clipboard. 2286 // Moving the cursor without a selection should not change the clipboard.
2257 SendKeyEvent(ui::VKEY_LEFT, false, false); 2287 SendKeyEvent(ui::VKEY_LEFT, false, false);
2258 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange()); 2288 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange());
2259 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2289 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2260 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); 2290 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
2261 2291
2262 // Middle clicking should paste at the mouse (not cursor) location. 2292 // Middle clicking should paste at the mouse (not cursor) location.
2263 // The cursor should be placed at the end of the pasted text. 2293 // The cursor should be placed at the end of the pasted text.
2264 ui::MouseEvent middle(ui::ET_MOUSE_PRESSED, point_4, point_4, 2294 ui::MouseEvent middle(
2265 ui::EventTimeForNow(), ui::EF_MIDDLE_MOUSE_BUTTON, 2295 ui::ET_MOUSE_PRESSED, point_4, point_4, ui::EventTimeForNow(),
2266 ui::EF_MIDDLE_MOUSE_BUTTON); 2296 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON,
2297 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2267 textfield_->OnMousePressed(middle); 2298 textfield_->OnMousePressed(middle);
2268 EXPECT_STR_EQ("01230123", textfield_->text()); 2299 EXPECT_STR_EQ("01230123", textfield_->text());
2269 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange()); 2300 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange());
2270 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2301 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2271 2302
2272 // Middle clicking on an unfocused textfield should focus it and paste. 2303 // Middle clicking on an unfocused textfield should focus it and paste.
2273 textfield_->GetFocusManager()->ClearFocus(); 2304 textfield_->GetFocusManager()->ClearFocus();
2274 EXPECT_FALSE(textfield_->HasFocus()); 2305 EXPECT_FALSE(textfield_->HasFocus());
2275 textfield_->OnMousePressed(middle); 2306 textfield_->OnMousePressed(middle);
2276 EXPECT_TRUE(textfield_->HasFocus()); 2307 EXPECT_TRUE(textfield_->HasFocus());
(...skipping 15 matching lines...) Expand all
2292 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); 2323 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo");
2293 textfield_->SelectRange(gfx::Range(2, 6)); 2324 textfield_->SelectRange(gfx::Range(2, 6));
2294 textfield_->OnMousePressed(middle); 2325 textfield_->OnMousePressed(middle);
2295 EXPECT_STR_EQ("012301230123", textfield_->text()); 2326 EXPECT_STR_EQ("012301230123", textfield_->text());
2296 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); 2327 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange());
2297 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); 2328 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
2298 2329
2299 // Double and triple clicking should update the clipboard contents. 2330 // Double and triple clicking should update the clipboard contents.
2300 textfield_->SetText(ASCIIToUTF16("ab cd ef")); 2331 textfield_->SetText(ASCIIToUTF16("ab cd ef"));
2301 gfx::Point word(GetCursorPositionX(4), 0); 2332 gfx::Point word(GetCursorPositionX(4), 0);
2302 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, 2333 ui::MouseEvent press_word(
2303 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2334 ui::ET_MOUSE_PRESSED, word, word, ui::EventTimeForNow(),
2304 ui::EF_LEFT_MOUSE_BUTTON); 2335 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2336 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2305 textfield_->OnMousePressed(press_word); 2337 textfield_->OnMousePressed(press_word);
2306 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, 2338 ui::MouseEvent release_word(
2307 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2339 ui::ET_MOUSE_RELEASED, word, word, ui::EventTimeForNow(),
2308 ui::EF_LEFT_MOUSE_BUTTON); 2340 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
2341 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2309 textfield_->OnMouseReleased(release_word); 2342 textfield_->OnMouseReleased(release_word);
2310 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word, 2343 ui::MouseEvent double_click(
2311 ui::EventTimeForNow(), 2344 ui::ET_MOUSE_PRESSED, word, word, ui::EventTimeForNow(),
2312 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, 2345 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
2313 ui::EF_LEFT_MOUSE_BUTTON); 2346 ui::EF_LEFT_MOUSE_BUTTON,
2347 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
2314 textfield_->OnMousePressed(double_click); 2348 textfield_->OnMousePressed(double_click);
2315 textfield_->OnMouseReleased(release_word); 2349 textfield_->OnMouseReleased(release_word);
2316 EXPECT_EQ(gfx::Range(3, 5), textfield_->GetSelectedRange()); 2350 EXPECT_EQ(gfx::Range(3, 5), textfield_->GetSelectedRange());
2317 EXPECT_STR_EQ("cd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2351 EXPECT_STR_EQ("cd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2318 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 2352 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
2319 textfield_->OnMousePressed(press_word); 2353 textfield_->OnMousePressed(press_word);
2320 textfield_->OnMouseReleased(release_word); 2354 textfield_->OnMouseReleased(release_word);
2321 EXPECT_EQ(gfx::Range(0, 8), textfield_->GetSelectedRange()); 2355 EXPECT_EQ(gfx::Range(0, 8), textfield_->GetSelectedRange());
2322 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 2356 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
2323 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 2357 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2551 2585
2552 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2586 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2553 ui::AXViewState state_protected; 2587 ui::AXViewState state_protected;
2554 textfield_->GetAccessibleState(&state_protected); 2588 textfield_->GetAccessibleState(&state_protected);
2555 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2589 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2556 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2590 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2557 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2591 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2558 } 2592 }
2559 2593
2560 } // namespace views 2594 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698