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

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: Use SetClipboardText on other platforms too. 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 1938 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 textfield_->GetFocusManager()->ClearFocus();
1969 EXPECT_FALSE(textfield_->HasFocus());
1970 textfield_->OnMousePressed(middle);
1971 EXPECT_TRUE(textfield_->HasFocus());
1972 EXPECT_STR_EQ("012301230123", textfield_->text());
1973 EXPECT_EQ(gfx::Range(8, 8), textfield_->GetSelectedRange());
1974 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
1975
1976 // Middle clicking with an empty selection clipboard should still focus.
1977 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, std::string());
1978 textfield_->GetFocusManager()->ClearFocus();
1979 EXPECT_FALSE(textfield_->HasFocus());
1980 textfield_->OnMousePressed(middle);
1981 EXPECT_TRUE(textfield_->HasFocus());
1982 EXPECT_STR_EQ("012301230123", textfield_->text());
1983 EXPECT_EQ(gfx::Range(4, 4), textfield_->GetSelectedRange());
1984 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
1985
1986 // Middle clicking in the selection should clear the clipboard and selection.
1987 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo");
1988 textfield_->SelectRange(gfx::Range(2, 6));
1968 textfield_->OnMousePressed(middle); 1989 textfield_->OnMousePressed(middle);
1969 EXPECT_STR_EQ("012301230123", textfield_->text()); 1990 EXPECT_STR_EQ("012301230123", textfield_->text());
1970 EXPECT_EQ(gfx::Range(9, 9), textfield_->GetSelectedRange());
1971
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
1978 // Middle clicking in the selection should clear the clipboard and selection.
1979 textfield_->SelectRange(gfx::Range(2, 6));
1980 textfield_->OnMousePressed(middle);
1981 EXPECT_STR_EQ("0123012301230123", textfield_->text());
1982 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); 1991 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange());
1983 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); 1992 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
1984 1993
1985 // Double and triple clicking should update the clipboard contents. 1994 // Double and triple clicking should update the clipboard contents.
1986 textfield_->SetText(ASCIIToUTF16("ab cd ef")); 1995 textfield_->SetText(ASCIIToUTF16("ab cd ef"));
1987 gfx::Point word(GetCursorPositionX(4), 0); 1996 gfx::Point word(GetCursorPositionX(4), 0);
1988 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, 1997 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word,
1989 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 1998 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
1990 textfield_->OnMousePressed(press_word); 1999 textfield_->OnMousePressed(press_word);
1991 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, 2000 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 2237
2229 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2238 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2230 ui::AXViewState state_protected; 2239 ui::AXViewState state_protected;
2231 textfield_->GetAccessibleState(&state_protected); 2240 textfield_->GetAccessibleState(&state_protected);
2232 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2241 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2233 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2242 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2234 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2243 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2235 } 2244 }
2236 2245
2237 } // namespace views 2246 } // 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