| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return key; | 78 return key; |
| 79 | 79 |
| 80 key_handled_ = key; | 80 key_handled_ = key; |
| 81 | 81 |
| 82 return key_handled_; | 82 return key_handled_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool OnKeyReleased(const ui::KeyEvent& e) override { | 85 bool OnKeyReleased(const ui::KeyEvent& e) override { |
| 86 key_received_ = true; | 86 key_received_ = true; |
| 87 key_handled_ = views::Textfield::OnKeyReleased(e); | 87 key_handled_ = views::Textfield::OnKeyReleased(e); |
| 88 EXPECT_FALSE(key_handled_); // Textfield doesn't override OnKeyReleased. |
| 88 return key_handled_; | 89 return key_handled_; |
| 89 } | 90 } |
| 90 | 91 |
| 92 // On Mac, characters are inserted directly rather than attempting to get a |
| 93 // unicode character from the ui::KeyEvent (which isn't always possible). |
| 94 // Also, editing commands are translated from AppKit "action messages", which |
| 95 // conform to custom keybindings a user may have. For these, count them as |
| 96 // both received and handled. If a Mac key event does not map to a character |
| 97 // or editing command, it falls back to OnKeyPressed(), which will be logged |
| 98 // above as received, but not handled. |
| 99 |
| 100 // ui::TextInputClient overrides: |
| 101 void InsertChar(base::char16 ch, int flags) override { |
| 102 views::Textfield::InsertChar(ch, flags); |
| 103 #if defined(OS_MACOSX) |
| 104 key_received_ = true; |
| 105 #endif |
| 106 } |
| 107 |
| 108 void ExecuteEditingCommand(int command_id) override { |
| 109 views::Textfield::ExecuteEditingCommand(command_id); |
| 110 #if defined(OS_MACOSX) |
| 111 key_received_ = true; |
| 112 key_handled_ = true; |
| 113 #endif |
| 114 } |
| 115 |
| 116 bool HandleAsKeyEventOnly(const ui::KeyEvent& key_event) override { |
| 117 #if defined(OS_MACOSX) |
| 118 key_received_ = true; |
| 119 #endif |
| 120 return views::Textfield::HandleAsKeyEventOnly(key_event); |
| 121 } |
| 122 |
| 91 bool key_handled() const { return key_handled_; } | 123 bool key_handled() const { return key_handled_; } |
| 92 bool key_received() const { return key_received_; } | 124 bool key_received() const { return key_received_; } |
| 93 | 125 |
| 94 void clear() { key_received_ = key_handled_ = false; } | 126 void clear() { key_received_ = key_handled_ = false; } |
| 95 | 127 |
| 96 private: | 128 private: |
| 97 bool key_handled_; | 129 bool key_handled_; |
| 98 bool key_received_; | 130 bool key_received_; |
| 99 | 131 |
| 100 base::WeakPtrFactory<TestTextfield> weak_ptr_factory_; | 132 base::WeakPtrFactory<TestTextfield> weak_ptr_factory_; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 207 |
| 176 // TextfieldController: | 208 // TextfieldController: |
| 177 void ContentsChanged(Textfield* sender, | 209 void ContentsChanged(Textfield* sender, |
| 178 const base::string16& new_contents) override { | 210 const base::string16& new_contents) override { |
| 179 // Paste calls TextfieldController::ContentsChanged() explicitly even if the | 211 // Paste calls TextfieldController::ContentsChanged() explicitly even if the |
| 180 // paste action did not change the content. So |new_contents| may match | 212 // paste action did not change the content. So |new_contents| may match |
| 181 // |last_contents_|. For more info, see http://crbug.com/79002 | 213 // |last_contents_|. For more info, see http://crbug.com/79002 |
| 182 last_contents_ = new_contents; | 214 last_contents_ = new_contents; |
| 183 } | 215 } |
| 184 | 216 |
| 217 // views::TextfieldController: |
| 218 bool HandleKeyEvent(views::Textfield* sender, |
| 219 const ui::KeyEvent& key_event) override { |
| 220 if (!input_method_->HasMockComposition()) |
| 221 return false; |
| 222 |
| 223 input_method_->InsertMockComposition(); |
| 224 input_method_->ClearMockComposition(); |
| 225 return true; |
| 226 } |
| 227 |
| 185 void OnBeforeUserAction(Textfield* sender) override { | 228 void OnBeforeUserAction(Textfield* sender) override { |
| 186 ++on_before_user_action_; | 229 ++on_before_user_action_; |
| 187 } | 230 } |
| 188 | 231 |
| 189 void OnAfterUserAction(Textfield* sender) override { | 232 void OnAfterUserAction(Textfield* sender) override { |
| 190 ++on_after_user_action_; | 233 ++on_after_user_action_; |
| 191 } | 234 } |
| 192 | 235 |
| 193 void OnAfterCutOrCopy(ui::ClipboardType clipboard_type) override { | 236 void OnAfterCutOrCopy(ui::ClipboardType clipboard_type) override { |
| 194 copied_to_clipboard_ = clipboard_type; | 237 copied_to_clipboard_ = clipboard_type; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 bool control = true; | 376 bool control = true; |
| 334 bool caps = false; | 377 bool caps = false; |
| 335 if (TestingNativeMac()) { | 378 if (TestingNativeMac()) { |
| 336 // Use Alt+Left/Right/Backspace on native Mac. | 379 // Use Alt+Left/Right/Backspace on native Mac. |
| 337 alt = true; | 380 alt = true; |
| 338 control = false; | 381 control = false; |
| 339 } | 382 } |
| 340 SendKeyEvent(key, alt, shift, control, caps); | 383 SendKeyEvent(key, alt, shift, control, caps); |
| 341 } | 384 } |
| 342 | 385 |
| 386 // Sends Shift+Delete if supported, otherwise Cmd+X again. |
| 387 void SendAlternateCut() { |
| 388 if (TestingNativeMac()) |
| 389 SendKeyEvent(ui::VKEY_X, false, true); |
| 390 else |
| 391 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 392 } |
| 393 |
| 394 // Sends Ctrl+Insert if supported, otherwise Cmd+C again. |
| 395 void SendAlternateCopy() { |
| 396 if (TestingNativeMac()) |
| 397 SendKeyEvent(ui::VKEY_C, false, true); |
| 398 else |
| 399 SendKeyEvent(ui::VKEY_INSERT, false, true); |
| 400 } |
| 401 |
| 402 // Sends Shift+Insert if supported, otherwise Cmd+V again. |
| 403 void SendAlternatePaste() { |
| 404 if (TestingNativeMac()) |
| 405 SendKeyEvent(ui::VKEY_V, false, true); |
| 406 else |
| 407 SendKeyEvent(ui::VKEY_INSERT, true, false); |
| 408 } |
| 409 |
| 410 // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac |
| 411 // that is bound to "Show full history", so is not mapped as an editing |
| 412 // command. So, on Mac, send Cmd+Shift+Z. |
| 413 void SendAlternateRedo() { |
| 414 if (TestingNativeMac()) |
| 415 SendKeyEvent(ui::VKEY_Z, true, true); |
| 416 else |
| 417 SendKeyEvent(ui::VKEY_Y, false, true); |
| 418 } |
| 419 |
| 343 View* GetFocusedView() { | 420 View* GetFocusedView() { |
| 344 return widget_->GetFocusManager()->GetFocusedView(); | 421 return widget_->GetFocusManager()->GetFocusedView(); |
| 345 } | 422 } |
| 346 | 423 |
| 347 int GetCursorPositionX(int cursor_pos) { | 424 int GetCursorPositionX(int cursor_pos) { |
| 348 return test_api_->GetRenderText()->GetCursorBounds( | 425 return test_api_->GetRenderText()->GetCursorBounds( |
| 349 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); | 426 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); |
| 350 } | 427 } |
| 351 | 428 |
| 352 // Get the current cursor bounds. | 429 // Get the current cursor bounds. |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 model_->SelectAll(false); | 650 model_->SelectAll(false); |
| 574 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); | 651 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); |
| 575 | 652 |
| 576 // Cut and copy should be disabled. | 653 // Cut and copy should be disabled. |
| 577 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 654 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 578 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 655 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 579 SendKeyEvent(ui::VKEY_X, false, true); | 656 SendKeyEvent(ui::VKEY_X, false, true); |
| 580 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 657 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 581 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 658 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 582 SendKeyEvent(ui::VKEY_C, false, true); | 659 SendKeyEvent(ui::VKEY_C, false, true); |
| 583 SendKeyEvent(ui::VKEY_INSERT, false, true); | 660 SendAlternateCopy(); |
| 584 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 661 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 585 EXPECT_STR_EQ("password", textfield_->text()); | 662 EXPECT_STR_EQ("password", textfield_->text()); |
| 586 // [Shift]+[Delete] should just delete without copying text to the clipboard. | 663 // [Shift]+[Delete] should just delete without copying text to the clipboard. |
| 587 textfield_->SelectAll(false); | 664 textfield_->SelectAll(false); |
| 588 SendKeyEvent(ui::VKEY_DELETE, true, false); | 665 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 589 | 666 |
| 590 // Paste should work normally. | 667 // Paste should work normally. |
| 591 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 668 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 592 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 669 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 593 SendKeyEvent(ui::VKEY_V, false, true); | 670 SendKeyEvent(ui::VKEY_V, false, true); |
| 594 SendKeyEvent(ui::VKEY_INSERT, true, false); | 671 SendAlternatePaste(); |
| 595 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 672 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 596 EXPECT_STR_EQ("foofoofoo", textfield_->text()); | 673 EXPECT_STR_EQ("foofoofoo", textfield_->text()); |
| 597 } | 674 } |
| 598 | 675 |
| 599 TEST_F(TextfieldTest, TextInputType) { | 676 TEST_F(TextfieldTest, TextInputType) { |
| 600 InitTextfield(); | 677 InitTextfield(); |
| 601 | 678 |
| 602 // Defaults to TEXT | 679 // Defaults to TEXT |
| 603 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, textfield_->GetTextInputType()); | 680 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, textfield_->GetTextInputType()); |
| 604 | 681 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 SendKeyEvent(ui::VKEY_LEFT); | 713 SendKeyEvent(ui::VKEY_LEFT); |
| 637 EXPECT_TRUE(textfield_->key_received()); | 714 EXPECT_TRUE(textfield_->key_received()); |
| 638 EXPECT_TRUE(textfield_->key_handled()); | 715 EXPECT_TRUE(textfield_->key_handled()); |
| 639 textfield_->clear(); | 716 textfield_->clear(); |
| 640 | 717 |
| 641 SendKeyEvent(ui::VKEY_RIGHT); | 718 SendKeyEvent(ui::VKEY_RIGHT); |
| 642 EXPECT_TRUE(textfield_->key_received()); | 719 EXPECT_TRUE(textfield_->key_received()); |
| 643 EXPECT_TRUE(textfield_->key_handled()); | 720 EXPECT_TRUE(textfield_->key_handled()); |
| 644 textfield_->clear(); | 721 textfield_->clear(); |
| 645 | 722 |
| 646 SendKeyEvent(ui::VKEY_HOME); | 723 bool shift = false; |
| 724 SendHomeEvent(shift); |
| 647 EXPECT_TRUE(textfield_->key_received()); | 725 EXPECT_TRUE(textfield_->key_received()); |
| 648 EXPECT_TRUE(textfield_->key_handled()); | 726 EXPECT_TRUE(textfield_->key_handled()); |
| 649 textfield_->clear(); | 727 textfield_->clear(); |
| 650 | 728 |
| 651 SendKeyEvent(ui::VKEY_END); | 729 SendEndEvent(shift); |
| 652 EXPECT_TRUE(textfield_->key_received()); | 730 EXPECT_TRUE(textfield_->key_received()); |
| 653 EXPECT_TRUE(textfield_->key_handled()); | 731 EXPECT_TRUE(textfield_->key_handled()); |
| 654 textfield_->clear(); | 732 textfield_->clear(); |
| 655 | 733 |
| 656 // F24, up/down key won't be handled. | 734 // F20, up/down key won't be handled. |
| 657 SendKeyEvent(ui::VKEY_F24); | 735 SendKeyEvent(ui::VKEY_F20); |
| 736 #if defined(OS_MACOSX) |
| 737 // On Mac, key combinations that don't map to editing commands are forwarded |
| 738 // on to the next responder, usually ending up at the window, which will beep. |
| 739 EXPECT_FALSE(textfield_->key_received()); |
| 740 #else |
| 658 EXPECT_TRUE(textfield_->key_received()); | 741 EXPECT_TRUE(textfield_->key_received()); |
| 742 #endif |
| 659 EXPECT_FALSE(textfield_->key_handled()); | 743 EXPECT_FALSE(textfield_->key_handled()); |
| 660 textfield_->clear(); | 744 textfield_->clear(); |
| 661 | 745 |
| 662 SendKeyEvent(ui::VKEY_UP); | 746 SendKeyEvent(ui::VKEY_UP); |
| 663 EXPECT_TRUE(textfield_->key_received()); | 747 EXPECT_TRUE(textfield_->key_received()); |
| 664 EXPECT_FALSE(textfield_->key_handled()); | 748 EXPECT_FALSE(textfield_->key_handled()); |
| 665 textfield_->clear(); | 749 textfield_->clear(); |
| 666 | 750 |
| 667 SendKeyEvent(ui::VKEY_DOWN); | 751 SendKeyEvent(ui::VKEY_DOWN); |
| 668 EXPECT_TRUE(textfield_->key_received()); | 752 EXPECT_TRUE(textfield_->key_received()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 TEST_F(TextfieldTest, CursorMovement) { | 804 TEST_F(TextfieldTest, CursorMovement) { |
| 721 InitTextfield(); | 805 InitTextfield(); |
| 722 | 806 |
| 723 // Test with trailing whitespace. | 807 // Test with trailing whitespace. |
| 724 textfield_->SetText(ASCIIToUTF16("one two hre ")); | 808 textfield_->SetText(ASCIIToUTF16("one two hre ")); |
| 725 | 809 |
| 726 // Send the cursor at the end. | 810 // Send the cursor at the end. |
| 727 SendKeyEvent(ui::VKEY_END); | 811 SendKeyEvent(ui::VKEY_END); |
| 728 | 812 |
| 729 // Ctrl+Left should move the cursor just before the last word. | 813 // Ctrl+Left should move the cursor just before the last word. |
| 730 SendKeyEvent(ui::VKEY_LEFT, false, true); | 814 bool shift = false; |
| 815 SendWordEvent(ui::VKEY_LEFT, shift); |
| 731 SendKeyEvent(ui::VKEY_T); | 816 SendKeyEvent(ui::VKEY_T); |
| 732 EXPECT_STR_EQ("one two thre ", textfield_->text()); | 817 EXPECT_STR_EQ("one two thre ", textfield_->text()); |
| 733 EXPECT_STR_EQ("one two thre ", last_contents_); | 818 EXPECT_STR_EQ("one two thre ", last_contents_); |
| 734 | 819 |
| 735 // Ctrl+Right should move the cursor to the end of the last word. | 820 // Ctrl+Right should move the cursor to the end of the last word. |
| 736 SendKeyEvent(ui::VKEY_RIGHT, false, true); | 821 SendWordEvent(ui::VKEY_RIGHT, shift); |
| 737 SendKeyEvent(ui::VKEY_E); | 822 SendKeyEvent(ui::VKEY_E); |
| 738 EXPECT_STR_EQ("one two three ", textfield_->text()); | 823 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 739 EXPECT_STR_EQ("one two three ", last_contents_); | 824 EXPECT_STR_EQ("one two three ", last_contents_); |
| 740 | 825 |
| 741 // Ctrl+Right again should move the cursor to the end. | 826 // Ctrl+Right again should move the cursor to the end. |
| 742 SendKeyEvent(ui::VKEY_RIGHT, false, true); | 827 SendWordEvent(ui::VKEY_RIGHT, shift); |
| 743 SendKeyEvent(ui::VKEY_BACK); | 828 SendKeyEvent(ui::VKEY_BACK); |
| 744 EXPECT_STR_EQ("one two three", textfield_->text()); | 829 EXPECT_STR_EQ("one two three", textfield_->text()); |
| 745 EXPECT_STR_EQ("one two three", last_contents_); | 830 EXPECT_STR_EQ("one two three", last_contents_); |
| 746 | 831 |
| 747 // Test with leading whitespace. | 832 // Test with leading whitespace. |
| 748 textfield_->SetText(ASCIIToUTF16(" ne two")); | 833 textfield_->SetText(ASCIIToUTF16(" ne two")); |
| 749 | 834 |
| 750 // Send the cursor at the beginning. | 835 // Send the cursor at the beginning. |
| 751 SendKeyEvent(ui::VKEY_HOME); | 836 SendHomeEvent(shift); |
| 752 | 837 |
| 753 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the | 838 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the |
| 754 // first word. | 839 // first word. |
| 755 SendKeyEvent(ui::VKEY_RIGHT, false, true); | 840 SendWordEvent(ui::VKEY_RIGHT, shift); |
| 756 SendKeyEvent(ui::VKEY_LEFT, false, true); | 841 SendWordEvent(ui::VKEY_LEFT, shift); |
| 757 SendKeyEvent(ui::VKEY_O); | 842 SendKeyEvent(ui::VKEY_O); |
| 758 EXPECT_STR_EQ(" one two", textfield_->text()); | 843 EXPECT_STR_EQ(" one two", textfield_->text()); |
| 759 EXPECT_STR_EQ(" one two", last_contents_); | 844 EXPECT_STR_EQ(" one two", last_contents_); |
| 760 | 845 |
| 761 // Ctrl+Left to move the cursor to the beginning of the first word. | 846 // Ctrl+Left to move the cursor to the beginning of the first word. |
| 762 SendKeyEvent(ui::VKEY_LEFT, false, true); | 847 SendWordEvent(ui::VKEY_LEFT, shift); |
| 763 // Ctrl+Left again should move the cursor back to the very beginning. | 848 // Ctrl+Left again should move the cursor back to the very beginning. |
| 764 SendKeyEvent(ui::VKEY_LEFT, false, true); | 849 SendWordEvent(ui::VKEY_LEFT, shift); |
| 765 SendKeyEvent(ui::VKEY_DELETE); | 850 SendKeyEvent(ui::VKEY_DELETE); |
| 766 EXPECT_STR_EQ("one two", textfield_->text()); | 851 EXPECT_STR_EQ("one two", textfield_->text()); |
| 767 EXPECT_STR_EQ("one two", last_contents_); | 852 EXPECT_STR_EQ("one two", last_contents_); |
| 768 } | 853 } |
| 769 | 854 |
| 770 TEST_F(TextfieldTest, FocusTraversalTest) { | 855 TEST_F(TextfieldTest, FocusTraversalTest) { |
| 771 InitTextfields(3); | 856 InitTextfields(3); |
| 772 textfield_->RequestFocus(); | 857 textfield_->RequestFocus(); |
| 773 | 858 |
| 774 EXPECT_EQ(1, GetFocusedView()->id()); | 859 EXPECT_EQ(1, GetFocusedView()->id()); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 1117 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| 1033 textfield_->OnDragDone(); | 1118 textfield_->OnDragDone(); |
| 1034 | 1119 |
| 1035 // Undo/Redo the drag&drop change. | 1120 // Undo/Redo the drag&drop change. |
| 1036 SendKeyEvent(ui::VKEY_Z, false, true); | 1121 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1037 EXPECT_STR_EQ("hello world", textfield_->text()); | 1122 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1038 SendKeyEvent(ui::VKEY_Z, false, true); | 1123 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1039 EXPECT_STR_EQ("", textfield_->text()); | 1124 EXPECT_STR_EQ("", textfield_->text()); |
| 1040 SendKeyEvent(ui::VKEY_Z, false, true); | 1125 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1041 EXPECT_STR_EQ("", textfield_->text()); | 1126 EXPECT_STR_EQ("", textfield_->text()); |
| 1042 SendKeyEvent(ui::VKEY_Y, false, true); | 1127 SendAlternateRedo(); |
| 1043 EXPECT_STR_EQ("hello world", textfield_->text()); | 1128 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1044 SendKeyEvent(ui::VKEY_Y, false, true); | 1129 SendAlternateRedo(); |
| 1045 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 1130 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| 1046 SendKeyEvent(ui::VKEY_Y, false, true); | 1131 SendAlternateRedo(); |
| 1047 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 1132 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| 1048 } | 1133 } |
| 1049 | 1134 |
| 1050 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { | 1135 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
| 1051 InitTextfield(); | 1136 InitTextfield(); |
| 1052 textfield_->SetText(ASCIIToUTF16("hello world")); | 1137 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1053 | 1138 |
| 1054 base::string16 string; | 1139 base::string16 string; |
| 1055 ui::OSExchangeData data; | 1140 ui::OSExchangeData data; |
| 1056 int formats = 0; | 1141 int formats = 0; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1085 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1170 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 1086 textfield_->OnDragDone(); | 1171 textfield_->OnDragDone(); |
| 1087 | 1172 |
| 1088 // Undo/Redo the drag&drop change. | 1173 // Undo/Redo the drag&drop change. |
| 1089 SendKeyEvent(ui::VKEY_Z, false, true); | 1174 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1090 EXPECT_STR_EQ("hello world", textfield_->text()); | 1175 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1091 SendKeyEvent(ui::VKEY_Z, false, true); | 1176 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1092 EXPECT_STR_EQ("", textfield_->text()); | 1177 EXPECT_STR_EQ("", textfield_->text()); |
| 1093 SendKeyEvent(ui::VKEY_Z, false, true); | 1178 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1094 EXPECT_STR_EQ("", textfield_->text()); | 1179 EXPECT_STR_EQ("", textfield_->text()); |
| 1095 SendKeyEvent(ui::VKEY_Y, false, true); | 1180 SendAlternateRedo(); |
| 1096 EXPECT_STR_EQ("hello world", textfield_->text()); | 1181 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1097 SendKeyEvent(ui::VKEY_Y, false, true); | 1182 SendAlternateRedo(); |
| 1098 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1183 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 1099 SendKeyEvent(ui::VKEY_Y, false, true); | 1184 SendAlternateRedo(); |
| 1100 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1185 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 1101 } | 1186 } |
| 1102 | 1187 |
| 1103 TEST_F(TextfieldTest, DragAndDrop_Canceled) { | 1188 TEST_F(TextfieldTest, DragAndDrop_Canceled) { |
| 1104 InitTextfield(); | 1189 InitTextfield(); |
| 1105 textfield_->SetText(ASCIIToUTF16("hello world")); | 1190 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1106 | 1191 |
| 1107 // Start dragging "worl". | 1192 // Start dragging "worl". |
| 1108 textfield_->SelectRange(gfx::Range(6, 10)); | 1193 textfield_->SelectRange(gfx::Range(6, 10)); |
| 1109 gfx::Point point(GetCursorPositionX(8), 0); | 1194 gfx::Point point(GetCursorPositionX(8), 0); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1130 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 1215 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
| 1131 } | 1216 } |
| 1132 | 1217 |
| 1133 TEST_F(TextfieldTest, ReadOnlyTest) { | 1218 TEST_F(TextfieldTest, ReadOnlyTest) { |
| 1134 InitTextfield(); | 1219 InitTextfield(); |
| 1135 textfield_->SetText(ASCIIToUTF16("read only")); | 1220 textfield_->SetText(ASCIIToUTF16("read only")); |
| 1136 textfield_->SetReadOnly(true); | 1221 textfield_->SetReadOnly(true); |
| 1137 EXPECT_TRUE(textfield_->enabled()); | 1222 EXPECT_TRUE(textfield_->enabled()); |
| 1138 EXPECT_TRUE(textfield_->IsFocusable()); | 1223 EXPECT_TRUE(textfield_->IsFocusable()); |
| 1139 | 1224 |
| 1140 SendKeyEvent(ui::VKEY_HOME); | 1225 bool shift = false; |
| 1226 SendHomeEvent(shift); |
| 1141 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1227 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 1142 SendKeyEvent(ui::VKEY_END); | 1228 SendEndEvent(shift); |
| 1143 EXPECT_EQ(9U, textfield_->GetCursorPosition()); | 1229 EXPECT_EQ(9U, textfield_->GetCursorPosition()); |
| 1144 | 1230 |
| 1145 SendKeyEvent(ui::VKEY_LEFT, false, false); | 1231 SendKeyEvent(ui::VKEY_LEFT, shift, false); |
| 1146 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | 1232 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
| 1147 SendKeyEvent(ui::VKEY_LEFT, false, true); | 1233 SendWordEvent(ui::VKEY_LEFT, shift); |
| 1148 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | 1234 EXPECT_EQ(5U, textfield_->GetCursorPosition()); |
| 1149 SendKeyEvent(ui::VKEY_LEFT, true, true); | 1235 shift = true; |
| 1236 SendWordEvent(ui::VKEY_LEFT, shift); |
| 1150 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1237 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 1151 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); | 1238 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); |
| 1152 textfield_->SelectAll(false); | 1239 textfield_->SelectAll(false); |
| 1153 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); | 1240 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); |
| 1154 | 1241 |
| 1155 // Cut should be disabled. | 1242 // Cut should be disabled. |
| 1156 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); | 1243 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1157 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 1244 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 1158 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 1245 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 1159 SendKeyEvent(ui::VKEY_X, false, true); | 1246 SendKeyEvent(ui::VKEY_X, false, true); |
| 1160 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1247 SendAlternateCut(); |
| 1161 EXPECT_STR_EQ("Test", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1248 EXPECT_STR_EQ("Test", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1162 EXPECT_STR_EQ("read only", textfield_->text()); | 1249 EXPECT_STR_EQ("read only", textfield_->text()); |
| 1163 | 1250 |
| 1164 // Paste should be disabled. | 1251 // Paste should be disabled. |
| 1165 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1252 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 1166 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 1253 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 1167 SendKeyEvent(ui::VKEY_V, false, true); | 1254 SendKeyEvent(ui::VKEY_V, false, true); |
| 1168 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1255 SendAlternatePaste(); |
| 1169 EXPECT_STR_EQ("read only", textfield_->text()); | 1256 EXPECT_STR_EQ("read only", textfield_->text()); |
| 1170 | 1257 |
| 1171 // Copy should work normally. | 1258 // Copy should work normally. |
| 1172 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); | 1259 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1173 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 1260 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1174 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 1261 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1175 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1262 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1176 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); | 1263 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1177 SendKeyEvent(ui::VKEY_C, false, true); | 1264 SendKeyEvent(ui::VKEY_C, false, true); |
| 1178 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1265 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1179 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); | 1266 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1180 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1267 SendAlternateCopy(); |
| 1181 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1268 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1182 | 1269 |
| 1183 // SetText should work even in read only mode. | 1270 // SetText should work even in read only mode. |
| 1184 textfield_->SetText(ASCIIToUTF16(" four five six ")); | 1271 textfield_->SetText(ASCIIToUTF16(" four five six ")); |
| 1185 EXPECT_STR_EQ(" four five six ", textfield_->text()); | 1272 EXPECT_STR_EQ(" four five six ", textfield_->text()); |
| 1186 | 1273 |
| 1187 textfield_->SelectAll(false); | 1274 textfield_->SelectAll(false); |
| 1188 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1275 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1189 | 1276 |
| 1190 // Text field is unmodifiable and selection shouldn't change. | 1277 // Text field is unmodifiable and selection shouldn't change. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1220 EXPECT_STR_EQ("0456789", textfield_->text()); | 1307 EXPECT_STR_EQ("0456789", textfield_->text()); |
| 1221 | 1308 |
| 1222 ui::CompositionText composition; | 1309 ui::CompositionText composition; |
| 1223 composition.text = UTF8ToUTF16("321"); | 1310 composition.text = UTF8ToUTF16("321"); |
| 1224 // Set composition through input method. | 1311 // Set composition through input method. |
| 1225 input_method_->Clear(); | 1312 input_method_->Clear(); |
| 1226 input_method_->SetCompositionTextForNextKey(composition); | 1313 input_method_->SetCompositionTextForNextKey(composition); |
| 1227 textfield_->clear(); | 1314 textfield_->clear(); |
| 1228 | 1315 |
| 1229 on_before_user_action_ = on_after_user_action_ = 0; | 1316 on_before_user_action_ = on_after_user_action_ = 0; |
| 1230 SendKeyEvent(ui::VKEY_A); | 1317 SendKeyEvent(ui::VKEY_RETURN); |
| 1231 EXPECT_TRUE(textfield_->key_received()); | 1318 EXPECT_TRUE(textfield_->key_received()); |
| 1232 EXPECT_FALSE(textfield_->key_handled()); | 1319 EXPECT_FALSE(textfield_->key_handled()); |
| 1233 EXPECT_TRUE(client->HasCompositionText()); | 1320 EXPECT_TRUE(client->HasCompositionText()); |
| 1234 EXPECT_TRUE(client->GetCompositionTextRange(&range)); | 1321 EXPECT_TRUE(client->GetCompositionTextRange(&range)); |
| 1235 EXPECT_STR_EQ("0321456789", textfield_->text()); | 1322 EXPECT_STR_EQ("0321456789", textfield_->text()); |
| 1236 EXPECT_EQ(gfx::Range(1, 4), range); | 1323 EXPECT_EQ(gfx::Range(1, 4), range); |
| 1237 EXPECT_EQ(1, on_before_user_action_); | 1324 EXPECT_EQ(1, on_before_user_action_); |
| 1238 EXPECT_EQ(1, on_after_user_action_); | 1325 EXPECT_EQ(1, on_after_user_action_); |
| 1239 | 1326 |
| 1240 input_method_->SetResultTextForNextKey(UTF8ToUTF16("123")); | 1327 input_method_->SetResultTextForNextKey(UTF8ToUTF16("123")); |
| 1241 on_before_user_action_ = on_after_user_action_ = 0; | 1328 on_before_user_action_ = on_after_user_action_ = 0; |
| 1242 textfield_->clear(); | 1329 textfield_->clear(); |
| 1243 SendKeyEvent(ui::VKEY_A); | 1330 SendKeyEvent(ui::VKEY_RETURN); |
| 1244 EXPECT_TRUE(textfield_->key_received()); | 1331 EXPECT_TRUE(textfield_->key_received()); |
| 1245 EXPECT_FALSE(textfield_->key_handled()); | 1332 EXPECT_FALSE(textfield_->key_handled()); |
| 1246 EXPECT_FALSE(client->HasCompositionText()); | 1333 EXPECT_FALSE(client->HasCompositionText()); |
| 1247 EXPECT_FALSE(input_method_->cancel_composition_called()); | 1334 EXPECT_FALSE(input_method_->cancel_composition_called()); |
| 1248 EXPECT_STR_EQ("0123456789", textfield_->text()); | 1335 EXPECT_STR_EQ("0123456789", textfield_->text()); |
| 1249 EXPECT_EQ(1, on_before_user_action_); | 1336 EXPECT_EQ(1, on_before_user_action_); |
| 1250 EXPECT_EQ(1, on_after_user_action_); | 1337 EXPECT_EQ(1, on_after_user_action_); |
| 1251 | 1338 |
| 1252 input_method_->Clear(); | 1339 input_method_->Clear(); |
| 1253 input_method_->SetCompositionTextForNextKey(composition); | 1340 input_method_->SetCompositionTextForNextKey(composition); |
| 1254 textfield_->clear(); | 1341 textfield_->clear(); |
| 1255 SendKeyEvent(ui::VKEY_A); | 1342 SendKeyEvent(ui::VKEY_RETURN); |
| 1256 EXPECT_TRUE(client->HasCompositionText()); | 1343 EXPECT_TRUE(client->HasCompositionText()); |
| 1257 EXPECT_STR_EQ("0123321456789", textfield_->text()); | 1344 EXPECT_STR_EQ("0123321456789", textfield_->text()); |
| 1258 | 1345 |
| 1259 on_before_user_action_ = on_after_user_action_ = 0; | 1346 on_before_user_action_ = on_after_user_action_ = 0; |
| 1260 textfield_->clear(); | 1347 textfield_->clear(); |
| 1261 SendKeyEvent(ui::VKEY_RIGHT); | 1348 SendKeyEvent(ui::VKEY_RIGHT); |
| 1262 EXPECT_FALSE(client->HasCompositionText()); | 1349 EXPECT_FALSE(client->HasCompositionText()); |
| 1263 EXPECT_TRUE(input_method_->cancel_composition_called()); | 1350 EXPECT_TRUE(input_method_->cancel_composition_called()); |
| 1264 EXPECT_TRUE(textfield_->key_received()); | 1351 EXPECT_TRUE(textfield_->key_received()); |
| 1265 EXPECT_TRUE(textfield_->key_handled()); | 1352 EXPECT_TRUE(textfield_->key_handled()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1277 // On{Before,After}UserAction should be called by whatever user action | 1364 // On{Before,After}UserAction should be called by whatever user action |
| 1278 // triggers clearing or setting a selection if appropriate. | 1365 // triggers clearing or setting a selection if appropriate. |
| 1279 on_before_user_action_ = on_after_user_action_ = 0; | 1366 on_before_user_action_ = on_after_user_action_ = 0; |
| 1280 textfield_->clear(); | 1367 textfield_->clear(); |
| 1281 textfield_->ClearSelection(); | 1368 textfield_->ClearSelection(); |
| 1282 textfield_->SelectAll(false); | 1369 textfield_->SelectAll(false); |
| 1283 EXPECT_EQ(0, on_before_user_action_); | 1370 EXPECT_EQ(0, on_before_user_action_); |
| 1284 EXPECT_EQ(0, on_after_user_action_); | 1371 EXPECT_EQ(0, on_after_user_action_); |
| 1285 | 1372 |
| 1286 input_method_->Clear(); | 1373 input_method_->Clear(); |
| 1374 |
| 1375 // Changing the Textfield to readonly shouldn't change the input client, since |
| 1376 // it's still required for selections and clipboard copy. |
| 1377 ui::TextInputClient* text_input_client = textfield_->GetTextInputClient(); |
| 1378 EXPECT_TRUE(text_input_client); |
| 1379 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType()); |
| 1287 textfield_->SetReadOnly(true); | 1380 textfield_->SetReadOnly(true); |
| 1288 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1381 EXPECT_TRUE(input_method_->text_input_type_changed()); |
| 1289 EXPECT_FALSE(textfield_->GetTextInputClient()); | 1382 EXPECT_EQ(text_input_client, textfield_->GetTextInputClient()); |
| 1383 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType()); |
| 1290 | 1384 |
| 1291 textfield_->SetReadOnly(false); | 1385 textfield_->SetReadOnly(false); |
| 1386 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType()); |
| 1387 |
| 1292 input_method_->Clear(); | 1388 input_method_->Clear(); |
| 1293 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 1389 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 1294 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1390 EXPECT_TRUE(input_method_->text_input_type_changed()); |
| 1295 EXPECT_TRUE(textfield_->GetTextInputClient()); | 1391 EXPECT_TRUE(textfield_->GetTextInputClient()); |
| 1296 } | 1392 } |
| 1297 | 1393 |
| 1298 TEST_F(TextfieldTest, UndoRedoTest) { | 1394 TEST_F(TextfieldTest, UndoRedoTest) { |
| 1299 InitTextfield(); | 1395 InitTextfield(); |
| 1300 SendKeyEvent(ui::VKEY_A); | 1396 SendKeyEvent(ui::VKEY_A); |
| 1301 EXPECT_STR_EQ("a", textfield_->text()); | 1397 EXPECT_STR_EQ("a", textfield_->text()); |
| 1302 SendKeyEvent(ui::VKEY_Z, false, true); | 1398 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1303 EXPECT_STR_EQ("", textfield_->text()); | 1399 EXPECT_STR_EQ("", textfield_->text()); |
| 1304 SendKeyEvent(ui::VKEY_Z, false, true); | 1400 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1305 EXPECT_STR_EQ("", textfield_->text()); | 1401 EXPECT_STR_EQ("", textfield_->text()); |
| 1306 SendKeyEvent(ui::VKEY_Y, false, true); | 1402 SendAlternateRedo(); |
| 1307 EXPECT_STR_EQ("a", textfield_->text()); | 1403 EXPECT_STR_EQ("a", textfield_->text()); |
| 1308 SendKeyEvent(ui::VKEY_Y, false, true); | 1404 SendAlternateRedo(); |
| 1309 EXPECT_STR_EQ("a", textfield_->text()); | 1405 EXPECT_STR_EQ("a", textfield_->text()); |
| 1310 | 1406 |
| 1311 // AppendText | 1407 // AppendText |
| 1312 textfield_->AppendText(ASCIIToUTF16("b")); | 1408 textfield_->AppendText(ASCIIToUTF16("b")); |
| 1313 last_contents_.clear(); // AppendText doesn't call ContentsChanged. | 1409 last_contents_.clear(); // AppendText doesn't call ContentsChanged. |
| 1314 EXPECT_STR_EQ("ab", textfield_->text()); | 1410 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1315 SendKeyEvent(ui::VKEY_Z, false, true); | 1411 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1316 EXPECT_STR_EQ("a", textfield_->text()); | 1412 EXPECT_STR_EQ("a", textfield_->text()); |
| 1317 SendKeyEvent(ui::VKEY_Y, false, true); | 1413 SendAlternateRedo(); |
| 1318 EXPECT_STR_EQ("ab", textfield_->text()); | 1414 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1319 | 1415 |
| 1320 // SetText | 1416 // SetText |
| 1321 SendKeyEvent(ui::VKEY_C); | 1417 SendKeyEvent(ui::VKEY_C); |
| 1322 // Undo'ing append moves the cursor to the end for now. | 1418 // Undo'ing append moves the cursor to the end for now. |
| 1323 // A no-op SetText won't add a new edit; see TextfieldModel::SetText. | 1419 // A no-op SetText won't add a new edit; see TextfieldModel::SetText. |
| 1324 EXPECT_STR_EQ("abc", textfield_->text()); | 1420 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1325 textfield_->SetText(ASCIIToUTF16("abc")); | 1421 textfield_->SetText(ASCIIToUTF16("abc")); |
| 1326 EXPECT_STR_EQ("abc", textfield_->text()); | 1422 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1327 SendKeyEvent(ui::VKEY_Z, false, true); | 1423 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1328 EXPECT_STR_EQ("ab", textfield_->text()); | 1424 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1329 SendKeyEvent(ui::VKEY_Y, false, true); | 1425 SendAlternateRedo(); |
| 1330 EXPECT_STR_EQ("abc", textfield_->text()); | 1426 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1331 SendKeyEvent(ui::VKEY_Y, false, true); | 1427 SendAlternateRedo(); |
| 1332 EXPECT_STR_EQ("abc", textfield_->text()); | 1428 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1333 textfield_->SetText(ASCIIToUTF16("123")); | 1429 textfield_->SetText(ASCIIToUTF16("123")); |
| 1334 textfield_->SetText(ASCIIToUTF16("123")); | 1430 textfield_->SetText(ASCIIToUTF16("123")); |
| 1335 EXPECT_STR_EQ("123", textfield_->text()); | 1431 EXPECT_STR_EQ("123", textfield_->text()); |
| 1336 SendKeyEvent(ui::VKEY_END, false, false); | 1432 SendKeyEvent(ui::VKEY_END, false, false); |
| 1337 SendKeyEvent(ui::VKEY_4, false, false); | 1433 SendKeyEvent(ui::VKEY_4, false, false); |
| 1338 EXPECT_STR_EQ("1234", textfield_->text()); | 1434 EXPECT_STR_EQ("1234", textfield_->text()); |
| 1339 last_contents_.clear(); | 1435 last_contents_.clear(); |
| 1340 SendKeyEvent(ui::VKEY_Z, false, true); | 1436 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1341 EXPECT_STR_EQ("123", textfield_->text()); | 1437 EXPECT_STR_EQ("123", textfield_->text()); |
| 1342 SendKeyEvent(ui::VKEY_Z, false, true); | 1438 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1343 // the insert edit "c" and set edit "123" are merged to single edit, | 1439 // the insert edit "c" and set edit "123" are merged to single edit, |
| 1344 // so text becomes "ab" after undo. | 1440 // so text becomes "ab" after undo. |
| 1345 EXPECT_STR_EQ("ab", textfield_->text()); | 1441 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1346 SendKeyEvent(ui::VKEY_Z, false, true); | 1442 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1347 EXPECT_STR_EQ("a", textfield_->text()); | 1443 EXPECT_STR_EQ("a", textfield_->text()); |
| 1348 SendKeyEvent(ui::VKEY_Y, false, true); | 1444 SendAlternateRedo(); |
| 1349 EXPECT_STR_EQ("ab", textfield_->text()); | 1445 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1350 SendKeyEvent(ui::VKEY_Y, false, true); | 1446 SendAlternateRedo(); |
| 1351 EXPECT_STR_EQ("123", textfield_->text()); | 1447 EXPECT_STR_EQ("123", textfield_->text()); |
| 1352 SendKeyEvent(ui::VKEY_Y, false, true); | 1448 SendAlternateRedo(); |
| 1353 EXPECT_STR_EQ("1234", textfield_->text()); | 1449 EXPECT_STR_EQ("1234", textfield_->text()); |
| 1354 | 1450 |
| 1355 // Undoing to the same text shouldn't call ContentsChanged. | 1451 // Undoing to the same text shouldn't call ContentsChanged. |
| 1356 SendKeyEvent(ui::VKEY_A, false, true); // select all | 1452 SendKeyEvent(ui::VKEY_A, false, true); // select all |
| 1357 SendKeyEvent(ui::VKEY_A); | 1453 SendKeyEvent(ui::VKEY_A); |
| 1358 EXPECT_STR_EQ("a", textfield_->text()); | 1454 EXPECT_STR_EQ("a", textfield_->text()); |
| 1359 SendKeyEvent(ui::VKEY_B); | 1455 SendKeyEvent(ui::VKEY_B); |
| 1360 SendKeyEvent(ui::VKEY_C); | 1456 SendKeyEvent(ui::VKEY_C); |
| 1361 EXPECT_STR_EQ("abc", textfield_->text()); | 1457 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1362 SendKeyEvent(ui::VKEY_Z, false, true); | 1458 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1363 EXPECT_STR_EQ("1234", textfield_->text()); | 1459 EXPECT_STR_EQ("1234", textfield_->text()); |
| 1364 SendKeyEvent(ui::VKEY_Y, false, true); | 1460 SendAlternateRedo(); |
| 1365 EXPECT_STR_EQ("abc", textfield_->text()); | 1461 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1366 | 1462 |
| 1367 // Delete/Backspace | 1463 // Delete/Backspace |
| 1368 SendKeyEvent(ui::VKEY_BACK); | 1464 SendKeyEvent(ui::VKEY_BACK); |
| 1369 EXPECT_STR_EQ("ab", textfield_->text()); | 1465 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1370 SendKeyEvent(ui::VKEY_HOME); | 1466 bool shift = false; |
| 1467 SendHomeEvent(shift); |
| 1371 SendKeyEvent(ui::VKEY_DELETE); | 1468 SendKeyEvent(ui::VKEY_DELETE); |
| 1372 EXPECT_STR_EQ("b", textfield_->text()); | 1469 EXPECT_STR_EQ("b", textfield_->text()); |
| 1373 SendKeyEvent(ui::VKEY_A, false, true); | 1470 SendKeyEvent(ui::VKEY_A, false, true); |
| 1374 SendKeyEvent(ui::VKEY_DELETE); | 1471 SendKeyEvent(ui::VKEY_DELETE); |
| 1375 EXPECT_STR_EQ("", textfield_->text()); | 1472 EXPECT_STR_EQ("", textfield_->text()); |
| 1376 SendKeyEvent(ui::VKEY_Z, false, true); | 1473 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1377 EXPECT_STR_EQ("b", textfield_->text()); | 1474 EXPECT_STR_EQ("b", textfield_->text()); |
| 1378 SendKeyEvent(ui::VKEY_Z, false, true); | 1475 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1379 EXPECT_STR_EQ("ab", textfield_->text()); | 1476 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1380 SendKeyEvent(ui::VKEY_Z, false, true); | 1477 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1381 EXPECT_STR_EQ("abc", textfield_->text()); | 1478 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1382 SendKeyEvent(ui::VKEY_Y, false, true); | 1479 SendAlternateRedo(); |
| 1383 EXPECT_STR_EQ("ab", textfield_->text()); | 1480 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1384 SendKeyEvent(ui::VKEY_Y, false, true); | 1481 SendAlternateRedo(); |
| 1385 EXPECT_STR_EQ("b", textfield_->text()); | 1482 EXPECT_STR_EQ("b", textfield_->text()); |
| 1386 SendKeyEvent(ui::VKEY_Y, false, true); | 1483 SendAlternateRedo(); |
| 1387 EXPECT_STR_EQ("", textfield_->text()); | 1484 EXPECT_STR_EQ("", textfield_->text()); |
| 1388 SendKeyEvent(ui::VKEY_Y, false, true); | 1485 SendAlternateRedo(); |
| 1389 EXPECT_STR_EQ("", textfield_->text()); | 1486 EXPECT_STR_EQ("", textfield_->text()); |
| 1390 } | 1487 } |
| 1391 | 1488 |
| 1392 TEST_F(TextfieldTest, CutCopyPaste) { | 1489 TEST_F(TextfieldTest, CutCopyPaste) { |
| 1393 InitTextfield(); | 1490 InitTextfield(); |
| 1394 | 1491 |
| 1395 // Ensure IDS_APP_CUT cuts. | 1492 // Ensure IDS_APP_CUT cuts. |
| 1396 textfield_->SetText(ASCIIToUTF16("123")); | 1493 textfield_->SetText(ASCIIToUTF16("123")); |
| 1397 textfield_->SelectAll(false); | 1494 textfield_->SelectAll(false); |
| 1398 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 1495 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1409 EXPECT_STR_EQ("456", textfield_->text()); | 1506 EXPECT_STR_EQ("456", textfield_->text()); |
| 1410 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 1507 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 1411 SendKeyEvent(ui::VKEY_X, false, true); | 1508 SendKeyEvent(ui::VKEY_X, false, true); |
| 1412 EXPECT_STR_EQ("456", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1509 EXPECT_STR_EQ("456", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1413 EXPECT_STR_EQ("", textfield_->text()); | 1510 EXPECT_STR_EQ("", textfield_->text()); |
| 1414 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1511 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1415 | 1512 |
| 1416 // Ensure [Shift]+[Delete] cuts. | 1513 // Ensure [Shift]+[Delete] cuts. |
| 1417 textfield_->SetText(ASCIIToUTF16("123")); | 1514 textfield_->SetText(ASCIIToUTF16("123")); |
| 1418 textfield_->SelectAll(false); | 1515 textfield_->SelectAll(false); |
| 1419 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1516 SendAlternateCut(); |
| 1420 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1517 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1421 EXPECT_STR_EQ("", textfield_->text()); | 1518 EXPECT_STR_EQ("", textfield_->text()); |
| 1422 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1519 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1423 | 1520 |
| 1424 // Ensure IDS_APP_COPY copies. | 1521 // Ensure IDS_APP_COPY copies. |
| 1425 textfield_->SetText(ASCIIToUTF16("789")); | 1522 textfield_->SetText(ASCIIToUTF16("789")); |
| 1426 textfield_->SelectAll(false); | 1523 textfield_->SelectAll(false); |
| 1427 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 1524 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1428 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 1525 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1429 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1526 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1430 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1527 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1431 | 1528 |
| 1432 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | 1529 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. |
| 1433 textfield_->SetText(ASCIIToUTF16("012")); | 1530 textfield_->SetText(ASCIIToUTF16("012")); |
| 1434 textfield_->SelectAll(false); | 1531 textfield_->SelectAll(false); |
| 1435 SendKeyEvent(ui::VKEY_C, true, false, true, false); | 1532 SendKeyEvent(ui::VKEY_C, true, false, true, false); |
| 1436 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1533 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1437 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 1534 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 1438 SendKeyEvent(ui::VKEY_C, false, true); | 1535 SendKeyEvent(ui::VKEY_C, false, true); |
| 1439 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1536 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1440 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1537 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1441 | 1538 |
| 1442 // Ensure [Ctrl]+[Insert] copies. | 1539 // Ensure [Ctrl]+[Insert] copies. |
| 1443 textfield_->SetText(ASCIIToUTF16("345")); | 1540 textfield_->SetText(ASCIIToUTF16("345")); |
| 1444 textfield_->SelectAll(false); | 1541 textfield_->SelectAll(false); |
| 1445 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1542 SendAlternateCopy(); |
| 1446 EXPECT_STR_EQ("345", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1543 EXPECT_STR_EQ("345", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1447 EXPECT_STR_EQ("345", textfield_->text()); | 1544 EXPECT_STR_EQ("345", textfield_->text()); |
| 1448 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1545 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1449 | 1546 |
| 1450 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; | 1547 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; |
| 1451 // also ensure that [Ctrl]+[Alt]+[V] does nothing. | 1548 // also ensure that [Ctrl]+[Alt]+[V] does nothing. |
| 1452 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "abc"); | 1549 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "abc"); |
| 1453 textfield_->SetText(base::string16()); | 1550 textfield_->SetText(base::string16()); |
| 1454 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1551 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 1455 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 1552 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 1456 EXPECT_STR_EQ("abc", textfield_->text()); | 1553 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1457 SendKeyEvent(ui::VKEY_V, false, true); | 1554 SendKeyEvent(ui::VKEY_V, false, true); |
| 1458 EXPECT_STR_EQ("abcabc", textfield_->text()); | 1555 EXPECT_STR_EQ("abcabc", textfield_->text()); |
| 1459 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1556 SendAlternatePaste(); |
| 1460 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1557 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1461 SendKeyEvent(ui::VKEY_V, true, false, true, false); | 1558 SendKeyEvent(ui::VKEY_V, true, false, true, false); |
| 1462 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1559 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1463 | 1560 |
| 1464 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. | 1561 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. |
| 1465 textfield_->SelectAll(false); | 1562 textfield_->SelectAll(false); |
| 1466 SendKeyEvent(ui::VKEY_INSERT, true, true); | 1563 SendKeyEvent(ui::VKEY_INSERT, true, true); |
| 1467 EXPECT_STR_EQ("abc", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1564 EXPECT_STR_EQ("abc", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1468 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1565 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1469 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | 1566 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 1470 } | 1567 } |
| 1471 | 1568 |
| 1472 TEST_F(TextfieldTest, OvertypeMode) { | 1569 TEST_F(TextfieldTest, OvertypeMode) { |
| 1473 InitTextfield(); | 1570 InitTextfield(); |
| 1474 // Overtype mode should be disabled (no-op [Insert]). | 1571 // Overtype mode should be disabled (no-op [Insert]). |
| 1475 textfield_->SetText(ASCIIToUTF16("2")); | 1572 textfield_->SetText(ASCIIToUTF16("2")); |
| 1476 SendKeyEvent(ui::VKEY_HOME); | 1573 bool shift = false; |
| 1574 SendHomeEvent(shift); |
| 1575 // Note: On Mac, there is no insert key. Insert sends kVK_Help. Currently, |
| 1576 // since there is no overtype on toolkit-views, the behavior happens to match. |
| 1577 // However, there's no enable-overtype equivalent key combination on OSX. |
| 1477 SendKeyEvent(ui::VKEY_INSERT); | 1578 SendKeyEvent(ui::VKEY_INSERT); |
| 1478 SendKeyEvent(ui::VKEY_1, false, false); | 1579 SendKeyEvent(ui::VKEY_1, false, false); |
| 1479 EXPECT_STR_EQ("12", textfield_->text()); | 1580 EXPECT_STR_EQ("12", textfield_->text()); |
| 1480 } | 1581 } |
| 1481 | 1582 |
| 1482 TEST_F(TextfieldTest, TextCursorDisplayTest) { | 1583 TEST_F(TextfieldTest, TextCursorDisplayTest) { |
| 1483 InitTextfield(); | 1584 InitTextfield(); |
| 1484 // LTR-RTL string in LTR context. | 1585 // LTR-RTL string in LTR context. |
| 1485 SendKeyEvent('a'); | 1586 SendKeyEvent('a'); |
| 1486 EXPECT_STR_EQ("a", textfield_->text()); | 1587 EXPECT_STR_EQ("a", textfield_->text()); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 NonClientMouseClick(); | 1745 NonClientMouseClick(); |
| 1645 } | 1746 } |
| 1646 } | 1747 } |
| 1647 | 1748 |
| 1648 TEST_F(TextfieldTest, HitOutsideTextAreaTest) { | 1749 TEST_F(TextfieldTest, HitOutsideTextAreaTest) { |
| 1649 InitTextfield(); | 1750 InitTextfield(); |
| 1650 | 1751 |
| 1651 // LTR-RTL string in LTR context. | 1752 // LTR-RTL string in LTR context. |
| 1652 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1753 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
| 1653 | 1754 |
| 1654 SendKeyEvent(ui::VKEY_HOME); | 1755 bool shift = false; |
| 1756 SendHomeEvent(shift); |
| 1655 gfx::Rect bound = GetCursorBounds(); | 1757 gfx::Rect bound = GetCursorBounds(); |
| 1656 MouseClick(bound, -10); | 1758 MouseClick(bound, -10); |
| 1657 EXPECT_EQ(bound, GetCursorBounds()); | 1759 EXPECT_EQ(bound, GetCursorBounds()); |
| 1658 | 1760 |
| 1659 SendKeyEvent(ui::VKEY_END); | 1761 SendEndEvent(shift); |
| 1660 bound = GetCursorBounds(); | 1762 bound = GetCursorBounds(); |
| 1661 MouseClick(bound, 10); | 1763 MouseClick(bound, 10); |
| 1662 EXPECT_EQ(bound, GetCursorBounds()); | 1764 EXPECT_EQ(bound, GetCursorBounds()); |
| 1663 | 1765 |
| 1664 NonClientMouseClick(); | 1766 NonClientMouseClick(); |
| 1665 | 1767 |
| 1666 // RTL-LTR string in LTR context. | 1768 // RTL-LTR string in LTR context. |
| 1667 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); | 1769 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); |
| 1668 | 1770 |
| 1669 SendKeyEvent(ui::VKEY_HOME); | 1771 SendHomeEvent(shift); |
| 1670 bound = GetCursorBounds(); | 1772 bound = GetCursorBounds(); |
| 1671 MouseClick(bound, 10); | 1773 MouseClick(bound, 10); |
| 1672 EXPECT_EQ(bound, GetCursorBounds()); | 1774 EXPECT_EQ(bound, GetCursorBounds()); |
| 1673 | 1775 |
| 1674 SendKeyEvent(ui::VKEY_END); | 1776 SendEndEvent(shift); |
| 1675 bound = GetCursorBounds(); | 1777 bound = GetCursorBounds(); |
| 1676 MouseClick(bound, -10); | 1778 MouseClick(bound, -10); |
| 1677 EXPECT_EQ(bound, GetCursorBounds()); | 1779 EXPECT_EQ(bound, GetCursorBounds()); |
| 1678 } | 1780 } |
| 1679 | 1781 |
| 1680 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { | 1782 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { |
| 1681 std::string locale = l10n_util::GetApplicationLocale(""); | 1783 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1682 base::i18n::SetICUDefaultLocale("he"); | 1784 base::i18n::SetICUDefaultLocale("he"); |
| 1683 | 1785 |
| 1684 InitTextfield(); | 1786 InitTextfield(); |
| 1685 | 1787 |
| 1686 // RTL-LTR string in RTL context. | 1788 // RTL-LTR string in RTL context. |
| 1687 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); | 1789 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); |
| 1688 SendKeyEvent(ui::VKEY_HOME); | 1790 bool shift = false; |
| 1791 SendHomeEvent(shift); |
| 1689 gfx::Rect bound = GetCursorBounds(); | 1792 gfx::Rect bound = GetCursorBounds(); |
| 1690 MouseClick(bound, 10); | 1793 MouseClick(bound, 10); |
| 1691 EXPECT_EQ(bound, GetCursorBounds()); | 1794 EXPECT_EQ(bound, GetCursorBounds()); |
| 1692 | 1795 |
| 1693 SendKeyEvent(ui::VKEY_END); | 1796 SendEndEvent(shift); |
| 1694 bound = GetCursorBounds(); | 1797 bound = GetCursorBounds(); |
| 1695 MouseClick(bound, -10); | 1798 MouseClick(bound, -10); |
| 1696 EXPECT_EQ(bound, GetCursorBounds()); | 1799 EXPECT_EQ(bound, GetCursorBounds()); |
| 1697 | 1800 |
| 1698 NonClientMouseClick(); | 1801 NonClientMouseClick(); |
| 1699 | 1802 |
| 1700 // LTR-RTL string in RTL context. | 1803 // LTR-RTL string in RTL context. |
| 1701 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1804 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
| 1702 SendKeyEvent(ui::VKEY_HOME); | 1805 SendHomeEvent(shift); |
| 1703 bound = GetCursorBounds(); | 1806 bound = GetCursorBounds(); |
| 1704 MouseClick(bound, -10); | 1807 MouseClick(bound, -10); |
| 1705 EXPECT_EQ(bound, GetCursorBounds()); | 1808 EXPECT_EQ(bound, GetCursorBounds()); |
| 1706 | 1809 |
| 1707 SendKeyEvent(ui::VKEY_END); | 1810 SendEndEvent(shift); |
| 1708 bound = GetCursorBounds(); | 1811 bound = GetCursorBounds(); |
| 1709 MouseClick(bound, 10); | 1812 MouseClick(bound, 10); |
| 1710 EXPECT_EQ(bound, GetCursorBounds()); | 1813 EXPECT_EQ(bound, GetCursorBounds()); |
| 1711 | 1814 |
| 1712 // Reset locale. | 1815 // Reset locale. |
| 1713 base::i18n::SetICUDefaultLocale(locale); | 1816 base::i18n::SetICUDefaultLocale(locale); |
| 1714 } | 1817 } |
| 1715 | 1818 |
| 1716 TEST_F(TextfieldTest, OverflowTest) { | 1819 TEST_F(TextfieldTest, OverflowTest) { |
| 1717 InitTextfield(); | 1820 InitTextfield(); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 // Tests that a textfield view can be destroyed from OnKeyEvent() on its | 2136 // Tests that a textfield view can be destroyed from OnKeyEvent() on its |
| 2034 // controller and it does not crash. | 2137 // controller and it does not crash. |
| 2035 TEST_F(TextfieldTest, DestroyingTextfieldFromOnKeyEvent) { | 2138 TEST_F(TextfieldTest, DestroyingTextfieldFromOnKeyEvent) { |
| 2036 InitTextfield(); | 2139 InitTextfield(); |
| 2037 | 2140 |
| 2038 // The controller assumes ownership of the textfield. | 2141 // The controller assumes ownership of the textfield. |
| 2039 TextfieldDestroyerController controller(textfield_); | 2142 TextfieldDestroyerController controller(textfield_); |
| 2040 EXPECT_TRUE(controller.target()); | 2143 EXPECT_TRUE(controller.target()); |
| 2041 | 2144 |
| 2042 // Send a key to trigger OnKeyEvent(). | 2145 // Send a key to trigger OnKeyEvent(). |
| 2043 SendKeyEvent('X'); | 2146 SendKeyEvent(ui::VKEY_RETURN); |
| 2044 | 2147 |
| 2045 EXPECT_FALSE(controller.target()); | 2148 EXPECT_FALSE(controller.target()); |
| 2046 } | 2149 } |
| 2047 | 2150 |
| 2048 class TextfieldTouchSelectionTest : public TextfieldTest { | 2151 class TextfieldTouchSelectionTest : public TextfieldTest { |
| 2049 public: | 2152 public: |
| 2050 // TextfieldTest: | 2153 // TextfieldTest: |
| 2051 void SetUp() override { | 2154 void SetUp() override { |
| 2052 TextfieldTest::SetUp(); | 2155 TextfieldTest::SetUp(); |
| 2053 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 2156 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 | 2253 |
| 2151 // Make textfield unfocusable and tap on it. Touch text selection should not | 2254 // Make textfield unfocusable and tap on it. Touch text selection should not |
| 2152 // get activated. | 2255 // get activated. |
| 2153 textfield_->SetFocusable(false); | 2256 textfield_->SetFocusable(false); |
| 2154 Tap(touch_point); | 2257 Tap(touch_point); |
| 2155 EXPECT_FALSE(textfield_->HasFocus()); | 2258 EXPECT_FALSE(textfield_->HasFocus()); |
| 2156 EXPECT_FALSE(test_api_->touch_selection_controller()); | 2259 EXPECT_FALSE(test_api_->touch_selection_controller()); |
| 2157 textfield_->SetFocusable(true); | 2260 textfield_->SetFocusable(true); |
| 2158 } | 2261 } |
| 2159 | 2262 |
| 2160 TEST_F(TextfieldTouchSelectionTest, TapOnSelection) { | 2263 // No touch on desktop Mac. Tracked in http://crbug.com/445520. |
| 2264 #if defined(OS_MACOSX) && !defined(USE_AURA) |
| 2265 #define MAYBE_TapOnSelection DISABLED_TapOnSelection |
| 2266 #else |
| 2267 #define MAYBE_TapOnSelection TapOnSelection |
| 2268 #endif |
| 2269 |
| 2270 TEST_F(TextfieldTouchSelectionTest, MAYBE_TapOnSelection) { |
| 2161 InitTextfield(); | 2271 InitTextfield(); |
| 2162 textfield_->SetText(ASCIIToUTF16("hello world")); | 2272 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 2163 gfx::Range sel_range(2, 7); | 2273 gfx::Range sel_range(2, 7); |
| 2164 gfx::Range tap_range(5, 5); | 2274 gfx::Range tap_range(5, 5); |
| 2165 gfx::Rect tap_rect = | 2275 gfx::Rect tap_rect = |
| 2166 GetCursorBounds(gfx::SelectionModel(tap_range, gfx::CURSOR_FORWARD)); | 2276 GetCursorBounds(gfx::SelectionModel(tap_range, gfx::CURSOR_FORWARD)); |
| 2167 gfx::Point tap_point = tap_rect.CenterPoint(); | 2277 gfx::Point tap_point = tap_rect.CenterPoint(); |
| 2168 | 2278 |
| 2169 // Select range |sel_range| and check if touch selection handles are not | 2279 // Select range |sel_range| and check if touch selection handles are not |
| 2170 // present and correct range is selected. | 2280 // present and correct range is selected. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2183 | 2293 |
| 2184 // Tap again on selection and check if touch selection handles are still | 2294 // Tap again on selection and check if touch selection handles are still |
| 2185 // present and selection is changed to a cursor at tap location. | 2295 // present and selection is changed to a cursor at tap location. |
| 2186 Tap(tap_point); | 2296 Tap(tap_point); |
| 2187 textfield_->GetSelectionRange(&range); | 2297 textfield_->GetSelectionRange(&range); |
| 2188 EXPECT_TRUE(test_api_->touch_selection_controller()); | 2298 EXPECT_TRUE(test_api_->touch_selection_controller()); |
| 2189 EXPECT_EQ(tap_range, range); | 2299 EXPECT_EQ(tap_range, range); |
| 2190 } | 2300 } |
| 2191 | 2301 |
| 2192 } // namespace views | 2302 } // namespace views |
| OLD | NEW |