Commit b3873b4d authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

Fix flaky test ServerAddressConvertsToSameLocalAddress

Bug: 917498
Change-Id: I3eb7d91ae4ff95db1b55830b293a244515073cdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1642629
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666639}
parent 9b8477e7
......@@ -467,7 +467,7 @@ IN_PROC_BROWSER_TEST_P(
// Flaky. http://crbug.com/917498
IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest,
DISABLED_ServerAddressConvertsToSameLocalAddress) {
ServerAddressConvertsToSameLocalAddress) {
GetFakeServer()->SetWalletData(
{CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"),
CreateDefaultSyncPaymentsCustomerData()});
......
......@@ -275,7 +275,9 @@ base::Optional<syncer::ModelError> AutofillProfileSyncBridge::FlushSyncTracker(
base::Unretained(web_data_backend_))));
std::vector<std::unique_ptr<AutofillProfile>> profiles_to_upload_to_sync;
RETURN_IF_ERROR(tracker->FlushToSync(&profiles_to_upload_to_sync));
std::vector<std::string> profiles_to_delete_from_sync;
RETURN_IF_ERROR(tracker->FlushToSync(&profiles_to_upload_to_sync,
&profiles_to_delete_from_sync));
for (const std::unique_ptr<AutofillProfile>& entry :
profiles_to_upload_to_sync) {
change_processor()->Put(GetStorageKeyFromAutofillProfile(*entry),
......@@ -285,6 +287,9 @@ base::Optional<syncer::ModelError> AutofillProfileSyncBridge::FlushSyncTracker(
// TODO(crbug.com/904390): Remove when the investigation is over.
ReportAutofillProfileAddOrUpdateOrigin(origin);
}
for (const std::string& storage_key : profiles_to_delete_from_sync) {
change_processor()->Delete(storage_key, metadata_change_list.get());
}
return static_cast<syncer::SyncMetadataStoreChangeList*>(
metadata_change_list.get())
......
......@@ -71,30 +71,51 @@ AutofillProfileSyncDifferenceTracker::IncorporateRemoteProfile(
// Look for exact duplicates, compare only profile contents (and
// ignore origin and language code in comparison).
if (local.Compare(*remote) == 0) {
// We found a duplicate, we keep the new (remote) one and delete the
// local one.
// We found a duplicate. We keep the version with the bigger storage key.
DVLOG(2)
<< "[AUTOFILL SYNC] The profile "
<< base::UTF16ToUTF8(local.GetRawInfo(NAME_FIRST))
<< base::UTF16ToUTF8(local.GetRawInfo(NAME_LAST))
<< " already exists with a different storage key; keep the remote key"
<< remote_storage_key << " and delete the local key "
<< local_storage_key;
<< " already exists with a different storage key; keep the bigger key"
<< std::max(remote_storage_key, local_storage_key)
<< " and delete the smaller key "
<< std::min(remote_storage_key, local_storage_key);
if (remote_storage_key > local_storage_key) {
// We keep the remote entity and delete the local one.
// Ensure that a verified profile can never revert back to an unverified
// one. In such a case, take over the local origin for the new (remote)
// entry.
// one. In such a case, take over the old origin for the new entry.
if (local.IsVerified() && !remote->IsVerified()) {
remote->set_origin(local.origin());
// Save a copy of the remote profile also to sync.
save_to_sync_.push_back(std::make_unique<AutofillProfile>(*remote));
}
// Delete the local profile that gets replaced by |remote|.
add_to_local_.push_back(std::move(remote));
DeleteFromLocal(local_storage_key);
break;
} else {
// We keep the local entity and delete the remote one.
// Ensure that a verified profile can never revert back to an unverified
// one. In such a case, modify the origin and re-upload. Otherwise,
// there's no need to upload it: either is was already uploaded before
// (if this is incremental sync) or we'll upload it with all the
// remaining data in GetLocalOnlyEntries (if this is an initial sync).
if (remote->IsVerified() && !local.IsVerified()) {
auto modified_local = std::make_unique<AutofillProfile>(local);
modified_local->set_origin(remote->origin());
update_to_local_.push_back(
std::make_unique<AutofillProfile>(*modified_local));
save_to_sync_.push_back(std::move(modified_local));
// The local entity is already marked for upload so it is not local
// only anymore (we do not want to upload it once again while flushing
// if this is initial sync).
GetLocalOnlyEntries()->erase(local_storage_key);
}
delete_from_sync_.insert(remote_storage_key);
}
return base::nullopt;
}
}
// If no duplicate was found, just add the remote profile.
add_to_local_.push_back(std::move(remote));
return base::nullopt;
}
......@@ -132,10 +153,14 @@ Optional<ModelError> AutofillProfileSyncDifferenceTracker::FlushToLocal(
}
Optional<ModelError> AutofillProfileSyncDifferenceTracker::FlushToSync(
std::vector<std::unique_ptr<AutofillProfile>>* profiles_to_upload_to_sync) {
std::vector<std::unique_ptr<AutofillProfile>>* profiles_to_upload_to_sync,
std::vector<std::string>* profiles_to_delete_from_sync) {
for (std::unique_ptr<AutofillProfile>& entry : save_to_sync_) {
profiles_to_upload_to_sync->push_back(std::move(entry));
}
for (const std::string& entry : delete_from_sync_) {
profiles_to_delete_from_sync->push_back(std::move(entry));
}
return base::nullopt;
}
......@@ -200,9 +225,11 @@ AutofillProfileInitialSyncDifferenceTracker::IncorporateRemoteDelete(
}
Optional<ModelError> AutofillProfileInitialSyncDifferenceTracker::FlushToSync(
std::vector<std::unique_ptr<AutofillProfile>>* profiles_to_upload_to_sync) {
std::vector<std::unique_ptr<AutofillProfile>>* profiles_to_upload_to_sync,
std::vector<std::string>* profiles_to_delete_from_sync) {
// First, flush standard updates to sync.
AutofillProfileSyncDifferenceTracker::FlushToSync(profiles_to_upload_to_sync);
AutofillProfileSyncDifferenceTracker::FlushToSync(
profiles_to_upload_to_sync, profiles_to_delete_from_sync);
// For initial sync, we additionally need to upload all local only entries.
if (!GetLocalOnlyEntries()) {
......
......@@ -50,11 +50,12 @@ class AutofillProfileSyncDifferenceTracker {
base::OnceClosure autofill_changes_callback);
// Writes into |profiles_to_upload_to_sync| all autofill profiles to be sent
// to the sync server. After flushing, not further remote changes should get
// incorporated.
// to the sync server, and into |profiles_to_delete_from_sync| the storage
// keys of all profiles to be deleted from the server. After flushing, no
// further remote changes should get incorporated.
virtual base::Optional<syncer::ModelError> FlushToSync(
std::vector<std::unique_ptr<AutofillProfile>>*
profiles_to_upload_to_sync);
std::vector<std::unique_ptr<AutofillProfile>>* profiles_to_upload_to_sync,
std::vector<std::string>* profiles_to_delete_from_sync);
protected:
// If the entry is found, |entry| will be return, otherwise base::nullopt is
......@@ -98,9 +99,13 @@ class AutofillProfileSyncDifferenceTracker {
std::vector<std::unique_ptr<AutofillProfile>> add_to_local_;
std::vector<std::unique_ptr<AutofillProfile>> update_to_local_;
// Contains merged data for entries that existed on both sync and local sides
// Contains data for entries that existed on both sync and local sides
// and need to be saved back to sync.
std::vector<std::unique_ptr<AutofillProfile>> save_to_sync_;
// Contains data for entries that existed on both sync and local
// sides and need to be deleted from sync (because the conflict resolution
// preferred the local copies).
std::set<std::string> delete_from_sync_;
private:
DISALLOW_COPY_AND_ASSIGN(AutofillProfileSyncDifferenceTracker);
......@@ -116,8 +121,8 @@ class AutofillProfileInitialSyncDifferenceTracker
const std::string& storage_key) override;
base::Optional<syncer::ModelError> FlushToSync(
std::vector<std::unique_ptr<AutofillProfile>>* profiles_to_upload_to_sync)
override;
std::vector<std::unique_ptr<AutofillProfile>>* profiles_to_upload_to_sync,
std::vector<std::string>* profiles_to_delete_from_sync) override;
// Performs an additional pass through remote entries incorporated from sync
// to find any similarities with local entries. Should be run after all
......
......@@ -30,13 +30,18 @@ using testing::ElementsAre;
using testing::IsEmpty;
// Some guids for testing.
const char kGuidA[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44A";
const char kGuidB[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
const char kSmallerGuid[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44A";
const char kBiggerGuid[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
const char kHttpOrigin[] = "http://www.example.com/";
const char kHttpsOrigin[] = "https://www.example.com/";
const char kLocaleString[] = "en-US";
const base::Time kJune2017 = base::Time::FromDoubleT(1497552271);
struct UpdatesToSync {
std::vector<AutofillProfile> profiles_to_upload_to_sync;
std::vector<std::string> profiles_to_delete_from_sync;
};
} // namespace
class AutofillProfileSyncDifferenceTrackerTestBase : public testing::Test {
......@@ -65,24 +70,26 @@ class AutofillProfileSyncDifferenceTrackerTestBase : public testing::Test {
std::make_unique<AutofillProfile>(profile)));
}
std::vector<AutofillProfile> FlushAndReturnProfilesToUploadToSync() {
UpdatesToSync FlushToSync() {
EXPECT_EQ(base::nullopt,
tracker()->FlushToLocal(
/*autofill_changes_callback=*/base::DoNothing()));
UpdatesToSync updates;
std::vector<std::unique_ptr<AutofillProfile>> vector_of_unique_ptrs;
EXPECT_EQ(base::nullopt,
tracker()->FlushToSync(
/*profiles_to_upload_to_sync=*/&vector_of_unique_ptrs));
/*profiles_to_upload_to_sync=*/&vector_of_unique_ptrs,
/*profiles_to_delete_from_sync=*/&updates
.profiles_to_delete_from_sync));
// Copy all the elements by value so that we have a vector that is easier to
// work with in the test.
std::vector<AutofillProfile> vector_of_values;
for (const std::unique_ptr<AutofillProfile>& entry :
vector_of_unique_ptrs) {
vector_of_values.push_back(*entry);
updates.profiles_to_upload_to_sync.push_back(*entry);
}
return vector_of_values;
return updates;
}
std::vector<AutofillProfile> GetAllLocalData() {
......@@ -130,63 +137,69 @@ class AutofillProfileSyncDifferenceTrackerTest
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldOverwriteProfileWithSameKey) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpOrigin);
local.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
AddAutofillProfilesToTable({local});
// The remote profile is completely different but it has the same key.
AutofillProfile remote = AutofillProfile(kGuidA, kHttpsOrigin);
AutofillProfile remote = AutofillProfile(kSmallerGuid, kHttpsOrigin);
remote.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom"));
IncorporateRemoteProfile(remote);
// Nothing gets uploaded to sync and the remote profile wins.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), IsEmpty());
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, IsEmpty());
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(remote));
}
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldOverwriteUnverifiedProfileByVerified) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpsOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpsOrigin);
local.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
AddAutofillProfilesToTable({local});
// The remote profile has the same key but it is not verified.
AutofillProfile remote = AutofillProfile(kGuidA, kSettingsOrigin);
AutofillProfile remote = AutofillProfile(kSmallerGuid, kSettingsOrigin);
remote.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom"));
IncorporateRemoteProfile(remote);
// Nothing gets uploaded to sync and the local profile wins.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), IsEmpty());
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, IsEmpty());
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(remote));
}
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldNotOverwriteVerifiedProfileByUnverified) {
AutofillProfile local = AutofillProfile(kGuidA, kSettingsOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kSettingsOrigin);
local.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
AddAutofillProfilesToTable({local});
// The remote profile has the same key but it is not verified.
AutofillProfile remote = AutofillProfile(kGuidA, kHttpsOrigin);
AutofillProfile remote = AutofillProfile(kSmallerGuid, kHttpsOrigin);
remote.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom"));
IncorporateRemoteProfile(remote);
// Nothing gets uploaded to sync and the local profile wins.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), IsEmpty());
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, IsEmpty());
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(local));
}
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldNotOverwriteFullNameByEmptyString) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpOrigin);
local.SetRawInfo(NAME_FULL, ASCIIToUTF16("John"));
AddAutofillProfilesToTable({local});
// The remote profile has the same key.
AutofillProfile remote = AutofillProfile(kGuidA, kHttpsOrigin);
AutofillProfile remote = AutofillProfile(kSmallerGuid, kHttpsOrigin);
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("2 2st st"));
AutofillProfile merged(remote);
......@@ -196,40 +209,45 @@ TEST_F(AutofillProfileSyncDifferenceTrackerTest,
// Nothing gets uploaded to sync and the remote profile wins except for the
// full name.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), IsEmpty());
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, IsEmpty());
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(merged));
}
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldMergeIdenticalProfilesWithDifferentKeys) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpOrigin);
TEST_F(
AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldKeepRemoteKeyWhenMergingDuplicateProfileWithBiggerKey) {
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpOrigin);
local.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
AddAutofillProfilesToTable({local});
// The remote profile is identical to the local one, except that the guids and
// origins are different.
AutofillProfile remote = AutofillProfile(kGuidB, kHttpsOrigin);
AutofillProfile remote = AutofillProfile(kBiggerGuid, kHttpsOrigin);
remote.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
IncorporateRemoteProfile(remote);
// Nothing gets uploaded to sync and the remote profile wins.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), IsEmpty());
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, IsEmpty());
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(remote));
}
TEST_F(
AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldMergeIdenticalProfilesWithDifferentKeysButKeepVerifiedOrigin) {
AutofillProfile local = AutofillProfile(kGuidA, kSettingsOrigin);
IncorporateRemoteProfileShouldKeepRemoteKeyAndLocalOriginWhenMergingDuplicateProfileWithBiggerKey) {
AutofillProfile local = AutofillProfile(kSmallerGuid, kSettingsOrigin);
local.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
AddAutofillProfilesToTable({local});
// The remote profile has the same key.
AutofillProfile remote = AutofillProfile(kGuidB, kHttpsOrigin);
AutofillProfile remote = AutofillProfile(kBiggerGuid, kHttpsOrigin);
remote.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
......@@ -240,7 +258,60 @@ TEST_F(
// Nothing gets uploaded to sync and the remote profile wins except for the
// full name.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), ElementsAre(merged));
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, ElementsAre(merged));
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(merged));
}
TEST_F(
AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldKeepLocalKeyWhenMergingDuplicateProfileWithSmallerKey) {
AutofillProfile local = AutofillProfile(kBiggerGuid, kHttpOrigin);
local.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
AddAutofillProfilesToTable({local});
// The remote profile is identical to the local one, except that the guids and
// origins are different.
AutofillProfile remote = AutofillProfile(kSmallerGuid, kHttpsOrigin);
remote.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
IncorporateRemoteProfile(remote);
// Nothing gets uploaded to sync and the remote profile wins.
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, IsEmpty());
EXPECT_THAT(updates.profiles_to_delete_from_sync,
ElementsAre(std::string(kSmallerGuid)));
EXPECT_THAT(GetAllLocalData(), ElementsAre(local));
}
TEST_F(
AutofillProfileSyncDifferenceTrackerTest,
IncorporateRemoteProfileShouldKeepLocalKeyAndRemoteOriginWhenMergingDuplicateProfileWithSmallerKey) {
AutofillProfile local = AutofillProfile(kBiggerGuid, kHttpsOrigin);
local.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
AddAutofillProfilesToTable({local});
// The remote profile has the same key.
AutofillProfile remote = AutofillProfile(kSmallerGuid, kSettingsOrigin);
remote.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
AutofillProfile merged(local);
merged.set_origin(kSettingsOrigin);
IncorporateRemoteProfile(remote);
// Nothing gets uploaded to sync and the remote profile wins except for the
// full name.
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, ElementsAre(merged));
EXPECT_THAT(updates.profiles_to_delete_from_sync,
ElementsAre(std::string(kSmallerGuid)));
EXPECT_THAT(GetAllLocalData(), ElementsAre(merged));
}
......@@ -255,10 +326,10 @@ TEST_F(AutofillProfileSyncDifferenceTrackerTest,
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
FlushToLocalShouldCallbackWhenProfileDeleted) {
AutofillProfile local = AutofillProfile(kGuidA, kSettingsOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kSettingsOrigin);
AddAutofillProfilesToTable({local});
tracker()->IncorporateRemoteDelete(kGuidA);
tracker()->IncorporateRemoteDelete(kSmallerGuid);
MockCallback<base::OnceClosure> autofill_changes_callback;
EXPECT_CALL(autofill_changes_callback, Run()).Times(1);
......@@ -271,7 +342,7 @@ TEST_F(AutofillProfileSyncDifferenceTrackerTest,
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
FlushToLocalShouldCallbackWhenProfileAdded) {
AutofillProfile remote = AutofillProfile(kGuidA, kSettingsOrigin);
AutofillProfile remote = AutofillProfile(kSmallerGuid, kSettingsOrigin);
IncorporateRemoteProfile(remote);
MockCallback<base::OnceClosure> autofill_changes_callback;
......@@ -285,10 +356,10 @@ TEST_F(AutofillProfileSyncDifferenceTrackerTest,
TEST_F(AutofillProfileSyncDifferenceTrackerTest,
FlushToLocalShouldCallbackWhenProfileUpdated) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpsOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpsOrigin);
AddAutofillProfilesToTable({local});
AutofillProfile remote = AutofillProfile(kGuidA, kHttpsOrigin);
AutofillProfile remote = AutofillProfile(kSmallerGuid, kHttpsOrigin);
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
IncorporateRemoteProfile(remote);
......@@ -297,7 +368,7 @@ TEST_F(AutofillProfileSyncDifferenceTrackerTest,
EXPECT_EQ(base::nullopt,
tracker()->FlushToLocal(autofill_changes_callback.Get()));
// On top of that, the profile with key kGuidA should also get updated.
// On top of that, the profile with key kSmallerGuid should also get updated.
EXPECT_THAT(GetAllLocalData(), ElementsAre(remote));
}
......@@ -324,13 +395,13 @@ class AutofillProfileInitialSyncDifferenceTrackerTest
TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
MergeSimilarEntriesForInitialSyncShouldSyncUpChanges) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpOrigin);
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
local.set_use_count(27);
AddAutofillProfilesToTable({local});
// The remote profile matches the local one (except for origin and use count).
AutofillProfile remote = AutofillProfile(kGuidB, kHttpsOrigin);
AutofillProfile remote = AutofillProfile(kBiggerGuid, kHttpsOrigin);
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
remote.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc."));
remote.set_use_count(13);
......@@ -346,19 +417,21 @@ TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
MergeSimilarEntriesForInitialSync();
// The merged profile needs to get uploaded back to sync and stored locally.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), ElementsAre(merged));
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, ElementsAre(merged));
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(merged));
}
TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
MergeSimilarEntriesForInitialSyncShouldNotSyncUpWhenNotNeeded) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpOrigin);
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
local.set_use_count(13);
AddAutofillProfilesToTable({local});
// The remote profile matches the local one and has some additional data.
AutofillProfile remote = AutofillProfile(kGuidB, kHttpOrigin);
AutofillProfile remote = AutofillProfile(kBiggerGuid, kHttpOrigin);
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
remote.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc."));
// Merging two profile takes their max use count, so use count of 27 is taken.
......@@ -368,19 +441,21 @@ TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
MergeSimilarEntriesForInitialSync();
// Nothing gets uploaded to sync and the remote profile wins.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), IsEmpty());
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, IsEmpty());
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(remote));
}
TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
MergeSimilarEntriesForInitialSyncNotMatchNonsimilarEntries) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpOrigin);
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
local.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc."));
AddAutofillProfilesToTable({local});
// The remote profile has a different street address.
AutofillProfile remote = AutofillProfile(kGuidB, kHttpOrigin);
AutofillProfile remote = AutofillProfile(kBiggerGuid, kHttpOrigin);
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("2 2st st"));
remote.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc."));
......@@ -389,19 +464,21 @@ TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
// The local profile gets uploaded (due to initial sync) and the remote
// profile gets stored locally.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), ElementsAre(local));
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, ElementsAre(local));
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(local, remote));
}
TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
MergeSimilarEntriesForInitialSyncDoesNotMatchLocalVerifiedEntry) {
// The local entry is verified, should not get merged.
AutofillProfile local = AutofillProfile(kGuidA, kSettingsOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kSettingsOrigin);
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
AddAutofillProfilesToTable({local});
// The remote profile is similar to the local one.
AutofillProfile remote = AutofillProfile(kGuidB, kHttpOrigin);
AutofillProfile remote = AutofillProfile(kBiggerGuid, kHttpOrigin);
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
remote.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc."));
......@@ -410,19 +487,21 @@ TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
// The local profile gets uploaded (due to initial sync) and the remote
// profile gets stored locally.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), ElementsAre(local));
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, ElementsAre(local));
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(local, remote));
}
TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
MergeSimilarEntriesForInitialSyncDoesNotMatchRemoteVerifiedEntry) {
AutofillProfile local = AutofillProfile(kGuidA, kHttpOrigin);
AutofillProfile local = AutofillProfile(kSmallerGuid, kHttpOrigin);
local.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
AddAutofillProfilesToTable({local});
// The remote profile is similar to the local one but is verified and thus it
// should not get merged.
AutofillProfile remote = AutofillProfile(kGuidB, kSettingsOrigin);
AutofillProfile remote = AutofillProfile(kBiggerGuid, kSettingsOrigin);
remote.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("1 1st st"));
remote.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc."));
......@@ -431,7 +510,9 @@ TEST_F(AutofillProfileInitialSyncDifferenceTrackerTest,
// The local profile gets uploaded (due to initial sync) and the remote
// profile gets stored locally.
EXPECT_THAT(FlushAndReturnProfilesToUploadToSync(), ElementsAre(local));
UpdatesToSync updates = FlushToSync();
EXPECT_THAT(updates.profiles_to_upload_to_sync, ElementsAre(local));
EXPECT_THAT(updates.profiles_to_delete_from_sync, IsEmpty());
EXPECT_THAT(GetAllLocalData(), ElementsAre(local, remote));
}
......
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