1// Copyright 2013 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.
4
5#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TEST_UTILS_H_
6#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TEST_UTILS_H_
7
8#include "base/memory/scoped_ptr.h"
9
10class PrefService;
11
12namespace autofill {
13
14class AutofillProfile;
15class CreditCard;
16struct FormData;
17struct FormFieldData;
18
19// Common utilities shared amongst Autofill tests.
20namespace test {
21
22// Returns a PrefService that can be used for Autofill-related testing in
23// contexts where the PrefService would otherwise have to be constructed
24// manually (e.g., in unit tests within Autofill core code). The returned
25// PrefService has had Autofill preferences registered on its associated
26// registry.
27scoped_ptr<PrefService> PrefServiceForTesting();
28
29// Provides a quick way to populate a FormField with c-strings.
30void CreateTestFormField(const char* label,
31                         const char* name,
32                         const char* value,
33                         const char* type,
34                         FormFieldData* field);
35
36// Populates |form| with data corresponding to a simple address form.
37// Note that this actually appends fields to the form data, which can be useful
38// for building up more complex test forms.
39void CreateTestAddressFormData(FormData* form);
40
41// Returns a profile full of dummy info.
42AutofillProfile GetFullProfile();
43
44// Returns a profile full of dummy info, different to the above.
45AutofillProfile GetFullProfile2();
46
47// Returns a verified profile full of dummy info.
48AutofillProfile GetVerifiedProfile();
49
50// Returns a verified profile full of dummy info, different to the above.
51AutofillProfile GetVerifiedProfile2();
52
53// Returns a credit card full of dummy info.
54CreditCard GetCreditCard();
55
56// Returns a credit card full of dummy info, different to the above.
57CreditCard GetCreditCard2();
58
59// Returns a verified credit card full of dummy info.
60CreditCard GetVerifiedCreditCard();
61
62// Returns a verified credit card full of dummy info, different to the above.
63CreditCard GetVerifiedCreditCard2();
64
65// A unit testing utility that is common to a number of the Autofill unit
66// tests.  |SetProfileInfo| provides a quick way to populate a profile with
67// c-strings.
68void SetProfileInfo(AutofillProfile* profile,
69    const char* first_name, const char* middle_name,
70    const char* last_name, const char* email, const char* company,
71    const char* address1, const char* address2, const char* city,
72    const char* state, const char* zipcode, const char* country,
73    const char* phone);
74
75void SetProfileInfoWithGuid(AutofillProfile* profile,
76    const char* guid, const char* first_name, const char* middle_name,
77    const char* last_name, const char* email, const char* company,
78    const char* address1, const char* address2, const char* city,
79    const char* state, const char* zipcode, const char* country,
80    const char* phone);
81
82// A unit testing utility that is common to a number of the Autofill unit
83// tests.  |SetCreditCardInfo| provides a quick way to populate a credit card
84// with c-strings.
85void SetCreditCardInfo(CreditCard* credit_card,
86    const char* name_on_card, const char* card_number,
87    const char* expiration_month, const char* expiration_year);
88
89// TODO(isherman): We should do this automatically for all tests, not manually
90// on a per-test basis: http://crbug.com/57221
91// Disables or mocks out code that would otherwise reach out to system services.
92void DisableSystemServices(PrefService* prefs);
93
94}  // namespace test
95}  // namespace autofill
96
97#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TEST_UTILS_H_
98