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

Unified Diff: chrome/renderer/autofill/password_generation_test_utils.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
Index: chrome/renderer/autofill/password_generation_test_utils.cc
diff --git a/chrome/renderer/autofill/password_generation_test_utils.cc b/chrome/renderer/autofill/password_generation_test_utils.cc
index 455dd6c5acbfe919674ab36fac7470786a0c925f..b66a5140829fd4d5b550b9713ca3b2f491cb5bbe 100644
--- a/chrome/renderer/autofill/password_generation_test_utils.cc
+++ b/chrome/renderer/autofill/password_generation_test_utils.cc
@@ -4,8 +4,6 @@
#include "chrome/renderer/autofill/password_generation_test_utils.h"
-#include <vector>
-
#include "base/strings/stringprintf.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
#include "components/autofill/content/renderer/test_password_generation_agent.h"
@@ -17,6 +15,13 @@
namespace autofill {
+namespace {
+
+// Events that should be triggered when Chrome fills a field.
+const char* const kEvents[] = {"focus", "keydown", "input",
+ "change", "keyup", "blur"};
+} // namespace
+
void SetNotBlacklistedMessage(TestPasswordGenerationAgent* generation_agent,
const char* form_str) {
autofill::PasswordForm form;
@@ -47,4 +52,28 @@ void SetAccountCreationFormsDetectedMessage(
generation_agent->FoundFormsEligibleForGeneration(forms);
}
+// Creates script that registers event listeners for |element_name| field. To
+// check whether the listeners are called, check that the variables from
+// |variables_to_check| are set to 1.
+std::string CreateScriptToRegisterListeners(
+ const char* const element_name,
+ std::vector<std::string>* variables_to_check) {
+ DCHECK(variables_to_check);
+
+ std::string all_scripts;
+ for (const char* event : kEvents) {
+ std::string script = base::StringPrintf(
+ "var %1$s_%2$s_event = 0;"
+ "document.getElementById('%1$s').on%2$s = function() {"
+ " %1$s_%2$s_event = 1;"
+ "};\n",
+ element_name, event);
+ all_scripts += script;
+ variables_to_check->push_back(
+ base::StringPrintf("%s_%s_event", element_name, event));
+ }
+
+ return all_scripts;
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698