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

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: Fix compile error on Chrome OS. Created 6 years, 9 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: 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 7be602a6cb981c69e6827a036c7bc20654699724..0f6492f51ad6ccd71f767296d799dff8a63669a2 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

Powered by Google App Engine
This is Rietveld 408576698