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

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: ugh. left the MAYBE_ on 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
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1068 EXPECT_STR_EQ("h welloorld", textfield_->text());
1069 textfield_->OnDragDone(); 1069 textfield_->OnDragDone();
1070 1070
1071 // Undo/Redo the drag&drop change. 1071 // Undo/Redo the drag&drop change.
1072 SendKeyEvent(ui::VKEY_Z, false, true); 1072 SendKeyEvent(ui::VKEY_Z, false, true);
1073 EXPECT_STR_EQ("hello world", textfield_->text()); 1073 EXPECT_STR_EQ("hello world", textfield_->text());
1074 SendKeyEvent(ui::VKEY_Z, false, true); 1074 SendKeyEvent(ui::VKEY_Z, false, true);
1075 EXPECT_STR_EQ("", textfield_->text()); 1075 EXPECT_STR_EQ("", textfield_->text());
1076 SendKeyEvent(ui::VKEY_Z, false, true); 1076 SendKeyEvent(ui::VKEY_Z, false, true);
1077 EXPECT_STR_EQ("", textfield_->text()); 1077 EXPECT_STR_EQ("", textfield_->text());
1078 SendKeyEvent(ui::VKEY_Y, false, true); 1078 SendKeyEvent(ui::VKEY_Z, true, true);
1079 EXPECT_STR_EQ("hello world", textfield_->text()); 1079 EXPECT_STR_EQ("hello world", textfield_->text());
1080 SendKeyEvent(ui::VKEY_Y, false, true); 1080 SendKeyEvent(ui::VKEY_Z, true, true);
1081 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1081 EXPECT_STR_EQ("h welloorld", textfield_->text());
1082 SendKeyEvent(ui::VKEY_Y, false, true); 1082 SendKeyEvent(ui::VKEY_Z, true, true);
1083 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1083 EXPECT_STR_EQ("h welloorld", textfield_->text());
1084 } 1084 }
1085 1085
1086 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { 1086 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) {
1087 InitTextfield(); 1087 InitTextfield();
1088 textfield_->SetText(ASCIIToUTF16("hello world")); 1088 textfield_->SetText(ASCIIToUTF16("hello world"));
1089 1089
1090 base::string16 string; 1090 base::string16 string;
1091 ui::OSExchangeData data; 1091 ui::OSExchangeData data;
1092 int formats = 0; 1092 int formats = 0;
(...skipping 28 matching lines...) Expand all
1121 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1121 EXPECT_STR_EQ("h worlellod", textfield_->text());
1122 textfield_->OnDragDone(); 1122 textfield_->OnDragDone();
1123 1123
1124 // Undo/Redo the drag&drop change. 1124 // Undo/Redo the drag&drop change.
1125 SendKeyEvent(ui::VKEY_Z, false, true); 1125 SendKeyEvent(ui::VKEY_Z, false, true);
1126 EXPECT_STR_EQ("hello world", textfield_->text()); 1126 EXPECT_STR_EQ("hello world", textfield_->text());
1127 SendKeyEvent(ui::VKEY_Z, false, true); 1127 SendKeyEvent(ui::VKEY_Z, false, true);
1128 EXPECT_STR_EQ("", textfield_->text()); 1128 EXPECT_STR_EQ("", textfield_->text());
1129 SendKeyEvent(ui::VKEY_Z, false, true); 1129 SendKeyEvent(ui::VKEY_Z, false, true);
1130 EXPECT_STR_EQ("", textfield_->text()); 1130 EXPECT_STR_EQ("", textfield_->text());
1131 SendKeyEvent(ui::VKEY_Y, false, true); 1131 SendKeyEvent(ui::VKEY_Z, true, true);
1132 EXPECT_STR_EQ("hello world", textfield_->text()); 1132 EXPECT_STR_EQ("hello world", textfield_->text());
1133 SendKeyEvent(ui::VKEY_Y, false, true); 1133 SendKeyEvent(ui::VKEY_Z, true, true);
1134 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1134 EXPECT_STR_EQ("h worlellod", textfield_->text());
1135 SendKeyEvent(ui::VKEY_Y, false, true); 1135 SendKeyEvent(ui::VKEY_Z, true, true);
1136 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1136 EXPECT_STR_EQ("h worlellod", textfield_->text());
1137 } 1137 }
1138 1138
1139 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1139 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1140 InitTextfield(); 1140 InitTextfield();
1141 textfield_->SetText(ASCIIToUTF16("hello world")); 1141 textfield_->SetText(ASCIIToUTF16("hello world"));
1142 1142
1143 // Start dragging "worl". 1143 // Start dragging "worl".
1144 textfield_->SelectRange(gfx::Range(6, 10)); 1144 textfield_->SelectRange(gfx::Range(6, 10));
1145 gfx::Point point(GetCursorPositionX(8), 0); 1145 gfx::Point point(GetCursorPositionX(8), 0);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 } 1342 }
1343 1343
1344 TEST_F(TextfieldTest, UndoRedoTest) { 1344 TEST_F(TextfieldTest, UndoRedoTest) {
1345 InitTextfield(); 1345 InitTextfield();
1346 SendKeyEvent(ui::VKEY_A); 1346 SendKeyEvent(ui::VKEY_A);
1347 EXPECT_STR_EQ("a", textfield_->text()); 1347 EXPECT_STR_EQ("a", textfield_->text());
1348 SendKeyEvent(ui::VKEY_Z, false, true); 1348 SendKeyEvent(ui::VKEY_Z, false, true);
1349 EXPECT_STR_EQ("", textfield_->text()); 1349 EXPECT_STR_EQ("", textfield_->text());
1350 SendKeyEvent(ui::VKEY_Z, false, true); 1350 SendKeyEvent(ui::VKEY_Z, false, true);
1351 EXPECT_STR_EQ("", textfield_->text()); 1351 EXPECT_STR_EQ("", textfield_->text());
1352 SendKeyEvent(ui::VKEY_Y, false, true); 1352 SendKeyEvent(ui::VKEY_Z, true, true);
1353 EXPECT_STR_EQ("a", textfield_->text()); 1353 EXPECT_STR_EQ("a", textfield_->text());
1354 SendKeyEvent(ui::VKEY_Y, false, true); 1354 SendKeyEvent(ui::VKEY_Z, true, true);
1355 EXPECT_STR_EQ("a", textfield_->text()); 1355 EXPECT_STR_EQ("a", textfield_->text());
1356 1356
1357 // AppendText 1357 // AppendText
1358 textfield_->AppendText(ASCIIToUTF16("b")); 1358 textfield_->AppendText(ASCIIToUTF16("b"));
1359 last_contents_.clear(); // AppendText doesn't call ContentsChanged. 1359 last_contents_.clear(); // AppendText doesn't call ContentsChanged.
1360 EXPECT_STR_EQ("ab", textfield_->text()); 1360 EXPECT_STR_EQ("ab", textfield_->text());
1361 SendKeyEvent(ui::VKEY_Z, false, true); 1361 SendKeyEvent(ui::VKEY_Z, false, true);
1362 EXPECT_STR_EQ("a", textfield_->text()); 1362 EXPECT_STR_EQ("a", textfield_->text());
1363 SendKeyEvent(ui::VKEY_Y, false, true); 1363 SendKeyEvent(ui::VKEY_Z, true, true);
1364 EXPECT_STR_EQ("ab", textfield_->text()); 1364 EXPECT_STR_EQ("ab", textfield_->text());
1365 1365
1366 // SetText 1366 // SetText
1367 SendKeyEvent(ui::VKEY_C); 1367 SendKeyEvent(ui::VKEY_C);
1368 // Undo'ing append moves the cursor to the end for now. 1368 // 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. 1369 // A no-op SetText won't add a new edit; see TextfieldModel::SetText.
1370 EXPECT_STR_EQ("abc", textfield_->text()); 1370 EXPECT_STR_EQ("abc", textfield_->text());
1371 textfield_->SetText(ASCIIToUTF16("abc")); 1371 textfield_->SetText(ASCIIToUTF16("abc"));
1372 EXPECT_STR_EQ("abc", textfield_->text()); 1372 EXPECT_STR_EQ("abc", textfield_->text());
1373 SendKeyEvent(ui::VKEY_Z, false, true); 1373 SendKeyEvent(ui::VKEY_Z, false, true);
1374 EXPECT_STR_EQ("ab", textfield_->text()); 1374 EXPECT_STR_EQ("ab", textfield_->text());
1375 SendKeyEvent(ui::VKEY_Y, false, true); 1375 SendKeyEvent(ui::VKEY_Z, true, true);
1376 EXPECT_STR_EQ("abc", textfield_->text()); 1376 EXPECT_STR_EQ("abc", textfield_->text());
1377 SendKeyEvent(ui::VKEY_Y, false, true); 1377 SendKeyEvent(ui::VKEY_Z, true, true);
1378 EXPECT_STR_EQ("abc", textfield_->text()); 1378 EXPECT_STR_EQ("abc", textfield_->text());
1379 textfield_->SetText(ASCIIToUTF16("123")); 1379 textfield_->SetText(ASCIIToUTF16("123"));
1380 textfield_->SetText(ASCIIToUTF16("123")); 1380 textfield_->SetText(ASCIIToUTF16("123"));
1381 EXPECT_STR_EQ("123", textfield_->text()); 1381 EXPECT_STR_EQ("123", textfield_->text());
1382 SendKeyEvent(ui::VKEY_END, false, false); 1382 SendKeyEvent(ui::VKEY_END, false, false);
1383 SendKeyEvent(ui::VKEY_4, false, false); 1383 SendKeyEvent(ui::VKEY_4, false, false);
1384 EXPECT_STR_EQ("1234", textfield_->text()); 1384 EXPECT_STR_EQ("1234", textfield_->text());
1385 last_contents_.clear(); 1385 last_contents_.clear();
1386 SendKeyEvent(ui::VKEY_Z, false, true); 1386 SendKeyEvent(ui::VKEY_Z, false, true);
1387 EXPECT_STR_EQ("123", textfield_->text()); 1387 EXPECT_STR_EQ("123", textfield_->text());
1388 SendKeyEvent(ui::VKEY_Z, false, true); 1388 SendKeyEvent(ui::VKEY_Z, false, true);
1389 // the insert edit "c" and set edit "123" are merged to single edit, 1389 // the insert edit "c" and set edit "123" are merged to single edit,
1390 // so text becomes "ab" after undo. 1390 // so text becomes "ab" after undo.
1391 EXPECT_STR_EQ("ab", textfield_->text()); 1391 EXPECT_STR_EQ("ab", textfield_->text());
1392 SendKeyEvent(ui::VKEY_Z, false, true); 1392 SendKeyEvent(ui::VKEY_Z, false, true);
1393 EXPECT_STR_EQ("a", textfield_->text()); 1393 EXPECT_STR_EQ("a", textfield_->text());
1394 SendKeyEvent(ui::VKEY_Y, false, true); 1394 SendKeyEvent(ui::VKEY_Z, true, true);
1395 EXPECT_STR_EQ("ab", textfield_->text()); 1395 EXPECT_STR_EQ("ab", textfield_->text());
1396 SendKeyEvent(ui::VKEY_Y, false, true); 1396 SendKeyEvent(ui::VKEY_Z, true, true);
1397 EXPECT_STR_EQ("123", textfield_->text()); 1397 EXPECT_STR_EQ("123", textfield_->text());
1398 SendKeyEvent(ui::VKEY_Y, false, true); 1398 SendKeyEvent(ui::VKEY_Z, true, true);
1399 EXPECT_STR_EQ("1234", textfield_->text()); 1399 EXPECT_STR_EQ("1234", textfield_->text());
1400 1400
1401 // Undoing to the same text shouldn't call ContentsChanged. 1401 // Undoing to the same text shouldn't call ContentsChanged.
1402 SendKeyEvent(ui::VKEY_A, false, true); // select all 1402 SendKeyEvent(ui::VKEY_A, false, true); // select all
1403 SendKeyEvent(ui::VKEY_A); 1403 SendKeyEvent(ui::VKEY_A);
1404 EXPECT_STR_EQ("a", textfield_->text()); 1404 EXPECT_STR_EQ("a", textfield_->text());
1405 SendKeyEvent(ui::VKEY_B); 1405 SendKeyEvent(ui::VKEY_B);
1406 SendKeyEvent(ui::VKEY_C); 1406 SendKeyEvent(ui::VKEY_C);
1407 EXPECT_STR_EQ("abc", textfield_->text()); 1407 EXPECT_STR_EQ("abc", textfield_->text());
1408 SendKeyEvent(ui::VKEY_Z, false, true); 1408 SendKeyEvent(ui::VKEY_Z, false, true);
1409 EXPECT_STR_EQ("1234", textfield_->text()); 1409 EXPECT_STR_EQ("1234", textfield_->text());
1410 SendKeyEvent(ui::VKEY_Y, false, true); 1410 SendKeyEvent(ui::VKEY_Z, true, true);
1411 EXPECT_STR_EQ("abc", textfield_->text()); 1411 EXPECT_STR_EQ("abc", textfield_->text());
1412 1412
1413 // Delete/Backspace 1413 // Delete/Backspace
1414 SendKeyEvent(ui::VKEY_BACK); 1414 SendKeyEvent(ui::VKEY_BACK);
1415 EXPECT_STR_EQ("ab", textfield_->text()); 1415 EXPECT_STR_EQ("ab", textfield_->text());
1416 SendKeyEvent(ui::VKEY_HOME); 1416 SendHomeEvent(false);
1417 SendKeyEvent(ui::VKEY_DELETE); 1417 SendKeyEvent(ui::VKEY_DELETE);
1418 EXPECT_STR_EQ("b", textfield_->text()); 1418 EXPECT_STR_EQ("b", textfield_->text());
1419 SendKeyEvent(ui::VKEY_A, false, true); 1419 SendKeyEvent(ui::VKEY_A, false, true);
1420 SendKeyEvent(ui::VKEY_DELETE); 1420 SendKeyEvent(ui::VKEY_DELETE);
1421 EXPECT_STR_EQ("", textfield_->text()); 1421 EXPECT_STR_EQ("", textfield_->text());
1422 SendKeyEvent(ui::VKEY_Z, false, true); 1422 SendKeyEvent(ui::VKEY_Z, false, true);
1423 EXPECT_STR_EQ("b", textfield_->text()); 1423 EXPECT_STR_EQ("b", textfield_->text());
1424 SendKeyEvent(ui::VKEY_Z, false, true); 1424 SendKeyEvent(ui::VKEY_Z, false, true);
1425 EXPECT_STR_EQ("ab", textfield_->text()); 1425 EXPECT_STR_EQ("ab", textfield_->text());
1426 SendKeyEvent(ui::VKEY_Z, false, true); 1426 SendKeyEvent(ui::VKEY_Z, false, true);
1427 EXPECT_STR_EQ("abc", textfield_->text()); 1427 EXPECT_STR_EQ("abc", textfield_->text());
1428 SendKeyEvent(ui::VKEY_Y, false, true); 1428 SendKeyEvent(ui::VKEY_Z, true, true);
1429 EXPECT_STR_EQ("ab", textfield_->text()); 1429 EXPECT_STR_EQ("ab", textfield_->text());
1430 SendKeyEvent(ui::VKEY_Y, false, true); 1430 SendKeyEvent(ui::VKEY_Z, true, true);
1431 EXPECT_STR_EQ("b", textfield_->text()); 1431 EXPECT_STR_EQ("b", textfield_->text());
1432 SendKeyEvent(ui::VKEY_Y, false, true); 1432 SendKeyEvent(ui::VKEY_Z, true, true);
1433 EXPECT_STR_EQ("", textfield_->text());
1434 SendKeyEvent(ui::VKEY_Z, true, true);
1435 EXPECT_STR_EQ("", textfield_->text());
1436 }
1437
1438 // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac
1439 // that is bound to "Show full history", so is not mapped as an editing
1440 // command. So, on Mac, send Cmd+Shift+Z.
1441 #if !defined(OS_MACOSX)
1442
1443 // Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z.
1444 TEST_F(TextfieldTest, RedoWithCtrlY) {
1445 InitTextfield();
1446 SendKeyEvent(ui::VKEY_A);
1447 EXPECT_STR_EQ("a", textfield_->text());
1448 SendKeyEvent(ui::VKEY_Z, false, true);
1433 EXPECT_STR_EQ("", textfield_->text()); 1449 EXPECT_STR_EQ("", textfield_->text());
1434 SendKeyEvent(ui::VKEY_Y, false, true); 1450 SendKeyEvent(ui::VKEY_Y, false, true);
1451 EXPECT_STR_EQ("a", textfield_->text());
1452 SendKeyEvent(ui::VKEY_Z, false, true);
1435 EXPECT_STR_EQ("", textfield_->text()); 1453 EXPECT_STR_EQ("", textfield_->text());
1454 SendKeyEvent(ui::VKEY_Z, true, true);
1455 EXPECT_STR_EQ("a", textfield_->text());
1436 } 1456 }
1437 1457
1458 #endif // !defined(OS_MACOSX)
1459
1438 TEST_F(TextfieldTest, CutCopyPaste) { 1460 TEST_F(TextfieldTest, CutCopyPaste) {
1439 InitTextfield(); 1461 InitTextfield();
1440 1462
1441 // Ensure IDS_APP_CUT cuts. 1463 // Ensure IDS_APP_CUT cuts.
1442 textfield_->SetText(ASCIIToUTF16("123")); 1464 textfield_->SetText(ASCIIToUTF16("123"));
1443 textfield_->SelectAll(false); 1465 textfield_->SelectAll(false);
1444 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); 1466 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT));
1445 textfield_->ExecuteCommand(IDS_APP_CUT, 0); 1467 textfield_->ExecuteCommand(IDS_APP_CUT, 0);
1446 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); 1468 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
1447 EXPECT_STR_EQ("", textfield_->text()); 1469 EXPECT_STR_EQ("", textfield_->text());
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 2278
2257 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2279 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2258 ui::AXViewState state_protected; 2280 ui::AXViewState state_protected;
2259 textfield_->GetAccessibleState(&state_protected); 2281 textfield_->GetAccessibleState(&state_protected);
2260 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2282 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2261 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2283 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2262 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2284 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2263 } 2285 }
2264 2286
2265 } // namespace views 2287 } // namespace views
OLDNEW
« no previous file with comments | « 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