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

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