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 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1831 EXPECT_STR_EQ("ab", textfield_->text()); | 1831 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1832 SendKeyEvent(ui::VKEY_Z, true, true); | 1832 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1833 EXPECT_STR_EQ("b", textfield_->text()); | 1833 EXPECT_STR_EQ("b", textfield_->text()); |
| 1834 SendKeyEvent(ui::VKEY_Z, true, true); | 1834 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1835 EXPECT_STR_EQ("", textfield_->text()); | 1835 EXPECT_STR_EQ("", textfield_->text()); |
| 1836 SendKeyEvent(ui::VKEY_Z, true, true); | 1836 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1837 EXPECT_STR_EQ("", textfield_->text()); | 1837 EXPECT_STR_EQ("", textfield_->text()); |
| 1838 } | 1838 } |
| 1839 | 1839 |
| 1840 // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac | 1840 // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac |
| 1841 // that is bound to "Show full history", so is not mapped as an editing | 1841 // Ctrl+Y is bound to "Yank" and Cmd+Y is bound to "Show full history". So, on |
| 1842 // command. So, on Mac, send Cmd+Shift+Z. | 1842 // Mac, Cmd+Shift+Z is sent for the tests above and the Ctrl+Y test below is |
| 1843 // skipped. | |
| 1843 #if !defined(OS_MACOSX) | 1844 #if !defined(OS_MACOSX) |
| 1844 | 1845 |
| 1845 // Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z. | 1846 // Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z. |
| 1846 TEST_F(TextfieldTest, RedoWithCtrlY) { | 1847 TEST_F(TextfieldTest, RedoWithCtrlY) { |
| 1847 InitTextfield(); | 1848 InitTextfield(); |
| 1848 SendKeyEvent(ui::VKEY_A); | 1849 SendKeyEvent(ui::VKEY_A); |
| 1849 EXPECT_STR_EQ("a", textfield_->text()); | 1850 EXPECT_STR_EQ("a", textfield_->text()); |
| 1850 SendKeyEvent(ui::VKEY_Z, false, true); | 1851 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1851 EXPECT_STR_EQ("", textfield_->text()); | 1852 EXPECT_STR_EQ("", textfield_->text()); |
| 1852 SendKeyEvent(ui::VKEY_Y, false, true); | 1853 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1853 EXPECT_STR_EQ("a", textfield_->text()); | 1854 EXPECT_STR_EQ("a", textfield_->text()); |
| 1854 SendKeyEvent(ui::VKEY_Z, false, true); | 1855 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1855 EXPECT_STR_EQ("", textfield_->text()); | 1856 EXPECT_STR_EQ("", textfield_->text()); |
| 1856 SendKeyEvent(ui::VKEY_Z, true, true); | 1857 SendKeyEvent(ui::VKEY_Z, true, true); |
| 1857 EXPECT_STR_EQ("a", textfield_->text()); | 1858 EXPECT_STR_EQ("a", textfield_->text()); |
| 1858 } | 1859 } |
| 1859 | 1860 |
| 1860 #endif // !defined(OS_MACOSX) | 1861 #endif // !defined(OS_MACOSX) |
| 1861 | 1862 |
| 1863 // Non-Mac platforms don't have a key binding for Yank. Since this test is only | |
| 1864 // run on Mac, it uses some Mac specific key bindings. | |
| 1865 #if defined(OS_MACOSX) | |
| 1866 | |
| 1867 TEST_F(TextfieldTest, Yank) { | |
| 1868 InitTextfields(2); | |
| 1869 textfield_->SetText(ASCIIToUTF16("abcdef")); | |
| 1870 textfield_->SelectRange(gfx::Range(2, 4)); | |
| 1871 | |
| 1872 // Press Ctrl+Y to yank. | |
| 1873 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); | |
| 1874 | |
| 1875 // Initially the kill buffer should be empty. Hence yanking should delete the | |
| 1876 // selected text. | |
| 1877 EXPECT_STR_EQ("abef", textfield_->text()); | |
| 1878 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); | |
| 1879 | |
| 1880 // Press Ctrl+K to delete to end of paragraph. This should place the deleted | |
| 1881 // text in the kill buffer. | |
| 1882 SendKeyPress(ui::VKEY_K, ui::EF_CONTROL_DOWN); | |
| 1883 | |
| 1884 EXPECT_STR_EQ("ab", textfield_->text()); | |
| 1885 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange()); | |
| 1886 | |
| 1887 // Yank twice. | |
| 1888 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); | |
| 1889 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); | |
| 1890 EXPECT_STR_EQ("abefef", textfield_->text()); | |
| 1891 EXPECT_EQ(gfx::Range(6), textfield_->GetSelectedRange()); | |
| 1892 | |
| 1893 // Verify pressing backspace does not modify the kill buffer. | |
| 1894 SendKeyEvent(ui::VKEY_BACK); | |
| 1895 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); | |
| 1896 EXPECT_STR_EQ("abefeef", textfield_->text()); | |
| 1897 EXPECT_EQ(gfx::Range(7), textfield_->GetSelectedRange()); | |
| 1898 | |
| 1899 // Move focus to next textfield. | |
| 1900 widget_->GetFocusManager()->AdvanceFocus(false); | |
| 1901 EXPECT_EQ(2, GetFocusedView()->id()); | |
| 1902 Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView()); | |
| 1903 EXPECT_STR_EQ("", textfield2->text()); | |
| 1904 | |
| 1905 // Verify yanked text persists across multiple textfields. | |
| 1906 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN); | |
| 1907 EXPECT_STR_EQ("ef", textfield2->text()); | |
| 1908 EXPECT_EQ(gfx::Range(2), textfield2->GetSelectedRange()); | |
| 1909 } | |
| 1910 | |
| 1911 #endif // defined(OS_MACOSX) | |
|
tapted
2016/07/20 06:32:21
nit: extra space before //
karandeepb
2016/07/20 07:51:30
Done.
| |
| 1912 | |
| 1862 TEST_F(TextfieldTest, CutCopyPaste) { | 1913 TEST_F(TextfieldTest, CutCopyPaste) { |
| 1863 InitTextfield(); | 1914 InitTextfield(); |
| 1864 | 1915 |
| 1865 // Ensure IDS_APP_CUT cuts. | 1916 // Ensure IDS_APP_CUT cuts. |
| 1866 textfield_->SetText(ASCIIToUTF16("123")); | 1917 textfield_->SetText(ASCIIToUTF16("123")); |
| 1867 textfield_->SelectAll(false); | 1918 textfield_->SelectAll(false); |
| 1868 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 1919 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 1869 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 1920 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 1870 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 1921 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1871 EXPECT_STR_EQ("", textfield_->text()); | 1922 EXPECT_STR_EQ("", textfield_->text()); |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2699 | 2750 |
| 2700 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2751 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2701 ui::AXViewState state_protected; | 2752 ui::AXViewState state_protected; |
| 2702 textfield_->GetAccessibleState(&state_protected); | 2753 textfield_->GetAccessibleState(&state_protected); |
| 2703 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2754 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2704 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2755 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2705 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2756 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2706 } | 2757 } |
| 2707 | 2758 |
| 2708 } // namespace views | 2759 } // namespace views |
| OLD | NEW |