| 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 8d46caa4cd4711f1dbe48bc419a1143b035628b6..94f2af7ca0b1e92503480bb04e763a16f0a79a61 100644
|
| --- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| +++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
|
| @@ -132,6 +132,16 @@ const char kWebpageWithDynamicContent[] =
|
| " </body>"
|
| "</html>";
|
|
|
| +const char kJavaScriptClick[] =
|
| + "var event = new MouseEvent('click', {"
|
| + " 'view': window,"
|
| + " 'bubbles': true,"
|
| + " 'cancelable': true"
|
| + "});"
|
| + "var form = document.getElementById('myform1');"
|
| + "form.dispatchEvent(event);"
|
| + "console.log('clicked!');";
|
| +
|
| } // namespace
|
|
|
| namespace autofill {
|
| @@ -255,15 +265,20 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| bool username_autofilled,
|
| const WebInputElement& password_element,
|
| const std::string& password,
|
| - bool password_autofilled) {
|
| + bool password_autofilled,
|
| + bool checkSuggestedValue = true) {
|
| EXPECT_EQ(username,
|
| static_cast<std::string>(username_element.value().utf8()));
|
| EXPECT_EQ(username_autofilled, username_element.isAutofilled());
|
| EXPECT_EQ(password,
|
| - static_cast<std::string>(password_element.value().utf8()));
|
| + static_cast<std::string>(
|
| + checkSuggestedValue ? password_element.suggestedValue().utf8()
|
| + : password_element.value().utf8()));
|
| EXPECT_EQ(password_autofilled, password_element.isAutofilled());
|
| }
|
|
|
| + // Checks the DOM-accessible value of the username element and the
|
| + // *suggested* value of the password element.
|
| void CheckTextFieldsState(const std::string& username,
|
| bool username_autofilled,
|
| const std::string& password,
|
| @@ -273,6 +288,21 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
|
| password, password_autofilled);
|
| }
|
|
|
| + // Checks the DOM-accessible value of the username element and the
|
| + // DOM-accessible value of the password element.
|
| + void CheckTextFieldsDOMState(const std::string& username,
|
| + bool username_autofilled,
|
| + const std::string& password,
|
| + bool password_autofilled) {
|
| + CheckTextFieldsStateForElements(username_element_,
|
| + username,
|
| + username_autofilled,
|
| + password_element_,
|
| + password,
|
| + password_autofilled,
|
| + false);
|
| + }
|
| +
|
| void CheckUsernameSelection(int start, int end) {
|
| EXPECT_EQ(start, username_element_.selectionStart());
|
| EXPECT_EQ(end, username_element_.selectionEnd());
|
| @@ -778,4 +808,32 @@ TEST_F(PasswordAutofillAgentTest, IframeNoFillTest) {
|
| password_input, kAlicePassword, true);
|
| }
|
|
|
| +// Tests that a password will only be filled as a suggested and will not be
|
| +// accessible by the DOM until a user gesture has occurred.
|
| +TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) {
|
| + // Trigger the initial autocomplete.
|
| + SimulateOnFillPasswordForm(fill_data_);
|
| +
|
| + // The username and password should have been autocompleted.
|
| + CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
|
| +
|
| + // However, it should only have completed with the suggested value, as tested
|
| + // above, and it should not have completed into the DOM accessible value for
|
| + // the password field.
|
| + CheckTextFieldsDOMState(kAliceUsername, true, "", true);
|
| +
|
| + // Simulate a user click so that the password field's real value is filled.
|
| + SimulateElementClick(kUsernameName);
|
| + CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
|
| +}
|
| +
|
| +// Verfies that a DOM-activated UI event will not cause an autofill.
|
| +TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) {
|
| + // Trigger the initial autocomplete.
|
| + SimulateOnFillPasswordForm(fill_data_);
|
| +
|
| + ExecuteJavaScript(kJavaScriptClick);
|
| + CheckTextFieldsDOMState(kAliceUsername, true, "", true);
|
| +}
|
| +
|
| } // namespace autofill
|
|
|