Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 SendWordEvent(ui::VKEY_RIGHT, shift); | 860 SendWordEvent(ui::VKEY_RIGHT, shift); |
| 861 shift = true; | 861 shift = true; |
| 862 SendWordEvent(ui::VKEY_DELETE, shift); | 862 SendWordEvent(ui::VKEY_DELETE, shift); |
| 863 #if defined(OS_LINUX) | 863 #if defined(OS_LINUX) |
| 864 EXPECT_STR_EQ(" two", textfield_->text()); | 864 EXPECT_STR_EQ(" two", textfield_->text()); |
| 865 #else | 865 #else |
| 866 EXPECT_STR_EQ(" two four", textfield_->text()); | 866 EXPECT_STR_EQ(" two four", textfield_->text()); |
| 867 #endif | 867 #endif |
| 868 } | 868 } |
| 869 | 869 |
| 870 // Test that deletion operations behave correctly in case there is an active | |
| 871 // selection. | |
| 872 TEST_F(TextfieldTest, DeletionWithSelection) { | |
|
karandeepb
2016/04/27 05:27:56
Ideally, this should fail on master for Linux. How
msw
2016/04/28 18:22:02
Since all cases have the same behavior, you could
msw
2016/04/28 18:22:02
Add a comment to that effect at a condition that s
karandeepb
2016/04/29 01:40:59
Done.
karandeepb
2016/04/29 01:40:59
I wasn't probably clear enough. I meant that it sh
| |
| 873 InitTextfield(); | |
| 874 textfield_->SetText(ASCIIToUTF16("one two three")); | |
| 875 | |
| 876 // Make selection as - on|e tw|o three | |
| 877 textfield_->SelectRange(gfx::Range(2, 6)); | |
| 878 // Send keyboard event for delete previous word. | |
| 879 bool shift = false; | |
| 880 SendWordEvent(ui::VKEY_BACK, shift); | |
| 881 // Verify state is on|o three. | |
| 882 EXPECT_STR_EQ("ono three", textfield_->text()); | |
| 883 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); | |
| 884 | |
| 885 // Make selection as on|o th|ree. | |
| 886 textfield_->SelectRange(gfx::Range(2, 6)); | |
| 887 // Delete to a line break on Linux and ChromeOS, to a word break on Windows | |
|
msw
2016/04/28 18:22:02
nit: Shouldn't this comment say "[Shift]+[Backspac
karandeepb
2016/04/29 01:40:59
Yeah, it should. Though it's actually Ctrl + Shift
| |
| 888 // and Mac. However since there is an active selection, only the selection | |
| 889 // should be deleted. | |
| 890 shift = true; | |
| 891 SendWordEvent(ui::VKEY_BACK, shift); | |
| 892 | |
| 893 // Verify state is on|ree. | |
| 894 EXPECT_STR_EQ("onree", textfield_->text()); | |
| 895 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); | |
| 896 | |
| 897 textfield_->SetText(ASCIIToUTF16("one two three")); | |
| 898 | |
| 899 // Make selection as - on|e tw|o three | |
| 900 textfield_->SelectRange(gfx::Range(2, 6)); | |
| 901 // Send keyboard event for delete next word. | |
| 902 shift = false; | |
| 903 SendWordEvent(ui::VKEY_DELETE, shift); | |
| 904 // Verify state is on|o three. | |
| 905 EXPECT_STR_EQ("ono three", textfield_->text()); | |
| 906 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); | |
| 907 | |
| 908 // Make selection as on|o th|ree. | |
| 909 textfield_->SelectRange(gfx::Range(2, 6)); | |
| 910 // Delete to a line break on Linux and ChromeOS, to a word break on Windows | |
|
msw
2016/04/28 18:22:02
ditto nit: Shouldn't this comment say "[Shift]+[De
karandeepb
2016/04/29 01:40:59
Done.
| |
| 911 // and Mac. However since there is an active selection, only the selection | |
| 912 // should be deleted. | |
| 913 shift = true; | |
| 914 SendWordEvent(ui::VKEY_DELETE, shift); | |
| 915 | |
| 916 // Verify state is on|ree. | |
| 917 EXPECT_STR_EQ("onree", textfield_->text()); | |
| 918 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); | |
| 919 } | |
| 920 | |
| 870 TEST_F(TextfieldTest, PasswordTest) { | 921 TEST_F(TextfieldTest, PasswordTest) { |
| 871 InitTextfield(); | 922 InitTextfield(); |
| 872 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 923 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 873 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); | 924 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 874 EXPECT_TRUE(textfield_->enabled()); | 925 EXPECT_TRUE(textfield_->enabled()); |
| 875 EXPECT_TRUE(textfield_->IsFocusable()); | 926 EXPECT_TRUE(textfield_->IsFocusable()); |
| 876 | 927 |
| 877 last_contents_.clear(); | 928 last_contents_.clear(); |
| 878 textfield_->SetText(ASCIIToUTF16("password")); | 929 textfield_->SetText(ASCIIToUTF16("password")); |
| 879 // Ensure text() and the callback returns the actual text instead of "*". | 930 // Ensure text() and the callback returns the actual text instead of "*". |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1799 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1850 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1800 | 1851 |
| 1801 // Ensure [Shift]+[Delete] cuts. | 1852 // Ensure [Shift]+[Delete] cuts. |
| 1802 textfield_->SetText(ASCIIToUTF16("123")); | 1853 textfield_->SetText(ASCIIToUTF16("123")); |
| 1803 textfield_->SelectAll(false); | 1854 textfield_->SelectAll(false); |
| 1804 SendAlternateCut(); | 1855 SendAlternateCut(); |
| 1805 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1856 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1806 EXPECT_STR_EQ("", textfield_->text()); | 1857 EXPECT_STR_EQ("", textfield_->text()); |
| 1807 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1858 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1808 | 1859 |
| 1860 // Reset clipboard text. | |
| 1861 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, ""); | |
| 1862 | |
| 1863 // Ensure [Shift]+[Delete] is a no-op in case there is no selection. | |
| 1864 textfield_->SetText(ASCIIToUTF16("123")); | |
| 1865 textfield_->SelectRange(gfx::Range(0)); | |
| 1866 SendAlternateCut(); | |
| 1867 EXPECT_STR_EQ("", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | |
| 1868 EXPECT_STR_EQ("123", textfield_->text()); | |
| 1869 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | |
| 1870 | |
| 1809 // Ensure IDS_APP_COPY copies. | 1871 // Ensure IDS_APP_COPY copies. |
| 1810 textfield_->SetText(ASCIIToUTF16("789")); | 1872 textfield_->SetText(ASCIIToUTF16("789")); |
| 1811 textfield_->SelectAll(false); | 1873 textfield_->SelectAll(false); |
| 1812 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 1874 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1813 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 1875 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1814 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1876 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1815 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1877 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1816 | 1878 |
| 1817 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | 1879 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. |
| 1818 textfield_->SetText(ASCIIToUTF16("012")); | 1880 textfield_->SetText(ASCIIToUTF16("012")); |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2604 | 2666 |
| 2605 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2667 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2606 ui::AXViewState state_protected; | 2668 ui::AXViewState state_protected; |
| 2607 textfield_->GetAccessibleState(&state_protected); | 2669 textfield_->GetAccessibleState(&state_protected); |
| 2608 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2670 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2609 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2671 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2610 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2672 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2611 } | 2673 } |
| 2612 | 2674 |
| 2613 } // namespace views | 2675 } // namespace views |
| OLD | NEW |