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

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

Issue 927743002: Focus and trail cursor on Views Textfield selection clipboard paste. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Leave the test disabled... Created 5 years, 10 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
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 1888
1889 // Drag the mouse to the beginning of the textfield. 1889 // Drag the mouse to the beginning of the textfield.
1890 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, 1890 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning,
1891 ui::EF_LEFT_MOUSE_BUTTON, 0); 1891 ui::EF_LEFT_MOUSE_BUTTON, 0);
1892 textfield_->OnMouseDragged(drag_event); 1892 textfield_->OnMouseDragged(drag_event);
1893 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 1893 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
1894 } 1894 }
1895 1895
1896 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1896 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1897 // flaky: http://crbug.com/396477 1897 // flaky: http://crbug.com/396477
1898 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) { 1898 TEST_F(TextfieldTest, DISABLED_SelectionClipboard) {
msw 2015/02/13 23:38:43 This passes locally on Linux, but I didn't solve t
1899 InitTextfield(); 1899 InitTextfield();
1900 textfield_->SetText(ASCIIToUTF16("0123")); 1900 textfield_->SetText(ASCIIToUTF16("0123"));
1901 gfx::Point point_1(GetCursorPositionX(1), 0); 1901 gfx::Point point_1(GetCursorPositionX(1), 0);
1902 gfx::Point point_2(GetCursorPositionX(2), 0); 1902 gfx::Point point_2(GetCursorPositionX(2), 0);
1903 gfx::Point point_3(GetCursorPositionX(3), 0); 1903 gfx::Point point_3(GetCursorPositionX(3), 0);
1904 gfx::Point point_4(GetCursorPositionX(4), 0); 1904 gfx::Point point_4(GetCursorPositionX(4), 0);
1905 1905
1906 // Text selected by the mouse should be placed on the selection clipboard. 1906 // Text selected by the mouse should be placed on the selection clipboard.
1907 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, 1907 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1,
1908 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 1908 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 1949 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
1950 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard()); 1950 EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
1951 1951
1952 // Moving the cursor without a selection should not change the clipboard. 1952 // Moving the cursor without a selection should not change the clipboard.
1953 SendKeyEvent(ui::VKEY_LEFT, false, false); 1953 SendKeyEvent(ui::VKEY_LEFT, false, false);
1954 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange()); 1954 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange());
1955 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 1955 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
1956 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard()); 1956 EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
1957 1957
1958 // Middle clicking should paste at the mouse (not cursor) location. 1958 // Middle clicking should paste at the mouse (not cursor) location.
1959 // The cursor should be placed at the end of the pasted text.
1959 ui::MouseEvent middle(ui::ET_MOUSE_PRESSED, point_4, point_4, 1960 ui::MouseEvent middle(ui::ET_MOUSE_PRESSED, point_4, point_4,
1960 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON); 1961 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON);
1961 textfield_->OnMousePressed(middle); 1962 textfield_->OnMousePressed(middle);
1962 EXPECT_STR_EQ("01230123", textfield_->text()); 1963 EXPECT_STR_EQ("01230123", textfield_->text());
1963 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange()); 1964 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange());
1964 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); 1965 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
1965 1966
1966 // Middle click pasting should adjust trailing cursors. 1967 // Middle clicking on an unfocused textfield should focus it and paste.
1967 textfield_->SelectRange(gfx::Range(5, 5)); 1968 // TODO(msw): Add tests with stored selections and select-all on focus.
msw 2015/02/13 23:38:43 I tested this manually, but didn't bother writing
1969 textfield_->GetFocusManager()->ClearFocus();
1970 EXPECT_FALSE(textfield_->HasFocus());
1968 textfield_->OnMousePressed(middle); 1971 textfield_->OnMousePressed(middle);
1972 EXPECT_TRUE(textfield_->HasFocus());
1969 EXPECT_STR_EQ("012301230123", textfield_->text()); 1973 EXPECT_STR_EQ("012301230123", textfield_->text());
1970 EXPECT_EQ(gfx::Range(9, 9), textfield_->GetSelectedRange()); 1974 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange());
1971 1975 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
1972 // Middle click pasting should adjust trailing selections.
1973 textfield_->SelectRange(gfx::Range(7, 9));
1974 textfield_->OnMousePressed(middle);
1975 EXPECT_STR_EQ("0123012301230123", textfield_->text());
1976 EXPECT_EQ(gfx::Range(11, 13), textfield_->GetSelectedRange());
1977 1976
1978 // Middle clicking in the selection should clear the clipboard and selection. 1977 // Middle clicking in the selection should clear the clipboard and selection.
1979 textfield_->SelectRange(gfx::Range(2, 6)); 1978 textfield_->SelectRange(gfx::Range(2, 6));
1980 textfield_->OnMousePressed(middle); 1979 textfield_->OnMousePressed(middle);
1981 EXPECT_STR_EQ("0123012301230123", textfield_->text()); 1980 EXPECT_STR_EQ("012301230123", textfield_->text());
1982 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); 1981 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange());
1983 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); 1982 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
1984 1983
1985 // Double and triple clicking should update the clipboard contents. 1984 // Double and triple clicking should update the clipboard contents.
1986 textfield_->SetText(ASCIIToUTF16("ab cd ef")); 1985 textfield_->SetText(ASCIIToUTF16("ab cd ef"));
1987 gfx::Point word(GetCursorPositionX(4), 0); 1986 gfx::Point word(GetCursorPositionX(4), 0);
1988 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, 1987 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word,
1989 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 1988 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
1990 textfield_->OnMousePressed(press_word); 1989 textfield_->OnMousePressed(press_word);
1991 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, 1990 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 2227
2229 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2228 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2230 ui::AXViewState state_protected; 2229 ui::AXViewState state_protected;
2231 textfield_->GetAccessibleState(&state_protected); 2230 textfield_->GetAccessibleState(&state_protected);
2232 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2231 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2233 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2232 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2234 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2233 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2235 } 2234 }
2236 2235
2237 } // namespace views 2236 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698