| 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 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 EXPECT_STR_EQ("ab", textfield_->text()); | 1790 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1791 SendKeyEvent(ui::VKEY_Z, true, true); | 1791 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1792 EXPECT_STR_EQ("b", textfield_->text()); | 1792 EXPECT_STR_EQ("b", textfield_->text()); |
| 1793 SendKeyEvent(ui::VKEY_Z, true, true); | 1793 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1794 EXPECT_STR_EQ("", textfield_->text()); | 1794 EXPECT_STR_EQ("", textfield_->text()); |
| 1795 SendKeyEvent(ui::VKEY_Z, true, true); | 1795 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1796 EXPECT_STR_EQ("", textfield_->text()); | 1796 EXPECT_STR_EQ("", textfield_->text()); |
| 1797 } | 1797 } |
| 1798 | 1798 |
| 1799 // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac | 1799 // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac |
| 1800 // that is bound to "Show full history", so is not mapped as an editing | 1800 // Ctrl+Y is bound to "Yank" and Cmd+Y is bound to "Show full history". So, on |
| 1801 // command. So, on Mac, send Cmd+Shift+Z. | 1801 // Mac, send Cmd+Shift+Z. |
| 1802 #if !defined(OS_MACOSX) | 1802 #if !defined(OS_MACOSX) |
| 1803 | 1803 |
| 1804 // Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z. | 1804 // Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z. |
| 1805 TEST_F(TextfieldTest, RedoWithCtrlY) { | 1805 TEST_F(TextfieldTest, RedoWithCtrlY) { |
| 1806 InitTextfield(); | 1806 InitTextfield(); |
| 1807 SendKeyEvent(ui::VKEY_A); | 1807 SendKeyEvent(ui::VKEY_A); |
| 1808 EXPECT_STR_EQ("a", textfield_->text()); | 1808 EXPECT_STR_EQ("a", textfield_->text()); |
| 1809 SendKeyEvent(ui::VKEY_Z, false, true); | 1809 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1810 EXPECT_STR_EQ("", textfield_->text()); | 1810 EXPECT_STR_EQ("", textfield_->text()); |
| 1811 SendKeyEvent(ui::VKEY_Y, false, true); | 1811 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1812 EXPECT_STR_EQ("a", textfield_->text()); | 1812 EXPECT_STR_EQ("a", textfield_->text()); |
| 1813 SendKeyEvent(ui::VKEY_Z, false, true); | 1813 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1814 EXPECT_STR_EQ("", textfield_->text()); | 1814 EXPECT_STR_EQ("", textfield_->text()); |
| 1815 SendKeyEvent(ui::VKEY_Z, true, true); | 1815 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1816 EXPECT_STR_EQ("a", textfield_->text()); | 1816 EXPECT_STR_EQ("a", textfield_->text()); |
| 1817 } | 1817 } |
| 1818 | 1818 |
| 1819 #endif // !defined(OS_MACOSX) | 1819 #endif // !defined(OS_MACOSX) |
| 1820 | 1820 |
| 1821 // Non-Mac platforms don't have a key binding for Yank. Since this test is only |
| 1822 // run on Mac, it uses some Mac specific key bindings. |
| 1823 #if defined(OS_MACOSX) |
| 1824 |
| 1825 TEST_F(TextfieldTest, Yank) { |
| 1826 InitTextfields(2); |
| 1827 textfield_->SetText(ASCIIToUTF16("abcdef")); |
| 1828 textfield_->SelectRange(gfx::Range(2, 4)); |
| 1829 |
| 1830 // Press Ctrl+Y to yank. |
| 1831 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 1832 |
| 1833 // Initially the kill buffer should be empty. Hence yanking should delete the |
| 1834 // selected text. |
| 1835 EXPECT_STR_EQ("abef", textfield_->text()); |
| 1836 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); |
| 1837 |
| 1838 // Press Ctrl+K to delete to end of paragraph. This should place the deleted |
| 1839 // text in the kill buffer. |
| 1840 SendKeyPress(ui::VKEY_K, ui::EF_CONTROL_DOWN); |
| 1841 |
| 1842 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1843 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); |
| 1844 |
| 1845 // Yank twice. |
| 1846 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 1847 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 1848 EXPECT_STR_EQ("abefef", textfield_->text()); |
| 1849 EXPECT_EQ(gfx::Range(6), textfield_->GetSelectedRange()); |
| 1850 |
| 1851 // Verify pressing backspace does not modify the kill buffer. |
| 1852 SendKeyEvent(ui::VKEY_BACK); |
| 1853 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 1854 EXPECT_STR_EQ("abefeef", textfield_->text()); |
| 1855 EXPECT_EQ(gfx::Range(7), textfield_->GetSelectedRange()); |
| 1856 |
| 1857 // Move focus to next textfield. |
| 1858 widget_->GetFocusManager()->AdvanceFocus(false); |
| 1859 EXPECT_EQ(2, GetFocusedView()->id()); |
| 1860 Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView()); |
| 1861 EXPECT_STR_EQ("", textfield2->text()); |
| 1862 |
| 1863 // Verify yanked text persists across multiple textfields. |
| 1864 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); |
| 1865 EXPECT_STR_EQ("ef", textfield2->text()); |
| 1866 EXPECT_EQ(gfx::Range(2), textfield2->GetSelectedRange()); |
| 1867 } |
| 1868 |
| 1869 #endif |
| 1870 |
| 1821 TEST_F(TextfieldTest, CutCopyPaste) { | 1871 TEST_F(TextfieldTest, CutCopyPaste) { |
| 1822 InitTextfield(); | 1872 InitTextfield(); |
| 1823 | 1873 |
| 1824 // Ensure IDS_APP_CUT cuts. | 1874 // Ensure IDS_APP_CUT cuts. |
| 1825 textfield_->SetText(ASCIIToUTF16("123")); | 1875 textfield_->SetText(ASCIIToUTF16("123")); |
| 1826 textfield_->SelectAll(false); | 1876 textfield_->SelectAll(false); |
| 1827 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 1877 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 1828 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 1878 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 1829 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1879 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1830 EXPECT_STR_EQ("", textfield_->text()); | 1880 EXPECT_STR_EQ("", textfield_->text()); |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2658 | 2708 |
| 2659 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2709 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2660 ui::AXViewState state_protected; | 2710 ui::AXViewState state_protected; |
| 2661 textfield_->GetAccessibleState(&state_protected); | 2711 textfield_->GetAccessibleState(&state_protected); |
| 2662 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2712 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2663 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2713 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2664 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2714 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2665 } | 2715 } |
| 2666 | 2716 |
| 2667 } // namespace views | 2717 } // namespace views |
| OLD | NEW |