OLD | NEW |
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 <vector> |
8 | 8 |
9 #include "components/autofill/content/common/autofill_messages.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
11 #include "components/autofill/content/renderer/test_password_generation_agent.h" | 11 #include "components/autofill/content/renderer/test_password_generation_agent.h" |
12 #include "components/autofill/core/common/password_form_generation_data.h" | 12 #include "components/autofill/core/common/password_form_generation_data.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/WebKit/public/web/WebDocument.h" | 14 #include "third_party/WebKit/public/web/WebDocument.h" |
15 #include "third_party/WebKit/public/web/WebFormElement.h" | 15 #include "third_party/WebKit/public/web/WebFormElement.h" |
16 | 16 |
17 namespace autofill { | 17 namespace autofill { |
18 | 18 |
19 void SetNotBlacklistedMessage(TestPasswordGenerationAgent* generation_agent, | 19 void SetNotBlacklistedMessage(TestPasswordGenerationAgent* generation_agent, |
20 const char* form_str) { | 20 const char* form_str) { |
21 autofill::PasswordForm form; | 21 autofill::PasswordForm form; |
22 form.origin = | 22 form.origin = |
23 GURL(base::StringPrintf("data:text/html;charset=utf-8,%s", form_str)); | 23 GURL(base::StringPrintf("data:text/html;charset=utf-8,%s", form_str)); |
24 AutofillMsg_FormNotBlacklisted msg(0, form); | 24 generation_agent->FormNotBlacklisted(form); |
25 static_cast<IPC::Listener*>(generation_agent)->OnMessageReceived(msg); | |
26 } | 25 } |
27 | 26 |
28 // Sends a message that the |form_index| form on the page is valid for | 27 // Sends a message that the |form_index| form on the page is valid for |
29 // account creation. | 28 // account creation. |
30 void SetAccountCreationFormsDetectedMessage( | 29 void SetAccountCreationFormsDetectedMessage( |
31 TestPasswordGenerationAgent* generation_agent, | 30 TestPasswordGenerationAgent* generation_agent, |
32 blink::WebDocument document, | 31 blink::WebDocument document, |
33 int form_index, | 32 int form_index, |
34 int field_index) { | 33 int field_index) { |
35 blink::WebVector<blink::WebFormElement> web_forms; | 34 blink::WebVector<blink::WebFormElement> web_forms; |
36 document.forms(web_forms); | 35 document.forms(web_forms); |
37 | 36 |
38 autofill::FormData form_data; | 37 autofill::FormData form_data; |
39 WebFormElementToFormData( | 38 WebFormElementToFormData( |
40 web_forms[form_index], blink::WebFormControlElement(), nullptr, | 39 web_forms[form_index], blink::WebFormControlElement(), nullptr, |
41 form_util::EXTRACT_NONE, &form_data, nullptr /* FormFieldData */); | 40 form_util::EXTRACT_NONE, &form_data, nullptr /* FormFieldData */); |
42 | 41 |
43 std::vector<autofill::PasswordFormGenerationData> forms; | 42 std::vector<autofill::PasswordFormGenerationData> forms; |
44 forms.push_back(autofill::PasswordFormGenerationData{ | 43 forms.push_back(autofill::PasswordFormGenerationData{ |
45 form_data.name, form_data.action, form_data.fields[field_index]}); | 44 form_data.name, form_data.action, form_data.fields[field_index]}); |
46 AutofillMsg_FoundFormsEligibleForGeneration msg(0, forms); | 45 generation_agent->FoundFormsEligibleForGeneration(forms); |
47 static_cast<IPC::Listener*>(generation_agent)->OnMessageReceived(msg); | |
48 } | 46 } |
49 | 47 |
50 } // namespace autofill | 48 } // namespace autofill |
OLD | NEW |