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

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

Issue 2750323003: [Password Manager] Replace WebInputElement.setValue with WebInputElement.setAutofillValue (Closed)
Patch Set: Fixed a comment 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..ed08c6ba918739c3fe1c4d72adffe8166acdc2d7 100644
--- a/chrome/renderer/autofill/password_generation_test_utils.cc
+++ b/chrome/renderer/autofill/password_generation_test_utils.cc
@@ -4,8 +4,7 @@
#include "chrome/renderer/autofill/password_generation_test_utils.h"
-#include <vector>
-
+#include <base/strings/utf_string_conversions.h>
#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 +16,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 +53,30 @@ 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<base::string16>* variables_to_check) {
+ DCHECK(variables_to_check);
+ std::string element = element_name;
+
+ std::string all_scripts = "<script>";
+ for (const char* const event : kEvents) {
+ std::string script = base::StringPrintf(
+ "%s_%s_event = 0;"
+ "document.getElementById('%s').on%s = function() {"
+ " %s_%s_event = 1;"
+ "};",
+ element_name, event, element_name, event, element_name, event);
+ all_scripts += script;
+ variables_to_check->push_back(base::UTF8ToUTF16(
+ base::StringPrintf("%s_%s_event", element_name, event)));
+ }
+
+ all_scripts += "</script>";
+ return all_scripts;
+}
+
} // namespace autofill
« no previous file with comments | « chrome/renderer/autofill/password_generation_test_utils.h ('k') | components/autofill/content/renderer/form_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698