Index: chrome/renderer/autofill/password_generation_agent_browsertest.cc |
diff --git a/chrome/renderer/autofill/password_generation_agent_browsertest.cc b/chrome/renderer/autofill/password_generation_agent_browsertest.cc |
index 7da0adfe1dbb9479d116792b9d458b5970e771c2..6fa67444a98e8c1f5f8734679e2d15592d3a93e4 100644 |
--- a/chrome/renderer/autofill/password_generation_agent_browsertest.cc |
+++ b/chrome/renderer/autofill/password_generation_agent_browsertest.cc |
@@ -250,18 +250,6 @@ const char kNewPasswordAutocompleteAttributeFormHTML[] = |
" <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>"; |
- |
const char kPasswordChangeFormHTML[] = |
"<FORM name = 'ChangeWithUsernameForm' action = 'http://www.bidule.com'> " |
" <INPUT type = 'text' id = 'username'/> " |
@@ -317,8 +305,7 @@ TEST_F(PasswordGenerationAgentTest, DetectionTest) { |
TEST_F(PasswordGenerationAgentTest, FillTest) { |
// Make sure that we are enabled before loading HTML. |
- std::string html = std::string(kAccountCreationFormHTML) + |
- ChangeDetectionScript; |
+ std::string html = std::string(kAccountCreationFormHTML); |
LoadHTMLWithUserGesture(html.c_str()); |
SetNotBlacklistedMessage(password_generation_, html.c_str()); |
SetAccountCreationFormsDetectedMessage(password_generation_, |
@@ -337,6 +324,13 @@ TEST_F(PasswordGenerationAgentTest, FillTest) { |
EXPECT_TRUE(first_password_element.value().isNull()); |
EXPECT_TRUE(second_password_element.value().isNull()); |
+ // Add event listeners for password fields. |
+ std::vector<std::string> variables_to_check; |
+ std::string events_registration_script = |
+ CreateScriptToRegisterListeners("first_password", &variables_to_check) + |
+ CreateScriptToRegisterListeners("second_password", &variables_to_check); |
+ ExecuteJavaScriptForTests(events_registration_script.c_str()); |
+ |
base::string16 password = base::ASCIIToUTF16("random_password"); |
password_generation_->GeneratedPasswordAccepted(password); |
@@ -346,19 +340,13 @@ 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); |
+ // Make sure all events are called. |
+ for (const std::string& variable : variables_to_check) { |
+ int value; |
+ EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(base::UTF8ToUTF16(variable), |
+ &value)); |
+ EXPECT_EQ(1, value) << variable; |
+ } |
// Focus moved to the next input field. |
// TODO(zysxqn): Change this back to the address element once Bug 90224 |