Commit f01dc638 authored by Matthias Körber's avatar Matthias Körber Committed by Commit Bot

[Autofill][Slimshady] Syncing tests for structured names

Bug: 1099202
Change-Id: I4f756f5a228f0fdc47fbda3d50d8c0078a97a31a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363760
Commit-Queue: Matthias Körber <koerber@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810644}
parent fe4c7a83
......@@ -56,8 +56,7 @@ ACTION_P(SignalEvent, event) {
class MockWebDataServiceObserver
: public AutofillWebDataServiceObserverOnDBSequence {
public:
MOCK_METHOD1(AutofillEntriesChanged,
void(const AutofillChangeList& changes));
MOCK_METHOD1(AutofillEntriesChanged, void(const AutofillChangeList& changes));
};
scoped_refptr<AutofillWebDataService> GetWebDataService(int index) {
......@@ -102,8 +101,8 @@ void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) {
void GetAllAutofillEntriesOnDBSequence(AutofillWebDataService* wds,
std::vector<AutofillEntry>* entries) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase(
wds->GetDatabase())->GetAllAutofillEntries(entries);
AutofillTable::FromWebDatabase(wds->GetDatabase())
->GetAllAutofillEntries(entries);
}
std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) {
......@@ -177,45 +176,40 @@ AutofillProfile CreateAutofillProfile(ProfileType type) {
AutofillProfile profile;
switch (type) {
case PROFILE_MARION:
autofill::test::SetProfileInfoWithGuid(&profile,
"C837507A-6C3B-4872-AC14-5113F157D668",
"Marion", "Mitchell", "Morrison",
"johnwayne@me.xyz", "Fox",
"123 Zoo St.", "unit 5", "Hollywood", "CA",
"91601", "US", "12345678910");
autofill::test::SetProfileInfoWithGuid(
&profile, "C837507A-6C3B-4872-AC14-5113F157D668", "Marion",
"Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
"unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
break;
case PROFILE_HOMER:
autofill::test::SetProfileInfoWithGuid(&profile,
"137DE1C3-6A30-4571-AC86-109B1ECFBE7F",
"Homer", "J.", "Simpson",
"homer@abc.com", "SNPP",
"742 Evergreen Terrace", "PO Box 1", "Springfield", "MA",
"94101", "US", "14155551212");
autofill::test::SetProfileInfoWithGuid(
&profile, "137DE1C3-6A30-4571-AC86-109B1ECFBE7F", "Homer", "J.",
"Simpson", "homer@abc.com", "SNPP", "742 Evergreen Terrace",
"PO Box 1", "Springfield", "MA", "94101", "US", "14155551212");
break;
case PROFILE_FRASIER:
autofill::test::SetProfileInfoWithGuid(&profile,
"9A5E6872-6198-4688-BF75-0016E781BB0A",
"Frasier", "Winslow", "Crane",
"", "randomness", "", "Apt. 4", "Seattle", "WA",
autofill::test::SetProfileInfoWithGuid(
&profile, "9A5E6872-6198-4688-BF75-0016E781BB0A", "Frasier",
"Winslow", "Crane", "", "randomness", "", "Apt. 4", "Seattle", "WA",
"99121", "US", "0000000000");
break;
case PROFILE_NULL:
autofill::test::SetProfileInfoWithGuid(&profile,
"FE461507-7E13-4198-8E66-74C7DB6D8322",
"", "", "", "", "", "", "", "", "", "", "", "");
autofill::test::SetProfileInfoWithGuid(
&profile, "FE461507-7E13-4198-8E66-74C7DB6D8322", "", "", "", "", "",
"", "", "", "", "", "", "");
break;
}
profile.FinalizeAfterImport();
return profile;
}
AutofillProfile CreateUniqueAutofillProfile() {
AutofillProfile profile;
autofill::test::SetProfileInfoWithGuid(&profile,
base::GenerateGUID().c_str(),
"First", "Middle", "Last",
"email@domain.tld", "Company",
"123 Main St", "Apt 456", "Nowhere", "OK",
autofill::test::SetProfileInfoWithGuid(
&profile, base::GenerateGUID().c_str(), "First", "Middle", "Last",
"email@domain.tld", "Company", "123 Main St", "Apt 456", "Nowhere", "OK",
"73038", "US", "12345678910");
profile.FinalizeAfterImport();
return profile;
}
......@@ -327,12 +321,14 @@ void RemoveProfile(int profile, const std::string& guid) {
void UpdateProfile(int profile,
const std::string& guid,
const AutofillType& type,
const base::string16& value) {
const base::string16& value,
autofill::structured_address::VerificationStatus status) {
std::vector<AutofillProfile> profiles;
for (AutofillProfile* profile : GetAllAutoFillProfiles(profile)) {
profiles.push_back(*profile);
if (profile->guid() == guid) {
profiles.back().SetRawInfo(type.GetStorableType(), value);
profiles.back().SetRawInfoWithVerificationStatus(type.GetStorableType(),
value, status);
}
}
autofill_helper::SetProfiles(profile, &profiles);
......
......@@ -13,6 +13,7 @@
#include "base/memory/ref_counted.h"
#include "base/strings/string16.h"
#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address_component.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -23,6 +24,7 @@ class AutofillProfile;
class AutofillType;
class CreditCard;
class PersonalDataManager;
} // namespace autofill
namespace autofill_helper {
......@@ -74,11 +76,14 @@ void AddProfile(int profile, const autofill::AutofillProfile& autofill_profile);
void RemoveProfile(int profile, const std::string& guid);
// Updates the autofill profile with guid |guid| in sync profile |profile|
// to |type| and |value|.
void UpdateProfile(int profile,
const std::string& guid,
const autofill::AutofillType& type,
const base::string16& value);
// to |type| and |value| with the verification status |status|.
void UpdateProfile(
int profile,
const std::string& guid,
const autofill::AutofillType& type,
const base::string16& value,
autofill::structured_address::VerificationStatus status =
autofill::structured_address::VerificationStatus::kObserved);
// Gets all the Autofill profiles in the PersonalDataManager of sync profile
// |profile|.
......
......@@ -16,14 +16,15 @@
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
using autofill::AutofillTable;
using autofill::AutofillProfile;
using autofill::AutofillTable;
using autofill::AutofillType;
using autofill::CreditCard;
using autofill::PersonalDataManager;
......@@ -33,11 +34,11 @@ using autofill_helper::CreateUniqueAutofillProfile;
using autofill_helper::GetAllAutoFillProfiles;
using autofill_helper::GetPersonalDataManager;
using autofill_helper::GetProfileCount;
using autofill_helper::ProfilesMatch;
using autofill_helper::PROFILE_FRASIER;
using autofill_helper::PROFILE_HOMER;
using autofill_helper::PROFILE_MARION;
using autofill_helper::PROFILE_NULL;
using autofill_helper::ProfilesMatch;
using autofill_helper::RemoveProfile;
using autofill_helper::SetCreditCards;
using autofill_helper::UpdateProfile;
......@@ -85,10 +86,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest,
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
// Client0 updates a profile.
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FIRST),
base::ASCIIToUTF16("Bart"));
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FIRST), base::ASCIIToUTF16("Bart"));
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
// Client1 removes remaining profile.
......@@ -339,6 +338,35 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, UpdateFields) {
autofill::EMAIL_ADDRESS)));
}
// Tests that modifying the verification status of a token in the profile will
// be propagated.
IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest,
UpdateVerificationStatus) {
// This test is only applicable for structured names.
if (!base::FeatureList::IsEnabled(
autofill::features::kAutofillEnableSupportForMoreStructureInNames)) {
return;
}
ASSERT_TRUE(SetupSync());
AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
ASSERT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
AutofillProfile* profile = GetAllAutoFillProfiles(0)[0];
ASSERT_TRUE(profile);
UpdateProfile(
0, profile->guid(), AutofillType(autofill::NAME_FIRST),
profile->GetRawInfo(autofill::NAME_FIRST),
autofill::structured_address::VerificationStatus::kUserVerified);
// Make sure the change is propagated to the other client.
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
EXPECT_EQ(autofill::structured_address::VerificationStatus::kUserVerified,
GetAllAutoFillProfiles(1)[0]->GetVerificationStatus(
autofill::NAME_FIRST));
}
// Tests that modifying a profile at the same time one two clients while
// syncing results in the both client having the same profile (doesn't matter
// which one).
......@@ -351,10 +379,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest,
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
// Update the same field differently on the two clients at the same time.
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FIRST),
base::ASCIIToUTF16("Lisa"));
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FIRST), base::ASCIIToUTF16("Lisa"));
UpdateProfile(1, GetAllAutoFillProfiles(1)[0]->guid(),
AutofillType(autofill::NAME_FIRST), base::ASCIIToUTF16("Bart"));
......@@ -445,18 +471,12 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, MaxLength) {
ASSERT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
base::string16 max_length_string(AutofillTable::kMaxDataLength, '.');
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FULL),
max_length_string);
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::EMAIL_ADDRESS),
max_length_string);
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::ADDRESS_HOME_LINE1),
max_length_string);
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FULL), max_length_string);
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::EMAIL_ADDRESS), max_length_string);
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::ADDRESS_HOME_LINE1), max_length_string);
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
}
......@@ -467,22 +487,16 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, ExceedsMaxLength) {
AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
ASSERT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
base::string16 exceeds_max_length_string(
AutofillTable::kMaxDataLength + 1, '.');
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FIRST),
exceeds_max_length_string);
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_LAST),
exceeds_max_length_string);
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
base::string16 exceeds_max_length_string(AutofillTable::kMaxDataLength + 1,
'.');
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_FIRST), exceeds_max_length_string);
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_LAST), exceeds_max_length_string);
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::EMAIL_ADDRESS),
exceeds_max_length_string);
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::ADDRESS_HOME_LINE1),
exceeds_max_length_string);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment