diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-11 20:44:42 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-11 20:44:42 +0000 |
commit | 5322a7f16a374a15fe69b3bb2621678aede48bca (patch) | |
tree | 56c8ee955ed32cd69f8b3395cb609dcdd504e58c /chrome/test/live_sync | |
parent | 192a05f2e4d8f66d095227439d4dce7bb14b16b5 (diff) | |
download | chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.zip chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.tar.gz chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.tar.bz2 |
Continuing with the out-of-lining of test code.
BUG=none
TEST=compiles
Review URL: http://codereview.chromium.org/6485015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/live_sync')
-rw-r--r-- | chrome/test/live_sync/live_autofill_sync_test.cc | 275 | ||||
-rw-r--r-- | chrome/test/live_sync/live_autofill_sync_test.h | 282 | ||||
-rw-r--r-- | chrome/test/live_sync/two_client_live_autofill_sync_test.cc | 39 |
3 files changed, 323 insertions, 273 deletions
diff --git a/chrome/test/live_sync/live_autofill_sync_test.cc b/chrome/test/live_sync/live_autofill_sync_test.cc new file mode 100644 index 0000000..3050a28 --- /dev/null +++ b/chrome/test/live_sync/live_autofill_sync_test.cc @@ -0,0 +1,275 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_autofill_sync_test.h" + +#include "chrome/browser/autofill/autofill_common_test.h" +#include "chrome/browser/autofill/autofill_type.h" +#include "chrome/browser/autofill/autofill_profile.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/sync/profile_sync_test_util.h" +#include "chrome/browser/webdata/autofill_entry.h" +#include "chrome/browser/webdata/web_database.h" +#include "chrome/test/thread_observer_helper.h" + +using base::WaitableEvent; +using testing::_; + +namespace { +class GetAllAutofillEntries + : public base::RefCountedThreadSafe<GetAllAutofillEntries> { + public: + explicit GetAllAutofillEntries(WebDataService* web_data_service) + : web_data_service_(web_data_service), + done_event_(false, false) {} + + void Init() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + BrowserThread::PostTask( + BrowserThread::DB, + FROM_HERE, + NewRunnableMethod(this, &GetAllAutofillEntries::Run)); + done_event_.Wait(); + } + + const std::vector<AutofillEntry>& entries() const { + return entries_; + } + + private: + friend class base::RefCountedThreadSafe<GetAllAutofillEntries>; + + void Run() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); + web_data_service_->GetDatabase()->GetAllAutofillEntries(&entries_); + done_event_.Signal(); + } + + WebDataService* web_data_service_; + base::WaitableEvent done_event_; + std::vector<AutofillEntry> entries_; +}; + +ACTION_P(SignalEvent, event) { + event->Signal(); +} + +class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { + protected: + virtual void RegisterObservers() { + registrar_.Add(&observer_, + NotificationType::AUTOFILL_ENTRIES_CHANGED, + NotificationService::AllSources()); + registrar_.Add(&observer_, + NotificationType::AUTOFILL_PROFILE_CHANGED, + NotificationService::AllSources()); + } +}; + +class MockPersonalDataManagerObserver : public PersonalDataManager::Observer { + public: + MOCK_METHOD0(OnPersonalDataLoaded, void()); +}; + +} // namespace + +AutoFillProfile CreateAutofillProfile(LiveAutofillSyncTest::ProfileType type) { + AutoFillProfile profile; + switch (type) { + case LiveAutofillSyncTest::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", "01987654321"); + break; + case LiveAutofillSyncTest::PROFILE_HOMER: + autofill_test::SetProfileInfoWithGuid(&profile, + "137DE1C3-6A30-4571-AC86-109B1ECFBE7F", + "Homer", "J.", "Simpson", + "homer@abc.com", "SNPP", + "1 Main St", "PO Box 1", "Springfield", "MA", + "94101", "US", "14155551212", "14155551313"); + break; + case LiveAutofillSyncTest::PROFILE_FRASIER: + autofill_test::SetProfileInfoWithGuid(&profile, + "9A5E6872-6198-4688-BF75-0016E781BB0A", + "Frasier", "Winslow", "Crane", + "", "randomness", "", "Apt. 4", "Seattle", "WA", + "99121", "US", "0000000000", "ABCDEFGHIJK"); + break; + case LiveAutofillSyncTest::PROFILE_NULL: + autofill_test::SetProfileInfoWithGuid(&profile, + "FE461507-7E13-4198-8E66-74C7DB6D8322", + "", "", "", "", "", "", "", "", "", "", "", "", ""); + break; + } + return profile; +} + +LiveAutofillSyncTest::LiveAutofillSyncTest(TestType test_type) + : LiveSyncTest(test_type) {} + +LiveAutofillSyncTest::~LiveAutofillSyncTest() {} + +WebDataService* LiveAutofillSyncTest::GetWebDataService(int index) { + return GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); +} + +PersonalDataManager* LiveAutofillSyncTest::GetPersonalDataManager(int index) { + return GetProfile(index)->GetPersonalDataManager(); +} + +void LiveAutofillSyncTest::AddKeys(int profile, + const std::set<AutofillKey>& keys) { + std::vector<webkit_glue::FormField> form_fields; + for (std::set<AutofillKey>::const_iterator i = keys.begin(); + i != keys.end(); + ++i) { + form_fields.push_back(webkit_glue::FormField(string16(), + (*i).name(), + (*i).value(), + string16(), + 0, + false)); + } + + WaitableEvent done_event(false, false); + scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( + new AutofillDBThreadObserverHelper()); + observer_helper->Init(); + + EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). + WillOnce(SignalEvent(&done_event)); + WebDataService* wds = GetWebDataService(profile); + wds->AddFormFields(form_fields); + done_event.Wait(); +} + +void LiveAutofillSyncTest::RemoveKey(int profile, const AutofillKey& key) { + WaitableEvent done_event(false, false); + scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( + new AutofillDBThreadObserverHelper()); + observer_helper->Init(); + + EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). + WillOnce(SignalEvent(&done_event)); + WebDataService* wds = GetWebDataService(profile); + wds->RemoveFormValueForElementName(key.name(), key.value()); + done_event.Wait(); +} + +std::set<AutofillEntry> LiveAutofillSyncTest::GetAllKeys(int profile) { + WebDataService* wds = GetWebDataService(profile); + scoped_refptr<GetAllAutofillEntries> get_all_entries = + new GetAllAutofillEntries(wds); + get_all_entries->Init(); + const std::vector<AutofillEntry>& all_entries = get_all_entries->entries(); + std::set<AutofillEntry> all_keys; + for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); + it != all_entries.end(); ++it) { + all_keys.insert(*it); + } + return all_keys; +} + +bool LiveAutofillSyncTest::KeysMatch(int profile_a, int profile_b) { + return GetAllKeys(profile_a) == GetAllKeys(profile_b); +} + +void LiveAutofillSyncTest::SetProfiles( + int profile, std::vector<AutoFillProfile>* autofill_profiles) { + MockPersonalDataManagerObserver observer; + EXPECT_CALL(observer, OnPersonalDataLoaded()). + WillOnce(QuitUIMessageLoop()); + PersonalDataManager* pdm = GetPersonalDataManager(profile); + pdm->SetObserver(&observer); + pdm->SetProfiles(autofill_profiles); + MessageLoop::current()->Run(); + pdm->RemoveObserver(&observer); +} + +void LiveAutofillSyncTest::AddProfile(int profile, + const AutoFillProfile& autofill_profile) { + const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); + std::vector<AutoFillProfile> autofill_profiles; + for (size_t i = 0; i < all_profiles.size(); ++i) + autofill_profiles.push_back(*all_profiles[i]); + autofill_profiles.push_back(autofill_profile); + SetProfiles(profile, &autofill_profiles); +} + +void LiveAutofillSyncTest::RemoveProfile(int profile, const std::string& guid) { + const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); + std::vector<AutoFillProfile> autofill_profiles; + for (size_t i = 0; i < all_profiles.size(); ++i) { + if (all_profiles[i]->guid() != guid) + autofill_profiles.push_back(*all_profiles[i]); + } + SetProfiles(profile, &autofill_profiles); +} + +void LiveAutofillSyncTest::UpdateProfile(int profile, + const std::string& guid, + const AutoFillType& type, + const string16& value) { + const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); + std::vector<AutoFillProfile> profiles; + for (size_t i = 0; i < all_profiles.size(); ++i) { + profiles.push_back(*all_profiles[i]); + if (all_profiles[i]->guid() == guid) + profiles.back().SetInfo(type, value); + } + SetProfiles(profile, &profiles); +} + +const std::vector<AutoFillProfile*>& LiveAutofillSyncTest::GetAllProfiles( + int profile) { + MockPersonalDataManagerObserver observer; + EXPECT_CALL(observer, OnPersonalDataLoaded()). + WillOnce(QuitUIMessageLoop()); + PersonalDataManager* pdm = GetPersonalDataManager(profile); + pdm->SetObserver(&observer); + pdm->Refresh(); + MessageLoop::current()->Run(); + pdm->RemoveObserver(&observer); + return pdm->web_profiles(); +} + +bool LiveAutofillSyncTest::ProfilesMatch(int profile_a, int profile_b) { + const std::vector<AutoFillProfile*>& autofill_profiles_a = + GetAllProfiles(profile_a); + std::map<std::string, AutoFillProfile> autofill_profiles_a_map; + for (size_t i = 0; i < autofill_profiles_a.size(); ++i) { + const AutoFillProfile* p = autofill_profiles_a[i]; + autofill_profiles_a_map[p->guid()] = *p; + } + + const std::vector<AutoFillProfile*>& autofill_profiles_b = + GetAllProfiles(profile_b); + for (size_t i = 0; i < autofill_profiles_b.size(); ++i) { + const AutoFillProfile* p = autofill_profiles_b[i]; + if (!autofill_profiles_a_map.count(p->guid())) { + VLOG(1) << "GUID " << p->guid() << " not found in profile " + << profile_b << "."; + return false; + } + AutoFillProfile* expected_profile = &autofill_profiles_a_map[p->guid()]; + expected_profile->set_guid(p->guid()); + if (*expected_profile != *p) { + VLOG(1) << "Mismatch in profile with GUID " << p->guid() << "."; + return false; + } + autofill_profiles_a_map.erase(p->guid()); + } + + if (autofill_profiles_a_map.size()) { + VLOG(1) << "Entries present in Profile " << profile_a + << " but not in " << profile_b << "."; + return false; + } + return true; +} diff --git a/chrome/test/live_sync/live_autofill_sync_test.h b/chrome/test/live_sync/live_autofill_sync_test.h index f00be3a..0492429 100644 --- a/chrome/test/live_sync/live_autofill_sync_test.h +++ b/chrome/test/live_sync/live_autofill_sync_test.h @@ -6,312 +6,84 @@ #define CHROME_TEST_LIVE_SYNC_LIVE_AUTOFILL_SYNC_TEST_H_ #pragma once -#include <map> #include <set> #include <vector> #include "base/compiler_specific.h" -#include "chrome/browser/autofill/autofill_common_test.h" -#include "chrome/browser/autofill/autofill_profile.h" -#include "chrome/browser/autofill/autofill_type.h" #include "chrome/browser/autofill/personal_data_manager.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/profile_sync_test_util.h" -#include "chrome/browser/webdata/autofill_entry.h" -#include "chrome/browser/webdata/web_database.h" #include "chrome/test/live_sync/live_sync_test.h" -#include "chrome/test/thread_observer_helper.h" -using base::WaitableEvent; -using testing::_; - -namespace { -class GetAllAutofillEntries - : public base::RefCountedThreadSafe<GetAllAutofillEntries> { - public: - explicit GetAllAutofillEntries(WebDataService* web_data_service) - : web_data_service_(web_data_service), - done_event_(false, false) {} - - void Init() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - BrowserThread::PostTask( - BrowserThread::DB, - FROM_HERE, - NewRunnableMethod(this, &GetAllAutofillEntries::Run)); - done_event_.Wait(); - } - - const std::vector<AutofillEntry>& entries() const { - return entries_; - } - - private: - friend class base::RefCountedThreadSafe<GetAllAutofillEntries>; - - void Run() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); - web_data_service_->GetDatabase()->GetAllAutofillEntries(&entries_); - done_event_.Signal(); - } - - WebDataService* web_data_service_; - base::WaitableEvent done_event_; - std::vector<AutofillEntry> entries_; -}; - -ACTION_P(SignalEvent, event) { - event->Signal(); -} - -class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { - protected: - virtual void RegisterObservers() { - registrar_.Add(&observer_, - NotificationType::AUTOFILL_ENTRIES_CHANGED, - NotificationService::AllSources()); - registrar_.Add(&observer_, - NotificationType::AUTOFILL_PROFILE_CHANGED, - NotificationService::AllSources()); - } -}; - -enum ProfileType { - PROFILE_MARION, - PROFILE_HOMER, - PROFILE_FRASIER, - PROFILE_NULL -}; - -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", "01987654321"); - break; - case PROFILE_HOMER: - autofill_test::SetProfileInfoWithGuid(&profile, - "137DE1C3-6A30-4571-AC86-109B1ECFBE7F", - "Homer", "J.", "Simpson", - "homer@abc.com", "SNPP", - "1 Main St", "PO Box 1", "Springfield", "MA", - "94101", "US", "14155551212", "14155551313"); - break; - case PROFILE_FRASIER: - autofill_test::SetProfileInfoWithGuid(&profile, - "9A5E6872-6198-4688-BF75-0016E781BB0A", - "Frasier", "Winslow", "Crane", - "", "randomness", "", "Apt. 4", "Seattle", "WA", - "99121", "US", "0000000000", "ABCDEFGHIJK"); - break; - case PROFILE_NULL: - autofill_test::SetProfileInfoWithGuid(&profile, - "FE461507-7E13-4198-8E66-74C7DB6D8322", - "", "", "", "", "", "", "", "", "", "", "", "", ""); - break; - } - return profile; -} - -class MockPersonalDataManagerObserver : public PersonalDataManager::Observer { - public: - MOCK_METHOD0(OnPersonalDataLoaded, void()); -}; - -} // namespace +class AutofillEntry; +class AutofillKey; +class AutoFillProfile; +class WebDataService; class LiveAutofillSyncTest : public LiveSyncTest { public: - explicit LiveAutofillSyncTest(TestType test_type) : LiveSyncTest(test_type) {} - virtual ~LiveAutofillSyncTest() {} + enum ProfileType { + PROFILE_MARION, + PROFILE_HOMER, + PROFILE_FRASIER, + PROFILE_NULL + }; + + explicit LiveAutofillSyncTest(TestType test_type); + virtual ~LiveAutofillSyncTest(); // Used to access the web data service within a particular sync profile. - WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT { - return GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); - } + WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT; // Used to access the personal data manager within a particular sync profile. - PersonalDataManager* GetPersonalDataManager(int index) WARN_UNUSED_RESULT { - return GetProfile(index)->GetPersonalDataManager(); - } + PersonalDataManager* GetPersonalDataManager(int index) WARN_UNUSED_RESULT; // Adds the form fields in |keys| to the WebDataService of sync profile // |profile|. - void AddKeys(int profile, const std::set<AutofillKey>& keys) { - std::vector<webkit_glue::FormField> form_fields; - for (std::set<AutofillKey>::const_iterator i = keys.begin(); - i != keys.end(); - ++i) { - form_fields.push_back(webkit_glue::FormField(string16(), - (*i).name(), - (*i).value(), - string16(), - 0, - false)); - } - - WaitableEvent done_event(false, false); - scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( - new AutofillDBThreadObserverHelper()); - observer_helper->Init(); - - EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). - WillOnce(SignalEvent(&done_event)); - WebDataService* wds = GetWebDataService(profile); - wds->AddFormFields(form_fields); - done_event.Wait(); - } - + void AddKeys(int profile, const std::set<AutofillKey>& keys); // Removes the form field in |key| from the WebDataService of sync profile // |profile|. - void RemoveKey(int profile, const AutofillKey& key) { - WaitableEvent done_event(false, false); - scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( - new AutofillDBThreadObserverHelper()); - observer_helper->Init(); - - EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). - WillOnce(SignalEvent(&done_event)); - WebDataService* wds = GetWebDataService(profile); - wds->RemoveFormValueForElementName(key.name(), key.value()); - done_event.Wait(); - } + void RemoveKey(int profile, const AutofillKey& key); // Gets all the form fields in the WebDataService of sync profile |profile|. - std::set<AutofillEntry> GetAllKeys(int profile) WARN_UNUSED_RESULT { - WebDataService* wds = GetWebDataService(profile); - scoped_refptr<GetAllAutofillEntries> get_all_entries = - new GetAllAutofillEntries(wds); - get_all_entries->Init(); - const std::vector<AutofillEntry>& all_entries = get_all_entries->entries(); - std::set<AutofillEntry> all_keys; - for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); - it != all_entries.end(); ++it) { - all_keys.insert(*it); - } - return all_keys; - } + std::set<AutofillEntry> GetAllKeys(int profile) WARN_UNUSED_RESULT; // Compares the form fields in the WebDataServices of sync profiles // |profile_a| and |profile_b|. Returns true if they match. - bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT { - return GetAllKeys(profile_a) == GetAllKeys(profile_b); - } + bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; // Replaces the Autofill profiles in sync profile |profile| with // |autofill_profiles|. void SetProfiles( - int profile, std::vector<AutoFillProfile>* autofill_profiles) { - MockPersonalDataManagerObserver observer; - EXPECT_CALL(observer, OnPersonalDataLoaded()). - WillOnce(QuitUIMessageLoop()); - PersonalDataManager* pdm = GetPersonalDataManager(profile); - pdm->SetObserver(&observer); - pdm->SetProfiles(autofill_profiles); - MessageLoop::current()->Run(); - pdm->RemoveObserver(&observer); - } + int profile, std::vector<AutoFillProfile>* autofill_profiles); // Adds the autofill profile |autofill_profile| to sync profile |profile|. - void AddProfile(int profile, const AutoFillProfile& autofill_profile) { - const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); - std::vector<AutoFillProfile> autofill_profiles; - for (size_t i = 0; i < all_profiles.size(); ++i) - autofill_profiles.push_back(*all_profiles[i]); - autofill_profiles.push_back(autofill_profile); - SetProfiles(profile, &autofill_profiles); - } + void AddProfile(int profile, const AutoFillProfile& autofill_profile); // Removes the autofill profile with guid |guid| from sync profile // |profile|. - void RemoveProfile(int profile, const std::string& guid) { - const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); - std::vector<AutoFillProfile> autofill_profiles; - for (size_t i = 0; i < all_profiles.size(); ++i) { - if (all_profiles[i]->guid() != guid) - autofill_profiles.push_back(*all_profiles[i]); - } - SetProfiles(profile, &autofill_profiles); - } + 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 AutoFillType& type, - const string16& value) { - const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); - std::vector<AutoFillProfile> profiles; - for (size_t i = 0; i < all_profiles.size(); ++i) { - profiles.push_back(*all_profiles[i]); - if (all_profiles[i]->guid() == guid) - profiles.back().SetInfo(type, value); - } - SetProfiles(profile, &profiles); - } + const string16& value); // Gets all the Autofill profiles in the PersonalDataManager of sync profile // |profile|. const std::vector<AutoFillProfile*>& GetAllProfiles(int profile) - WARN_UNUSED_RESULT { - MockPersonalDataManagerObserver observer; - EXPECT_CALL(observer, OnPersonalDataLoaded()). - WillOnce(QuitUIMessageLoop()); - PersonalDataManager* pdm = GetPersonalDataManager(profile); - pdm->SetObserver(&observer); - pdm->Refresh(); - MessageLoop::current()->Run(); - pdm->RemoveObserver(&observer); - return pdm->web_profiles(); - } + WARN_UNUSED_RESULT; // Compares the Autofill profiles in the PersonalDataManagers of sync profiles // |profile_a| and |profile_b|. Returns true if they match. - bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT { - const std::vector<AutoFillProfile*>& autofill_profiles_a = - GetAllProfiles(profile_a); - std::map<std::string, AutoFillProfile> autofill_profiles_a_map; - for (size_t i = 0; i < autofill_profiles_a.size(); ++i) { - const AutoFillProfile* p = autofill_profiles_a[i]; - autofill_profiles_a_map[p->guid()] = *p; - } - - const std::vector<AutoFillProfile*>& autofill_profiles_b = - GetAllProfiles(profile_b); - for (size_t i = 0; i < autofill_profiles_b.size(); ++i) { - const AutoFillProfile* p = autofill_profiles_b[i]; - if (!autofill_profiles_a_map.count(p->guid())) { - VLOG(1) << "GUID " << p->guid() << " not found in profile " - << profile_b << "."; - return false; - } - AutoFillProfile* expected_profile = &autofill_profiles_a_map[p->guid()]; - expected_profile->set_guid(p->guid()); - if (*expected_profile != *p) { - VLOG(1) << "Mismatch in profile with GUID " << p->guid() << "."; - return false; - } - autofill_profiles_a_map.erase(p->guid()); - } - - if (autofill_profiles_a_map.size()) { - VLOG(1) << "Entries present in Profile " << profile_a - << " but not in " << profile_b << "."; - return false; - } - return true; - } + bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; private: DISALLOW_COPY_AND_ASSIGN(LiveAutofillSyncTest); }; +AutoFillProfile CreateAutofillProfile(LiveAutofillSyncTest::ProfileType type); + class TwoClientLiveAutofillSyncTest : public LiveAutofillSyncTest { public: TwoClientLiveAutofillSyncTest() : LiveAutofillSyncTest(TWO_CLIENT) {} diff --git a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc index 263eaef..0f1f998 100644 --- a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc @@ -4,6 +4,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/sync/profile_sync_service_harness.h" +#include "chrome/browser/webdata/autofill_entry.h" #include "chrome/test/live_sync/live_autofill_sync_test.h" IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, WebDataServiceSanity) { @@ -101,19 +102,19 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; // Client0 adds a profile. - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); // Client1 adds a profile. - AddProfile(1, CreateAutofillProfile(PROFILE_MARION)); + AddProfile(1, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(2U, GetAllProfiles(0).size()); // Client0 adds the same profile. - AddProfile(0, CreateAutofillProfile(PROFILE_MARION)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(2U, GetAllProfiles(0).size()); @@ -141,8 +142,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddDuplicateProfiles) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(ProfilesMatch(0,1)); @@ -153,8 +154,10 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddDuplicateProfiles) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, SameProfileWithConflict) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - AutoFillProfile profile0 = CreateAutofillProfile(PROFILE_HOMER); - AutoFillProfile profile1 = CreateAutofillProfile(PROFILE_HOMER); + AutoFillProfile profile0 = + CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER); + AutoFillProfile profile1 = + CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER); profile1.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("1234567890")); @@ -170,7 +173,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, SameProfileWithConflict) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddEmptyProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_NULL)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_NULL)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(0U, GetAllProfiles(0).size()); @@ -180,7 +183,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddEmptyProfile) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); @@ -190,9 +193,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddProfile) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddMultipleProfiles) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); - AddProfile(0, CreateAutofillProfile(PROFILE_MARION)); - AddProfile(0, CreateAutofillProfile(PROFILE_FRASIER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_FRASIER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(3U, GetAllProfiles(0).size()); @@ -202,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddMultipleProfiles) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DeleteProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); @@ -217,9 +220,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DeleteProfile) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, MergeProfiles) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); - AddProfile(1, CreateAutofillProfile(PROFILE_MARION)); - AddProfile(1, CreateAutofillProfile(PROFILE_FRASIER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); + AddProfile(1, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); + AddProfile(1, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_FRASIER)); ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(ProfilesMatch(0,1)); @@ -230,7 +233,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, MergeProfiles) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, UpdateFields) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); @@ -248,7 +251,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, UpdateFields) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ConflictingFields) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); |