Chromium Code Reviews| Index: chrome/browser/sync/test/integration/autofill_helper.cc |
| diff --git a/chrome/browser/sync/test/integration/autofill_helper.cc b/chrome/browser/sync/test/integration/autofill_helper.cc |
| index f88a9e7d5604f7c5c0cc2f6b509ad3162406ef2e..f99fda3dd6ddf39e38926975f2195a15ef2d2246 100644 |
| --- a/chrome/browser/sync/test/integration/autofill_helper.cc |
| +++ b/chrome/browser/sync/test/integration/autofill_helper.cc |
| @@ -6,13 +6,14 @@ |
| #include <stddef.h> |
| +#include <map> |
| + |
| #include "base/guid.h" |
| #include "base/run_loop.h" |
| #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sync/profile_sync_test_util.h" |
| -#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h" |
| #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| #include "chrome/browser/sync/test/integration/sync_test.h" |
| #include "chrome/browser/web_data_service_factory.h" |
| @@ -20,7 +21,6 @@ |
| #include "components/autofill/core/browser/autofill_test_utils.h" |
| #include "components/autofill/core/browser/autofill_type.h" |
| #include "components/autofill/core/browser/personal_data_manager.h" |
| -#include "components/autofill/core/browser/personal_data_manager_observer.h" |
| #include "components/autofill/core/browser/webdata/autofill_entry.h" |
| #include "components/autofill/core/browser/webdata/autofill_table.h" |
| #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| @@ -255,47 +255,6 @@ bool KeysMatch(int profile_a, int profile_b) { |
| return GetAllKeys(profile_a) == GetAllKeys(profile_b); |
| } |
| -namespace { |
| - |
| -class KeysMatchStatusChecker : public MultiClientStatusChangeChecker { |
| - public: |
| - KeysMatchStatusChecker(int profile_a, int profile_b); |
| - ~KeysMatchStatusChecker() override; |
| - |
| - bool IsExitConditionSatisfied() override; |
| - std::string GetDebugMessage() const override; |
| - |
| - private: |
| - const int profile_a_; |
| - const int profile_b_; |
| -}; |
| - |
| -KeysMatchStatusChecker::KeysMatchStatusChecker(int profile_a, int profile_b) |
| - : MultiClientStatusChangeChecker( |
| - sync_datatype_helper::test()->GetSyncServices()), |
| - profile_a_(profile_a), |
| - profile_b_(profile_b) { |
| -} |
| - |
| -KeysMatchStatusChecker::~KeysMatchStatusChecker() { |
| -} |
| - |
| -bool KeysMatchStatusChecker::IsExitConditionSatisfied() { |
| - return KeysMatch(profile_a_, profile_b_); |
| -} |
| - |
| -std::string KeysMatchStatusChecker::GetDebugMessage() const { |
| - return "Waiting for matching autofill keys"; |
| -} |
| - |
| -} // namespace |
| - |
| -bool AwaitKeysMatch(int a, int b) { |
| - KeysMatchStatusChecker checker(a, b); |
| - checker.Wait(); |
| - return !checker.TimedOut(); |
| -} |
| - |
| void SetProfiles(int profile, std::vector<AutofillProfile>* autofill_profiles) { |
| MockPersonalDataManagerObserver observer; |
| EXPECT_CALL(observer, OnPersonalDataChanged()). |
| @@ -434,86 +393,67 @@ bool AllProfilesMatch() { |
| return true; |
| } |
| -namespace { |
| +} // namespace autofill_helper |
| -class ProfilesMatchStatusChecker : public StatusChangeChecker, |
| - public PersonalDataManagerObserver { |
| - public: |
| - ProfilesMatchStatusChecker(int profile_a, int profile_b); |
| - ~ProfilesMatchStatusChecker() override; |
| +AutofillKeysChecker::AutofillKeysChecker(int profile_a, int profile_b) |
| + : MultiClientStatusChangeChecker( |
| + sync_datatype_helper::test()->GetSyncServices()), |
| + profile_a_(profile_a), |
| + profile_b_(profile_b) {} |
| - // StatusChangeChecker implementation. |
| - bool IsExitConditionSatisfied() override; |
| - std::string GetDebugMessage() const override; |
| +bool AutofillKeysChecker::IsExitConditionSatisfied() { |
| + return autofill_helper::KeysMatch(profile_a_, profile_b_); |
| +} |
| - // PersonalDataManager implementation. |
| - void OnPersonalDataChanged() override; |
| +std::string AutofillKeysChecker::GetDebugMessage() const { |
| + return "Waiting for matching autofill keys"; |
| +} |
| - // Wait for conidtion to beome true. |
| - void Wait(); |
| +AutofillProfileChecker::AutofillProfileChecker(int profile_a, int profile_b) |
| + : profile_a_(profile_a), profile_b_(profile_b) { |
| + PersonalDataManager* pdm_a = |
| + autofill_helper::GetPersonalDataManager(profile_a_); |
| + PersonalDataManager* pdm_b = |
| + autofill_helper::GetPersonalDataManager(profile_b_); |
| - private: |
| - const int profile_a_; |
| - const int profile_b_; |
| - bool registered_; |
| -}; |
| + pdm_a->AddObserver(this); |
| + pdm_b->AddObserver(this); |
| -ProfilesMatchStatusChecker::ProfilesMatchStatusChecker(int profile_a, |
| - int profile_b) |
| - : profile_a_(profile_a), profile_b_(profile_b), registered_(false) { |
| + // TODO(skym): If Wait() isn't immediately called, it's possible this might be |
|
maxbogue
2016/09/30 16:27:55
You could always make Wait() virtual and override
skym
2016/09/30 17:43:21
True. I kinda of wanted to understand better what
|
| + // a little racy. |
| + pdm_a->Refresh(); |
| + pdm_b->Refresh(); |
| } |
| -ProfilesMatchStatusChecker::~ProfilesMatchStatusChecker() { |
| - PersonalDataManager* pdm_a = GetPersonalDataManager(profile_a_); |
| - PersonalDataManager* pdm_b = GetPersonalDataManager(profile_b_); |
| - if (registered_) { |
| - pdm_a->RemoveObserver(this); |
| - pdm_b->RemoveObserver(this); |
| - } |
| +AutofillProfileChecker::~AutofillProfileChecker() { |
| + PersonalDataManager* pdm_a = |
| + autofill_helper::GetPersonalDataManager(profile_a_); |
| + PersonalDataManager* pdm_b = |
| + autofill_helper::GetPersonalDataManager(profile_b_); |
| + |
| + pdm_a->RemoveObserver(this); |
| + pdm_b->RemoveObserver(this); |
| } |
| -bool ProfilesMatchStatusChecker::IsExitConditionSatisfied() { |
| - PersonalDataManager* pdm_a = GetPersonalDataManager(profile_a_); |
| - PersonalDataManager* pdm_b = GetPersonalDataManager(profile_b_); |
| +bool AutofillProfileChecker::IsExitConditionSatisfied() { |
| + PersonalDataManager* pdm_a = |
| + autofill_helper::GetPersonalDataManager(profile_a_); |
| + PersonalDataManager* pdm_b = |
| + autofill_helper::GetPersonalDataManager(profile_b_); |
| const std::vector<AutofillProfile*>& autofill_profiles_a = |
| pdm_a->web_profiles(); |
| const std::vector<AutofillProfile*>& autofill_profiles_b = |
| pdm_b->web_profiles(); |
| - return ProfilesMatchImpl( |
| - profile_a_, autofill_profiles_a, profile_b_, autofill_profiles_b); |
| -} |
| - |
| -void ProfilesMatchStatusChecker::Wait() { |
| - PersonalDataManager* pdm_a = GetPersonalDataManager(profile_a_); |
| - PersonalDataManager* pdm_b = GetPersonalDataManager(profile_b_); |
| - |
| - pdm_a->AddObserver(this); |
| - pdm_b->AddObserver(this); |
| - |
| - pdm_a->Refresh(); |
| - pdm_b->Refresh(); |
| - |
| - registered_ = true; |
| - |
| - StartBlockingWait(); |
| + return autofill_helper::ProfilesMatchImpl(profile_a_, autofill_profiles_a, |
| + profile_b_, autofill_profiles_b); |
| } |
| -std::string ProfilesMatchStatusChecker::GetDebugMessage() const { |
| +std::string AutofillProfileChecker::GetDebugMessage() const { |
| return "Waiting for matching autofill profiles"; |
| } |
| -void ProfilesMatchStatusChecker::OnPersonalDataChanged() { |
| +void AutofillProfileChecker::OnPersonalDataChanged() { |
| CheckExitCondition(); |
| } |
| - |
| -} // namespace |
| - |
| -bool AwaitProfilesMatch(int a, int b) { |
| - ProfilesMatchStatusChecker checker(a, b); |
| - checker.Wait(); |
| - return !checker.TimedOut(); |
| -} |
| - |
| -} // namespace autofill_helper |