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

Unified Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 184103016: Autofill: Refactoring to support fetching password after a username is selected (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Actually fix compile failure. Created 6 years, 8 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
« no previous file with comments | « chrome/browser/ui/tab_helpers.cc ('k') | components/autofill.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/autofill/password_autofill_agent_browsertest.cc
diff --git a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
index 1872c8ba7409a29d97dea4c40fdd66ab338389a0..955156d58985b17bf0e878badcc60d89eaed3bb4 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -49,7 +49,6 @@ const char kCarolUsername[] = "Carol";
const char kCarolPassword[] = "test";
const char kCarolAlternateUsername[] = "RealCarolUsername";
-
const char kFormHTML[] =
"<FORM name='LoginTestForm' action='http://www.bidule.com'>"
" <INPUT type='text' id='username'/>"
@@ -157,6 +156,12 @@ const char kOnChangeDetectionScript[] =
" };"
"</script>";
+// Sets the "readonly" attribute of |element| to the value given by |read_only|.
+void SetElementReadOnly(WebInputElement& element, bool read_only) {
+ element.setAttribute(WebString::fromUTF8("readonly"),
+ read_only ? WebString::fromUTF8("true") : WebString());
+}
+
} // namespace
namespace autofill {
@@ -456,8 +461,7 @@ TEST_F(PasswordAutofillAgentTest, InitialAutocompleteForEmptyAction) {
// Tests that if a password is marked as readonly, neither field is autofilled
// on page load.
TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnlyPassword) {
- password_element_.setAttribute(WebString::fromUTF8("readonly"),
- WebString::fromUTF8("true"));
+ SetElementReadOnly(password_element_, true);
// Simulate the browser sending back the login info, it triggers the
// autocomplete.
@@ -471,8 +475,7 @@ TEST_F(PasswordAutofillAgentTest, NoInitialAutocompleteForReadOnlyPassword) {
TEST_F(PasswordAutofillAgentTest,
AutocompletePasswordForReadonlyUsernameMatched) {
username_element_.setValue(username3_);
- username_element_.setAttribute(WebString::fromUTF8("readonly"),
- WebString::fromUTF8("true"));
+ SetElementReadOnly(username_element_, true);
// Filled even though username is not the preferred match.
SimulateOnFillPasswordForm(fill_data_);
@@ -484,8 +487,7 @@ TEST_F(PasswordAutofillAgentTest,
TEST_F(PasswordAutofillAgentTest,
NoAutocompletePasswordForReadonlyUsernameUnmatched) {
username_element_.setValue(WebString::fromUTF8(""));
- username_element_.setAttribute(WebString::fromUTF8("readonly"),
- WebString::fromUTF8("true"));
+ SetElementReadOnly(username_element_, true);
SimulateOnFillPasswordForm(fill_data_);
CheckTextFieldsState(std::string(), false, std::string(), false);
@@ -1016,4 +1018,33 @@ TEST_F(PasswordAutofillAgentTest,
EXPECT_EQ(1, password_onchange_called);
}
+// Tests that |AcceptSuggestion| properly fills the username and password.
+TEST_F(PasswordAutofillAgentTest, AcceptSuggestion) {
+ // Simulate the browser sending the login info, but set |wait_for_username|
+ // to prevent the form from being immediately filled.
+ fill_data_.wait_for_username = true;
+ SimulateOnFillPasswordForm(fill_data_);
+
+ // Neither field should have been autocompleted.
+ CheckTextFieldsDOMState(std::string(), false, std::string(), false);
+
+ // If the password field is not autocompletable, it should not be affected.
+ SetElementReadOnly(password_element_, true);
+ EXPECT_FALSE(password_autofill_->AcceptSuggestion(
+ username_element_, kAliceUsername, kAlicePassword));
+ CheckTextFieldsDOMState(std::string(), false, std::string(), false);
+ SetElementReadOnly(password_element_, false);
+
+ // After accepting the suggestion, both fields should be autocompleted.
+ EXPECT_TRUE(password_autofill_->AcceptSuggestion(
+ username_element_, kAliceUsername, kAlicePassword));
+ CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
+
+ // Try accepting a suggestion with a password different from the one that was
+ // initially sent to the renderer.
+ EXPECT_TRUE(password_autofill_->AcceptSuggestion(
+ username_element_, kBobUsername, kCarolPassword));
+ CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true);
+}
+
} // namespace autofill
« no previous file with comments | « chrome/browser/ui/tab_helpers.cc ('k') | components/autofill.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698