autofill_helper.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1// Copyright (c) 2012 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 CHROME_BROWSER_SYNC_TEST_INTEGRATION_AUTOFILL_HELPER_H_
6#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_AUTOFILL_HELPER_H_
7
8#include <set>
9#include <string>
10#include <vector>
11
12#include "base/compiler_specific.h"
13#include "base/memory/ref_counted.h"
14#include "base/strings/string16.h"
15#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
16
17namespace autofill {
18class AutofillEntry;
19class AutofillKey;
20class AutofillProfile;
21class AutofillType;
22class AutofillWebDataService;
23class CreditCard;
24class PersonalDataManager;
25}  // namespace autofill
26
27namespace autofill_helper {
28
29enum ProfileType {
30  PROFILE_MARION,
31  PROFILE_HOMER,
32  PROFILE_FRASIER,
33  PROFILE_NULL
34};
35
36// Used to access the web data service within a particular sync profile.
37scoped_refptr<autofill::AutofillWebDataService> GetWebDataService(
38    int index) WARN_UNUSED_RESULT;
39
40// Used to access the personal data manager within a particular sync profile.
41autofill::PersonalDataManager* GetPersonalDataManager(
42    int index) WARN_UNUSED_RESULT;
43
44// Adds the form fields in |keys| to the WebDataService of sync profile
45// |profile|.
46void AddKeys(int profile, const std::set<autofill::AutofillKey>& keys);
47
48// Removes the form field in |key| from the WebDataService of sync profile
49// |profile|.
50void RemoveKey(int profile, const autofill::AutofillKey& key);
51
52// Removes all of the keys from the WebDataService of sync profile |profile|.
53void RemoveKeys(int profile);
54
55// Gets all the form fields in the WebDataService of sync profile |profile|.
56std::set<autofill::AutofillEntry> GetAllKeys(int profile) WARN_UNUSED_RESULT;
57
58// Compares the form fields in the WebDataServices of sync profiles
59// |profile_a| and |profile_b|. Returns true if they match.
60bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT;
61
62// Allows syncers to run until KeysMatch() returns true.
63bool AwaitKeysMatch(int profile_a, int profile_b);
64
65// Replaces the Autofill profiles in sync profile |profile| with
66// |autofill_profiles|.
67void SetProfiles(int profile,
68                 std::vector<autofill::AutofillProfile>* autofill_profiles);
69
70// Replaces the CreditCard profiles in sync profile |profile| with
71// |credit_cards|.
72void SetCreditCards(int profile,
73                    std::vector<autofill::CreditCard>* credit_cards);
74
75// Adds the autofill profile |autofill_profile| to sync profile |profile|.
76void AddProfile(int profile, const autofill::AutofillProfile& autofill_profile);
77
78// Removes the autofill profile with guid |guid| from sync profile
79// |profile|.
80void RemoveProfile(int profile, const std::string& guid);
81
82// Updates the autofill profile with guid |guid| in sync profile |profile|
83// to |type| and |value|.
84void UpdateProfile(int profile,
85                   const std::string& guid,
86                   const autofill::AutofillType& type,
87                   const base::string16& value);
88
89// Gets all the Autofill profiles in the PersonalDataManager of sync profile
90// |profile|.
91const std::vector<autofill::AutofillProfile*>& GetAllProfiles(
92    int profile) WARN_UNUSED_RESULT;
93
94// Returns the number of autofill profiles contained by sync profile
95// |profile|.
96int GetProfileCount(int profile);
97
98// Returns the number of autofill keys contained by sync profile |profile|.
99int GetKeyCount(int profile);
100
101// Compares the Autofill profiles in the PersonalDataManagers of sync profiles
102// |profile_a| and |profile_b|. Returns true if they match.
103bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT;
104
105// Compares the autofill profiles for all sync profiles, and returns true if
106// they all match.
107bool AllProfilesMatch() WARN_UNUSED_RESULT;
108
109// Allows the syncers to run until ProfilesMatch() returns true.
110bool AwaitProfilesMatch(int profile_a, int profile_b);
111
112// Creates a test autofill profile based on the persona specified in |type|.
113autofill::AutofillProfile CreateAutofillProfile(ProfileType type);
114
115}  // namespace autofill_helper
116
117#endif  // CHROME_BROWSER_SYNC_TEST_INTEGRATION_AUTOFILL_HELPER_H_
118