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

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

Issue 923903002: MacViews: Merge single-character edits, map (and validate) undo and redo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase for r316774 (remove "ing" from "Editing") Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } 369 }
370 370
371 // Sends Shift+Insert if supported, otherwise Cmd+V again. 371 // Sends Shift+Insert if supported, otherwise Cmd+V again.
372 void SendAlternatePaste() { 372 void SendAlternatePaste() {
373 if (TestingNativeMac()) 373 if (TestingNativeMac())
374 SendKeyEvent(ui::VKEY_V, false, true); 374 SendKeyEvent(ui::VKEY_V, false, true);
375 else 375 else
376 SendKeyEvent(ui::VKEY_INSERT, true, false); 376 SendKeyEvent(ui::VKEY_INSERT, true, false);
377 } 377 }
378 378
379 // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac
msw 2015/02/18 19:10:42 nit: CTRL+SHIFT+Z works on windows and linux. Mayb
tapted 2015/02/19 03:19:10 Done.
380 // that is bound to "Show full history", so is not mapped as an editing
381 // command. So, on Mac, send Cmd+Shift+Z.
382 void SendAlternateRedo() {
383 if (TestingNativeMac())
384 SendKeyEvent(ui::VKEY_Z, true, true);
385 else
386 SendKeyEvent(ui::VKEY_Y, false, true);
387 }
388
379 View* GetFocusedView() { 389 View* GetFocusedView() {
380 return widget_->GetFocusManager()->GetFocusedView(); 390 return widget_->GetFocusManager()->GetFocusedView();
381 } 391 }
382 392
383 int GetCursorPositionX(int cursor_pos) { 393 int GetCursorPositionX(int cursor_pos) {
384 return test_api_->GetRenderText()->GetCursorBounds( 394 return test_api_->GetRenderText()->GetCursorBounds(
385 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); 395 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x();
386 } 396 }
387 397
388 // Get the current cursor bounds. 398 // Get the current cursor bounds.
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1078 EXPECT_STR_EQ("h welloorld", textfield_->text());
1069 textfield_->OnDragDone(); 1079 textfield_->OnDragDone();
1070 1080
1071 // Undo/Redo the drag&drop change. 1081 // Undo/Redo the drag&drop change.
1072 SendKeyEvent(ui::VKEY_Z, false, true); 1082 SendKeyEvent(ui::VKEY_Z, false, true);
1073 EXPECT_STR_EQ("hello world", textfield_->text()); 1083 EXPECT_STR_EQ("hello world", textfield_->text());
1074 SendKeyEvent(ui::VKEY_Z, false, true); 1084 SendKeyEvent(ui::VKEY_Z, false, true);
1075 EXPECT_STR_EQ("", textfield_->text()); 1085 EXPECT_STR_EQ("", textfield_->text());
1076 SendKeyEvent(ui::VKEY_Z, false, true); 1086 SendKeyEvent(ui::VKEY_Z, false, true);
1077 EXPECT_STR_EQ("", textfield_->text()); 1087 EXPECT_STR_EQ("", textfield_->text());
1078 SendKeyEvent(ui::VKEY_Y, false, true); 1088 SendAlternateRedo();
1079 EXPECT_STR_EQ("hello world", textfield_->text()); 1089 EXPECT_STR_EQ("hello world", textfield_->text());
1080 SendKeyEvent(ui::VKEY_Y, false, true); 1090 SendAlternateRedo();
1081 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1091 EXPECT_STR_EQ("h welloorld", textfield_->text());
1082 SendKeyEvent(ui::VKEY_Y, false, true); 1092 SendAlternateRedo();
1083 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1093 EXPECT_STR_EQ("h welloorld", textfield_->text());
1084 } 1094 }
1085 1095
1086 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { 1096 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) {
1087 InitTextfield(); 1097 InitTextfield();
1088 textfield_->SetText(ASCIIToUTF16("hello world")); 1098 textfield_->SetText(ASCIIToUTF16("hello world"));
1089 1099
1090 base::string16 string; 1100 base::string16 string;
1091 ui::OSExchangeData data; 1101 ui::OSExchangeData data;
1092 int formats = 0; 1102 int formats = 0;
(...skipping 28 matching lines...) Expand all
1121 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1131 EXPECT_STR_EQ("h worlellod", textfield_->text());
1122 textfield_->OnDragDone(); 1132 textfield_->OnDragDone();
1123 1133
1124 // Undo/Redo the drag&drop change. 1134 // Undo/Redo the drag&drop change.
1125 SendKeyEvent(ui::VKEY_Z, false, true); 1135 SendKeyEvent(ui::VKEY_Z, false, true);
1126 EXPECT_STR_EQ("hello world", textfield_->text()); 1136 EXPECT_STR_EQ("hello world", textfield_->text());
1127 SendKeyEvent(ui::VKEY_Z, false, true); 1137 SendKeyEvent(ui::VKEY_Z, false, true);
1128 EXPECT_STR_EQ("", textfield_->text()); 1138 EXPECT_STR_EQ("", textfield_->text());
1129 SendKeyEvent(ui::VKEY_Z, false, true); 1139 SendKeyEvent(ui::VKEY_Z, false, true);
1130 EXPECT_STR_EQ("", textfield_->text()); 1140 EXPECT_STR_EQ("", textfield_->text());
1131 SendKeyEvent(ui::VKEY_Y, false, true); 1141 SendAlternateRedo();
1132 EXPECT_STR_EQ("hello world", textfield_->text()); 1142 EXPECT_STR_EQ("hello world", textfield_->text());
1133 SendKeyEvent(ui::VKEY_Y, false, true); 1143 SendAlternateRedo();
1134 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1144 EXPECT_STR_EQ("h worlellod", textfield_->text());
1135 SendKeyEvent(ui::VKEY_Y, false, true); 1145 SendAlternateRedo();
1136 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1146 EXPECT_STR_EQ("h worlellod", textfield_->text());
1137 } 1147 }
1138 1148
1139 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1149 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1140 InitTextfield(); 1150 InitTextfield();
1141 textfield_->SetText(ASCIIToUTF16("hello world")); 1151 textfield_->SetText(ASCIIToUTF16("hello world"));
1142 1152
1143 // Start dragging "worl". 1153 // Start dragging "worl".
1144 textfield_->SelectRange(gfx::Range(6, 10)); 1154 textfield_->SelectRange(gfx::Range(6, 10));
1145 gfx::Point point(GetCursorPositionX(8), 0); 1155 gfx::Point point(GetCursorPositionX(8), 0);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 } 1352 }
1343 1353
1344 TEST_F(TextfieldTest, UndoRedoTest) { 1354 TEST_F(TextfieldTest, UndoRedoTest) {
1345 InitTextfield(); 1355 InitTextfield();
1346 SendKeyEvent(ui::VKEY_A); 1356 SendKeyEvent(ui::VKEY_A);
1347 EXPECT_STR_EQ("a", textfield_->text()); 1357 EXPECT_STR_EQ("a", textfield_->text());
1348 SendKeyEvent(ui::VKEY_Z, false, true); 1358 SendKeyEvent(ui::VKEY_Z, false, true);
1349 EXPECT_STR_EQ("", textfield_->text()); 1359 EXPECT_STR_EQ("", textfield_->text());
1350 SendKeyEvent(ui::VKEY_Z, false, true); 1360 SendKeyEvent(ui::VKEY_Z, false, true);
1351 EXPECT_STR_EQ("", textfield_->text()); 1361 EXPECT_STR_EQ("", textfield_->text());
1352 SendKeyEvent(ui::VKEY_Y, false, true); 1362 SendAlternateRedo();
1353 EXPECT_STR_EQ("a", textfield_->text()); 1363 EXPECT_STR_EQ("a", textfield_->text());
1354 SendKeyEvent(ui::VKEY_Y, false, true); 1364 SendAlternateRedo();
1355 EXPECT_STR_EQ("a", textfield_->text()); 1365 EXPECT_STR_EQ("a", textfield_->text());
1356 1366
1357 // AppendText 1367 // AppendText
1358 textfield_->AppendText(ASCIIToUTF16("b")); 1368 textfield_->AppendText(ASCIIToUTF16("b"));
1359 last_contents_.clear(); // AppendText doesn't call ContentsChanged. 1369 last_contents_.clear(); // AppendText doesn't call ContentsChanged.
1360 EXPECT_STR_EQ("ab", textfield_->text()); 1370 EXPECT_STR_EQ("ab", textfield_->text());
1361 SendKeyEvent(ui::VKEY_Z, false, true); 1371 SendKeyEvent(ui::VKEY_Z, false, true);
1362 EXPECT_STR_EQ("a", textfield_->text()); 1372 EXPECT_STR_EQ("a", textfield_->text());
1363 SendKeyEvent(ui::VKEY_Y, false, true); 1373 SendAlternateRedo();
1364 EXPECT_STR_EQ("ab", textfield_->text()); 1374 EXPECT_STR_EQ("ab", textfield_->text());
1365 1375
1366 // SetText 1376 // SetText
1367 SendKeyEvent(ui::VKEY_C); 1377 SendKeyEvent(ui::VKEY_C);
1368 // Undo'ing append moves the cursor to the end for now. 1378 // Undo'ing append moves the cursor to the end for now.
1369 // A no-op SetText won't add a new edit; see TextfieldModel::SetText. 1379 // A no-op SetText won't add a new edit; see TextfieldModel::SetText.
1370 EXPECT_STR_EQ("abc", textfield_->text()); 1380 EXPECT_STR_EQ("abc", textfield_->text());
1371 textfield_->SetText(ASCIIToUTF16("abc")); 1381 textfield_->SetText(ASCIIToUTF16("abc"));
1372 EXPECT_STR_EQ("abc", textfield_->text()); 1382 EXPECT_STR_EQ("abc", textfield_->text());
1373 SendKeyEvent(ui::VKEY_Z, false, true); 1383 SendKeyEvent(ui::VKEY_Z, false, true);
1374 EXPECT_STR_EQ("ab", textfield_->text()); 1384 EXPECT_STR_EQ("ab", textfield_->text());
1375 SendKeyEvent(ui::VKEY_Y, false, true); 1385 SendAlternateRedo();
1376 EXPECT_STR_EQ("abc", textfield_->text()); 1386 EXPECT_STR_EQ("abc", textfield_->text());
1377 SendKeyEvent(ui::VKEY_Y, false, true); 1387 SendAlternateRedo();
1378 EXPECT_STR_EQ("abc", textfield_->text()); 1388 EXPECT_STR_EQ("abc", textfield_->text());
1379 textfield_->SetText(ASCIIToUTF16("123")); 1389 textfield_->SetText(ASCIIToUTF16("123"));
1380 textfield_->SetText(ASCIIToUTF16("123")); 1390 textfield_->SetText(ASCIIToUTF16("123"));
1381 EXPECT_STR_EQ("123", textfield_->text()); 1391 EXPECT_STR_EQ("123", textfield_->text());
1382 SendKeyEvent(ui::VKEY_END, false, false); 1392 SendKeyEvent(ui::VKEY_END, false, false);
1383 SendKeyEvent(ui::VKEY_4, false, false); 1393 SendKeyEvent(ui::VKEY_4, false, false);
1384 EXPECT_STR_EQ("1234", textfield_->text()); 1394 EXPECT_STR_EQ("1234", textfield_->text());
1385 last_contents_.clear(); 1395 last_contents_.clear();
1386 SendKeyEvent(ui::VKEY_Z, false, true); 1396 SendKeyEvent(ui::VKEY_Z, false, true);
1387 EXPECT_STR_EQ("123", textfield_->text()); 1397 EXPECT_STR_EQ("123", textfield_->text());
1388 SendKeyEvent(ui::VKEY_Z, false, true); 1398 SendKeyEvent(ui::VKEY_Z, false, true);
1389 // the insert edit "c" and set edit "123" are merged to single edit, 1399 // the insert edit "c" and set edit "123" are merged to single edit,
1390 // so text becomes "ab" after undo. 1400 // so text becomes "ab" after undo.
1391 EXPECT_STR_EQ("ab", textfield_->text()); 1401 EXPECT_STR_EQ("ab", textfield_->text());
1392 SendKeyEvent(ui::VKEY_Z, false, true); 1402 SendKeyEvent(ui::VKEY_Z, false, true);
1393 EXPECT_STR_EQ("a", textfield_->text()); 1403 EXPECT_STR_EQ("a", textfield_->text());
1394 SendKeyEvent(ui::VKEY_Y, false, true); 1404 SendAlternateRedo();
1395 EXPECT_STR_EQ("ab", textfield_->text()); 1405 EXPECT_STR_EQ("ab", textfield_->text());
1396 SendKeyEvent(ui::VKEY_Y, false, true); 1406 SendAlternateRedo();
1397 EXPECT_STR_EQ("123", textfield_->text()); 1407 EXPECT_STR_EQ("123", textfield_->text());
1398 SendKeyEvent(ui::VKEY_Y, false, true); 1408 SendAlternateRedo();
1399 EXPECT_STR_EQ("1234", textfield_->text()); 1409 EXPECT_STR_EQ("1234", textfield_->text());
1400 1410
1401 // Undoing to the same text shouldn't call ContentsChanged. 1411 // Undoing to the same text shouldn't call ContentsChanged.
1402 SendKeyEvent(ui::VKEY_A, false, true); // select all 1412 SendKeyEvent(ui::VKEY_A, false, true); // select all
1403 SendKeyEvent(ui::VKEY_A); 1413 SendKeyEvent(ui::VKEY_A);
1404 EXPECT_STR_EQ("a", textfield_->text()); 1414 EXPECT_STR_EQ("a", textfield_->text());
1405 SendKeyEvent(ui::VKEY_B); 1415 SendKeyEvent(ui::VKEY_B);
1406 SendKeyEvent(ui::VKEY_C); 1416 SendKeyEvent(ui::VKEY_C);
1407 EXPECT_STR_EQ("abc", textfield_->text()); 1417 EXPECT_STR_EQ("abc", textfield_->text());
1408 SendKeyEvent(ui::VKEY_Z, false, true); 1418 SendKeyEvent(ui::VKEY_Z, false, true);
1409 EXPECT_STR_EQ("1234", textfield_->text()); 1419 EXPECT_STR_EQ("1234", textfield_->text());
1410 SendKeyEvent(ui::VKEY_Y, false, true); 1420 SendAlternateRedo();
1411 EXPECT_STR_EQ("abc", textfield_->text()); 1421 EXPECT_STR_EQ("abc", textfield_->text());
1412 1422
1413 // Delete/Backspace 1423 // Delete/Backspace
1414 SendKeyEvent(ui::VKEY_BACK); 1424 SendKeyEvent(ui::VKEY_BACK);
1415 EXPECT_STR_EQ("ab", textfield_->text()); 1425 EXPECT_STR_EQ("ab", textfield_->text());
1416 SendKeyEvent(ui::VKEY_HOME); 1426 bool shift = false;
1427 SendHomeEvent(shift);
1417 SendKeyEvent(ui::VKEY_DELETE); 1428 SendKeyEvent(ui::VKEY_DELETE);
1418 EXPECT_STR_EQ("b", textfield_->text()); 1429 EXPECT_STR_EQ("b", textfield_->text());
1419 SendKeyEvent(ui::VKEY_A, false, true); 1430 SendKeyEvent(ui::VKEY_A, false, true);
1420 SendKeyEvent(ui::VKEY_DELETE); 1431 SendKeyEvent(ui::VKEY_DELETE);
1421 EXPECT_STR_EQ("", textfield_->text()); 1432 EXPECT_STR_EQ("", textfield_->text());
1422 SendKeyEvent(ui::VKEY_Z, false, true); 1433 SendKeyEvent(ui::VKEY_Z, false, true);
1423 EXPECT_STR_EQ("b", textfield_->text()); 1434 EXPECT_STR_EQ("b", textfield_->text());
1424 SendKeyEvent(ui::VKEY_Z, false, true); 1435 SendKeyEvent(ui::VKEY_Z, false, true);
1425 EXPECT_STR_EQ("ab", textfield_->text()); 1436 EXPECT_STR_EQ("ab", textfield_->text());
1426 SendKeyEvent(ui::VKEY_Z, false, true); 1437 SendKeyEvent(ui::VKEY_Z, false, true);
1427 EXPECT_STR_EQ("abc", textfield_->text()); 1438 EXPECT_STR_EQ("abc", textfield_->text());
1428 SendKeyEvent(ui::VKEY_Y, false, true); 1439 SendAlternateRedo();
1429 EXPECT_STR_EQ("ab", textfield_->text()); 1440 EXPECT_STR_EQ("ab", textfield_->text());
1430 SendKeyEvent(ui::VKEY_Y, false, true); 1441 SendAlternateRedo();
1431 EXPECT_STR_EQ("b", textfield_->text()); 1442 EXPECT_STR_EQ("b", textfield_->text());
1432 SendKeyEvent(ui::VKEY_Y, false, true); 1443 SendAlternateRedo();
1433 EXPECT_STR_EQ("", textfield_->text()); 1444 EXPECT_STR_EQ("", textfield_->text());
1434 SendKeyEvent(ui::VKEY_Y, false, true); 1445 SendAlternateRedo();
1435 EXPECT_STR_EQ("", textfield_->text()); 1446 EXPECT_STR_EQ("", textfield_->text());
1436 } 1447 }
1437 1448
1438 TEST_F(TextfieldTest, CutCopyPaste) { 1449 TEST_F(TextfieldTest, CutCopyPaste) {
1439 InitTextfield(); 1450 InitTextfield();
1440 1451
1441 // Ensure IDS_APP_CUT cuts. 1452 // Ensure IDS_APP_CUT cuts.
1442 textfield_->SetText(ASCIIToUTF16("123")); 1453 textfield_->SetText(ASCIIToUTF16("123"));
1443 textfield_->SelectAll(false); 1454 textfield_->SelectAll(false);
1444 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); 1455 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT));
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 2267
2257 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2268 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2258 ui::AXViewState state_protected; 2269 ui::AXViewState state_protected;
2259 textfield_->GetAccessibleState(&state_protected); 2270 textfield_->GetAccessibleState(&state_protected);
2260 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2271 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2261 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2272 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2262 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2273 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2263 } 2274 }
2264 2275
2265 } // namespace views 2276 } // namespace views
OLDNEW
« ui/views/cocoa/bridged_content_view.mm ('K') | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698