| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 SendKeyEvent(ui::VKEY_1, true, false, true); | 288 SendKeyEvent(ui::VKEY_1, true, false, true); |
| 289 SendKeyEvent(ui::VKEY_1, true, false, false); | 289 SendKeyEvent(ui::VKEY_1, true, false, false); |
| 290 EXPECT_STR_EQ("cC1!!", textfield_->text()); | 290 EXPECT_STR_EQ("cC1!!", textfield_->text()); |
| 291 EXPECT_STR_EQ("cC1!!", last_contents_); | 291 EXPECT_STR_EQ("cC1!!", last_contents_); |
| 292 } | 292 } |
| 293 | 293 |
| 294 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { | 294 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { |
| 295 // Insert a test string in a textfield. | 295 // Insert a test string in a textfield. |
| 296 InitTextfield(Textfield::STYLE_DEFAULT); | 296 InitTextfield(Textfield::STYLE_DEFAULT); |
| 297 textfield_->SetText(ASCIIToUTF16("one two three")); | 297 textfield_->SetText(ASCIIToUTF16("one two three")); |
| 298 SendKeyEvent(ui::VKEY_RIGHT, | 298 SendKeyEvent(ui::VKEY_RIGHT, true /* shift */, false /* control */); |
| 299 true /* shift */, false /* control */); | |
| 300 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 299 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 301 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 300 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 302 | 301 |
| 302 #if defined(OS_WIN) |
| 303 // TODO(msw): Revise word break algorithms and improve tests. |
| 304 // Advance past the space to avoid the word break at "one |two three". |
| 305 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 306 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); |
| 307 #else |
| 303 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 308 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
| 309 #endif |
| 304 | 310 |
| 305 // Test word select. | 311 // Test word select. |
| 306 SendKeyEvent(ui::VKEY_RIGHT, true, true); | 312 SendKeyEvent(ui::VKEY_RIGHT, true, true); |
| 313 #if defined(OS_WIN) |
| 314 // TODO(msw): Revise word break algorithms and improve tests. |
| 315 // The current breaks are at "|one |two |three|". |
| 316 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); |
| 317 #else |
| 307 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); | 318 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); |
| 319 #endif |
| 308 SendKeyEvent(ui::VKEY_RIGHT, true, true); | 320 SendKeyEvent(ui::VKEY_RIGHT, true, true); |
| 309 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); | 321 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); |
| 310 SendKeyEvent(ui::VKEY_LEFT, true, true); | 322 SendKeyEvent(ui::VKEY_LEFT, true, true); |
| 311 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); | 323 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); |
| 312 SendKeyEvent(ui::VKEY_LEFT, true, true); | 324 SendKeyEvent(ui::VKEY_LEFT, true, true); |
| 313 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); | 325 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); |
| 314 | 326 |
| 315 // Replace the selected text. | 327 // Replace the selected text. |
| 316 SendKeyEvent(ui::VKEY_Z, true, false); | 328 SendKeyEvent(ui::VKEY_Z, true, false); |
| 317 SendKeyEvent(ui::VKEY_E, true, false); | 329 SendKeyEvent(ui::VKEY_E, true, false); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 #if defined(OS_WIN) | 387 #if defined(OS_WIN) |
| 376 EXPECT_STR_EQ("one two three ", textfield_->text()); | 388 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 377 #else | 389 #else |
| 378 EXPECT_STR_EQ("three ", textfield_->text()); | 390 EXPECT_STR_EQ("three ", textfield_->text()); |
| 379 #endif | 391 #endif |
| 380 | 392 |
| 381 // Delete the next word from cursor. | 393 // Delete the next word from cursor. |
| 382 textfield_->SetText(ASCIIToUTF16("one two three four")); | 394 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 383 SendKeyEvent(ui::VKEY_HOME); | 395 SendKeyEvent(ui::VKEY_HOME); |
| 384 SendKeyEvent(ui::VKEY_DELETE, false, true, false); | 396 SendKeyEvent(ui::VKEY_DELETE, false, true, false); |
| 397 #if defined(OS_WIN) |
| 398 // TODO(msw): Revise word break algorithms and improve tests. |
| 399 // The current word breaks are at "|one |two |three |four|". |
| 400 EXPECT_STR_EQ("two three four", textfield_->text()); |
| 401 #else |
| 385 EXPECT_STR_EQ(" two three four", textfield_->text()); | 402 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 403 #endif |
| 386 | 404 |
| 387 // Delete upto the end of the buffer from cursor in chromeos, do nothing | 405 // Delete upto the end of the buffer from cursor in chromeos, do nothing |
| 388 // in windows. | 406 // in windows. |
| 389 SendKeyEvent(ui::VKEY_RIGHT, false, true, false); | 407 SendKeyEvent(ui::VKEY_RIGHT, false, true, false); |
| 390 SendKeyEvent(ui::VKEY_DELETE, true, true, false); | 408 SendKeyEvent(ui::VKEY_DELETE, true, true, false); |
| 391 #if defined(OS_WIN) | 409 #if defined(OS_WIN) |
| 392 EXPECT_STR_EQ(" two three four", textfield_->text()); | 410 EXPECT_STR_EQ("two three four", textfield_->text()); |
| 393 #else | 411 #else |
| 394 EXPECT_STR_EQ(" two", textfield_->text()); | 412 EXPECT_STR_EQ(" two", textfield_->text()); |
| 395 #endif | 413 #endif |
| 396 } | 414 } |
| 397 | 415 |
| 398 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 416 TEST_F(NativeTextfieldViewsTest, PasswordTest) { |
| 399 InitTextfield(Textfield::STYLE_PASSWORD); | 417 InitTextfield(Textfield::STYLE_PASSWORD); |
| 400 | 418 |
| 401 last_contents_.clear(); | 419 last_contents_.clear(); |
| 402 textfield_->SetText(ASCIIToUTF16("my password")); | 420 textfield_->SetText(ASCIIToUTF16("my password")); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 SendKeyEvent(ui::VKEY_END); | 465 SendKeyEvent(ui::VKEY_END); |
| 448 | 466 |
| 449 // Ctrl+Left should move the cursor just before the last word. | 467 // Ctrl+Left should move the cursor just before the last word. |
| 450 SendKeyEvent(ui::VKEY_LEFT, false, true); | 468 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 451 SendKeyEvent(ui::VKEY_T); | 469 SendKeyEvent(ui::VKEY_T); |
| 452 EXPECT_STR_EQ("one two thre ", textfield_->text()); | 470 EXPECT_STR_EQ("one two thre ", textfield_->text()); |
| 453 EXPECT_STR_EQ("one two thre ", last_contents_); | 471 EXPECT_STR_EQ("one two thre ", last_contents_); |
| 454 | 472 |
| 455 // Ctrl+Right should move the cursor to the end of the last word. | 473 // Ctrl+Right should move the cursor to the end of the last word. |
| 456 SendKeyEvent(ui::VKEY_RIGHT, false, true); | 474 SendKeyEvent(ui::VKEY_RIGHT, false, true); |
| 475 #if defined(OS_WIN) |
| 476 // TODO(msw): Revise word break algorithms and improve tests. |
| 477 // Move the cursor left one space; the breaks are at "|one |two |thre |". |
| 478 SendKeyEvent(ui::VKEY_LEFT, false, false); |
| 479 #endif |
| 457 SendKeyEvent(ui::VKEY_E); | 480 SendKeyEvent(ui::VKEY_E); |
| 458 EXPECT_STR_EQ("one two three ", textfield_->text()); | 481 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 459 EXPECT_STR_EQ("one two three ", last_contents_); | 482 EXPECT_STR_EQ("one two three ", last_contents_); |
| 460 | 483 |
| 461 // Ctrl+Right again should move the cursor to the end. | 484 // Ctrl+Right again should move the cursor to the end. |
| 462 SendKeyEvent(ui::VKEY_RIGHT, false, true); | 485 SendKeyEvent(ui::VKEY_RIGHT, false, true); |
| 463 SendKeyEvent(ui::VKEY_BACK); | 486 SendKeyEvent(ui::VKEY_BACK); |
| 464 EXPECT_STR_EQ("one two three", textfield_->text()); | 487 EXPECT_STR_EQ("one two three", textfield_->text()); |
| 465 EXPECT_STR_EQ("one two three", last_contents_); | 488 EXPECT_STR_EQ("one two three", last_contents_); |
| 466 | 489 |
| 467 // Test with leading whitespace. | 490 // Test with leading whitespace. |
| 468 textfield_->SetText(ASCIIToUTF16(" ne two")); | 491 textfield_->SetText(ASCIIToUTF16(" ne two")); |
| 469 | 492 |
| 470 // Send the cursor at the beginning. | 493 // Send the cursor at the beginning. |
| 471 SendKeyEvent(ui::VKEY_HOME); | 494 SendKeyEvent(ui::VKEY_HOME); |
| 472 | 495 |
| 473 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the | 496 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the |
| 474 // first word. | 497 // first word. |
| 475 SendKeyEvent(ui::VKEY_RIGHT, false, true); | 498 SendKeyEvent(ui::VKEY_RIGHT, false, true); |
| 499 #if defined(OS_WIN) |
| 500 // TODO(msw): Revise word break algorithms and improve tests. |
| 501 // Move right past the word. The current word breaks are at "| |one |two|". |
| 502 SendKeyEvent(ui::VKEY_RIGHT, false, true); |
| 503 #endif |
| 476 SendKeyEvent(ui::VKEY_LEFT, false, true); | 504 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 477 SendKeyEvent(ui::VKEY_O); | 505 SendKeyEvent(ui::VKEY_O); |
| 478 EXPECT_STR_EQ(" one two", textfield_->text()); | 506 EXPECT_STR_EQ(" one two", textfield_->text()); |
| 479 EXPECT_STR_EQ(" one two", last_contents_); | 507 EXPECT_STR_EQ(" one two", last_contents_); |
| 480 | 508 |
| 481 // Ctrl+Left to move the cursor to the beginning of the first word. | 509 // Ctrl+Left to move the cursor to the beginning of the first word. |
| 482 SendKeyEvent(ui::VKEY_LEFT, false, true); | 510 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 483 // Ctrl+Left again should move the cursor back to the very beginning. | 511 // Ctrl+Left again should move the cursor back to the very beginning. |
| 484 SendKeyEvent(ui::VKEY_LEFT, false, true); | 512 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 485 SendKeyEvent(ui::VKEY_DELETE); | 513 SendKeyEvent(ui::VKEY_DELETE); |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 EXPECT_STR_EQ("a23", textfield_->text()); | 1106 EXPECT_STR_EQ("a23", textfield_->text()); |
| 1079 SendKeyEvent(ui::VKEY_B); | 1107 SendKeyEvent(ui::VKEY_B); |
| 1080 EXPECT_STR_EQ("ab3", textfield_->text()); | 1108 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1081 SendKeyEvent(ui::VKEY_Z, false, true); | 1109 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1082 EXPECT_STR_EQ("123", textfield_->text()); | 1110 EXPECT_STR_EQ("123", textfield_->text()); |
| 1083 SendKeyEvent(ui::VKEY_Y, false, true); | 1111 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1084 EXPECT_STR_EQ("ab3", textfield_->text()); | 1112 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1085 } | 1113 } |
| 1086 | 1114 |
| 1087 } // namespace views | 1115 } // namespace views |
| OLD | NEW |