| 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 with an active selection. |
| 873 TEST_F(TextfieldTest, DeletionWithSelection) { |
| 874 struct { |
| 875 ui::KeyboardCode key; |
| 876 bool shift; |
| 877 } cases[] = { |
| 878 {ui::VKEY_BACK, false}, |
| 879 {ui::VKEY_BACK, true}, |
| 880 {ui::VKEY_DELETE, false}, |
| 881 {ui::VKEY_DELETE, true}, |
| 882 }; |
| 883 |
| 884 InitTextfield(); |
| 885 // [Ctrl] ([Alt] on Mac) + [Delete]/[Backspace] should delete the active |
| 886 // selection, regardless of [Shift]. |
| 887 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 888 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); |
| 889 textfield_->SetText(ASCIIToUTF16("one two three")); |
| 890 textfield_->SelectRange(gfx::Range(2, 6)); |
| 891 // Make selection as - on|e tw|o three. |
| 892 SendWordEvent(cases[i].key, cases[i].shift); |
| 893 // Verify state is on|o three. |
| 894 EXPECT_STR_EQ("ono three", textfield_->text()); |
| 895 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); |
| 896 } |
| 897 } |
| 898 |
| 870 TEST_F(TextfieldTest, PasswordTest) { | 899 TEST_F(TextfieldTest, PasswordTest) { |
| 871 InitTextfield(); | 900 InitTextfield(); |
| 872 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 901 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 873 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); | 902 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 874 EXPECT_TRUE(textfield_->enabled()); | 903 EXPECT_TRUE(textfield_->enabled()); |
| 875 EXPECT_TRUE(textfield_->IsFocusable()); | 904 EXPECT_TRUE(textfield_->IsFocusable()); |
| 876 | 905 |
| 877 last_contents_.clear(); | 906 last_contents_.clear(); |
| 878 textfield_->SetText(ASCIIToUTF16("password")); | 907 textfield_->SetText(ASCIIToUTF16("password")); |
| 879 // Ensure text() and the callback returns the actual text instead of "*". | 908 // 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()); | 1828 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1800 | 1829 |
| 1801 // Ensure [Shift]+[Delete] cuts. | 1830 // Ensure [Shift]+[Delete] cuts. |
| 1802 textfield_->SetText(ASCIIToUTF16("123")); | 1831 textfield_->SetText(ASCIIToUTF16("123")); |
| 1803 textfield_->SelectAll(false); | 1832 textfield_->SelectAll(false); |
| 1804 SendAlternateCut(); | 1833 SendAlternateCut(); |
| 1805 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1834 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1806 EXPECT_STR_EQ("", textfield_->text()); | 1835 EXPECT_STR_EQ("", textfield_->text()); |
| 1807 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1836 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1808 | 1837 |
| 1838 // Reset clipboard text. |
| 1839 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, ""); |
| 1840 |
| 1841 // Ensure [Shift]+[Delete] is a no-op in case there is no selection. |
| 1842 textfield_->SetText(ASCIIToUTF16("123")); |
| 1843 textfield_->SelectRange(gfx::Range(0)); |
| 1844 SendAlternateCut(); |
| 1845 EXPECT_STR_EQ("", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1846 EXPECT_STR_EQ("123", textfield_->text()); |
| 1847 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); |
| 1848 |
| 1809 // Ensure IDS_APP_COPY copies. | 1849 // Ensure IDS_APP_COPY copies. |
| 1810 textfield_->SetText(ASCIIToUTF16("789")); | 1850 textfield_->SetText(ASCIIToUTF16("789")); |
| 1811 textfield_->SelectAll(false); | 1851 textfield_->SelectAll(false); |
| 1812 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 1852 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1813 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 1853 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1814 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1854 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1815 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); | 1855 EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard()); |
| 1816 | 1856 |
| 1817 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | 1857 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. |
| 1818 textfield_->SetText(ASCIIToUTF16("012")); | 1858 textfield_->SetText(ASCIIToUTF16("012")); |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2604 | 2644 |
| 2605 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2645 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2606 ui::AXViewState state_protected; | 2646 ui::AXViewState state_protected; |
| 2607 textfield_->GetAccessibleState(&state_protected); | 2647 textfield_->GetAccessibleState(&state_protected); |
| 2608 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2648 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2609 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2649 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2610 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2650 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2611 } | 2651 } |
| 2612 | 2652 |
| 2613 } // namespace views | 2653 } // namespace views |
| OLD | NEW |