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 7b310372848d9f2f916f9030edf7c41cdc5425e8..d0fc1c49c417be7f7ec1efe37f202062799eac35 100644 |
| --- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
| +++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
| @@ -21,6 +21,7 @@ |
| #include "third_party/WebKit/public/web/WebDocument.h" |
| #include "third_party/WebKit/public/web/WebElement.h" |
| #include "third_party/WebKit/public/web/WebFormElement.h" |
| +#include "third_party/WebKit/public/web/WebFormControlElement.h" |
| #include "third_party/WebKit/public/web/WebInputElement.h" |
| #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| #include "third_party/WebKit/public/web/WebNode.h" |
| @@ -44,6 +45,7 @@ const int kPasswordFillFormDataId = 1234; |
| // The name of the username/password element in the form. |
| const char kUsernameName[] = "username"; |
| const char kPasswordName[] = "password"; |
| +const char kEmailName[] = "email"; |
| const char kAliceUsername[] = "alice"; |
| const char kAlicePassword[] = "password"; |
| @@ -160,6 +162,15 @@ const char kOnChangeDetectionScript[] = |
| " };" |
| "</script>"; |
| +const char kFormHTMLWithTwoTextFields[] = |
| + "<FORM name='LoginTestForm' id='LoginTestForm' " |
| + "action='http://www.bidule.com'>" |
| + " <INPUT type='text' id='username'/>" |
| + " <INPUT type='text' id='email'/>" |
| + " <INPUT type='password' id='password'/>" |
| + " <INPUT type='submit' value='Login'/>" |
| + "</FORM>"; |
| + |
| // 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"), |
| @@ -267,6 +278,12 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
| password_element_ = element.to<blink::WebInputElement>(); |
| } |
| + blink::WebInputElement GetInputElementByID(const char* id) { |
| + WebDocument document = GetMainFrame()->document(); |
| + WebElement element = document.getElementById(WebString::fromUTF8(id)); |
| + return element.to<blink::WebInputElement>(); |
| + } |
| + |
| void ClearUsernameAndPasswordFields() { |
| username_element_.setValue(""); |
| username_element_.setAutofilled(false); |
| @@ -1854,4 +1871,53 @@ TEST_F(PasswordAutofillAgentTest, |
| CheckTextFieldsState(std::string("foobar"), false, std::string(), false); |
| } |
| +// Tests that in a password form with 2 text input elements the last before |
|
vabr (Chromium)
2015/03/25 10:12:33
nit: I found that sentence a bit difficult to pars
dvadym
2015/03/25 16:34:07
Done.
|
| +// a password field text input element will be chosen as username. |
| +TEST_F(PasswordAutofillAgentTest, FindingUsernameWithoutAutofillPredictions) { |
| + LoadHTML(kFormHTMLWithTwoTextFields); |
| + UpdateUsernameAndPasswordElements(); |
| + blink::WebInputElement email_element = GetInputElementByID(kEmailName); |
| + SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, |
| + true); |
| + SimulateInputChangeForElement("temp@google.com", true, GetMainFrame(), |
| + email_element, true); |
| + SimulateInputChangeForElement("random", true, GetMainFrame(), |
| + password_element_, true); |
| + static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| + ->WillSubmitForm(username_element_.form()); |
| + |
| + // Observe that the PasswordAutofillAgent parse email as username. |
|
vabr (Chromium)
2015/03/25 10:12:33
grammar: parse -> parses
But, actually, I suggest
dvadym
2015/03/25 16:34:07
Done.
|
| + ExpectFormSubmittedWithUsernameAndPasswords("temp@google.com", "random", ""); |
| +} |
| + |
| +// Tests that in a password form with 2 text input elements it's chosen as |
|
vabr (Chromium)
2015/03/25 10:12:33
The sentence has broken grammar and is hard to und
dvadym
2015/03/25 16:34:07
Done.
|
| +// usernamethe that element that are in Autofill server predictions. |
| +TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) { |
| + LoadHTML(kFormHTMLWithTwoTextFields); |
| + UpdateUsernameAndPasswordElements(); |
| + blink::WebInputElement email_element = GetInputElementByID(kEmailName); |
| + SimulateInputChangeForElement("temp", true, GetMainFrame(), username_element_, |
| + true); |
| + SimulateInputChangeForElement("temp@google.com", true, GetMainFrame(), |
| + email_element, true); |
| + SimulateInputChangeForElement("random", true, GetMainFrame(), |
| + password_element_, true); |
| + |
| + // Find FormData for visible password form. |
| + blink::WebFormElement form_element = username_element_.form(); |
| + FormData form_data; |
| + ASSERT_TRUE(WebFormElementToFormData( |
| + form_element, blink::WebFormControlElement(), REQUIRE_NONE, EXTRACT_NONE, |
| + &form_data, nullptr)); |
| + // Simulate Autofill predictions: the first field is username. |
| + std::map<autofill::FormData, autofill::FormFieldData> predictions; |
| + predictions[form_data] = form_data.fields[0]; |
| + password_autofill_agent_->OnAutofillDataReceived(predictions); |
| + static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| + ->WillSubmitForm(username_element_.form()); |
| + |
| + // Observe that the PasswordAutofillAgent parse email as username. |
|
vabr (Chromium)
2015/03/25 10:12:33
Similarly to line 1893, I suggest:
// Observe that
dvadym
2015/03/25 16:34:07
Done.
|
| + ExpectFormSubmittedWithUsernameAndPasswords("temp", "random", ""); |
| +} |
| + |
| } // namespace autofill |