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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/format_macros.h" | |
| 15 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/pickle.h" | 18 #include "base/pickle.h" |
| 18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/stringprintf.h" | |
| 19 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 20 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 21 #include "ui/accessibility/ax_view_state.h" | 23 #include "ui/accessibility/ax_view_state.h" |
| 22 #include "ui/base/clipboard/clipboard.h" | 24 #include "ui/base/clipboard/clipboard.h" |
| 23 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 25 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 24 #include "ui/base/dragdrop/drag_drop_types.h" | 26 #include "ui/base/dragdrop/drag_drop_types.h" |
| 25 #include "ui/base/ime/input_method_base.h" | 27 #include "ui/base/ime/input_method_base.h" |
| 26 #include "ui/base/ime/input_method_delegate.h" | 28 #include "ui/base/ime/input_method_delegate.h" |
| 27 #include "ui/base/ime/input_method_factory.h" | 29 #include "ui/base/ime/input_method_factory.h" |
| 28 #include "ui/base/ime/text_input_client.h" | 30 #include "ui/base/ime/text_input_client.h" |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 SendWordEvent(ui::VKEY_RIGHT, shift); | 862 SendWordEvent(ui::VKEY_RIGHT, shift); |
| 861 shift = true; | 863 shift = true; |
| 862 SendWordEvent(ui::VKEY_DELETE, shift); | 864 SendWordEvent(ui::VKEY_DELETE, shift); |
| 863 #if defined(OS_LINUX) | 865 #if defined(OS_LINUX) |
| 864 EXPECT_STR_EQ(" two", textfield_->text()); | 866 EXPECT_STR_EQ(" two", textfield_->text()); |
| 865 #else | 867 #else |
| 866 EXPECT_STR_EQ(" two four", textfield_->text()); | 868 EXPECT_STR_EQ(" two four", textfield_->text()); |
| 867 #endif | 869 #endif |
| 868 } | 870 } |
| 869 | 871 |
| 872 // Test that deletion operations behave correctly in case there is an active | |
|
msw
2016/04/29 16:59:22
nit: one liner "// Test that deletion operations b
karandeepb
2016/05/02 03:01:42
Done.
| |
| 873 // selection. | |
| 874 TEST_F(TextfieldTest, DeletionWithSelection) { | |
| 875 struct { | |
| 876 ui::KeyboardCode key; | |
| 877 bool shift; | |
| 878 } cases[] = { | |
| 879 {ui::VKEY_BACK, false}, | |
| 880 {ui::VKEY_DELETE, false}, | |
|
msw
2016/04/29 16:59:22
optional nit: swap cases so it's back, back, delet
karandeepb
2016/05/02 03:01:42
Done.
| |
| 881 {ui::VKEY_BACK, true}, | |
| 882 {ui::VKEY_DELETE, true}, | |
| 883 }; | |
| 884 | |
| 885 InitTextfield(); | |
| 886 // [Ctrl] ([Alt] on Mac) + [Delete]/[Backspace] should delete the active | |
| 887 // selection, regardless of [Shift]. | |
| 888 for (size_t i = 0; i < arraysize(cases); ++i) { | |
| 889 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); | |
| 890 textfield_->SetText(ASCIIToUTF16("one two three")); | |
| 891 textfield_->SelectRange(gfx::Range(2, 6)); | |
| 892 // Make selection as - on|e tw|o three. | |
| 893 SendWordEvent(cases[i].key, cases[i].shift); | |
| 894 // Verify state is on|o three. | |
| 895 EXPECT_STR_EQ("ono three", textfield_->text()); | |
| 896 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); | |
| 897 } | |
| 898 } | |
| 899 | |
| 870 TEST_F(TextfieldTest, PasswordTest) { | 900 TEST_F(TextfieldTest, PasswordTest) { |
| 871 InitTextfield(); | 901 InitTextfield(); |
| 872 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 902 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 873 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); | 903 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 874 EXPECT_TRUE(textfield_->enabled()); | 904 EXPECT_TRUE(textfield_->enabled()); |
| 875 EXPECT_TRUE(textfield_->IsFocusable()); | 905 EXPECT_TRUE(textfield_->IsFocusable()); |
| 876 | 906 |
| 877 last_contents_.clear(); | 907 last_contents_.clear(); |
| 878 textfield_->SetText(ASCIIToUTF16("password")); | 908 textfield_->SetText(ASCIIToUTF16("password")); |
| 879 // Ensure text() and the callback returns the actual text instead of "*". | 909 // 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()); | 1829 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1800 | 1830 |
| 1801 // Ensure [Shift]+[Delete] cuts. | 1831 // Ensure [Shift]+[Delete] cuts. |
| 1802 textfield_->SetText(ASCIIToUTF16("123")); | 1832 textfield_->SetText(ASCIIToUTF16("123")); |
| 1803 textfield_->SelectAll(false); | 1833 textfield_->SelectAll(false); |
| 1804 SendAlternateCut(); | 1834 SendAlternateCut(); |
| 1805 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1835 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1806 EXPECT_STR_EQ("", textfield_->text()); | 1836 EXPECT_STR_EQ("", textfield_->text()); |
| 1807 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1837 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1808 | 1838 |
| 1839 // Reset clipboard text. | |
| 1840 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, ""); | |
| 1841 | |
| 1842 // Ensure [Shift]+[Delete] is a no-op in case there is no selection. | |
| 1843 textfield_->SetText(ASCIIToUTF16("123")); | |
| 1844 textfield_->SelectRange(gfx::Range(0)); | |
| 1845 SendAlternateCut(); | |
| 1846 EXPECT_STR_EQ("", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | |
| 1847 EXPECT_STR_EQ("123", textfield_->text()); | |
| 1848 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); | |
| 1849 | |
| 1809 // Ensure IDS_APP_COPY copies. | 1850 // Ensure IDS_APP_COPY copies. |
| 1810 textfield_->SetText(ASCIIToUTF16("789")); | 1851 textfield_->SetText(ASCIIToUTF16("789")); |
| 1811 textfield_->SelectAll(false); | 1852 textfield_->SelectAll(false); |
| 1812 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 1853 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1813 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 1854 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1814 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1855 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1815 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1856 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1816 | 1857 |
| 1817 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | 1858 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. |
| 1818 textfield_->SetText(ASCIIToUTF16("012")); | 1859 textfield_->SetText(ASCIIToUTF16("012")); |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2604 | 2645 |
| 2605 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2646 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2606 ui::AXViewState state_protected; | 2647 ui::AXViewState state_protected; |
| 2607 textfield_->GetAccessibleState(&state_protected); | 2648 textfield_->GetAccessibleState(&state_protected); |
| 2608 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2649 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2609 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2650 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2610 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2651 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2611 } | 2652 } |
| 2612 | 2653 |
| 2613 } // namespace views | 2654 } // namespace views |
| OLD | NEW |