1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/test_utils/test_profiles.h"
#include "base/feature_list.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/data_model/addresses/autofill_profile.h"
#include "components/autofill/core/common/autofill_features.h"
namespace autofill {
namespace test {
void SetProfileTestValues(AutofillProfile* profile,
const std::vector<ProfileTestData>& profile_test_data,
bool finalize) {
DCHECK(profile);
std::ranges::for_each(
profile_test_data, [&](const ProfileTestData& test_data) {
profile->SetRawInfoWithVerificationStatus(
test_data.field_type, base::UTF8ToUTF16(test_data.value),
test_data.verification_status);
});
if (finalize) {
profile->FinalizeAfterImport();
}
}
void CopyGUID(const AutofillProfile& from, AutofillProfile* to) {
to->set_guid(from.guid());
}
void SetProfileObservedTestValues(AutofillProfile* profile,
const std::vector<ProfileTestData>& test_data,
bool finalize) {
// Make a copy of the test data with all verification statuses replaced with
// 'kObserved'.
std::vector<ProfileTestData> observed_test_data;
std::ranges::for_each(test_data, [&](const ProfileTestData& entry) {
observed_test_data.emplace_back(ProfileTestData{
entry.field_type, entry.value, VerificationStatus::kObserved});
});
// Set this data to the profile.
SetProfileTestValues(profile, observed_test_data, finalize);
}
AutofillProfile StandardProfile(AddressCountryCode country_code) {
AutofillProfile profile(country_code);
const std::vector<ProfileTestData> observed_profile_test_data = {
{NAME_FULL, "Pablo Diego de la Ruiz y Picasso",
VerificationStatus::kUserVerified},
{ADDRESS_HOME_STREET_ADDRESS, "123 Mainstreet",
VerificationStatus::kObserved},
{ADDRESS_HOME_STATE, "CA", VerificationStatus::kObserved},
{ADDRESS_HOME_ZIP, "98765", VerificationStatus::kObserved},
{ADDRESS_HOME_CITY, "Mountainview", VerificationStatus::kObserved}};
SetProfileTestValues(&profile, observed_profile_test_data);
return profile;
}
AutofillProfile UpdateableStandardProfile() {
AutofillProfile profile(AddressCountryCode("US"));
const std::vector<ProfileTestData> observed_profile_test_data = {
{NAME_FULL, "Pablo Diego de la Ruiz y Picasso",
VerificationStatus::kObserved},
{ADDRESS_HOME_STREET_ADDRESS, "123 Mainstreet",
VerificationStatus::kObserved},
{ADDRESS_HOME_STATE, "CA", VerificationStatus::kObserved},
{ADDRESS_HOME_ZIP, "98765", VerificationStatus::kObserved},
{ADDRESS_HOME_CITY, "Mountainview", VerificationStatus::kObserved}};
SetProfileTestValues(&profile, observed_profile_test_data);
return profile;
}
AutofillProfile SubsetOfStandardProfile() {
AutofillProfile profile(AddressCountryCode("US"));
const std::vector<ProfileTestData> observed_profile_test_data = {
{NAME_FULL, "Pablo Diego de la Ruiz y Picasso"},
{ADDRESS_HOME_STREET_ADDRESS, "123 Mainstreet"},
{ADDRESS_HOME_STATE, "CA"},
{ADDRESS_HOME_ZIP, ""},
{ADDRESS_HOME_CITY, ""}};
SetProfileObservedTestValues(&profile, observed_profile_test_data);
return profile;
}
AutofillProfile DifferentFromStandardProfile() {
AutofillProfile profile(AddressCountryCode("US"));
const std::vector<ProfileTestData> observed_profile_test_data = {
{NAME_FULL, "Neo Anderson"},
{ADDRESS_HOME_STREET_ADDRESS, "119 Some Avenue"},
{ADDRESS_HOME_STATE, "CA"},
{ADDRESS_HOME_ZIP, "99666"},
{ADDRESS_HOME_CITY, "Los Angeles"}};
SetProfileObservedTestValues(&profile, observed_profile_test_data);
return profile;
}
AutofillProfile HiraganaProfile() {
AutofillProfile profile(AddressCountryCode("JP"));
const std::vector<ProfileTestData> observed_profile_test_data = {
{NAME_FULL, "山田 太郎", VerificationStatus::kObserved},
{ALTERNATIVE_FULL_NAME, "やまだ たろう", VerificationStatus::kObserved}};
SetProfileObservedTestValues(&profile, observed_profile_test_data);
return profile;
}
AutofillProfile ExtendedHiraganaProfile() {
AutofillProfile profile = HiraganaProfile();
// Add the address-related fields.
const std::vector<ProfileTestData> observed_profile_test_data = {
{ADDRESS_HOME_STREET_ADDRESS, "123 Mainstreet",
VerificationStatus::kObserved},
{ADDRESS_HOME_ZIP, "98765", VerificationStatus::kObserved}};
SetProfileTestValues(&profile, observed_profile_test_data);
return profile;
}
AutofillProfile KatakanaProfile1() {
AutofillProfile profile(AddressCountryCode("JP"));
const std::vector<ProfileTestData> observed_profile_test_data = {
{NAME_FULL, "山田 太郎", VerificationStatus::kObserved},
{ALTERNATIVE_FULL_NAME, "ヤマダ タロウ", VerificationStatus::kObserved}};
SetProfileObservedTestValues(&profile, observed_profile_test_data);
return profile;
}
AutofillProfile KatakanaProfile2() {
AutofillProfile profile(AddressCountryCode("JP"));
const std::vector<ProfileTestData> observed_profile_test_data = {
{NAME_FULL, "ネオ アンダーソン"},
{ALTERNATIVE_FULL_NAME, "ネオ アンダーソン"}};
SetProfileObservedTestValues(&profile, observed_profile_test_data);
return profile;
}
} // namespace test
} // namespace autofill
|