Chromium Code Reviews| 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 858cb51e9c176c40c53af41d8d2764f5a0f24268..19dfd711c2a35f4e3a0b60234957252a26dab6f9 100644 |
| --- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
| +++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
| @@ -19,6 +19,7 @@ |
| #include "components/autofill/core/common/autofill_constants.h" |
| #include "components/autofill/core/common/form_data.h" |
| #include "components/autofill/core/common/form_field_data.h" |
| +#include <components/autofill/core/common/password_form.h> |
| #include "components/autofill/core/common/password_form_field_prediction_map.h" |
| #include "components/password_manager/core/common/password_manager_features.h" |
| #include "content/public/renderer/render_frame.h" |
| @@ -209,6 +210,7 @@ const char kCreditCardFormHTML[] = |
| "</FORM>"; |
| const char kNoFormHTML[] = |
| + " <INPUT type='text' id='random_field'/>" |
| " <INPUT type='text' id='username'/>" |
| " <INPUT type='password' id='password'/>"; |
| @@ -486,6 +488,27 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
| std::get<0>(args).new_password_value); |
| } |
| + void ExpectFieldPropertiesMasks(uint32_t expected_message_id) { |
|
vabr (Chromium)
2016/07/28 11:33:53
nit: It is not clear what expectation this functio
kolos1
2016/07/28 13:44:03
Done.
|
| + const IPC::Message* message = |
| + render_thread_->sink().GetFirstMessageMatching(expected_message_id); |
| + ASSERT_TRUE(message); |
| + std::tuple<autofill::PasswordForm> args; |
| + AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); |
| + const autofill::PasswordForm& form = std::get<0>(args); |
| + |
| + ASSERT_EQ(3U, form.form_data.fields.size()); |
| + EXPECT_EQ(0U, form.form_data.fields[0].properties_mask) |
| + << "Wrong field properties mask for 'random_field'"; |
| + EXPECT_EQ(FieldPropertiesFlags::USER_TYPED, |
| + form.form_data.fields[1].properties_mask) |
| + << "Wrong field properties mask for username"; |
| + EXPECT_EQ( |
| + static_cast<FieldPropertiesMask>(FieldPropertiesFlags::USER_TYPED | |
| + FieldPropertiesFlags::HAD_FOCUS), |
| + form.form_data.fields[2].properties_mask) |
| + << "Wrong field properties mask for password"; |
| + } |
| + |
| void ExpectInPageNavigationWithUsernameAndPasswords( |
| const std::string& username_value, |
| const std::string& password_value, |
| @@ -1494,6 +1517,37 @@ TEST_F(PasswordAutofillAgentTest, |
| ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); |
| } |
| +TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnSubmit) { |
| + SimulateUsernameChange("temp"); |
| + SimulatePasswordChange("random"); |
| + |
| + // Simulate that the username and the password value was changed by the |
| + // site's JavaScript before submit. |
| + username_element_.setValue(WebString("new username")); |
| + password_element_.setValue(WebString("new password")); |
| + static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| + ->WillSendSubmitEvent(username_element_.form()); |
| + static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| + ->WillSubmitForm(username_element_.form()); |
| + |
| + ExpectFieldPropertiesMasks(AutofillHostMsg_PasswordFormSubmitted::ID); |
| +} |
| + |
| +TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { |
| + LoadHTML(kNoFormHTML); |
| + UpdateUsernameAndPasswordElements(); |
| + |
| + SimulateUsernameChange("Bob"); |
| + SimulatePasswordChange("mypassword"); |
| + |
| + username_element_.setAttribute("style", "display:none;"); |
| + password_element_.setAttribute("style", "display:none;"); |
| + |
| + password_autofill_agent_->AJAXSucceeded(); |
| + |
| + ExpectFieldPropertiesMasks(AutofillHostMsg_InPageNavigation::ID); |
| +} |
| + |
| // The username/password is autofilled by password manager then just before |
| // sending the form off, a script changes them. This test checks that |
| // PasswordAutofillAgent can still get the username and the password autofilled. |
| @@ -1779,9 +1833,9 @@ TEST_F(PasswordAutofillAgentTest, FindingFieldsWithAutofillPredictions) { |
| // Find FormData for visible password form. |
| blink::WebFormElement form_element = username_element_.form(); |
| FormData form_data; |
| - ASSERT_TRUE( |
| - WebFormElementToFormData(form_element, blink::WebFormControlElement(), |
| - form_util::EXTRACT_NONE, &form_data, nullptr)); |
| + ASSERT_TRUE(WebFormElementToFormData( |
| + form_element, blink::WebFormControlElement(), nullptr, |
| + form_util::EXTRACT_NONE, &form_data, nullptr)); |
| // Simulate Autofill predictions: the first field is username, the third |
| // one is password. |
| std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
| @@ -2008,9 +2062,9 @@ TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { |
| // Find FormData for visible form. |
| blink::WebFormElement form_element = credit_card_number_element.form(); |
| FormData form_data; |
| - ASSERT_TRUE( |
| - WebFormElementToFormData(form_element, blink::WebFormControlElement(), |
| - form_util::EXTRACT_NONE, &form_data, nullptr)); |
| + ASSERT_TRUE(WebFormElementToFormData( |
| + form_element, blink::WebFormControlElement(), nullptr, |
| + form_util::EXTRACT_NONE, &form_data, nullptr)); |
| // Simulate Autofill predictions: the third field is not a password. |
| std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
| predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; |