Commit dfef9806 authored by gcasto's avatar gcasto Committed by Commit bot

[Password Generation] Send onchange event when password is filled

Failure to do so causes UI issues on some sites, and causes form submission
to fail on Yahoo.

BUG=159043

Review URL: https://codereview.chromium.org/680413004

Cr-Commit-Position: refs/heads/master@{#302510}
parent b9ebd386
......@@ -110,6 +110,18 @@ const char kInvalidActionAccountCreationFormHTML[] =
" <INPUT type = 'submit' value = 'LOGIN' />"
"</FORM>";
const char ChangeDetectionScript[] =
"<script>"
" firstOnChangeCalled = false;"
" secondOnChangeCalled = false;"
" document.getElementById('first_password').onchange = function() {"
" firstOnChangeCalled = true;"
" };"
" document.getElementById('second_password').onchange = function() {"
" secondOnChangeCalled = true;"
" };"
"</script>";
TEST_F(PasswordGenerationAgentTest, DetectionTest) {
// Don't shown the icon for non account creation forms.
LoadHTML(kSigninFormHTML);
......@@ -143,7 +155,9 @@ TEST_F(PasswordGenerationAgentTest, DetectionTest) {
TEST_F(PasswordGenerationAgentTest, FillTest) {
// Make sure that we are enabled before loading HTML.
LoadHTML(kAccountCreationFormHTML);
std::string html = std::string(kAccountCreationFormHTML) +
ChangeDetectionScript;
LoadHTML(html.c_str());
WebDocument document = GetMainFrame()->document();
WebElement element =
......@@ -168,6 +182,20 @@ TEST_F(PasswordGenerationAgentTest, FillTest) {
EXPECT_TRUE(first_password_element.isAutofilled());
EXPECT_TRUE(second_password_element.isAutofilled());
// Make sure onchange events are called.
int first_onchange_called = -1;
int second_onchange_called = -1;
ASSERT_TRUE(
ExecuteJavaScriptAndReturnIntValue(
base::ASCIIToUTF16("firstOnChangeCalled ? 1 : 0"),
&first_onchange_called));
EXPECT_EQ(1, first_onchange_called);
ASSERT_TRUE(
ExecuteJavaScriptAndReturnIntValue(
base::ASCIIToUTF16("secondOnChangeCalled ? 1 : 0"),
&second_onchange_called));
EXPECT_EQ(1, second_onchange_called);
// Focus moved to the next input field.
// TODO(zysxqn): Change this back to the address element once Bug 90224
// https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed.
......
......@@ -97,7 +97,7 @@ void CopyValueToAllInputElements(
std::vector<blink::WebInputElement>* elements) {
for (std::vector<blink::WebInputElement>::iterator it = elements->begin();
it != elements->end(); ++it) {
it->setValue(value);
it->setValue(value, true /* sendEvents */);
}
}
......@@ -256,7 +256,7 @@ void PasswordGenerationAgent::OnPasswordAccepted(
for (std::vector<blink::WebInputElement>::iterator it =
password_elements_.begin();
it != password_elements_.end(); ++it) {
it->setValue(password);
it->setValue(password, true /* sendEvents */);
it->setAutofilled(true);
// Advance focus to the next input field. We assume password fields in
// an account creation form are always adjacent.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment