From 476d0f61b6d5f226eb4950dce6c750e4a061cb18 Mon Sep 17 00:00:00 2001 From: "rsimha@chromium.org" Date: Wed, 3 Aug 2011 17:37:16 +0000 Subject: Allow sync integration tests to operate on multiple datatypes: Autofill The sync integration tests currently use a class hierarchy where the test classes for each datatype are subclasses of LiveSyncTest. While this design worked in the past, it allows tests to work with only one datatype at a time, and therefore doesn't allow us to test the interplay between datatypes. This patch is another in the series of patches that will move away from an inheritance model to one where test cases can operate on more than one datatype. It updates the Autofill datatype to the new model, and contains the following changes: - LiveAutofillSyncTest no longer inherits from LiveSyncTest, but is renamed to AutofillHelper, and contains a bunch of static methods that perform various operations related to Autofill. - TwoClientLiveAutofillSyncTest is renamed to TwoClientAutofillSyncTest, and is a subclass of LiveSyncTest. It uses the methods in AutofillHelper by including its header file and attaching itself to the helper. BUG=88510 TEST=sync_integration_tests, sync_performance_tests Review URL: http://codereview.chromium.org/7536001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95263 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/autofill/personal_data_manager.h | 2 +- chrome/chrome_tests.gypi | 10 +- chrome/test/live_sync/autofill_helper.cc | 309 +++++++++++++++ chrome/test/live_sync/autofill_helper.h | 98 +++++ chrome/test/live_sync/live_autofill_sync_test.cc | 294 -------------- chrome/test/live_sync/live_autofill_sync_test.h | 104 ----- .../performance/autofill_sync_perf_test.cc | 37 +- .../live_sync/two_client_autofill_sync_test.cc | 437 +++++++++++++++++++++ .../two_client_live_autofill_sync_test.cc | 360 ----------------- 9 files changed, 871 insertions(+), 780 deletions(-) create mode 100644 chrome/test/live_sync/autofill_helper.cc create mode 100644 chrome/test/live_sync/autofill_helper.h delete mode 100644 chrome/test/live_sync/live_autofill_sync_test.cc delete mode 100644 chrome/test/live_sync/live_autofill_sync_test.h create mode 100644 chrome/test/live_sync/two_client_autofill_sync_test.cc delete mode 100644 chrome/test/live_sync/two_client_live_autofill_sync_test.cc diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h index da7b0b8..3e945ec 100644 --- a/chrome/browser/autofill/personal_data_manager.h +++ b/chrome/browser/autofill/personal_data_manager.h @@ -141,8 +141,8 @@ class PersonalDataManager // Make sure that only Profile and certain tests can create an instance of // PersonalDataManager. friend class base::RefCountedThreadSafe; + friend class AutofillHelper; friend class AutofillMergeTest; - friend class LiveAutofillSyncTest; friend class PersonalDataManagerTest; friend class ProfileImpl; friend class ProfileSyncServiceAutofillTest; diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 6b1accd..d0356e1 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -3503,12 +3503,12 @@ 'test/base/test_notification_tracker.cc', 'test/base/test_notification_tracker.h', 'test/data/resource.rc', + 'test/live_sync/autofill_helper.cc', + 'test/live_sync/autofill_helper.h', 'test/live_sync/bookmarks_helper.cc', 'test/live_sync/bookmarks_helper.h', 'test/live_sync/live_apps_sync_test.cc', 'test/live_sync/live_apps_sync_test.h', - 'test/live_sync/live_autofill_sync_test.cc', - 'test/live_sync/live_autofill_sync_test.h', 'test/live_sync/live_extensions_sync_test.cc', 'test/live_sync/live_extensions_sync_test.h', 'test/live_sync/live_passwords_sync_test.cc', @@ -3545,9 +3545,9 @@ 'test/live_sync/sync_datatype_helper.cc', 'test/live_sync/sync_datatype_helper.h', 'test/live_sync/sync_errors_test.cc', + 'test/live_sync/two_client_autofill_sync_test.cc', 'test/live_sync/two_client_bookmarks_sync_test.cc', 'test/live_sync/two_client_live_apps_sync_test.cc', - 'test/live_sync/two_client_live_autofill_sync_test.cc', 'test/live_sync/two_client_live_extensions_sync_test.cc', 'test/live_sync/two_client_live_passwords_sync_test.cc', 'test/live_sync/two_client_live_sessions_sync_test.cc', @@ -3640,10 +3640,10 @@ 'sources': [ 'browser/password_manager/password_form_data.cc', 'test/base/out_of_proc_test_runner.cc', + 'test/live_sync/autofill_helper.cc', + 'test/live_sync/autofill_helper.h', 'test/live_sync/bookmarks_helper.cc', 'test/live_sync/bookmarks_helper.h', - 'test/live_sync/live_autofill_sync_test.cc', - 'test/live_sync/live_autofill_sync_test.h', 'test/live_sync/live_extensions_sync_test.cc', 'test/live_sync/live_extensions_sync_test.h', 'test/live_sync/live_passwords_sync_test.cc', diff --git a/chrome/test/live_sync/autofill_helper.cc b/chrome/test/live_sync/autofill_helper.cc new file mode 100644 index 0000000..b81d8e2 --- /dev/null +++ b/chrome/test/live_sync/autofill_helper.cc @@ -0,0 +1,309 @@ +// 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/autofill_helper.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/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/autofill_table.h" +#include "chrome/browser/webdata/web_database.h" +#include "chrome/common/chrome_notification_types.h" +#include "chrome/test/live_sync/live_sync_test.h" +#include "chrome/test/base/thread_observer_helper.h" +#include "webkit/glue/form_field.h" + +using base::WaitableEvent; +using testing::_; + +namespace { +class GetAllAutofillEntries + : public base::RefCountedThreadSafe { + 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& entries() const { + return entries_; + } + + private: + friend class base::RefCountedThreadSafe; + + void Run() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); + web_data_service_->GetDatabase()->GetAutofillTable()->GetAllAutofillEntries( + &entries_); + done_event_.Signal(); + } + + WebDataService* web_data_service_; + base::WaitableEvent done_event_; + std::vector entries_; +}; + +ACTION_P(SignalEvent, event) { + event->Signal(); +} + +class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { + protected: + virtual void RegisterObservers() { + registrar_.Add(&observer_, + chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, + NotificationService::AllSources()); + registrar_.Add(&observer_, + chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, + NotificationService::AllSources()); + } +}; + +class MockPersonalDataManagerObserver : public PersonalDataManager::Observer { + public: + MOCK_METHOD0(OnPersonalDataChanged, void()); +}; + +} // namespace + +AutofillHelper::AutofillHelper() {} + +AutofillHelper::~AutofillHelper() {} + +// static +AutofillProfile AutofillHelper::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; +} + +// static +WebDataService* AutofillHelper::GetWebDataService(int index) { + return test()->GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); +} + +// static +PersonalDataManager* AutofillHelper::GetPersonalDataManager(int index) { + return test()->GetProfile(index)->GetPersonalDataManager(); +} + +// static +void AutofillHelper::AddKeys(int profile, + const std::set& keys) { + std::vector form_fields; + for (std::set::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 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(); +} + +// static +void AutofillHelper::RemoveKey(int profile, const AutofillKey& key) { + WaitableEvent done_event(false, false); + scoped_refptr 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(); +} + +// static +std::set AutofillHelper::GetAllKeys(int profile) { + WebDataService* wds = GetWebDataService(profile); + scoped_refptr get_all_entries = + new GetAllAutofillEntries(wds); + get_all_entries->Init(); + const std::vector& all_entries = get_all_entries->entries(); + std::set all_keys; + for (std::vector::const_iterator it = all_entries.begin(); + it != all_entries.end(); ++it) { + all_keys.insert(*it); + } + return all_keys; +} + +// static +bool AutofillHelper::KeysMatch(int profile_a, int profile_b) { + return GetAllKeys(profile_a) == GetAllKeys(profile_b); +} + +// static +void AutofillHelper::SetProfiles( + int profile, std::vector* autofill_profiles) { + MockPersonalDataManagerObserver observer; + EXPECT_CALL(observer, OnPersonalDataChanged()). + WillOnce(QuitUIMessageLoop()); + PersonalDataManager* pdm = GetPersonalDataManager(profile); + pdm->SetObserver(&observer); + pdm->SetProfiles(autofill_profiles); + MessageLoop::current()->Run(); + pdm->RemoveObserver(&observer); +} + +// static +void AutofillHelper::AddProfile(int profile, + const AutofillProfile& autofill_profile) { + const std::vector& all_profiles = GetAllProfiles(profile); + std::vector 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); +} + +// static +void AutofillHelper::RemoveProfile(int profile, const std::string& guid) { + const std::vector& all_profiles = GetAllProfiles(profile); + std::vector 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); +} + +// static +void AutofillHelper::UpdateProfile(int profile, + const std::string& guid, + const AutofillType& type, + const string16& value) { + const std::vector& all_profiles = GetAllProfiles(profile); + std::vector 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.field_type(), value); + } + SetProfiles(profile, &profiles); +} + +// static +const std::vector& AutofillHelper::GetAllProfiles( + int profile) { + MockPersonalDataManagerObserver observer; + EXPECT_CALL(observer, OnPersonalDataChanged()). + WillOnce(QuitUIMessageLoop()); + PersonalDataManager* pdm = GetPersonalDataManager(profile); + pdm->SetObserver(&observer); + pdm->Refresh(); + MessageLoop::current()->Run(); + pdm->RemoveObserver(&observer); + return pdm->web_profiles(); +} + +// static +int AutofillHelper::GetProfileCount(int profile) { + return GetAllProfiles(profile).size(); +} + +// static +bool AutofillHelper::ProfilesMatch(int profile_a, int profile_b) { + const std::vector& autofill_profiles_a = + GetAllProfiles(profile_a); + std::map 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& 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())) { + LOG(ERROR) << "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) { + LOG(ERROR) << "Mismatch in profile with GUID " << p->guid() << "."; + return false; + } + autofill_profiles_a_map.erase(p->guid()); + } + + if (autofill_profiles_a_map.size()) { + LOG(ERROR) << "Entries present in Profile " << profile_a + << " but not in " << profile_b << "."; + return false; + } + return true; +} + +// static +bool AutofillHelper::AllProfilesMatch() { + for (int i = 1; i < test()->num_clients(); ++i) { + if (!ProfilesMatch(0, i)) { + LOG(ERROR) << "Profile " << i << "does not contain the same autofill " + "profiles as profile 0."; + return false; + } + } + return true; +} diff --git a/chrome/test/live_sync/autofill_helper.h b/chrome/test/live_sync/autofill_helper.h new file mode 100644 index 0000000..0c3dee4 --- /dev/null +++ b/chrome/test/live_sync/autofill_helper.h @@ -0,0 +1,98 @@ +// 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. + +#ifndef CHROME_TEST_LIVE_SYNC_AUTOFILL_HELPER_H_ +#define CHROME_TEST_LIVE_SYNC_AUTOFILL_HELPER_H_ +#pragma once + +#include +#include + +#include "base/compiler_specific.h" +#include "chrome/browser/autofill/personal_data_manager.h" +#include "chrome/test/live_sync/sync_datatype_helper.h" + +class AutofillEntry; +class AutofillKey; +class AutofillProfile; +class WebDataService; + +class AutofillHelper : public SyncDatatypeHelper { + public: + enum ProfileType { + PROFILE_MARION, + PROFILE_HOMER, + PROFILE_FRASIER, + PROFILE_NULL + }; + + // Used to access the web data service within a particular sync profile. + static WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT; + + // Used to access the personal data manager within a particular sync profile. + static PersonalDataManager* GetPersonalDataManager( + int index) WARN_UNUSED_RESULT; + + // Adds the form fields in |keys| to the WebDataService of sync profile + // |profile|. + static void AddKeys(int profile, const std::set& keys); + + // Removes the form field in |key| from the WebDataService of sync profile + // |profile|. + static void RemoveKey(int profile, const AutofillKey& key); + + // Gets all the form fields in the WebDataService of sync profile |profile|. + static std::set 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. + static bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; + + // Replaces the Autofill profiles in sync profile |profile| with + // |autofill_profiles|. + static void SetProfiles(int profile, + std::vector* autofill_profiles); + + // Adds the autofill profile |autofill_profile| to sync profile |profile|. + static void AddProfile(int profile, const AutofillProfile& autofill_profile); + + // Removes the autofill profile with guid |guid| from sync profile + // |profile|. + static void RemoveProfile(int profile, const std::string& guid); + + // Updates the autofill profile with guid |guid| in sync profile |profile| + // to |type| and |value|. + static void UpdateProfile(int profile, + const std::string& guid, + const AutofillType& type, + const string16& value); + + // Gets all the Autofill profiles in the PersonalDataManager of sync profile + // |profile|. + static const std::vector& GetAllProfiles( + int profile) WARN_UNUSED_RESULT; + + // Returns the number of autofill profiles contained by sync profile + // |profile|. + static int GetProfileCount(int profile); + + // Compares the Autofill profiles in the PersonalDataManagers of sync profiles + // |profile_a| and |profile_b|. Returns true if they match. + static bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; + + // Compares the autofill profiles for all sync profiles, and returns true if + // they all match. + static bool AllProfilesMatch() WARN_UNUSED_RESULT; + + // Creates a test autofill profile based on the persona specified in |type|. + static AutofillProfile CreateAutofillProfile(ProfileType type); + protected: + AutofillHelper(); + virtual ~AutofillHelper(); + + private: + DISALLOW_COPY_AND_ASSIGN(AutofillHelper); +}; + +#endif // CHROME_TEST_LIVE_SYNC_AUTOFILL_HELPER_H_ diff --git a/chrome/test/live_sync/live_autofill_sync_test.cc b/chrome/test/live_sync/live_autofill_sync_test.cc deleted file mode 100644 index 5ee55c6..0000000 --- a/chrome/test/live_sync/live_autofill_sync_test.cc +++ /dev/null @@ -1,294 +0,0 @@ -// 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_profile.h" -#include "chrome/browser/autofill/autofill_type.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/autofill_table.h" -#include "chrome/browser/webdata/web_database.h" -#include "chrome/common/chrome_notification_types.h" -#include "chrome/test/base/thread_observer_helper.h" -#include "webkit/glue/form_field.h" - -using base::WaitableEvent; -using testing::_; - -namespace { -class GetAllAutofillEntries - : public base::RefCountedThreadSafe { - 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& entries() const { - return entries_; - } - - private: - friend class base::RefCountedThreadSafe; - - void Run() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); - web_data_service_->GetDatabase()->GetAutofillTable()->GetAllAutofillEntries( - &entries_); - done_event_.Signal(); - } - - WebDataService* web_data_service_; - base::WaitableEvent done_event_; - std::vector entries_; -}; - -ACTION_P(SignalEvent, event) { - event->Signal(); -} - -class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { - protected: - virtual void RegisterObservers() { - registrar_.Add(&observer_, - chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, - NotificationService::AllSources()); - registrar_.Add(&observer_, - chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, - NotificationService::AllSources()); - } -}; - -class MockPersonalDataManagerObserver : public PersonalDataManager::Observer { - public: - MOCK_METHOD0(OnPersonalDataChanged, 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& keys) { - std::vector form_fields; - for (std::set::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 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 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 LiveAutofillSyncTest::GetAllKeys(int profile) { - WebDataService* wds = GetWebDataService(profile); - scoped_refptr get_all_entries = - new GetAllAutofillEntries(wds); - get_all_entries->Init(); - const std::vector& all_entries = get_all_entries->entries(); - std::set all_keys; - for (std::vector::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* autofill_profiles) { - MockPersonalDataManagerObserver observer; - EXPECT_CALL(observer, OnPersonalDataChanged()). - 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& all_profiles = GetAllProfiles(profile); - std::vector 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& all_profiles = GetAllProfiles(profile); - std::vector 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& all_profiles = GetAllProfiles(profile); - std::vector 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.field_type(), value); - } - SetProfiles(profile, &profiles); -} - -const std::vector& LiveAutofillSyncTest::GetAllProfiles( - int profile) { - MockPersonalDataManagerObserver observer; - EXPECT_CALL(observer, OnPersonalDataChanged()). - WillOnce(QuitUIMessageLoop()); - PersonalDataManager* pdm = GetPersonalDataManager(profile); - pdm->SetObserver(&observer); - pdm->Refresh(); - MessageLoop::current()->Run(); - pdm->RemoveObserver(&observer); - return pdm->web_profiles(); -} - -int LiveAutofillSyncTest::GetProfileCount(int profile) { - return GetAllProfiles(profile).size(); -} - -bool LiveAutofillSyncTest::ProfilesMatch(int profile_a, int profile_b) { - const std::vector& autofill_profiles_a = - GetAllProfiles(profile_a); - std::map 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& 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())) { - LOG(ERROR) << "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) { - LOG(ERROR) << "Mismatch in profile with GUID " << p->guid() << "."; - return false; - } - autofill_profiles_a_map.erase(p->guid()); - } - - if (autofill_profiles_a_map.size()) { - LOG(ERROR) << "Entries present in Profile " << profile_a - << " but not in " << profile_b << "."; - return false; - } - return true; -} - -bool LiveAutofillSyncTest::AllProfilesMatch() { - for (int i = 1; i < num_clients(); ++i) { - if (!ProfilesMatch(0, i)) { - LOG(ERROR) << "Profile " << i << "does not contain the same autofill " - "profiles as profile 0."; - 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 deleted file mode 100644 index c5bb58a..0000000 --- a/chrome/test/live_sync/live_autofill_sync_test.h +++ /dev/null @@ -1,104 +0,0 @@ -// 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. - -#ifndef CHROME_TEST_LIVE_SYNC_LIVE_AUTOFILL_SYNC_TEST_H_ -#define CHROME_TEST_LIVE_SYNC_LIVE_AUTOFILL_SYNC_TEST_H_ -#pragma once - -#include -#include - -#include "base/compiler_specific.h" -#include "chrome/browser/autofill/personal_data_manager.h" -#include "chrome/test/live_sync/live_sync_test.h" - -class AutofillEntry; -class AutofillKey; -class AutofillProfile; -class WebDataService; - -class LiveAutofillSyncTest : public LiveSyncTest { - public: - 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; - - // Used to access the personal data manager within a particular sync profile. - 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& keys); - // Removes the form field in |key| from the WebDataService of sync profile - // |profile|. - void RemoveKey(int profile, const AutofillKey& key); - - // Gets all the form fields in the WebDataService of sync profile |profile|. - std::set 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; - - // Replaces the Autofill profiles in sync profile |profile| with - // |autofill_profiles|. - void SetProfiles( - int profile, std::vector* autofill_profiles); - - // Adds the autofill profile |autofill_profile| to sync profile |profile|. - 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); - - // 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); - - // Gets all the Autofill profiles in the PersonalDataManager of sync profile - // |profile|. - const std::vector& GetAllProfiles(int profile) - WARN_UNUSED_RESULT; - - // Returns the number of autofill profiles contained by sync profile - // |profile|. - int GetProfileCount(int profile); - - // 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; - - // Compares the autofill profiles for all sync profiles, and returns true if - // they all match. - bool AllProfilesMatch() WARN_UNUSED_RESULT; - - private: - DISALLOW_COPY_AND_ASSIGN(LiveAutofillSyncTest); -}; - -AutofillProfile CreateAutofillProfile(LiveAutofillSyncTest::ProfileType type); - -class TwoClientLiveAutofillSyncTest : public LiveAutofillSyncTest { - public: - TwoClientLiveAutofillSyncTest() : LiveAutofillSyncTest(TWO_CLIENT) {} - virtual ~TwoClientLiveAutofillSyncTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(TwoClientLiveAutofillSyncTest); -}; - -#endif // CHROME_TEST_LIVE_SYNC_LIVE_AUTOFILL_SYNC_TEST_H_ diff --git a/chrome/test/live_sync/performance/autofill_sync_perf_test.cc b/chrome/test/live_sync/performance/autofill_sync_perf_test.cc index 685d7c4..f37d01c 100644 --- a/chrome/test/live_sync/performance/autofill_sync_perf_test.cc +++ b/chrome/test/live_sync/performance/autofill_sync_perf_test.cc @@ -6,7 +6,8 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/autofill/autofill_common_test.h" #include "chrome/browser/sync/profile_sync_service_harness.h" -#include "chrome/test/live_sync/live_autofill_sync_test.h" +#include "chrome/test/live_sync/autofill_helper.h" +#include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/live_sync/performance/sync_timing_helper.h" // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all @@ -17,9 +18,12 @@ static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 500}; -class AutofillSyncPerfTest : public TwoClientLiveAutofillSyncTest { +class AutofillSyncPerfTest : public LiveSyncTest { public: - AutofillSyncPerfTest() : guid_number_(0), name_number_(0) {} + AutofillSyncPerfTest() + : LiveSyncTest(TWO_CLIENT), + guid_number_(0), + name_number_(0) {} // Adds |num_profiles| new autofill profiles to the sync profile |profile|. void AddProfiles(int profile, int num_profiles); @@ -55,9 +59,9 @@ class AutofillSyncPerfTest : public TwoClientLiveAutofillSyncTest { DISALLOW_COPY_AND_ASSIGN(AutofillSyncPerfTest); }; -void AutofillSyncPerfTest::AddProfiles(int profile, - int num_profiles) { - const std::vector& all_profiles = GetAllProfiles(profile); +void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) { + const std::vector& all_profiles = + AutofillHelper::GetAllProfiles(profile); std::vector autofill_profiles; for (size_t i = 0; i < all_profiles.size(); ++i) { autofill_profiles.push_back(*all_profiles[i]); @@ -65,23 +69,24 @@ void AutofillSyncPerfTest::AddProfiles(int profile, for (int i = 0; i < num_profiles; ++i) { autofill_profiles.push_back(NextAutofillProfile()); } - SetProfiles(profile, &autofill_profiles); + AutofillHelper::SetProfiles(profile, &autofill_profiles); } void AutofillSyncPerfTest::UpdateProfiles(int profile) { - const std::vector& all_profiles = GetAllProfiles(profile); + const std::vector& all_profiles = + AutofillHelper::GetAllProfiles(profile); std::vector autofill_profiles; for (size_t i = 0; i < all_profiles.size(); ++i) { autofill_profiles.push_back(*all_profiles[i]); autofill_profiles.back().SetInfo(AutofillFieldType(NAME_FIRST), UTF8ToUTF16(NextName())); } - SetProfiles(profile, &autofill_profiles); + AutofillHelper::SetProfiles(profile, &autofill_profiles); } void AutofillSyncPerfTest::RemoveProfiles(int profile) { std::vector empty; - SetProfiles(profile, &empty); + AutofillHelper::SetProfiles(profile, &empty); } void AutofillSyncPerfTest::Cleanup() { @@ -146,24 +151,24 @@ IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, DISABLED_Benchmark) { AddProfiles(0, num_profiles); base::TimeDelta dt_add = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); - ASSERT_EQ(num_profiles, GetProfileCount(0)); - ASSERT_TRUE(AllProfilesMatch()); + ASSERT_EQ(num_profiles, AutofillHelper::GetProfileCount(0)); + ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); VLOG(0) << std::endl << "Add: " << num_profiles << " " << dt_add.InSecondsF(); UpdateProfiles(0); base::TimeDelta dt_update = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); - ASSERT_EQ(num_profiles, GetProfileCount(0)); - ASSERT_TRUE(AllProfilesMatch()); + ASSERT_EQ(num_profiles, AutofillHelper::GetProfileCount(0)); + ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); VLOG(0) << std::endl << "Update: " << num_profiles << " " << dt_update.InSecondsF(); RemoveProfiles(0); base::TimeDelta dt_delete = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); - ASSERT_EQ(0, GetProfileCount(0)); - ASSERT_TRUE(AllProfilesMatch()); + ASSERT_EQ(0, AutofillHelper::GetProfileCount(0)); + ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); VLOG(0) << std::endl << "Delete: " << num_profiles << " " << dt_delete.InSecondsF(); diff --git a/chrome/test/live_sync/two_client_autofill_sync_test.cc b/chrome/test/live_sync/two_client_autofill_sync_test.cc new file mode 100644 index 0000000..9925e46 --- /dev/null +++ b/chrome/test/live_sync/two_client_autofill_sync_test.cc @@ -0,0 +1,437 @@ +// 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 "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/autofill_helper.h" +#include "chrome/test/live_sync/live_sync_test.h" + +// Autofill entry length is limited to 1024. See http://crbug.com/49332. +const size_t kMaxDataLength = 1024; + +class TwoClientAutofillSyncTest : public LiveSyncTest { + public: + TwoClientAutofillSyncTest() : LiveSyncTest(TWO_CLIENT) {} + virtual ~TwoClientAutofillSyncTest() {} + + private: + DISALLOW_COPY_AND_ASSIGN(TwoClientAutofillSyncTest); +}; + +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, WebDataServiceSanity) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + // Client0 adds a key. + std::set keys; + keys.insert(AutofillKey("name0", "value0")); + AutofillHelper::AddKeys(0, keys); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllKeys(0).size()); + + // Client1 adds a key. + keys.clear(); + keys.insert(AutofillKey("name1", "value1-0")); + AutofillHelper::AddKeys(1, keys); + ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllKeys(0).size()); + + // Client0 adds a key with the same name. + keys.clear(); + keys.insert(AutofillKey("name1", "value1-1")); + AutofillHelper::AddKeys(0, keys); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); + ASSERT_EQ(3U, AutofillHelper::GetAllKeys(0).size()); + + // Client1 removes a key. + AutofillHelper::RemoveKey(1, AutofillKey("name1", "value1-0")); + ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllKeys(0).size()); + + // Client0 removes the rest. + AutofillHelper::RemoveKey(0, AutofillKey("name0", "value0")); + AutofillHelper::RemoveKey(0, AutofillKey("name1", "value1-1")); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); + ASSERT_EQ(0U, AutofillHelper::GetAllKeys(0).size()); +} + +// TCM ID - 3678296. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddUnicodeProfile) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + + std::set keys; + keys.insert(AutofillKey(WideToUTF16(L"Sigur R\u00F3s"), + WideToUTF16(L"\u00C1g\u00E6tis byrjun"))); + AutofillHelper::AddKeys(0, keys); + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); +} + +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, + AddDuplicateNamesToSameProfile) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + + std::set keys; + keys.insert(AutofillKey("name0", "value0-0")); + keys.insert(AutofillKey("name0", "value0-1")); + keys.insert(AutofillKey("name1", "value1")); + AutofillHelper::AddKeys(0, keys); + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllKeys(0).size()); +} + +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, + AddDuplicateNamesToDifferentProfiles) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + + std::set keys0; + keys0.insert(AutofillKey("name0", "value0-0")); + keys0.insert(AutofillKey("name1", "value1")); + AutofillHelper::AddKeys(0, keys0); + + std::set keys1; + keys1.insert(AutofillKey("name0", "value0-1")); + keys1.insert(AutofillKey("name2", "value2")); + keys1.insert(AutofillKey("name3", "value3")); + AutofillHelper::AddKeys(1, keys1); + + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::KeysMatch(0, 1)); + ASSERT_EQ(5U, AutofillHelper::GetAllKeys(0).size()); +} + +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, + PersonalDataManagerSanity) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + // Client0 adds a profile. + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + // Client1 adds a profile. + AutofillHelper::AddProfile( + 1, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_MARION)); + ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllProfiles(0).size()); + + // Client0 adds the same profile. + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_MARION)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllProfiles(0).size()); + + // Client1 removes a profile. + AutofillHelper::RemoveProfile( + 1, AutofillHelper::GetAllProfiles(1)[0]->guid()); + ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + // Client0 updates a profile. + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(NAME_FIRST), + ASCIIToUTF16("Bart")); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + // Client1 removes remaining profile. + AutofillHelper::RemoveProfile( + 1, AutofillHelper::GetAllProfiles(1)[0]->guid()); + ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(0U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 7261786. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddDuplicateProfiles) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3636294. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, SameProfileWithConflict) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + + AutofillProfile profile0 = + AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER); + AutofillProfile profile1 = + AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER); + profile1.SetInfo(PHONE_FAX_WHOLE_NUMBER, ASCIIToUTF16("1234567890")); + + AutofillHelper::AddProfile(0, profile0); + AutofillHelper::AddProfile(1, profile1); + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3626291. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddEmptyProfile) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_NULL)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(0U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3616283. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddProfile) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3632260. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddMultipleProfiles) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_MARION)); + AutofillHelper::AddProfile( + 0, + AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_FRASIER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(3U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3602257. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, DeleteProfile) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + AutofillHelper::RemoveProfile( + 1, AutofillHelper::GetAllProfiles(1)[0]->guid()); + ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(0U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3627300. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, MergeProfiles) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + AutofillHelper::AddProfile( + 1, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_MARION)); + AutofillHelper::AddProfile( + 1, + AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_FRASIER)); + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(3U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3665264. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, UpdateFields) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(NAME_FIRST), + ASCIIToUTF16("Lisa")); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(EMAIL_ADDRESS), + ASCIIToUTF16("grrrl@TV.com")); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3628299. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, ConflictingFields) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(NAME_FIRST), + ASCIIToUTF16("Lisa")); + AutofillHelper::UpdateProfile( + 1, + AutofillHelper::GetAllProfiles(1)[0]->guid(), + AutofillType(NAME_FIRST), + ASCIIToUTF16("Bart")); + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3663293. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, DisableAutofill) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(syncable::AUTOFILL)); + AutofillHelper::AddProfile( + 0, + AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_FRASIER)); + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_FALSE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllProfiles(0).size()); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(1).size()); + + ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(syncable::AUTOFILL)); + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3661291. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, DisableSync) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes()); + AutofillHelper::AddProfile( + 0, + AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_FRASIER)); + ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Added a profile.")); + ASSERT_FALSE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllProfiles(0).size()); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(1).size()); + + ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes()); + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(2U, AutofillHelper::GetAllProfiles(0).size()); +} + +// TCM ID - 3608295. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, MaxLength) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + string16 max_length_string(kMaxDataLength, '.'); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(NAME_FIRST), + max_length_string); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(NAME_LAST), + max_length_string); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(EMAIL_ADDRESS), + max_length_string); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(ADDRESS_HOME_LINE1), + max_length_string); + + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); +} + +// TODO(braffert): Remove FAILS annotation when crbug.com/85769 is resolved. +// TCM ID - 7735472. +IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, FAILS_ExceedsMaxLength) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + AutofillHelper::AddProfile( + 0, AutofillHelper::CreateAutofillProfile(AutofillHelper::PROFILE_HOMER)); + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_TRUE(AutofillHelper::ProfilesMatch(0, 1)); + ASSERT_EQ(1U, AutofillHelper::GetAllProfiles(0).size()); + + string16 exceeds_max_length_string(kMaxDataLength + 1, '.'); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(NAME_FIRST), + exceeds_max_length_string); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(NAME_LAST), + exceeds_max_length_string); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(EMAIL_ADDRESS), + exceeds_max_length_string); + AutofillHelper::UpdateProfile( + 0, + AutofillHelper::GetAllProfiles(0)[0]->guid(), + AutofillType(ADDRESS_HOME_LINE1), + exceeds_max_length_string); + + ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); + ASSERT_FALSE(AutofillHelper::ProfilesMatch(0, 1)); +} 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 deleted file mode 100644 index 1d891fb..0000000 --- a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc +++ /dev/null @@ -1,360 +0,0 @@ -// 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 "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" - -// Autofill entry length is limited to 1024. See http://crbug.com/49332. -const size_t kMaxDataLength = 1024; - -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, WebDataServiceSanity) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - // Client0 adds a key. - std::set keys; - keys.insert(AutofillKey("name0", "value0")); - AddKeys(0, keys); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(KeysMatch(0, 1)); - ASSERT_EQ(1U, GetAllKeys(0).size()); - - // Client1 adds a key. - keys.clear(); - keys.insert(AutofillKey("name1", "value1-0")); - AddKeys(1, keys); - ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); - ASSERT_TRUE(KeysMatch(0, 1)); - ASSERT_EQ(2U, GetAllKeys(0).size()); - - // Client0 adds a key with the same name. - keys.clear(); - keys.insert(AutofillKey("name1", "value1-1")); - AddKeys(0, keys); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(KeysMatch(0, 1)); - ASSERT_EQ(3U, GetAllKeys(0).size()); - - // Client1 removes a key. - RemoveKey(1, AutofillKey("name1", "value1-0")); - ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); - ASSERT_TRUE(KeysMatch(0, 1)); - ASSERT_EQ(2U, GetAllKeys(0).size()); - - // Client0 removes the rest. - RemoveKey(0, AutofillKey("name0", "value0")); - RemoveKey(0, AutofillKey("name1", "value1-1")); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(KeysMatch(0, 1)); - ASSERT_EQ(0U, GetAllKeys(0).size()); -} - -// TCM ID - 3678296. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddUnicodeProfile) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - std::set keys; - keys.insert(AutofillKey(WideToUTF16(L"Sigur R\u00F3s"), - WideToUTF16(L"\u00C1g\u00E6tis byrjun"))); - AddKeys(0, keys); - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_TRUE(KeysMatch(0, 1)); -} - -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, - AddDuplicateNamesToSameProfile) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - std::set keys; - keys.insert(AutofillKey("name0", "value0-0")); - keys.insert(AutofillKey("name0", "value0-1")); - keys.insert(AutofillKey("name1", "value1")); - AddKeys(0, keys); - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_TRUE(KeysMatch(0, 1)); - ASSERT_EQ(2U, GetAllKeys(0).size()); -} - -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, - AddDuplicateNamesToDifferentProfiles) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - std::set keys0; - keys0.insert(AutofillKey("name0", "value0-0")); - keys0.insert(AutofillKey("name1", "value1")); - AddKeys(0, keys0); - - std::set keys1; - keys1.insert(AutofillKey("name0", "value0-1")); - keys1.insert(AutofillKey("name2", "value2")); - keys1.insert(AutofillKey("name3", "value3")); - AddKeys(1, keys1); - - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_TRUE(KeysMatch(0, 1)); - ASSERT_EQ(5U, GetAllKeys(0).size()); -} - -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, - PersonalDataManagerSanity) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - // Client0 adds a profile. - 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(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(LiveAutofillSyncTest::PROFILE_MARION)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(2U, GetAllProfiles(0).size()); - - // Client1 removes a profile. - RemoveProfile(1, GetAllProfiles(1)[0]->guid()); - ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - // Client0 updates a profile. - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), AutofillType(NAME_FIRST), - ASCIIToUTF16("Bart")); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - // Client1 removes remaining profile. - RemoveProfile(1, GetAllProfiles(1)[0]->guid()); - ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(0U, GetAllProfiles(0).size()); -} - -// TCM ID - 7261786. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddDuplicateProfiles) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - 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)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); -} - -// TCM ID - 3636294. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, SameProfileWithConflict) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - AutofillProfile profile0 = - CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER); - AutofillProfile profile1 = - CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER); - profile1.SetInfo(PHONE_FAX_WHOLE_NUMBER, ASCIIToUTF16("1234567890")); - - AddProfile(0, profile0); - AddProfile(1, profile1); - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); -} - -// TCM ID - 3626291. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddEmptyProfile) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_NULL)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(0U, GetAllProfiles(0).size()); -} - -// TCM ID - 3616283. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddProfile) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); -} - -// TCM ID - 3632260. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddMultipleProfiles) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - 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()); -} - -// TCM ID - 3602257. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DeleteProfile) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - RemoveProfile(1, GetAllProfiles(1)[0]->guid()); - ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(0U, GetAllProfiles(0).size()); -} - -// TCM ID - 3627300. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, MergeProfiles) { - ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - - 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)); - ASSERT_EQ(3U, GetAllProfiles(0).size()); -} - -// TCM ID - 3665264. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, UpdateFields) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), AutofillType(NAME_FIRST), - ASCIIToUTF16("Lisa")); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), AutofillType(EMAIL_ADDRESS), - ASCIIToUTF16("grrrl@TV.com")); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); -} - -// TCM ID - 3628299. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ConflictingFields) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), AutofillType(NAME_FIRST), - ASCIIToUTF16("Lisa")); - UpdateProfile(1, GetAllProfiles(1)[0]->guid(), AutofillType(NAME_FIRST), - ASCIIToUTF16("Bart")); - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_TRUE(ProfilesMatch(0,1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); -} - -// TCM ID - 3663293. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DisableAutofill) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0, 1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(syncable::AUTOFILL)); - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_FRASIER)); - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_FALSE(ProfilesMatch(0, 1)); - ASSERT_EQ(2U, GetAllProfiles(0).size()); - ASSERT_EQ(1U, GetAllProfiles(1).size()); - - ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(syncable::AUTOFILL)); - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_TRUE(ProfilesMatch(0, 1)); - ASSERT_EQ(2U, GetAllProfiles(0).size()); -} - -// TCM ID - 3661291. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DisableSync) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0, 1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes()); - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_FRASIER)); - ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Added a profile.")); - ASSERT_FALSE(ProfilesMatch(0, 1)); - ASSERT_EQ(2U, GetAllProfiles(0).size()); - ASSERT_EQ(1U, GetAllProfiles(1).size()); - - ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes()); - ASSERT_TRUE(AwaitQuiescence()); - ASSERT_TRUE(ProfilesMatch(0, 1)); - ASSERT_EQ(2U, GetAllProfiles(0).size()); -} - -// TCM ID - 3608295. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, MaxLength) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0, 1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - string16 max_length_string(kMaxDataLength, '.'); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(NAME_FIRST), max_length_string); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(NAME_LAST), max_length_string); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(EMAIL_ADDRESS), max_length_string); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(ADDRESS_HOME_LINE1), max_length_string); - - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0, 1)); -} - -// See http://crbug.com/85769. -// TODO(braffert): Remove FAILS annotation when bug 85769 is resolved. -// TCM ID - 7735472. -IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, FAILS_ExceedsMaxLength) { - ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - - AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_TRUE(ProfilesMatch(0, 1)); - ASSERT_EQ(1U, GetAllProfiles(0).size()); - - string16 exceeds_max_length_string(kMaxDataLength + 1, '.'); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(NAME_FIRST), exceeds_max_length_string); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(NAME_LAST), exceeds_max_length_string); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(EMAIL_ADDRESS), exceeds_max_length_string); - UpdateProfile(0, GetAllProfiles(0)[0]->guid(), - AutofillType(ADDRESS_HOME_LINE1), exceeds_max_length_string); - - ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); - ASSERT_FALSE(ProfilesMatch(0, 1)); -} -- cgit v1.1