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

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

Issue 8747001: Reintroduce password support to NativeTextfieldViews (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for dcommit Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/textfield/textfield_views_model.cc ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 ui::Clipboard* clipboard 495 ui::Clipboard* clipboard
496 = views::ViewsDelegate::views_delegate->GetClipboard(); 496 = views::ViewsDelegate::views_delegate->GetClipboard();
497 string16 initial_clipboard_text = ASCIIToUTF16("initial text"); 497 string16 initial_clipboard_text = ASCIIToUTF16("initial text");
498 ui::ScopedClipboardWriter( 498 ui::ScopedClipboardWriter(
499 clipboard, 499 clipboard,
500 ui::Clipboard::BUFFER_STANDARD).WriteText(initial_clipboard_text); 500 ui::Clipboard::BUFFER_STANDARD).WriteText(initial_clipboard_text);
501 501
502 string16 clipboard_text; 502 string16 clipboard_text;
503 TextfieldViewsModel model(NULL); 503 TextfieldViewsModel model(NULL);
504 model.Append(ASCIIToUTF16("HELLO WORLD")); 504 model.Append(ASCIIToUTF16("HELLO WORLD"));
505
506 // Cut with an empty selection should do nothing.
505 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 507 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
506
507 // Test for cut: Empty selection.
508 EXPECT_FALSE(model.Cut()); 508 EXPECT_FALSE(model.Cut());
509 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 509 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
510 EXPECT_STR_EQ(UTF16ToUTF8(initial_clipboard_text), clipboard_text); 510 EXPECT_EQ(initial_clipboard_text, clipboard_text);
511 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); 511 EXPECT_STR_EQ("HELLO WORLD", model.GetText());
512 EXPECT_EQ(11U, model.GetCursorPosition()); 512 EXPECT_EQ(11U, model.GetCursorPosition());
513 513
514 // Test for cut: Non-empty selection. 514 // Copy with an empty selection should do nothing.
515 model.Copy();
516 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
517 EXPECT_EQ(initial_clipboard_text, clipboard_text);
518 EXPECT_STR_EQ("HELLO WORLD", model.GetText());
519 EXPECT_EQ(11U, model.GetCursorPosition());
520
521 // Cut on obscured (password) text should do nothing.
522 model.render_text()->SetObscured(true);
523 model.SelectAll();
524 EXPECT_FALSE(model.Cut());
525 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
526 EXPECT_EQ(initial_clipboard_text, clipboard_text);
527 EXPECT_STR_EQ("HELLO WORLD", model.GetText());
528 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText());
529
530 // Copy on obscured text should do nothing.
531 model.SelectAll();
532 EXPECT_FALSE(model.Copy());
533 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
534 EXPECT_EQ(initial_clipboard_text, clipboard_text);
535 EXPECT_STR_EQ("HELLO WORLD", model.GetText());
536 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText());
537
538 // Cut with non-empty selection.
539 model.render_text()->SetObscured(false);
540 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
515 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 541 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
516 EXPECT_TRUE(model.Cut()); 542 EXPECT_TRUE(model.Cut());
517 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 543 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
518 EXPECT_STR_EQ("WORLD", clipboard_text); 544 EXPECT_STR_EQ("WORLD", clipboard_text);
519 EXPECT_STR_EQ("HELLO ", model.GetText()); 545 EXPECT_STR_EQ("HELLO ", model.GetText());
520 EXPECT_EQ(6U, model.GetCursorPosition()); 546 EXPECT_EQ(6U, model.GetCursorPosition());
521 547
522 // Test for copy: Empty selection. 548 // Copy with non-empty selection.
523 model.Copy();
524 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
525 EXPECT_STR_EQ("WORLD", clipboard_text);
526 EXPECT_STR_EQ("HELLO ", model.GetText());
527 EXPECT_EQ(6U, model.GetCursorPosition());
528
529 // Test for copy: Non-empty selection.
530 model.Append(ASCIIToUTF16("HELLO WORLD")); 549 model.Append(ASCIIToUTF16("HELLO WORLD"));
531 model.SelectAll(); 550 model.SelectAll();
532 model.Copy(); 551 model.Copy();
533 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 552 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
534 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); 553 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
535 EXPECT_STR_EQ("HELLO HELLO WORLD", model.GetText()); 554 EXPECT_STR_EQ("HELLO HELLO WORLD", model.GetText());
536 EXPECT_EQ(17U, model.GetCursorPosition()); 555 EXPECT_EQ(17U, model.GetCursorPosition());
537 556
538 // Test for paste. 557 // Test for paste.
539 model.ClearSelection(); 558 model.ClearSelection();
540 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 559 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
541 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 560 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
542 EXPECT_TRUE(model.Paste()); 561 EXPECT_TRUE(model.Paste());
543 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 562 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
544 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); 563 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
545 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); 564 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText());
546 EXPECT_EQ(29U, model.GetCursorPosition()); 565 EXPECT_EQ(29U, model.GetCursorPosition());
566
567 // Paste ignores the obscured bit.
568 model.render_text()->SetObscured(true);
569 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
570 ui::ScopedClipboardWriter(
571 clipboard,
572 ui::Clipboard::BUFFER_STANDARD).WriteText(initial_clipboard_text);
573 EXPECT_TRUE(model.Paste());
574 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
575 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO initial text", model.GetText());
547 } 576 }
548 577
549 static void SelectWordTestVerifier(const TextfieldViewsModel& model, 578 static void SelectWordTestVerifier(const TextfieldViewsModel& model,
550 const string16 &expected_selected_string, size_t expected_cursor_pos) { 579 const string16 &expected_selected_string, size_t expected_cursor_pos) {
551 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); 580 EXPECT_EQ(expected_selected_string, model.GetSelectedText());
552 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); 581 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition());
553 } 582 }
554 583
555 TEST_F(TextfieldViewsModelTest, SelectWordTest) { 584 TEST_F(TextfieldViewsModelTest, SelectWordTest) {
556 TextfieldViewsModel model(NULL); 585 TextfieldViewsModel model(NULL);
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 EXPECT_TRUE(model.Undo()); 1558 EXPECT_TRUE(model.Undo());
1530 EXPECT_STR_EQ("ABCDE", model.GetText()); 1559 EXPECT_STR_EQ("ABCDE", model.GetText());
1531 EXPECT_TRUE(model.Redo()); 1560 EXPECT_TRUE(model.Redo());
1532 EXPECT_STR_EQ("1234", model.GetText()); 1561 EXPECT_STR_EQ("1234", model.GetText());
1533 EXPECT_FALSE(model.Redo()); 1562 EXPECT_FALSE(model.Redo());
1534 1563
1535 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1564 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1536 } 1565 }
1537 1566
1538 } // namespace views 1567 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield_views_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698