Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / renderer / autofill / password_generation_test_utils.cc
blob83c88dfeed9240a3bbaac3ae375ee06f98efba84
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
3 // found in the LICENSE file.
5 #include "chrome/renderer/autofill/password_generation_test_utils.h"
7 #include <vector>
9 #include "components/autofill/content/common/autofill_messages.h"
10 #include "components/autofill/content/renderer/form_autofill_util.h"
11 #include "components/autofill/content/renderer/test_password_generation_agent.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/web/WebDocument.h"
14 #include "third_party/WebKit/public/web/WebFormElement.h"
16 namespace autofill {
18 void SetNotBlacklistedMessage(TestPasswordGenerationAgent* generation_agent,
19 const char* form_str) {
20 autofill::PasswordForm form;
21 form.origin =
22 GURL(base::StringPrintf("data:text/html;charset=utf-8,%s", form_str));
23 AutofillMsg_FormNotBlacklisted msg(0, form);
24 generation_agent->OnMessageReceived(msg);
27 // Sends a message that the |form_index| form on the page is valid for
28 // account creation.
29 void SetAccountCreationFormsDetectedMessage(
30 TestPasswordGenerationAgent* generation_agent,
31 blink::WebDocument document,
32 int form_index) {
33 blink::WebVector<blink::WebFormElement> web_forms;
34 document.forms(web_forms);
36 autofill::FormData form_data;
37 WebFormElementToFormData(web_forms[form_index],
38 blink::WebFormControlElement(),
39 EXTRACT_NONE,
40 &form_data,
41 nullptr /* FormFieldData */);
43 std::vector<autofill::FormData> forms;
44 forms.push_back(form_data);
45 AutofillMsg_AccountCreationFormsDetected msg(0, forms);
46 generation_agent->OnMessageReceived(msg);
49 void ExpectPasswordGenerationAvailable(
50 TestPasswordGenerationAgent* password_generation,
51 bool available) {
52 if (available) {
53 ASSERT_EQ(1u, password_generation->messages().size());
54 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
55 password_generation->messages()[0]->type());
56 } else {
57 EXPECT_TRUE(password_generation->messages().empty());
59 password_generation->clear_messages();
62 } // namespace autofill