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) { ...@@ -56,8 +56,7 @@ ACTION_P(SignalEvent, event) {
class MockWebDataServiceObserver class MockWebDataServiceObserver
: public AutofillWebDataServiceObserverOnDBSequence { : public AutofillWebDataServiceObserverOnDBSequence {
public: public:
MOCK_METHOD1(AutofillEntriesChanged, MOCK_METHOD1(AutofillEntriesChanged, void(const AutofillChangeList& changes));
void(const AutofillChangeList& changes));
}; };
scoped_refptr<AutofillWebDataService> GetWebDataService(int index) { scoped_refptr<AutofillWebDataService> GetWebDataService(int index) {
...@@ -102,8 +101,8 @@ void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) { ...@@ -102,8 +101,8 @@ void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) {
void GetAllAutofillEntriesOnDBSequence(AutofillWebDataService* wds, void GetAllAutofillEntriesOnDBSequence(AutofillWebDataService* wds,
std::vector<AutofillEntry>* entries) { std::vector<AutofillEntry>* entries) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence()); DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase( AutofillTable::FromWebDatabase(wds->GetDatabase())
wds->GetDatabase())->GetAllAutofillEntries(entries); ->GetAllAutofillEntries(entries);
} }
std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) { std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) {
...@@ -177,45 +176,40 @@ AutofillProfile CreateAutofillProfile(ProfileType type) { ...@@ -177,45 +176,40 @@ AutofillProfile CreateAutofillProfile(ProfileType type) {
AutofillProfile profile; AutofillProfile profile;
switch (type) { switch (type) {
case PROFILE_MARION: case PROFILE_MARION:
autofill::test::SetProfileInfoWithGuid(&profile, autofill::test::SetProfileInfoWithGuid(
"C837507A-6C3B-4872-AC14-5113F157D668", &profile, "C837507A-6C3B-4872-AC14-5113F157D668", "Marion",
"Marion", "Mitchell", "Morrison", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.",
"johnwayne@me.xyz", "Fox", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
"123 Zoo St.", "unit 5", "Hollywood", "CA",
"91601", "US", "12345678910");
break; break;
case PROFILE_HOMER: case PROFILE_HOMER:
autofill::test::SetProfileInfoWithGuid(&profile, autofill::test::SetProfileInfoWithGuid(
"137DE1C3-6A30-4571-AC86-109B1ECFBE7F", &profile, "137DE1C3-6A30-4571-AC86-109B1ECFBE7F", "Homer", "J.",
"Homer", "J.", "Simpson", "Simpson", "homer@abc.com", "SNPP", "742 Evergreen Terrace",
"homer@abc.com", "SNPP", "PO Box 1", "Springfield", "MA", "94101", "US", "14155551212");
"742 Evergreen Terrace", "PO Box 1", "Springfield", "MA",
"94101", "US", "14155551212");
break; break;
case PROFILE_FRASIER: case PROFILE_FRASIER:
autofill::test::SetProfileInfoWithGuid(&profile, autofill::test::SetProfileInfoWithGuid(
"9A5E6872-6198-4688-BF75-0016E781BB0A", &profile, "9A5E6872-6198-4688-BF75-0016E781BB0A", "Frasier",
"Frasier", "Winslow", "Crane", "Winslow", "Crane", "", "randomness", "", "Apt. 4", "Seattle", "WA",
"", "randomness", "", "Apt. 4", "Seattle", "WA",
"99121", "US", "0000000000"); "99121", "US", "0000000000");
break; break;
case PROFILE_NULL: case PROFILE_NULL:
autofill::test::SetProfileInfoWithGuid(&profile, autofill::test::SetProfileInfoWithGuid(
"FE461507-7E13-4198-8E66-74C7DB6D8322", &profile, "FE461507-7E13-4198-8E66-74C7DB6D8322", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", ""); "", "", "", "", "", "", "");
break; break;
} }
profile.FinalizeAfterImport();
return profile; return profile;
} }
AutofillProfile CreateUniqueAutofillProfile() { AutofillProfile CreateUniqueAutofillProfile() {
AutofillProfile profile; AutofillProfile profile;
autofill::test::SetProfileInfoWithGuid(&profile, autofill::test::SetProfileInfoWithGuid(
base::GenerateGUID().c_str(), &profile, base::GenerateGUID().c_str(), "First", "Middle", "Last",
"First", "Middle", "Last", "email@domain.tld", "Company", "123 Main St", "Apt 456", "Nowhere", "OK",
"email@domain.tld", "Company",
"123 Main St", "Apt 456", "Nowhere", "OK",
"73038", "US", "12345678910"); "73038", "US", "12345678910");
profile.FinalizeAfterImport();
return profile; return profile;
} }
...@@ -327,12 +321,14 @@ void RemoveProfile(int profile, const std::string& guid) { ...@@ -327,12 +321,14 @@ void RemoveProfile(int profile, const std::string& guid) {
void UpdateProfile(int profile, void UpdateProfile(int profile,
const std::string& guid, const std::string& guid,
const AutofillType& type, const AutofillType& type,
const base::string16& value) { const base::string16& value,
autofill::structured_address::VerificationStatus status) {
std::vector<AutofillProfile> profiles; std::vector<AutofillProfile> profiles;
for (AutofillProfile* profile : GetAllAutoFillProfiles(profile)) { for (AutofillProfile* profile : GetAllAutoFillProfiles(profile)) {
profiles.push_back(*profile); profiles.push_back(*profile);
if (profile->guid() == guid) { if (profile->guid() == guid) {
profiles.back().SetRawInfo(type.GetStorableType(), value); profiles.back().SetRawInfoWithVerificationStatus(type.GetStorableType(),
value, status);
} }
} }
autofill_helper::SetProfiles(profile, &profiles); autofill_helper::SetProfiles(profile, &profiles);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.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 "components/autofill/core/browser/personal_data_manager_observer.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -23,6 +24,7 @@ class AutofillProfile; ...@@ -23,6 +24,7 @@ class AutofillProfile;
class AutofillType; class AutofillType;
class CreditCard; class CreditCard;
class PersonalDataManager; class PersonalDataManager;
} // namespace autofill } // namespace autofill
namespace autofill_helper { namespace autofill_helper {
...@@ -74,11 +76,14 @@ void AddProfile(int profile, const autofill::AutofillProfile& autofill_profile); ...@@ -74,11 +76,14 @@ void AddProfile(int profile, const autofill::AutofillProfile& autofill_profile);
void RemoveProfile(int profile, const std::string& guid); void RemoveProfile(int profile, const std::string& guid);
// Updates the autofill profile with guid |guid| in sync profile |profile| // Updates the autofill profile with guid |guid| in sync profile |profile|
// to |type| and |value|. // to |type| and |value| with the verification status |status|.
void UpdateProfile(int profile, void UpdateProfile(
const std::string& guid, int profile,
const autofill::AutofillType& type, const std::string& guid,
const base::string16& value); 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 // Gets all the Autofill profiles in the PersonalDataManager of sync profile
// |profile|. // |profile|.
......
...@@ -16,14 +16,15 @@ ...@@ -16,14 +16,15 @@
#include "components/autofill/core/browser/data_model/credit_card.h" #include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_table.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 "components/sync/driver/sync_driver_switches.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
using autofill::AutofillTable;
using autofill::AutofillProfile; using autofill::AutofillProfile;
using autofill::AutofillTable;
using autofill::AutofillType; using autofill::AutofillType;
using autofill::CreditCard; using autofill::CreditCard;
using autofill::PersonalDataManager; using autofill::PersonalDataManager;
...@@ -33,11 +34,11 @@ using autofill_helper::CreateUniqueAutofillProfile; ...@@ -33,11 +34,11 @@ using autofill_helper::CreateUniqueAutofillProfile;
using autofill_helper::GetAllAutoFillProfiles; using autofill_helper::GetAllAutoFillProfiles;
using autofill_helper::GetPersonalDataManager; using autofill_helper::GetPersonalDataManager;
using autofill_helper::GetProfileCount; using autofill_helper::GetProfileCount;
using autofill_helper::ProfilesMatch;
using autofill_helper::PROFILE_FRASIER; using autofill_helper::PROFILE_FRASIER;
using autofill_helper::PROFILE_HOMER; using autofill_helper::PROFILE_HOMER;
using autofill_helper::PROFILE_MARION; using autofill_helper::PROFILE_MARION;
using autofill_helper::PROFILE_NULL; using autofill_helper::PROFILE_NULL;
using autofill_helper::ProfilesMatch;
using autofill_helper::RemoveProfile; using autofill_helper::RemoveProfile;
using autofill_helper::SetCreditCards; using autofill_helper::SetCreditCards;
using autofill_helper::UpdateProfile; using autofill_helper::UpdateProfile;
...@@ -85,10 +86,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, ...@@ -85,10 +86,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest,
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait()); EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
// Client0 updates a profile. // Client0 updates a profile.
UpdateProfile(0, UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
GetAllAutoFillProfiles(0)[0]->guid(), AutofillType(autofill::NAME_FIRST), base::ASCIIToUTF16("Bart"));
AutofillType(autofill::NAME_FIRST),
base::ASCIIToUTF16("Bart"));
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait()); EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
// Client1 removes remaining profile. // Client1 removes remaining profile.
...@@ -339,6 +338,35 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, UpdateFields) { ...@@ -339,6 +338,35 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, UpdateFields) {
autofill::EMAIL_ADDRESS))); 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 // 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 // syncing results in the both client having the same profile (doesn't matter
// which one). // which one).
...@@ -351,10 +379,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, ...@@ -351,10 +379,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest,
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait()); EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
// Update the same field differently on the two clients at the same time. // Update the same field differently on the two clients at the same time.
UpdateProfile(0, UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
GetAllAutoFillProfiles(0)[0]->guid(), AutofillType(autofill::NAME_FIRST), base::ASCIIToUTF16("Lisa"));
AutofillType(autofill::NAME_FIRST),
base::ASCIIToUTF16("Lisa"));
UpdateProfile(1, GetAllAutoFillProfiles(1)[0]->guid(), UpdateProfile(1, GetAllAutoFillProfiles(1)[0]->guid(),
AutofillType(autofill::NAME_FIRST), base::ASCIIToUTF16("Bart")); AutofillType(autofill::NAME_FIRST), base::ASCIIToUTF16("Bart"));
...@@ -445,18 +471,12 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, MaxLength) { ...@@ -445,18 +471,12 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, MaxLength) {
ASSERT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait()); ASSERT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
base::string16 max_length_string(AutofillTable::kMaxDataLength, '.'); base::string16 max_length_string(AutofillTable::kMaxDataLength, '.');
UpdateProfile(0, UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
GetAllAutoFillProfiles(0)[0]->guid(), AutofillType(autofill::NAME_FULL), max_length_string);
AutofillType(autofill::NAME_FULL), UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
max_length_string); AutofillType(autofill::EMAIL_ADDRESS), max_length_string);
UpdateProfile(0, UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
GetAllAutoFillProfiles(0)[0]->guid(), AutofillType(autofill::ADDRESS_HOME_LINE1), max_length_string);
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()); EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
} }
...@@ -467,22 +487,16 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, ExceedsMaxLength) { ...@@ -467,22 +487,16 @@ IN_PROC_BROWSER_TEST_F(TwoClientAutofillProfileSyncTest, ExceedsMaxLength) {
AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
ASSERT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait()); ASSERT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
base::string16 exceeds_max_length_string( base::string16 exceeds_max_length_string(AutofillTable::kMaxDataLength + 1,
AutofillTable::kMaxDataLength + 1, '.'); '.');
UpdateProfile(0, UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
GetAllAutoFillProfiles(0)[0]->guid(), AutofillType(autofill::NAME_FIRST), exceeds_max_length_string);
AutofillType(autofill::NAME_FIRST), UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
exceeds_max_length_string); AutofillType(autofill::NAME_LAST), exceeds_max_length_string);
UpdateProfile(0, UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::NAME_LAST),
exceeds_max_length_string);
UpdateProfile(0,
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::EMAIL_ADDRESS), AutofillType(autofill::EMAIL_ADDRESS),
exceeds_max_length_string); exceeds_max_length_string);
UpdateProfile(0, UpdateProfile(0, GetAllAutoFillProfiles(0)[0]->guid(),
GetAllAutoFillProfiles(0)[0]->guid(),
AutofillType(autofill::ADDRESS_HOME_LINE1), AutofillType(autofill::ADDRESS_HOME_LINE1),
exceeds_max_length_string); 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