Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Side by Side Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 2119813002: views::Textfield: Implement yank editing command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, send Cmd+Shift+Z.
tapted 2016/07/06 01:46:37 The "So, on Mac.." doesn't fit any more... somethi
karandeepb 2016/07/19 07:04:40 Done.
1843 #if !defined(OS_MACOSX) 1843 #if !defined(OS_MACOSX)
1844 1844
1845 // Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z. 1845 // Test that Ctrl+Y works for Redo, as well as Ctrl+Shift+Z.
1846 TEST_F(TextfieldTest, RedoWithCtrlY) { 1846 TEST_F(TextfieldTest, RedoWithCtrlY) {
1847 InitTextfield(); 1847 InitTextfield();
1848 SendKeyEvent(ui::VKEY_A); 1848 SendKeyEvent(ui::VKEY_A);
1849 EXPECT_STR_EQ("a", textfield_->text()); 1849 EXPECT_STR_EQ("a", textfield_->text());
1850 SendKeyEvent(ui::VKEY_Z, false, true); 1850 SendKeyEvent(ui::VKEY_Z, false, true);
1851 EXPECT_STR_EQ("", textfield_->text()); 1851 EXPECT_STR_EQ("", textfield_->text());
1852 SendKeyEvent(ui::VKEY_Y, false, true); 1852 SendKeyEvent(ui::VKEY_Y, false, true);
1853 EXPECT_STR_EQ("a", textfield_->text()); 1853 EXPECT_STR_EQ("a", textfield_->text());
1854 SendKeyEvent(ui::VKEY_Z, false, true); 1854 SendKeyEvent(ui::VKEY_Z, false, true);
1855 EXPECT_STR_EQ("", textfield_->text()); 1855 EXPECT_STR_EQ("", textfield_->text());
1856 SendKeyEvent(ui::VKEY_Z, true, true); 1856 SendKeyEvent(ui::VKEY_Z, true, true);
1857 EXPECT_STR_EQ("a", textfield_->text()); 1857 EXPECT_STR_EQ("a", textfield_->text());
1858 } 1858 }
1859 1859
1860 #endif // !defined(OS_MACOSX) 1860 #endif // !defined(OS_MACOSX)
1861 1861
1862 // Non-Mac platforms don't have a key binding for Yank. Since this test is only
1863 // run on Mac, it uses some Mac specific key bindings.
1864 #if defined(OS_MACOSX)
1865
1866 TEST_F(TextfieldTest, Yank) {
tapted 2016/07/06 01:46:37 Same as before - we should test "Yank" in textfiel
karandeepb 2016/07/19 07:04:40 Done.
1867 InitTextfields(2);
1868 textfield_->SetText(ASCIIToUTF16("abcdef"));
1869 textfield_->SelectRange(gfx::Range(2, 4));
1870
1871 // Press Ctrl+Y to yank.
1872 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
1873
1874 // Initially the kill buffer should be empty. Hence yanking should delete the
1875 // selected text.
1876 EXPECT_STR_EQ("abef", textfield_->text());
1877 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange());
1878
1879 // Press Ctrl+K to delete to end of paragraph. This should place the deleted
1880 // text in the kill buffer.
1881 SendKeyPress(ui::VKEY_K, ui::EF_CONTROL_DOWN);
1882
1883 EXPECT_STR_EQ("ab", textfield_->text());
1884 EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange());
1885
1886 // Yank twice.
1887 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
1888 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
1889 EXPECT_STR_EQ("abefef", textfield_->text());
1890 EXPECT_EQ(gfx::Range(6), textfield_->GetSelectedRange());
1891
1892 // Verify pressing backspace does not modify the kill buffer.
1893 SendKeyEvent(ui::VKEY_BACK);
1894 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
1895 EXPECT_STR_EQ("abefeef", textfield_->text());
1896 EXPECT_EQ(gfx::Range(7), textfield_->GetSelectedRange());
1897
1898 // Move focus to next textfield.
1899 widget_->GetFocusManager()->AdvanceFocus(false);
1900 EXPECT_EQ(2, GetFocusedView()->id());
1901 Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView());
1902 EXPECT_STR_EQ("", textfield2->text());
1903
1904 // Verify yanked text persists across multiple textfields.
1905 SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
1906 EXPECT_STR_EQ("ef", textfield2->text());
1907 EXPECT_EQ(gfx::Range(2), textfield2->GetSelectedRange());
1908 }
1909
1910 #endif
tapted 2016/07/06 01:46:37 nit: // defined(OS_MACOSX)
karandeepb 2016/07/19 07:04:40 Done.
1911
1862 TEST_F(TextfieldTest, CutCopyPaste) { 1912 TEST_F(TextfieldTest, CutCopyPaste) {
1863 InitTextfield(); 1913 InitTextfield();
1864 1914
1865 // Ensure IDS_APP_CUT cuts. 1915 // Ensure IDS_APP_CUT cuts.
1866 textfield_->SetText(ASCIIToUTF16("123")); 1916 textfield_->SetText(ASCIIToUTF16("123"));
1867 textfield_->SelectAll(false); 1917 textfield_->SelectAll(false);
1868 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); 1918 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT));
1869 textfield_->ExecuteCommand(IDS_APP_CUT, 0); 1919 textfield_->ExecuteCommand(IDS_APP_CUT, 0);
1870 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); 1920 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
1871 EXPECT_STR_EQ("", textfield_->text()); 1921 EXPECT_STR_EQ("", textfield_->text());
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
2699 2749
2700 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2750 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2701 ui::AXViewState state_protected; 2751 ui::AXViewState state_protected;
2702 textfield_->GetAccessibleState(&state_protected); 2752 textfield_->GetAccessibleState(&state_protected);
2703 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2753 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2704 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2754 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2705 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2755 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2706 } 2756 }
2707 2757
2708 } // namespace views 2758 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698