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

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: rerebase Created 9 years 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
OLDNEW
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
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
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
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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 EXPECT_TRUE(model.Undo()); 1505 EXPECT_TRUE(model.Undo());
1528 EXPECT_STR_EQ("ABCDE", model.GetText()); 1506 EXPECT_STR_EQ("ABCDE", model.GetText());
1529 EXPECT_TRUE(model.Redo()); 1507 EXPECT_TRUE(model.Redo());
1530 EXPECT_STR_EQ("1234", model.GetText()); 1508 EXPECT_STR_EQ("1234", model.GetText());
1531 EXPECT_FALSE(model.Redo()); 1509 EXPECT_FALSE(model.Redo());
1532 1510
1533 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1511 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1534 } 1512 }
1535 1513
1536 } // namespace views 1514 } // namespace views
OLDNEW
« ui/gfx/render_text_unittest.cc ('K') | « 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