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

Unified Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 2358463002: Views::Textfield: Prevent revealing password text. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/textfield/textfield_unittest.cc
diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc
index 0a9b767754ef38ed307214bcce70ea9366aa1c00..7a4164b397109deea7cbc020e3c71f8c4c550dfe 100644
--- a/ui/views/controls/textfield/textfield_unittest.cc
+++ b/ui/views/controls/textfield/textfield_unittest.cc
@@ -2081,10 +2081,24 @@ TEST_F(TextfieldTest, Yank) {
Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView());
EXPECT_TRUE(textfield2->text().empty());
+ // Make |textfield2| a password textfield.
+ textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
Peter Kasting 2016/09/20 17:29:30 Nit: I would move this line down to be part of (an
karandeepb 2016/09/21 03:36:12 I'd like to keep it here since this also tests tha
Peter Kasting 2016/09/21 04:12:30 Perhaps in that case do this: // Verify yanked
karandeepb 2016/09/21 04:27:37 Done.
+
// Verify yanked text persists across multiple textfields.
SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
EXPECT_STR_EQ("ef", textfield2->text());
EXPECT_EQ(gfx::Range(2), textfield2->GetSelectedRange());
+
+ // Verify deletion in a password textfield does not modify the kill buffer.
+ textfield2->SetText(ASCIIToUTF16("hello"));
+ textfield2->SelectRange(gfx::Range(0));
+ SendKeyPress(ui::VKEY_K, ui::EF_CONTROL_DOWN);
+ EXPECT_TRUE(textfield2->text().empty());
+
+ textfield_->RequestFocus();
+ textfield_->SelectRange(gfx::Range(0));
+ SendKeyPress(ui::VKEY_Y, ui::EF_CONTROL_DOWN);
+ EXPECT_STR_EQ("efabefeef", textfield_->text());
}
#endif // defined(OS_MACOSX)
@@ -2720,6 +2734,48 @@ TEST_F(TextfieldTest, DISABLED_SelectionClipboard) {
EXPECT_STR_EQ("other", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
}
+
+// Verify that the selection clipboard is not updated for selections on a
+// password textfield. Disabled due to http://crbug.com/396477.
+TEST_F(TextfieldTest, DISABLED_SelectionClipboard_Password) {
+ InitTextfields(2);
+ textfield_->SetText(ASCIIToUTF16("abcd"));
+
+ // Select-all should update the selection clipboard for a non-password
+ // textfield.
+ SendKeyEvent(ui::VKEY_A, false, true);
+ EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange());
+ EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
+ EXPECT_EQ(ui::CLIPBOARD_TYPE_SELECTION, GetAndResetCopiedToClipboard());
+
+ // Move focus to the next textfield.
+ widget_->GetFocusManager()->AdvanceFocus(false);
+ EXPECT_EQ(2, GetFocusedView()->id());
+ Textfield* textfield2 = static_cast<Textfield*>(GetFocusedView());
+
+ // Make |textfield2| a password textfield.
+ textfield2->SetText(ASCIIToUTF16("1234"));
+ textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
Peter Kasting 2016/09/20 17:29:30 Nit: Again, I'd just merge this block into the nex
karandeepb 2016/09/21 03:36:12 Done.
+
+ // Select-all should not modify the selection clipboard for a password
+ // textfield.
+ SendKeyEvent(ui::VKEY_A, false, true);
+ EXPECT_EQ(gfx::Range(0, 4), textfield2->GetSelectedRange());
+ EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
+ EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
+
+ // Shift-Left/Right should not modify the selection clipboard for a password
+ // textfield.
+ SendKeyEvent(ui::VKEY_LEFT, true, false);
+ EXPECT_EQ(gfx::Range(0, 3), textfield2->GetSelectedRange());
+ EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
+ EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
+
+ SendKeyEvent(ui::VKEY_RIGHT, true, false);
+ EXPECT_EQ(gfx::Range(0, 4), textfield2->GetSelectedRange());
+ EXPECT_STR_EQ("abcd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION));
+ EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
+}
#endif
// Long_Press gesture in Textfield can initiate a drag and drop now.

Powered by Google App Engine
This is Rietveld 408576698