Commit e48682d8 authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[Autofill sync] Wait for converging on a specific number of profiles

This CL makes the integration tests more robust by waiting for a
pre-specified number of entities. This is a speculative fix for the
referred bug / a further step in understanding the actual root cause.

Bug: 997629
Change-Id: I74a3e7c0d2dba9a3d63664887c4d5d3e3b4b25c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2022712
Commit-Queue: Marc Treib <treib@chromium.org>
Auto-Submit: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735796}
parent ff2bf066
......@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/guid.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
......@@ -115,10 +116,18 @@ std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) {
}
bool ProfilesMatchImpl(
const base::Optional<unsigned int>& expected_count,
int profile_a,
const std::vector<AutofillProfile*>& autofill_profiles_a,
int profile_b,
const std::vector<AutofillProfile*>& autofill_profiles_b) {
if (expected_count.has_value() &&
autofill_profiles_a.size() != *expected_count) {
DVLOG(1) << "Profile " << profile_a
<< " does not have expected count of entities " << *expected_count;
return false;
}
std::map<std::string, AutofillProfile> autofill_profiles_a_map;
for (AutofillProfile* p : autofill_profiles_a) {
autofill_profiles_a_map[p->guid()] = *p;
......@@ -372,8 +381,8 @@ bool ProfilesMatch(int profile_a, int profile_b) {
GetAllAutoFillProfiles(profile_a);
const std::vector<AutofillProfile*>& autofill_profiles_b =
GetAllAutoFillProfiles(profile_b);
return ProfilesMatchImpl(
profile_a, autofill_profiles_a, profile_b, autofill_profiles_b);
return ProfilesMatchImpl(base::nullopt, profile_a, autofill_profiles_a,
profile_b, autofill_profiles_b);
}
} // namespace autofill_helper
......@@ -389,8 +398,13 @@ bool AutofillKeysChecker::IsExitConditionSatisfied(std::ostream* os) {
return autofill_helper::KeysMatch(profile_a_, profile_b_);
}
AutofillProfileChecker::AutofillProfileChecker(int profile_a, int profile_b)
: profile_a_(profile_a), profile_b_(profile_b) {
AutofillProfileChecker::AutofillProfileChecker(
int profile_a,
int profile_b,
base::Optional<unsigned int> expected_count)
: profile_a_(profile_a),
profile_b_(profile_b),
expected_count_(expected_count) {
autofill_helper::GetPersonalDataManager(profile_a_)->AddObserver(this);
autofill_helper::GetPersonalDataManager(profile_b_)->AddObserver(this);
}
......@@ -442,8 +456,8 @@ bool AutofillProfileChecker::IsExitConditionSatisfied(std::ostream* os) {
autofill_helper::GetPersonalDataManager(profile_a_)->GetProfiles();
const std::vector<AutofillProfile*>& autofill_profiles_b =
autofill_helper::GetPersonalDataManager(profile_b_)->GetProfiles();
return ProfilesMatchImpl(profile_a_, autofill_profiles_a, profile_b_,
autofill_profiles_b);
return ProfilesMatchImpl(expected_count_, profile_a_, autofill_profiles_a,
profile_b_, autofill_profiles_b);
}
void AutofillProfileChecker::OnPersonalDataChanged() {
......
......@@ -121,7 +121,9 @@ class AutofillKeysChecker : public MultiClientStatusChangeChecker {
class AutofillProfileChecker : public StatusChangeChecker,
public autofill::PersonalDataManagerObserver {
public:
AutofillProfileChecker(int profile_a, int profile_b);
AutofillProfileChecker(int profile_a,
int profile_b,
base::Optional<unsigned int> expected_count);
~AutofillProfileChecker() override;
// StatusChangeChecker implementation.
......@@ -134,6 +136,7 @@ class AutofillProfileChecker : public StatusChangeChecker,
private:
const int profile_a_;
const int profile_b_;
const base::Optional<unsigned int> expected_count_;
};
class PersonalDataLoadedObserverMock
......
......@@ -474,7 +474,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientWalletSyncTest,
// On top of expecting convergence on AutofillWalletChecker, expect
// convergence on wallet metadata and on autofill profiles.
EXPECT_TRUE(AutofillWalletMetadataSizeChecker(0, 1).Wait());
EXPECT_TRUE(AutofillProfileChecker(0, 1).Wait());
EXPECT_TRUE(AutofillProfileChecker(0, 1, /*expected_count=*/1U).Wait());
// Make sure both have has_converted true.
std::vector<AutofillProfile*> server_addresses = GetServerProfiles(0);
......
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