| 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
|
|
|