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

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

Issue 10693160: Add and specify Views::Textfield::SelectAll |reversed| flag, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove redundant comments. Created 8 years, 5 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
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 EXPECT_STR_EQ("this is", model_->GetText()); 345 EXPECT_STR_EQ("this is", model_->GetText());
346 EXPECT_STR_EQ("this is", textfield_->text()); 346 EXPECT_STR_EQ("this is", textfield_->text());
347 EXPECT_TRUE(last_contents_.empty()); 347 EXPECT_TRUE(last_contents_.empty());
348 348
349 textfield_->AppendText(ASCIIToUTF16(" a test")); 349 textfield_->AppendText(ASCIIToUTF16(" a test"));
350 EXPECT_STR_EQ("this is a test", model_->GetText()); 350 EXPECT_STR_EQ("this is a test", model_->GetText());
351 EXPECT_STR_EQ("this is a test", textfield_->text()); 351 EXPECT_STR_EQ("this is a test", textfield_->text());
352 EXPECT_TRUE(last_contents_.empty()); 352 EXPECT_TRUE(last_contents_.empty());
353 353
354 EXPECT_EQ(string16(), textfield_->GetSelectedText()); 354 EXPECT_EQ(string16(), textfield_->GetSelectedText());
355 textfield_->SelectAll(); 355 textfield_->SelectAll(false);
356 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); 356 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText());
357 EXPECT_TRUE(last_contents_.empty()); 357 EXPECT_TRUE(last_contents_.empty());
358 } 358 }
359 359
360 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) { 360 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) {
361 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. 361 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE.
362 InitTextfield(Textfield::STYLE_LOWERCASE); 362 InitTextfield(Textfield::STYLE_LOWERCASE);
363 EXPECT_EQ(0U, textfield_->GetCursorPosition()); 363 EXPECT_EQ(0U, textfield_->GetCursorPosition());
364 364
365 last_contents_.clear(); 365 last_contents_.clear();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 SendKeyEvent(ui::VKEY_BACK); 516 SendKeyEvent(ui::VKEY_BACK);
517 EXPECT_STR_EQ("this is test", textfield_->text()); 517 EXPECT_STR_EQ("this is test", textfield_->text());
518 518
519 // Delete using delete key and check resulting string. 519 // Delete using delete key and check resulting string.
520 for (int i = 0; i < 5; i++) { 520 for (int i = 0; i < 5; i++) {
521 SendKeyEvent(ui::VKEY_DELETE); 521 SendKeyEvent(ui::VKEY_DELETE);
522 } 522 }
523 EXPECT_STR_EQ("this is ", textfield_->text()); 523 EXPECT_STR_EQ("this is ", textfield_->text());
524 524
525 // Select all and replace with "k". 525 // Select all and replace with "k".
526 textfield_->SelectAll(); 526 textfield_->SelectAll(false);
527 SendKeyEvent(ui::VKEY_K); 527 SendKeyEvent(ui::VKEY_K);
528 EXPECT_STR_EQ("k", textfield_->text()); 528 EXPECT_STR_EQ("k", textfield_->text());
529 529
530 // Delete the previous word from cursor. 530 // Delete the previous word from cursor.
531 textfield_->SetText(ASCIIToUTF16("one two three four")); 531 textfield_->SetText(ASCIIToUTF16("one two three four"));
532 SendKeyEvent(ui::VKEY_END); 532 SendKeyEvent(ui::VKEY_END);
533 SendKeyEvent(ui::VKEY_BACK, false, true, false); 533 SendKeyEvent(ui::VKEY_BACK, false, true, false);
534 EXPECT_STR_EQ("one two three ", textfield_->text()); 534 EXPECT_STR_EQ("one two three ", textfield_->text());
535 535
536 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing 536 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing
(...skipping 29 matching lines...) Expand all
566 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); 566 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
567 567
568 last_contents_.clear(); 568 last_contents_.clear();
569 textfield_->SetText(ASCIIToUTF16("my password")); 569 textfield_->SetText(ASCIIToUTF16("my password"));
570 // Just to make sure the text() and callback returns 570 // Just to make sure the text() and callback returns
571 // the actual text instead of "*". 571 // the actual text instead of "*".
572 EXPECT_STR_EQ("my password", textfield_->text()); 572 EXPECT_STR_EQ("my password", textfield_->text());
573 EXPECT_TRUE(last_contents_.empty()); 573 EXPECT_TRUE(last_contents_.empty());
574 574
575 // Cut and copy should be disabled in the context menu. 575 // Cut and copy should be disabled in the context menu.
576 model_->SelectAll(); 576 model_->SelectAll(false);
577 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_CUT)); 577 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_CUT));
578 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_COPY)); 578 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_COPY));
579 579
580 // Cut and copy keyboard shortcuts and menu commands should do nothing. 580 // Cut and copy keyboard shortcuts and menu commands should do nothing.
581 SetClipboardText("foo"); 581 SetClipboardText("foo");
582 SendKeyEvent(ui::VKEY_C, false, true); 582 SendKeyEvent(ui::VKEY_C, false, true);
583 SendKeyEvent(ui::VKEY_X, false, true); 583 SendKeyEvent(ui::VKEY_X, false, true);
584 ExecuteCommand(IDS_APP_COPY); 584 ExecuteCommand(IDS_APP_COPY);
585 ExecuteCommand(IDS_APP_CUT); 585 ExecuteCommand(IDS_APP_CUT);
586 EXPECT_STR_EQ("foo", string16(GetClipboardText())); 586 EXPECT_STR_EQ("foo", string16(GetClipboardText()));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 textfield_view_->OnMousePressed(click); 749 textfield_view_->OnMousePressed(click);
750 EXPECT_EQ(1, GetFocusedView()->id()); 750 EXPECT_EQ(1, GetFocusedView()->id());
751 } 751 }
752 752
753 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { 753 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) {
754 InitTextfield(Textfield::STYLE_DEFAULT); 754 InitTextfield(Textfield::STYLE_DEFAULT);
755 textfield_->SetText(ASCIIToUTF16("hello world")); 755 textfield_->SetText(ASCIIToUTF16("hello world"));
756 EXPECT_TRUE(GetContextMenuModel()); 756 EXPECT_TRUE(GetContextMenuModel());
757 VerifyTextfieldContextMenuContents(false, GetContextMenuModel()); 757 VerifyTextfieldContextMenuContents(false, GetContextMenuModel());
758 758
759 textfield_->SelectAll(); 759 textfield_->SelectAll(false);
760 VerifyTextfieldContextMenuContents(true, GetContextMenuModel()); 760 VerifyTextfieldContextMenuContents(true, GetContextMenuModel());
761 } 761 }
762 762
763 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { 763 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) {
764 InitTextfield(Textfield::STYLE_DEFAULT); 764 InitTextfield(Textfield::STYLE_DEFAULT);
765 textfield_->SetText(ASCIIToUTF16("hello world")); 765 textfield_->SetText(ASCIIToUTF16("hello world"));
766 MouseEvent click(ui::ET_MOUSE_PRESSED, 0, 0, ui::EF_LEFT_MOUSE_BUTTON); 766 MouseEvent click(ui::ET_MOUSE_PRESSED, 0, 0, ui::EF_LEFT_MOUSE_BUTTON);
767 MouseEvent release(ui::ET_MOUSE_RELEASED, 0, 0, ui::EF_LEFT_MOUSE_BUTTON); 767 MouseEvent release(ui::ET_MOUSE_RELEASED, 0, 0, ui::EF_LEFT_MOUSE_BUTTON);
768 MouseEvent double_click(ui::ET_MOUSE_PRESSED, 0, 0, 768 MouseEvent double_click(ui::ET_MOUSE_PRESSED, 0, 0,
769 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK); 769 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 SendKeyEvent(ui::VKEY_LEFT, false, false); 1068 SendKeyEvent(ui::VKEY_LEFT, false, false);
1069 EXPECT_EQ(14U, textfield_->GetCursorPosition()); 1069 EXPECT_EQ(14U, textfield_->GetCursorPosition());
1070 1070
1071 SendKeyEvent(ui::VKEY_LEFT, false, true); 1071 SendKeyEvent(ui::VKEY_LEFT, false, true);
1072 EXPECT_EQ(9U, textfield_->GetCursorPosition()); 1072 EXPECT_EQ(9U, textfield_->GetCursorPosition());
1073 1073
1074 SendKeyEvent(ui::VKEY_LEFT, true, true); 1074 SendKeyEvent(ui::VKEY_LEFT, true, true);
1075 EXPECT_EQ(5U, textfield_->GetCursorPosition()); 1075 EXPECT_EQ(5U, textfield_->GetCursorPosition());
1076 EXPECT_STR_EQ("two ", textfield_->GetSelectedText()); 1076 EXPECT_STR_EQ("two ", textfield_->GetSelectedText());
1077 1077
1078 textfield_->SelectAll(); 1078 textfield_->SelectAll(false);
1079 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); 1079 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText());
1080 1080
1081 // CUT&PASTE does not work, but COPY works 1081 // CUT&PASTE does not work, but COPY works
1082 SetClipboardText("Test"); 1082 SetClipboardText("Test");
1083 SendKeyEvent(ui::VKEY_X, false, true); 1083 SendKeyEvent(ui::VKEY_X, false, true);
1084 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); 1084 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText());
1085 string16 str(GetClipboardText()); 1085 string16 str(GetClipboardText());
1086 EXPECT_STR_NE(" one two three ", str); 1086 EXPECT_STR_NE(" one two three ", str);
1087 1087
1088 SendKeyEvent(ui::VKEY_C, false, true); 1088 SendKeyEvent(ui::VKEY_C, false, true);
1089 views::ViewsDelegate::views_delegate->GetClipboard()-> 1089 views::ViewsDelegate::views_delegate->GetClipboard()->
1090 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); 1090 ReadText(ui::Clipboard::BUFFER_STANDARD, &str);
1091 EXPECT_STR_EQ(" one two three ", str); 1091 EXPECT_STR_EQ(" one two three ", str);
1092 1092
1093 // SetText should work even in read only mode. 1093 // SetText should work even in read only mode.
1094 textfield_->SetText(ASCIIToUTF16(" four five six ")); 1094 textfield_->SetText(ASCIIToUTF16(" four five six "));
1095 EXPECT_STR_EQ(" four five six ", textfield_->text()); 1095 EXPECT_STR_EQ(" four five six ", textfield_->text());
1096 1096
1097 // Paste shouldn't work. 1097 // Paste shouldn't work.
1098 SendKeyEvent(ui::VKEY_V, false, true); 1098 SendKeyEvent(ui::VKEY_V, false, true);
1099 EXPECT_STR_EQ(" four five six ", textfield_->text()); 1099 EXPECT_STR_EQ(" four five six ", textfield_->text());
1100 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1100 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1101 1101
1102 textfield_->SelectAll(); 1102 textfield_->SelectAll(false);
1103 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1103 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1104 1104
1105 // Text field is unmodifiable and selection shouldn't change. 1105 // Text field is unmodifiable and selection shouldn't change.
1106 SendKeyEvent(ui::VKEY_DELETE); 1106 SendKeyEvent(ui::VKEY_DELETE);
1107 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1107 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1108 SendKeyEvent(ui::VKEY_BACK); 1108 SendKeyEvent(ui::VKEY_BACK);
1109 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1109 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1110 SendKeyEvent(ui::VKEY_T); 1110 SendKeyEvent(ui::VKEY_T);
1111 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1111 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1112 } 1112 }
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i; 1661 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i;
1662 } 1662 }
1663 1663
1664 // Return false if the index is out of range. 1664 // Return false if the index is out of range.
1665 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); 1665 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect));
1666 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); 1666 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect));
1667 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); 1667 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect));
1668 } 1668 }
1669 1669
1670 } // namespace views 1670 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.cc ('k') | ui/views/controls/textfield/native_textfield_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698