Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4354)

Unified Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 2750323003: [Password Manager] Replace WebInputElement.setValue with WebInputElement.setAutofillValue (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/renderer/autofill/password_generation_agent_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b598bccc4fcb37a6a5a88c990ed3e5e10b49855d..1eccec80307b691487a5fb9e22d8121618091f95 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -177,18 +177,6 @@ const char kJavaScriptClick[] =
"form.dispatchEvent(event);"
"console.log('clicked!');";
-const char kOnChangeDetectionScript[] =
- "<script>"
- " usernameOnchangeCalled = false;"
- " passwordOnchangeCalled = false;"
- " document.getElementById('username').onchange = function() {"
- " usernameOnchangeCalled = true;"
- " };"
- " document.getElementById('password').onchange = function() {"
- " passwordOnchangeCalled = true;"
- " };"
- "</script>";
-
const char kFormHTMLWithTwoTextFields[] =
"<FORM name='LoginTestForm' id='LoginTestForm' "
"action='http://www.bidule.com'>"
@@ -551,6 +539,17 @@ class PasswordAutofillAgentTest : public ChromeRenderViewTest {
EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value);
}
+ void CheckIfEventsAreCalled(const std::vector<std::string> checkers,
vabr (Chromium) 2017/03/17 12:01:06 Please pass the vector by (const) reference, not b
kolos1 2017/03/17 12:47:36 Done.
+ bool expected) {
+ for (const std::string& variable : checkers) {
+ int value;
+ EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(
+ base::UTF8ToUTF16(variable), &value))
+ << variable;
+ EXPECT_EQ(expected, value == 1) << variable;
+ }
+ }
+
bool GetCalledShowPasswordGenerationPopup() {
fake_pw_client_.Flush();
return fake_pw_client_.called_show_pw_generation_popup();
@@ -919,11 +918,18 @@ TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) {
// forms that are filled on page load.
TEST_F(PasswordAutofillAgentTest,
PasswordAutofillTriggersOnChangeEventsOnLoad) {
- std::string html = std::string(kFormHTML) + kOnChangeDetectionScript;
+ std::string html = std::string(kFormHTML);
LoadHTML(html.c_str());
UpdateOriginForHTML(html);
UpdateUsernameAndPasswordElements();
+ std::vector<std::string> username_event_checkers;
+ std::vector<std::string> password_event_checkers;
+ std::string events_registration_script =
+ CreateScriptToRegisterListeners(kUsernameName, &username_event_checkers) +
+ CreateScriptToRegisterListeners(kPasswordName, &password_event_checkers);
+ ExecuteJavaScriptForTests(events_registration_script.c_str());
+
// Simulate the browser sending back the login info, it triggers the
// autocomplete.
SimulateOnFillPasswordForm(fill_data_);
@@ -936,19 +942,10 @@ TEST_F(PasswordAutofillAgentTest,
// A JavaScript onChange event should have been triggered for the username,
// but not yet for the password.
- int username_onchange_called = -1;
- int password_onchange_called = -1;
- ASSERT_TRUE(
- ExecuteJavaScriptAndReturnIntValue(
- ASCIIToUTF16("usernameOnchangeCalled ? 1 : 0"),
- &username_onchange_called));
- EXPECT_EQ(1, username_onchange_called);
- ASSERT_TRUE(
- ExecuteJavaScriptAndReturnIntValue(
- ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"),
- &password_onchange_called));
+
+ CheckIfEventsAreCalled(username_event_checkers, true);
// TODO(isherman): Re-enable this check once http://crbug.com/333144 is fixed.
vabr (Chromium) 2017/03/17 12:01:07 This comment looks obsoleted by your changes.
kolos1 2017/03/17 12:47:36 Done.
- // EXPECT_EQ(0, password_onchange_called);
+ CheckIfEventsAreCalled(password_event_checkers, false);
// Simulate a user click so that the password field's real value is filled.
SimulateElementClick(kUsernameName);
@@ -956,22 +953,24 @@ TEST_F(PasswordAutofillAgentTest,
// Now, a JavaScript onChange event should have been triggered for the
// password as well.
- ASSERT_TRUE(
- ExecuteJavaScriptAndReturnIntValue(
- ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"),
- &password_onchange_called));
- EXPECT_EQ(1, password_onchange_called);
+ CheckIfEventsAreCalled(password_event_checkers, true);
}
// Verifies that password autofill triggers onChange events in JavaScript for
// forms that are filled after page load.
TEST_F(PasswordAutofillAgentTest,
PasswordAutofillTriggersOnChangeEventsWaitForUsername) {
- std::string html = std::string(kFormHTML) + kOnChangeDetectionScript;
+ std::string html = std::string(kFormHTML);
LoadHTML(html.c_str());
UpdateOriginForHTML(html);
UpdateUsernameAndPasswordElements();
+ std::vector<std::string> event_checkers;
+ std::string events_registration_script =
+ CreateScriptToRegisterListeners(kUsernameName, &event_checkers) +
+ CreateScriptToRegisterListeners(kPasswordName, &event_checkers);
+ ExecuteJavaScriptForTests(events_registration_script.c_str());
+
// Simulate the browser sending back the login info, it triggers the
// autocomplete.
fill_data_.wait_for_username = true;
@@ -987,6 +986,10 @@ TEST_F(PasswordAutofillAgentTest,
// Simulate the user entering the first letter of their username and selecting
// the matching autofill from the dropdown.
SimulateUsernameChange("a");
+ // Since the username element has focus, blur event will ne be triggered.
+ event_checkers.erase(std::remove(event_checkers.begin(), event_checkers.end(),
vabr (Chromium) 2017/03/17 12:01:06 Please use base::Erase instead (this is a recent c
kolos1 2017/03/17 12:47:36 Done.
+ "username_blur_event"),
+ event_checkers.end());
SimulateSuggestionChoice(username_element_);
// The username and password should now have been autocompleted.
@@ -994,18 +997,7 @@ TEST_F(PasswordAutofillAgentTest,
// JavaScript onChange events should have been triggered both for the username
// and for the password.
- int username_onchange_called = -1;
- int password_onchange_called = -1;
- ASSERT_TRUE(
- ExecuteJavaScriptAndReturnIntValue(
- ASCIIToUTF16("usernameOnchangeCalled ? 1 : 0"),
- &username_onchange_called));
- EXPECT_EQ(1, username_onchange_called);
- ASSERT_TRUE(
- ExecuteJavaScriptAndReturnIntValue(
- ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"),
- &password_onchange_called));
- EXPECT_EQ(1, password_onchange_called);
+ CheckIfEventsAreCalled(event_checkers, true);
}
// Tests that |FillSuggestion| properly fills the username and password.
« no previous file with comments | « no previous file | chrome/renderer/autofill/password_generation_agent_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698