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

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

Issue 1999773002: views::Textfield: Implement transpose 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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 const int command = ui::EF_COMMAND_DOWN; 756 const int command = ui::EF_COMMAND_DOWN;
757 const int altgr = ui::EF_ALTGR_DOWN; 757 const int altgr = ui::EF_ALTGR_DOWN;
758 const int shift = ui::EF_SHIFT_DOWN; 758 const int shift = ui::EF_SHIFT_DOWN;
759 759
760 SendKeyPress(ui::VKEY_T, shift | alt | altgr); 760 SendKeyPress(ui::VKEY_T, shift | alt | altgr);
761 SendKeyPress(ui::VKEY_H, alt); 761 SendKeyPress(ui::VKEY_H, alt);
762 SendKeyPress(ui::VKEY_E, altgr); 762 SendKeyPress(ui::VKEY_E, altgr);
763 SendKeyPress(ui::VKEY_T, shift); 763 SendKeyPress(ui::VKEY_T, shift);
764 SendKeyPress(ui::VKEY_E, shift | altgr); 764 SendKeyPress(ui::VKEY_E, shift | altgr);
765 SendKeyPress(ui::VKEY_X, 0); 765 SendKeyPress(ui::VKEY_X, 0);
766 SendKeyPress(ui::VKEY_T, ctrl); 766 SendKeyPress(ui::VKEY_T, ctrl); // This causes transpose on Mac.
767 SendKeyPress(ui::VKEY_1, alt); 767 SendKeyPress(ui::VKEY_1, alt);
768 SendKeyPress(ui::VKEY_2, command); 768 SendKeyPress(ui::VKEY_2, command);
769 SendKeyPress(ui::VKEY_3, 0); 769 SendKeyPress(ui::VKEY_3, 0);
770 SendKeyPress(ui::VKEY_4, 0); 770 SendKeyPress(ui::VKEY_4, 0);
771 SendKeyPress(ui::VKEY_OEM_PLUS, ctrl); 771 SendKeyPress(ui::VKEY_OEM_PLUS, ctrl);
772 SendKeyPress(ui::VKEY_OEM_PLUS, ctrl | shift); 772 SendKeyPress(ui::VKEY_OEM_PLUS, ctrl | shift);
773 SendKeyPress(ui::VKEY_OEM_MINUS, ctrl); 773 SendKeyPress(ui::VKEY_OEM_MINUS, ctrl);
774 SendKeyPress(ui::VKEY_OEM_MINUS, ctrl | shift); 774 SendKeyPress(ui::VKEY_OEM_MINUS, ctrl | shift);
775 775
776 if (TestingNativeCrOs()) 776 if (TestingNativeCrOs())
777 EXPECT_STR_EQ("TeTEx34", textfield_->text()); 777 EXPECT_STR_EQ("TeTEx34", textfield_->text());
778 else if (TestingNativeMac()) 778 else if (TestingNativeMac())
779 EXPECT_STR_EQ("TheTEx134", textfield_->text()); 779 EXPECT_STR_EQ("TheTxE134", textfield_->text());
780 else 780 else
781 EXPECT_STR_EQ("TeTEx234", textfield_->text()); 781 EXPECT_STR_EQ("TeTEx234", textfield_->text());
782 } 782 }
783 783
784 TEST_F(TextfieldTest, ControlAndSelectTest) { 784 TEST_F(TextfieldTest, ControlAndSelectTest) {
785 // Insert a test string in a textfield. 785 // Insert a test string in a textfield.
786 InitTextfield(); 786 InitTextfield();
787 textfield_->SetText(ASCIIToUTF16("one two three")); 787 textfield_->SetText(ASCIIToUTF16("one two three"));
788 SendHomeEvent(false); 788 SendHomeEvent(false);
789 SendKeyEvent(ui::VKEY_RIGHT, true, false); 789 SendKeyEvent(ui::VKEY_RIGHT, true, false);
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 EXPECT_STR_EQ("abcabcabc", textfield_->text()); 1914 EXPECT_STR_EQ("abcabcabc", textfield_->text());
1915 1915
1916 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. 1916 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op.
1917 textfield_->SelectAll(false); 1917 textfield_->SelectAll(false);
1918 SendKeyEvent(ui::VKEY_INSERT, true, true); 1918 SendKeyEvent(ui::VKEY_INSERT, true, true);
1919 EXPECT_STR_EQ("abc", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); 1919 EXPECT_STR_EQ("abc", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
1920 EXPECT_STR_EQ("abcabcabc", textfield_->text()); 1920 EXPECT_STR_EQ("abcabcabc", textfield_->text());
1921 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); 1921 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
1922 } 1922 }
1923 1923
1924 // Non-Mac platforms don't have a key binding for Transpose.
1925 #if defined(OS_MACOSX)
1926 TEST_F(TextfieldTest, Transpose) {
1927 const base::string16 ltr = base::ASCIIToUTF16("12");
1928 const base::string16 rtl = base::WideToUTF16(L"\x0634\x0632");
1929 const base::string16 ltr_transposed = base::ASCIIToUTF16("21");
1930 const base::string16 rtl_transposed = base::WideToUTF16(L"\x0632\x0634");
1931
1932 // This is a string with an 'a' between two emojis.
1933 const base::string16 surrogate_pairs({0xD83D, 0xDE07, 'a', 0xD83D, 0xDE0E});
1934 const base::string16 test_strings[] = {ltr, rtl, surrogate_pairs};
1935
1936 struct {
1937 gfx::Range range;
1938 base::string16 expected_text;
1939 gfx::Range expected_selection;
1940 } cases[][4] = {
1941 {// Cases for LTR.
1942 {gfx::Range(0), ltr, gfx::Range(0)},
1943 {gfx::Range(1), ltr_transposed, gfx::Range(2)},
1944 {gfx::Range(2), ltr_transposed, gfx::Range(2)},
1945 {gfx::Range(0, 2), ltr, gfx::Range(0, 2)}},
1946 {
1947 // Cases for RTL.
1948 {gfx::Range(0), rtl, gfx::Range(0)},
1949 {gfx::Range(1), rtl_transposed, gfx::Range(2)},
1950 {gfx::Range(2), rtl_transposed, gfx::Range(2)},
1951 {gfx::Range(0, 1), rtl, gfx::Range(0, 1)},
1952 },
1953 {// Cases for surrogate pairs. We only test at valid grapheme boundaries.
1954 {gfx::Range(0), surrogate_pairs, gfx::Range(0)},
1955 {gfx::Range(2), base::string16({'a', 0xD83D, 0xDE07, 0xD83D, 0xDE0E}),
1956 gfx::Range(3)},
1957 {gfx::Range(3), base::string16({0xD83D, 0xDE07, 0xD83D, 0xDE0E, 'a'}),
1958 gfx::Range(5)},
1959 {gfx::Range(5), base::string16({0xD83D, 0xDE07, 0xD83D, 0xDE0E, 'a'}),
1960 gfx::Range(5)}}};
1961
1962 InitTextfield();
1963
1964 EXPECT_EQ(arraysize(cases), arraysize(test_strings));
1965
1966 for (size_t i = 0; i < arraysize(cases); i++) {
1967 for (size_t j = 0; j < arraysize(cases[i]); j++) {
1968 SCOPED_TRACE(base::StringPrintf(
1969 "Testing case [%" PRIuS ", %" PRIuS "] with string %s", i, j,
1970 base::UTF16ToUTF8(test_strings[i]).c_str()));
1971 auto test_case = cases[i][j];
1972 textfield_->SetText(test_strings[i]);
1973 textfield_->SelectRange(test_case.range);
1974
1975 // Press Ctrl+T.
1976 SendKeyPress(ui::VKEY_T, ui::EF_CONTROL_DOWN);
1977
1978 EXPECT_EQ(test_case.expected_text, textfield_->text());
1979 EXPECT_EQ(test_case.expected_selection, textfield_->GetSelectedRange());
1980 }
1981 }
1982 }
1983 #endif
1984
1924 TEST_F(TextfieldTest, OvertypeMode) { 1985 TEST_F(TextfieldTest, OvertypeMode) {
1925 InitTextfield(); 1986 InitTextfield();
1926 // Overtype mode should be disabled (no-op [Insert]). 1987 // Overtype mode should be disabled (no-op [Insert]).
1927 textfield_->SetText(ASCIIToUTF16("2")); 1988 textfield_->SetText(ASCIIToUTF16("2"));
1928 const bool shift = false; 1989 const bool shift = false;
1929 SendHomeEvent(shift); 1990 SendHomeEvent(shift);
1930 // Note: On Mac, there is no insert key. Insert sends kVK_Help. Currently, 1991 // Note: On Mac, there is no insert key. Insert sends kVK_Help. Currently,
1931 // since there is no overtype on toolkit-views, the behavior happens to match. 1992 // since there is no overtype on toolkit-views, the behavior happens to match.
1932 // However, there's no enable-overtype equivalent key combination on OSX. 1993 // However, there's no enable-overtype equivalent key combination on OSX.
1933 SendKeyEvent(ui::VKEY_INSERT); 1994 SendKeyEvent(ui::VKEY_INSERT);
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 2739
2679 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2740 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2680 ui::AXViewState state_protected; 2741 ui::AXViewState state_protected;
2681 textfield_->GetAccessibleState(&state_protected); 2742 textfield_->GetAccessibleState(&state_protected);
2682 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2743 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2683 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2744 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2684 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2745 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2685 } 2746 }
2686 2747
2687 } // namespace views 2748 } // namespace views
OLDNEW
« ui/views/cocoa/bridged_content_view.mm ('K') | « ui/views/controls/textfield/textfield_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698