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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/autofill/password_generation_test_utils.h" 5 #include "chrome/renderer/autofill/password_generation_test_utils.h"
6 6
7 #include <vector>
8
9 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
10 #include "components/autofill/content/renderer/form_autofill_util.h" 8 #include "components/autofill/content/renderer/form_autofill_util.h"
11 #include "components/autofill/content/renderer/test_password_generation_agent.h" 9 #include "components/autofill/content/renderer/test_password_generation_agent.h"
12 #include "components/autofill/core/common/password_form_generation_data.h" 10 #include "components/autofill/core/common/password_form_generation_data.h"
13 #include "components/autofill/core/common/signatures_util.h" 11 #include "components/autofill/core/common/signatures_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/web/WebDocument.h" 13 #include "third_party/WebKit/public/web/WebDocument.h"
16 #include "third_party/WebKit/public/web/WebFormElement.h" 14 #include "third_party/WebKit/public/web/WebFormElement.h"
17 15
18 namespace autofill { 16 namespace autofill {
19 17
18 namespace {
19
20 // Events that should be triggered when Chrome fills a field.
21 const char* const kEvents[] = {"focus", "keydown", "input",
22 "change", "keyup", "blur"};
23 } // namespace
24
20 void SetNotBlacklistedMessage(TestPasswordGenerationAgent* generation_agent, 25 void SetNotBlacklistedMessage(TestPasswordGenerationAgent* generation_agent,
21 const char* form_str) { 26 const char* form_str) {
22 autofill::PasswordForm form; 27 autofill::PasswordForm form;
23 form.origin = form_util::StripAuthAndParams( 28 form.origin = form_util::StripAuthAndParams(
24 GURL(base::StringPrintf("data:text/html;charset=utf-8,%s", form_str))); 29 GURL(base::StringPrintf("data:text/html;charset=utf-8,%s", form_str)));
25 generation_agent->FormNotBlacklisted(form); 30 generation_agent->FormNotBlacklisted(form);
26 } 31 }
27 32
28 // Sends a message that the |form_index| form on the page is valid for 33 // Sends a message that the |form_index| form on the page is valid for
29 // account creation. 34 // account creation.
(...skipping 10 matching lines...) Expand all
40 web_forms[form_index], blink::WebFormControlElement(), nullptr, 45 web_forms[form_index], blink::WebFormControlElement(), nullptr,
41 form_util::EXTRACT_NONE, &form_data, nullptr /* FormFieldData */); 46 form_util::EXTRACT_NONE, &form_data, nullptr /* FormFieldData */);
42 47
43 std::vector<autofill::PasswordFormGenerationData> forms; 48 std::vector<autofill::PasswordFormGenerationData> forms;
44 forms.push_back(autofill::PasswordFormGenerationData{ 49 forms.push_back(autofill::PasswordFormGenerationData{
45 CalculateFormSignature(form_data), 50 CalculateFormSignature(form_data),
46 CalculateFieldSignatureForField(form_data.fields[field_index])}); 51 CalculateFieldSignatureForField(form_data.fields[field_index])});
47 generation_agent->FoundFormsEligibleForGeneration(forms); 52 generation_agent->FoundFormsEligibleForGeneration(forms);
48 } 53 }
49 54
55 // Creates script that registers event listeners for |element_name| field. To
56 // check whether the listeners are called, check that the variables from
57 // |variables_to_check| are set to 1.
58 std::string CreateScriptToRegisterListeners(
59 const char* const element_name,
60 std::vector<std::string>* variables_to_check) {
61 DCHECK(variables_to_check);
62
63 std::string all_scripts;
64 for (const char* event : kEvents) {
65 std::string script = base::StringPrintf(
66 "var %1$s_%2$s_event = 0;"
67 "document.getElementById('%1$s').on%2$s = function() {"
68 " %1$s_%2$s_event = 1;"
69 "};\n",
70 element_name, event);
71 all_scripts += script;
72 variables_to_check->push_back(
73 base::StringPrintf("%s_%s_event", element_name, event));
74 }
75
76 return all_scripts;
77 }
78
50 } // namespace autofill 79 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698