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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 #endif | 237 #endif |
238 EXPECT_TRUE(model.Backspace()); | 238 EXPECT_TRUE(model.Backspace()); |
239 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), | 239 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), |
240 model.GetText()); | 240 model.GetText()); |
241 } | 241 } |
242 | 242 |
243 TEST_F(TextfieldViewsModelTest, EmptyString) { | 243 TEST_F(TextfieldViewsModelTest, EmptyString) { |
244 TextfieldViewsModel model(NULL); | 244 TextfieldViewsModel model(NULL); |
245 EXPECT_EQ(string16(), model.GetText()); | 245 EXPECT_EQ(string16(), model.GetText()); |
246 EXPECT_EQ(string16(), model.GetSelectedText()); | 246 EXPECT_EQ(string16(), model.GetSelectedText()); |
247 EXPECT_EQ(string16(), model.GetVisibleText()); | |
248 | 247 |
249 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | 248 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
250 EXPECT_EQ(0U, model.GetCursorPosition()); | 249 EXPECT_EQ(0U, model.GetCursorPosition()); |
251 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | 250 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
252 EXPECT_EQ(0U, model.GetCursorPosition()); | 251 EXPECT_EQ(0U, model.GetCursorPosition()); |
253 | 252 |
254 EXPECT_EQ(string16(), model.GetSelectedText()); | 253 EXPECT_EQ(string16(), model.GetSelectedText()); |
255 | 254 |
256 EXPECT_FALSE(model.Delete()); | 255 EXPECT_FALSE(model.Delete()); |
257 EXPECT_FALSE(model.Backspace()); | 256 EXPECT_FALSE(model.Backspace()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); // select "H" | 406 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); // select "H" |
408 model.ReplaceChar('B'); | 407 model.ReplaceChar('B'); |
409 EXPECT_STR_EQ("BELL", model.GetText()); | 408 EXPECT_STR_EQ("BELL", model.GetText()); |
410 model.MoveCursorRight(gfx::LINE_BREAK, false); | 409 model.MoveCursorRight(gfx::LINE_BREAK, false); |
411 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | 410 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
412 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); // select "ELL" | 411 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); // select "ELL" |
413 model.ReplaceChar('E'); | 412 model.ReplaceChar('E'); |
414 EXPECT_STR_EQ("BEE", model.GetText()); | 413 EXPECT_STR_EQ("BEE", model.GetText()); |
415 } | 414 } |
416 | 415 |
417 TEST_F(TextfieldViewsModelTest, Password) { | |
418 TextfieldViewsModel model(NULL); | |
419 model.set_is_password(true); | |
420 model.Append(ASCIIToUTF16("HELLO")); | |
421 EXPECT_STR_EQ("*****", model.GetVisibleText()); | |
422 EXPECT_STR_EQ("HELLO", model.GetText()); | |
423 EXPECT_TRUE(model.Delete()); | |
424 | |
425 EXPECT_STR_EQ("****", model.GetVisibleText()); | |
426 EXPECT_STR_EQ("ELLO", model.GetText()); | |
427 EXPECT_EQ(0U, model.GetCursorPosition()); | |
428 | |
429 model.SelectAll(); | |
430 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); | |
431 EXPECT_EQ(4U, model.GetCursorPosition()); | |
432 | |
433 model.InsertChar('X'); | |
434 EXPECT_STR_EQ("*", model.GetVisibleText()); | |
435 EXPECT_STR_EQ("X", model.GetText()); | |
436 } | |
437 | |
438 TEST_F(TextfieldViewsModelTest, Word) { | 416 TEST_F(TextfieldViewsModelTest, Word) { |
439 TextfieldViewsModel model(NULL); | 417 TextfieldViewsModel model(NULL); |
440 model.Append( | 418 model.Append( |
441 ASCIIToUTF16("The answer to Life, the Universe, and Everything")); | 419 ASCIIToUTF16("The answer to Life, the Universe, and Everything")); |
442 model.MoveCursorRight(gfx::WORD_BREAK, false); | 420 model.MoveCursorRight(gfx::WORD_BREAK, false); |
443 EXPECT_EQ(3U, model.GetCursorPosition()); | 421 EXPECT_EQ(3U, model.GetCursorPosition()); |
444 model.MoveCursorRight(gfx::WORD_BREAK, false); | 422 model.MoveCursorRight(gfx::WORD_BREAK, false); |
445 EXPECT_EQ(10U, model.GetCursorPosition()); | 423 EXPECT_EQ(10U, model.GetCursorPosition()); |
446 model.MoveCursorRight(gfx::WORD_BREAK, false); | 424 model.MoveCursorRight(gfx::WORD_BREAK, false); |
447 model.MoveCursorRight(gfx::WORD_BREAK, false); | 425 model.MoveCursorRight(gfx::WORD_BREAK, false); |
(...skipping 24 matching lines...) Expand all Loading... | |
472 EXPECT_STR_EQ("to Life", model.GetSelectedText()); | 450 EXPECT_STR_EQ("to Life", model.GetSelectedText()); |
473 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 451 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
474 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 452 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
475 model.MoveCursorLeft(gfx::WORD_BREAK, true); // Select to the begining. | 453 model.MoveCursorLeft(gfx::WORD_BREAK, true); // Select to the begining. |
476 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); | 454 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); |
477 // Should be safe to go pervious word at the begining. | 455 // Should be safe to go pervious word at the begining. |
478 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 456 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
479 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); | 457 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); |
480 model.ReplaceChar('4'); | 458 model.ReplaceChar('4'); |
481 EXPECT_EQ(string16(), model.GetSelectedText()); | 459 EXPECT_EQ(string16(), model.GetSelectedText()); |
482 EXPECT_STR_EQ("42", model.GetVisibleText()); | 460 EXPECT_STR_EQ("42", model.GetText()); |
483 } | 461 } |
484 | 462 |
485 TEST_F(TextfieldViewsModelTest, SetText) { | 463 TEST_F(TextfieldViewsModelTest, SetText) { |
486 TextfieldViewsModel model(NULL); | 464 TextfieldViewsModel model(NULL); |
487 model.Append(ASCIIToUTF16("HELLO")); | 465 model.Append(ASCIIToUTF16("HELLO")); |
488 model.MoveCursorRight(gfx::LINE_BREAK, false); | 466 model.MoveCursorRight(gfx::LINE_BREAK, false); |
489 model.SetText(ASCIIToUTF16("GOODBYE")); | 467 model.SetText(ASCIIToUTF16("GOODBYE")); |
490 EXPECT_STR_EQ("GOODBYE", model.GetText()); | 468 EXPECT_STR_EQ("GOODBYE", model.GetText()); |
491 // SetText won't reset the cursor posistion. | 469 // SetText won't reset the cursor posistion. |
492 EXPECT_EQ(5U, model.GetCursorPosition()); | 470 EXPECT_EQ(5U, model.GetCursorPosition()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 EXPECT_EQ(11U, model.GetCursorPosition()); | 505 EXPECT_EQ(11U, model.GetCursorPosition()); |
528 | 506 |
529 // Test for cut: Non-empty selection. | 507 // Test for cut: Non-empty selection. |
530 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 508 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
531 EXPECT_TRUE(model.Cut()); | 509 EXPECT_TRUE(model.Cut()); |
532 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 510 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
533 EXPECT_STR_EQ("WORLD", clipboard_text); | 511 EXPECT_STR_EQ("WORLD", clipboard_text); |
534 EXPECT_STR_EQ("HELLO ", model.GetText()); | 512 EXPECT_STR_EQ("HELLO ", model.GetText()); |
535 EXPECT_EQ(6U, model.GetCursorPosition()); | 513 EXPECT_EQ(6U, model.GetCursorPosition()); |
536 | 514 |
515 // Test for cut: Password field. | |
516 model.render_text()->SetIsPassword(true); | |
517 model.SelectAll(); | |
518 EXPECT_FALSE(model.Cut()); | |
519 model.MoveCursorRight(gfx::WORD_BREAK, false); | |
msw
2011/12/03 00:22:40
Do we care to test the cursor movement in a passwo
benrg
2011/12/08 21:40:55
Presumably yes, but not until it works.
| |
520 model.render_text()->SetIsPassword(false); | |
521 | |
537 // Test for copy: Empty selection. | 522 // Test for copy: Empty selection. |
538 model.Copy(); | 523 model.Copy(); |
539 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 524 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
540 EXPECT_STR_EQ("WORLD", clipboard_text); | 525 EXPECT_STR_EQ("WORLD", clipboard_text); |
541 EXPECT_STR_EQ("HELLO ", model.GetText()); | 526 EXPECT_STR_EQ("HELLO ", model.GetText()); |
542 EXPECT_EQ(6U, model.GetCursorPosition()); | 527 EXPECT_EQ(6U, model.GetCursorPosition()); |
543 | 528 |
544 // Test for copy: Non-empty selection. | 529 // Test for copy: Non-empty selection. |
545 model.Append(ASCIIToUTF16("HELLO WORLD")); | 530 model.Append(ASCIIToUTF16("HELLO WORLD")); |
546 model.SelectAll(); | 531 model.SelectAll(); |
547 model.Copy(); | 532 model.Copy(); |
548 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 533 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
549 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 534 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
550 EXPECT_STR_EQ("HELLO HELLO WORLD", model.GetText()); | 535 EXPECT_STR_EQ("HELLO HELLO WORLD", model.GetText()); |
551 EXPECT_EQ(17U, model.GetCursorPosition()); | 536 EXPECT_EQ(17U, model.GetCursorPosition()); |
552 | 537 |
553 // Test for paste. | 538 // Test for copy: Password field. |
539 model.render_text()->SetIsPassword(true); | |
540 model.MoveCursorLeft(gfx::WORD_BREAK, true); | |
541 model.Copy(); | |
542 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | |
543 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | |
msw
2011/12/03 00:22:40
Shouldn't this fail? Why is the password text copi
benrg
2011/12/06 17:21:30
That was the text left in the clipboard from the p
| |
544 | |
545 // Test for paste (should ignore password bit). | |
554 model.ClearSelection(); | 546 model.ClearSelection(); |
555 model.MoveCursorRight(gfx::LINE_BREAK, false); | 547 model.MoveCursorRight(gfx::LINE_BREAK, false); |
556 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 548 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
557 EXPECT_TRUE(model.Paste()); | 549 EXPECT_TRUE(model.Paste()); |
558 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 550 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
559 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 551 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
560 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); | 552 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); |
561 EXPECT_EQ(29U, model.GetCursorPosition()); | 553 EXPECT_EQ(29U, model.GetCursorPosition()); |
562 } | 554 } |
563 | 555 |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1527 EXPECT_TRUE(model.Undo()); | 1519 EXPECT_TRUE(model.Undo()); |
1528 EXPECT_STR_EQ("ABCDE", model.GetText()); | 1520 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1529 EXPECT_TRUE(model.Redo()); | 1521 EXPECT_TRUE(model.Redo()); |
1530 EXPECT_STR_EQ("1234", model.GetText()); | 1522 EXPECT_STR_EQ("1234", model.GetText()); |
1531 EXPECT_FALSE(model.Redo()); | 1523 EXPECT_FALSE(model.Redo()); |
1532 | 1524 |
1533 // TODO(oshima): We need MockInputMethod to test the behavior with IME. | 1525 // TODO(oshima): We need MockInputMethod to test the behavior with IME. |
1534 } | 1526 } |
1535 | 1527 |
1536 } // namespace views | 1528 } // namespace views |
OLD | NEW |