diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 23:49:54 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 23:49:54 +0000 |
commit | ea74cbfce2abdecca936a780e3de567ce397972c (patch) | |
tree | a2e837f23ac916a00a5b343e950903a5da29f0d6 | |
parent | 8476586cdaa1eaaf2f1284bb689b609ee04b48a7 (diff) | |
download | chromium_src-ea74cbfce2abdecca936a780e3de567ce397972c.zip chromium_src-ea74cbfce2abdecca936a780e3de567ce397972c.tar.gz chromium_src-ea74cbfce2abdecca936a780e3de567ce397972c.tar.bz2 |
Revert 63447 - sync: enable password sync by default.
BUG=none
TEST=Enable sync, notice passwords is an option / enabled. unit_tests
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=63223
Review URL: http://codereview.chromium.org/3913005
TBR=tim@chromium.org
Review URL: http://codereview.chromium.org/4543001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65142 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/abstract_profile_sync_service_test.h | 53 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_factory_impl.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_factory_impl_unittest.cc | 38 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_autofill_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_password_unittest.cc | 61 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_session_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_typed_url_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_test_util.h | 32 | ||||
-rw-r--r-- | chrome/browser/sync/test_profile_sync_service.cc | 181 | ||||
-rw-r--r-- | chrome/browser/sync/test_profile_sync_service.h | 145 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 6 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 2 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_test.cc | 5 |
16 files changed, 223 insertions, 319 deletions
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h index d13a3f8..57b3791 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.h +++ b/chrome/browser/sync/abstract_profile_sync_service_test.h @@ -51,28 +51,6 @@ using syncable::WriteTransaction; class ProfileSyncServiceTestHelper { public: - static const std::string GetTagForType(ModelType type) { - switch (type) { - case syncable::AUTOFILL: - return browser_sync::kAutofillTag; - case syncable::PREFERENCES: - return browser_sync::kPreferencesTag; - case syncable::PASSWORDS: - return browser_sync::kPasswordTag; - case syncable::NIGORI: - return browser_sync::kNigoriTag; - case syncable::TYPED_URLS: - return browser_sync::kTypedUrlTag; - case syncable::SESSIONS: - return browser_sync::kSessionsTag; - case syncable::BOOKMARKS: - return "google_chrome_bookmarks"; - default: - NOTREACHED(); - return std::string(); - } - } - static bool CreateRoot(ModelType model_type, ProfileSyncService* service, TestIdFactory* ids) { UserShare* user_share = service->backend()->GetUserShareHandle(); @@ -82,7 +60,30 @@ class ProfileSyncServiceTestHelper { if (!dir.good()) return false; - std::string tag_name = GetTagForType(model_type); + std::string tag_name; + switch (model_type) { + case syncable::AUTOFILL: + tag_name = browser_sync::kAutofillTag; + break; + case syncable::PREFERENCES: + tag_name = browser_sync::kPreferencesTag; + break; + case syncable::PASSWORDS: + tag_name = browser_sync::kPasswordTag; + break; + case syncable::NIGORI: + tag_name = browser_sync::kNigoriTag; + break; + case syncable::TYPED_URLS: + tag_name = browser_sync::kTypedUrlTag; + break; + case syncable::SESSIONS: + tag_name = browser_sync::kSessionsTag; + break; + default: + return false; + } + WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); MutableEntry node(&wtrans, CREATE, @@ -96,7 +97,7 @@ class ProfileSyncServiceTestHelper { node.Put(SERVER_VERSION, 20); node.Put(BASE_VERSION, 20); node.Put(IS_DEL, false); - EXPECT_TRUE(node.Put(syncable::ID, ids->MakeServer(tag_name))); + node.Put(syncable::ID, ids->MakeServer(tag_name)); sync_pb::EntitySpecifics specifics; syncable::AddDefaultExtensionValue(model_type, &specifics); node.Put(SPECIFICS, specifics); @@ -112,8 +113,7 @@ class AbstractProfileSyncServiceTest : public testing::Test { bool CreateRoot(ModelType model_type) { return ProfileSyncServiceTestHelper::CreateRoot(model_type, - service_.get(), - service_->id_factory()); + service_.get(), &ids_); } protected: @@ -123,6 +123,7 @@ class AbstractProfileSyncServiceTest : public testing::Test { ProfileSyncFactoryMock factory_; TokenService token_service_; scoped_ptr<TestProfileSyncService> service_; + TestIdFactory ids_; }; class CreateRootTask : public Task { diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index 0637850..7d833bd 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -120,8 +120,8 @@ void SyncBackendHost::Initialize( // TODO(tim): Remove this special case once NIGORI is populated by // default. We piggy back off of the passwords flag for now to not // require both encryption and passwords flags. - bool enable_encryption = !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableSyncPasswords) || types.count(syncable::PASSWORDS) > 0; + bool enable_encryption = CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableSyncPasswords) || types.count(syncable::PASSWORDS); if (enable_encryption) registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; diff --git a/chrome/browser/sync/profile_sync_factory_impl.cc b/chrome/browser/sync/profile_sync_factory_impl.cc index 2585f71..ed8f429 100644 --- a/chrome/browser/sync/profile_sync_factory_impl.cc +++ b/chrome/browser/sync/profile_sync_factory_impl.cc @@ -111,7 +111,7 @@ ProfileSyncService* ProfileSyncFactoryImpl::CreateProfileSyncService( // Password sync is disabled by default. Register only if // explicitly enabled. - if (!command_line_->HasSwitch(switches::kDisableSyncPasswords)) { + if (command_line_->HasSwitch(switches::kEnableSyncPasswords)) { pss->RegisterDataTypeController( new PasswordDataTypeController(this, profile_, pss)); } diff --git a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc index 2e1a708..f622ef4 100644 --- a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc +++ b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc @@ -43,14 +43,13 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDefault) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(7U, controller_states_ptr->size()); + EXPECT_EQ(6U, controller_states_ptr->size()); EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PASSWORDS)); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) { @@ -60,14 +59,13 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(6U, controller_states_ptr->size()); + EXPECT_EQ(5U, controller_states_ptr->size()); EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PASSWORDS)); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) { @@ -77,14 +75,13 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(6U, controller_states_ptr->size()); + EXPECT_EQ(5U, controller_states_ptr->size()); EXPECT_EQ(0U, controller_states_ptr->count(syncable::BOOKMARKS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PASSWORDS)); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) { @@ -94,14 +91,13 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(6U, controller_states_ptr->size()); + EXPECT_EQ(5U, controller_states_ptr->size()); EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); EXPECT_EQ(0U, controller_states_ptr->count(syncable::PREFERENCES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PASSWORDS)); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) { @@ -111,14 +107,13 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(6U, controller_states_ptr->size()); + EXPECT_EQ(5U, controller_states_ptr->size()); EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); EXPECT_EQ(0U, controller_states_ptr->count(syncable::THEMES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PASSWORDS)); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableExtensions) { @@ -128,14 +123,13 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableExtensions) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(6U, controller_states_ptr->size()); + EXPECT_EQ(5U, controller_states_ptr->size()); EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); EXPECT_EQ(0U, controller_states_ptr->count(syncable::EXTENSIONS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PASSWORDS)); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableApps) { @@ -145,29 +139,11 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableApps) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(6U, controller_states_ptr->size()); + EXPECT_EQ(5U, controller_states_ptr->size()); EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); EXPECT_EQ(0U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PASSWORDS)); -} - -TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePasswords) { - command_line_->AppendSwitch(switches::kDisableSyncPasswords); - scoped_ptr<ProfileSyncService> pss; - pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); - DataTypeController::StateMap controller_states; - DataTypeController::StateMap* controller_states_ptr = &controller_states; - pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(6U, controller_states_ptr->size()); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(0U, controller_states_ptr->count(syncable::PASSWORDS)); } diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 179f438..17354b0 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -421,7 +421,7 @@ class FakeServerUpdater: public base::RefCountedThreadSafe<FakeServerUpdater> { item.Put(SPECIFICS, entity_specifics); item.Put(SERVER_SPECIFICS, entity_specifics); item.Put(BASE_VERSION, 1); - syncable::Id server_parent_id = service_->id_factory()->NewServerId(); + syncable::Id server_parent_id = ids_.NewServerId(); item.Put(syncable::ID, server_parent_id); syncable::Id new_predecessor = SyncerUtil::ComputePrevIdFromServerPosition(&trans, &item, @@ -474,6 +474,7 @@ class FakeServerUpdater: public base::RefCountedThreadSafe<FakeServerUpdater> { scoped_ptr<WaitableEvent> *wait_for_syncapi_; WaitableEvent is_finished_; syncable::Id parent_id_; + TestIdFactory ids_; }; // TODO(skrul): Test abort startup. diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc index fede8a5..43ee1fb 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -185,20 +185,22 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { service_->Initialize(); MessageLoop::current()->Run(); - - EXPECT_CALL(observer_, - Observe( - NotificationType(NotificationType::SYNC_PASSPHRASE_ACCEPTED), - _,_)). - WillOnce(InvokeTask(node_task)); - EXPECT_CALL(observer_, - Observe( - NotificationType(NotificationType::SYNC_CONFIGURE_DONE), - _,_)). - WillOnce(QuitUIMessageLoop()); - service_->SetPassphrase("foo"); - MessageLoop::current()->Run(); - + // Only set the passphrase if we actually created the password and nigori + // root nodes. + if (root_task) { + EXPECT_CALL(observer_, + Observe( + NotificationType(NotificationType::SYNC_PASSPHRASE_ACCEPTED), + _,_)). + WillOnce(InvokeTask(node_task)); + EXPECT_CALL(observer_, + Observe( + NotificationType(NotificationType::SYNC_CONFIGURE_DONE), + _,_)). + WillOnce(QuitUIMessageLoop()); + service_->SetPassphrase("foo"); + MessageLoop::current()->Run(); + } } } @@ -268,6 +270,22 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { scoped_refptr<MockPasswordStore> password_store_; NotificationRegistrar registrar_; + TestIdFactory ids_; +}; + +class CreatePasswordRootTask : public Task { + public: + explicit CreatePasswordRootTask(AbstractProfileSyncServiceTest* test) + : test_(test) { + } + + virtual void Run() { + test_->CreateRoot(syncable::NIGORI); + test_->CreateRoot(syncable::PASSWORDS); + } + + private: + AbstractProfileSyncServiceTest* test_; }; class AddPasswordEntriesTask : public Task { @@ -289,7 +307,10 @@ class AddPasswordEntriesTask : public Task { }; TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { - StartSyncService(NULL, NULL, 1, 2); + // Create the nigori root node so that password model association is + // attempted, but not the password root node so that it fails. + CreateRootTask task(this, syncable::NIGORI); + StartSyncService(&task, NULL, 1, 2); EXPECT_TRUE(service_->unrecoverable_error_detected()); } @@ -299,7 +320,7 @@ TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) .WillOnce(Return(true)); SetIdleChangeProcessorExpectations(); - CreateRootTask task(this, syncable::PASSWORDS); + CreatePasswordRootTask task(this); StartSyncService(&task, NULL); std::vector<PasswordForm> sync_entries; GetPasswordEntriesFromSyncDB(&sync_entries); @@ -329,7 +350,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) .WillOnce(Return(true)); SetIdleChangeProcessorExpectations(); - CreateRootTask task(this, syncable::PASSWORDS); + CreatePasswordRootTask task(this); StartSyncService(&task, NULL); std::vector<PasswordForm> sync_forms; GetPasswordEntriesFromSyncDB(&sync_forms); @@ -381,7 +402,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) .WillOnce(Return(true)); SetIdleChangeProcessorExpectations(); - CreateRootTask task(this, syncable::PASSWORDS); + CreatePasswordRootTask task(this); StartSyncService(&task, NULL); std::vector<PasswordForm> sync_forms; GetPasswordEntriesFromSyncDB(&sync_forms); @@ -436,7 +457,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); - CreateRootTask root_task(this, syncable::PASSWORDS); + CreatePasswordRootTask root_task(this); AddPasswordEntriesTask node_task(this, sync_forms); StartSyncService(&root_task, &node_task); @@ -509,7 +530,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncMergeEntry) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); - CreateRootTask root_task(this, syncable::PASSWORDS); + CreatePasswordRootTask root_task(this); AddPasswordEntriesTask node_task(this, sync_forms); StartSyncService(&root_task, &node_task); diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc index fc0757e..6242f0e 100644 --- a/chrome/browser/sync/profile_sync_service_session_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc @@ -60,7 +60,7 @@ class ProfileSyncServiceSessionTest ProfileSyncService* sync_service() { return sync_service_.get(); } - TestIdFactory* ids() { return sync_service_->id_factory(); } + TestIdFactory* ids() { return &ids_; } protected: SessionService* service() { return helper_.service(); } @@ -134,6 +134,7 @@ class ProfileSyncServiceSessionTest SessionID window_id_; ProfileSyncFactoryMock factory_; scoped_ptr<TestProfileSyncService> sync_service_; + TestIdFactory ids_; const gfx::Rect window_bounds_; bool notified_of_update_; NotificationRegistrar registrar_; diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index c8aa931..17795c6 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -279,6 +279,8 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { ProfileSyncFactoryMock factory_; scoped_refptr<HistoryBackendMock> history_backend_; scoped_refptr<HistoryServiceMock> history_service_; + + TestIdFactory ids_; }; class AddTypedUrlEntriesTask : public Task { diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index 1b57605..0088829 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -55,10 +55,10 @@ using testing::Invoke; class TestBookmarkModelAssociator : public BookmarkModelAssociator { public: - TestBookmarkModelAssociator(TestProfileSyncService* service, + TestBookmarkModelAssociator(ProfileSyncService* service, UnrecoverableErrorHandler* persist_ids_error_handler) : BookmarkModelAssociator(service, persist_ids_error_handler), - helper_(new TestModelAssociatorHelper(service->id_factory())) { + helper_(new TestModelAssociatorHelper()) { } virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { return helper_->GetSyncIdForTaggedNode(this, tag, sync_id); diff --git a/chrome/browser/sync/profile_sync_test_util.h b/chrome/browser/sync/profile_sync_test_util.h index 6e9b77a..aa8584e 100644 --- a/chrome/browser/sync/profile_sync_test_util.h +++ b/chrome/browser/sync/profile_sync_test_util.h @@ -19,13 +19,11 @@ #include "chrome/browser/browser_thread.h" #include "chrome/browser/profile.h" #include "chrome/browser/webdata/web_database.h" -#include "chrome/browser/sync/abstract_profile_sync_service_test.h" #include "chrome/browser/sync/glue/bookmark_change_processor.h" #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" #include "chrome/browser/sync/glue/bookmark_model_associator.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/data_type_manager_impl.h" -#include "chrome/browser/sync/glue/sync_backend_host.h" #include "chrome/browser/sync/profile_sync_factory.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/unrecoverable_error_handler.h" @@ -54,8 +52,6 @@ ACTION_P(InvokeTask, task) { class TestModelAssociatorHelper { public: - TestModelAssociatorHelper(browser_sync::TestIdFactory* id_factory) - : id_factory_(id_factory) {} template <class ModelAssociatorImpl> bool GetSyncIdForTaggedNode(ModelAssociatorImpl* associator, const std::string& tag, int64* sync_id) { @@ -65,32 +61,10 @@ class TestModelAssociatorHelper { return false; } - browser_sync::SyncBackendHost::UserShareHandle share( + sync_api::WriteTransaction trans( associator->sync_service()->backend()->GetUserShareHandle()); - bool root_exists = false; - ModelType type = ModelAssociatorImpl::model_type(); - { - sync_api::WriteTransaction trans(share); - sync_api::ReadNode uber_root(&trans); - uber_root.InitByRootLookup(); - - // Look up the top level data type node. - sync_api::ReadNode root_lookup(&trans); - root_exists = root_lookup.InitByTagLookup( - ProfileSyncServiceTestHelper::GetTagForType(type)); - } - - if (!root_exists) { - bool created = ProfileSyncServiceTestHelper::CreateRoot(type, - associator->sync_service(), id_factory_); - if (!created) - return false; - } - - sync_api::WriteTransaction trans(share); sync_api::ReadNode root(&trans); - EXPECT_TRUE(root.InitByTagLookup( - ProfileSyncServiceTestHelper::GetTagForType(type))); + root.InitByRootLookup(); // First, try to find a node with the title among the root's children. // This will be the case if we are testing model persistence, and @@ -124,8 +98,6 @@ class TestModelAssociatorHelper { } ~TestModelAssociatorHelper() {} - private: - browser_sync::TestIdFactory* id_factory_; }; class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc deleted file mode 100644 index 1ef298f..0000000 --- a/chrome/browser/sync/test_profile_sync_service.cc +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) 2010 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/browser/sync/test_profile_sync_service.h" -#include "chrome/browser/sync/abstract_profile_sync_service_test.h" - -namespace browser_sync { - -SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( - TestProfileSyncService* service, - Profile* profile, - const FilePath& profile_path, - const DataTypeController::TypeMap& data_type_controllers, - Task* initial_condition_setup_task, - int num_expected_resumes, - int num_expected_pauses, - bool set_initial_sync_ended_on_init, - bool synchronous_init) - : browser_sync::SyncBackendHost(service, profile, profile_path, - data_type_controllers), - initial_condition_setup_task_(initial_condition_setup_task), - set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), - synchronous_init_(synchronous_init), - test_service_(service) { - // By default, the RequestPause and RequestResume methods will - // send the confirmation notification and return true. - ON_CALL(*this, RequestPause()). - WillByDefault(testing::DoAll(CallOnPaused(core_), - testing::Return(true))); - ON_CALL(*this, RequestResume()). - WillByDefault(testing::DoAll(CallOnResumed(core_), - testing::Return(true))); - ON_CALL(*this, RequestNudge()).WillByDefault(testing::Invoke(this, - &SyncBackendHostForProfileSyncTest:: - SimulateSyncCycleCompletedInitialSyncEnded)); - - EXPECT_CALL(*this, RequestPause()).Times(num_expected_pauses); - EXPECT_CALL(*this, RequestResume()).Times(num_expected_resumes); - EXPECT_CALL(*this, RequestNudge()). - Times(set_initial_sync_ended_on_init ? 0 : 1); -} - -void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForEnabledTypes() { - UserShare* user_share = core_->syncapi()->GetUserShare(); - DirectoryManager* dir_manager = user_share->dir_manager.get(); - - ScopedDirLookup dir(dir_manager, user_share->name); - if (!dir.good()) - FAIL(); - - ModelSafeRoutingInfo enabled_types; - GetModelSafeRoutingInfo(&enabled_types); - for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); - i != enabled_types.end(); ++i) { - dir->set_initial_sync_ended_for_type(i->first, true); - } -} - -void SyncBackendHostForProfileSyncTest:: - HandleInitializationCompletedOnFrontendLoop() { - set_syncapi_initialized(); // Need to do this asap so task below works. - - // Set up any nodes the test wants around before model association. - if (initial_condition_setup_task_) { - initial_condition_setup_task_->Run(); - } - - // Pretend we downloaded initial updates and set initial sync ended bits - // if we were asked to. - if (set_initial_sync_ended_on_init_) { - UserShare* user_share = core_->syncapi()->GetUserShare(); - DirectoryManager* dir_manager = user_share->dir_manager.get(); - - ScopedDirLookup dir(dir_manager, user_share->name); - if (!dir.good()) - FAIL(); - - // Do this check as some tests load from storage and we don't want to add - // twice. - // TODO(tim): This is madness. Too much test setup code! - if (!dir->initial_sync_ended_for_type(syncable::NIGORI)) { - ProfileSyncServiceTestHelper::CreateRoot( - syncable::NIGORI, test_service_, test_service_->id_factory()); - } - - SetInitialSyncEndedForEnabledTypes(); - } - - SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(); -} - -// Called when a nudge comes in. -void SyncBackendHostForProfileSyncTest:: - SimulateSyncCycleCompletedInitialSyncEnded() { - syncable::ModelTypeBitSet sync_ended; - ModelSafeRoutingInfo enabled_types; - GetModelSafeRoutingInfo(&enabled_types); - for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); - i != enabled_types.end(); ++i) { - sync_ended.set(i->first); - } - core_->HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot( - SyncerStatus(), ErrorCounters(), 0, 0, false, - sync_ended, false, false, 0, 0, false)); -} - -void SyncBackendHostForProfileSyncTest::InitCore( - const Core::DoInitializeOptions& options) { - std::wstring user = L"testuser"; - core_loop()->PostTask(FROM_HERE, - NewRunnableMethod(core_.get(), - &SyncBackendHost::Core::DoInitializeForTest, - user, - options.http_bridge_factory, - options.delete_sync_data_folder)); - - // TODO(akalin): Figure out a better way to do this. - if (synchronous_init_) { - // The SyncBackend posts a task to the current loop when - // initialization completes. - MessageLoop::current()->Run(); - } -} - -void SyncBackendHostForProfileSyncTest:: - SetDefaultExpectationsForWorkerCreation(ProfileMock* profile) { - EXPECT_CALL(*profile, GetPasswordStore(testing::_)). - WillOnce(testing::Return((PasswordStore*)NULL)); - EXPECT_CALL(*profile, GetHistoryService(testing::_)). - WillOnce(testing::Return((HistoryService*)NULL)); -} - -} // namespace browser_sync - -TestProfileSyncService::TestProfileSyncService(ProfileSyncFactory* factory, - Profile* profile, - const std::string& test_user, - bool synchronous_backend_initialization, - Task* initial_condition_setup_task) - : ProfileSyncService(factory, profile, - !test_user.empty() ? - test_user : ""), - synchronous_backend_initialization_( - synchronous_backend_initialization), - synchronous_sync_configuration_(false), - num_expected_resumes_(1), - num_expected_pauses_(1), - initial_condition_setup_task_(initial_condition_setup_task), - set_initial_sync_ended_on_init_(true) { - RegisterPreferences(); - SetSyncSetupCompleted(); -} - -void TestProfileSyncService::CreateBackend() { - backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( - this, profile(), - profile()->GetPath(), data_type_controllers(), - initial_condition_setup_task_.release(), - num_expected_resumes_, num_expected_pauses_, - set_initial_sync_ended_on_init_, - synchronous_backend_initialization_)); -} - -void TestProfileSyncService::OnBackendInitialized() { - ProfileSyncService::OnBackendInitialized(); - // TODO(akalin): Figure out a better way to do this. - if (synchronous_backend_initialization_) { - MessageLoop::current()->Quit(); - } -} - -void TestProfileSyncService::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - ProfileSyncService::Observe(type, source, details); - if (type == NotificationType::SYNC_CONFIGURE_DONE && - !synchronous_sync_configuration_) { - MessageLoop::current()->Quit(); - } -} diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h index b4115ad..3cad8dc 100644 --- a/chrome/browser/sync/test_profile_sync_service.h +++ b/chrome/browser/sync/test_profile_sync_service.h @@ -22,7 +22,6 @@ #include "chrome/common/notification_service.h" #include "chrome/test/profile_mock.h" #include "chrome/test/sync/test_http_bridge_factory.h" -#include "chrome/test/sync/engine/test_id_factory.h" #include "testing/gmock/include/gmock/gmock.h" using browser_sync::ModelSafeRoutingInfo; @@ -34,8 +33,6 @@ using syncable::DirectoryManager; using syncable::ModelType; using syncable::ScopedDirLookup; -class TestProfileSyncService; - ACTION_P(CallOnPaused, core) { core->OnPaused(); }; @@ -63,7 +60,7 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { // this is false, configuring data types will require a syncer nudge. // |synchronous_init| causes initialization to block until the syncapi has // completed setting itself up and called us back. - SyncBackendHostForProfileSyncTest(TestProfileSyncService* service, + SyncBackendHostForProfileSyncTest(SyncFrontend* frontend, Profile* profile, const FilePath& profile_path, const DataTypeController::TypeMap& data_type_controllers, @@ -71,33 +68,114 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { int num_expected_resumes, int num_expected_pauses, bool set_initial_sync_ended_on_init, - bool synchronous_init); + bool synchronous_init) + : browser_sync::SyncBackendHost(frontend, profile, profile_path, + data_type_controllers), + initial_condition_setup_task_(initial_condition_setup_task), + set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), + synchronous_init_(synchronous_init) { + // By default, the RequestPause and RequestResume methods will + // send the confirmation notification and return true. + ON_CALL(*this, RequestPause()). + WillByDefault(testing::DoAll(CallOnPaused(core_), + testing::Return(true))); + ON_CALL(*this, RequestResume()). + WillByDefault(testing::DoAll(CallOnResumed(core_), + testing::Return(true))); + ON_CALL(*this, RequestNudge()).WillByDefault(testing::Invoke(this, + &SyncBackendHostForProfileSyncTest:: + SimulateSyncCycleCompletedInitialSyncEnded)); + + EXPECT_CALL(*this, RequestPause()).Times(num_expected_pauses); + EXPECT_CALL(*this, RequestResume()).Times(num_expected_resumes); + EXPECT_CALL(*this, RequestNudge()). + Times(set_initial_sync_ended_on_init ? 0 : 1); + } MOCK_METHOD0(RequestPause, bool()); MOCK_METHOD0(RequestResume, bool()); MOCK_METHOD0(RequestNudge, void()); - void SetInitialSyncEndedForEnabledTypes(); + void SetInitialSyncEndedForEnabledTypes() { + UserShare* user_share = core_->syncapi()->GetUserShare(); + DirectoryManager* dir_manager = user_share->dir_manager.get(); + + ScopedDirLookup dir(dir_manager, user_share->name); + if (!dir.good()) + FAIL(); + + ModelSafeRoutingInfo enabled_types; + GetModelSafeRoutingInfo(&enabled_types); + for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); + i != enabled_types.end(); ++i) { + dir->set_initial_sync_ended_for_type(i->first, true); + } + } - virtual void HandleInitializationCompletedOnFrontendLoop(); + virtual void HandleInitializationCompletedOnFrontendLoop() { + set_syncapi_initialized(); // Need to do this asap so task below works. + + // Set up any nodes the test wants around before model association. + if (initial_condition_setup_task_) { + initial_condition_setup_task_->Run(); + } + + // Pretend we downloaded initial updates and set initial sync ended bits + // if we were asked to. + if (set_initial_sync_ended_on_init_) + SetInitialSyncEndedForEnabledTypes(); + + SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(); + } // Called when a nudge comes in. - void SimulateSyncCycleCompletedInitialSyncEnded(); + void SimulateSyncCycleCompletedInitialSyncEnded() { + syncable::ModelTypeBitSet sync_ended; + ModelSafeRoutingInfo enabled_types; + GetModelSafeRoutingInfo(&enabled_types); + for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); + i != enabled_types.end(); ++i) { + sync_ended.set(i->first); + } + core_->HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot( + SyncerStatus(), ErrorCounters(), 0, 0, false, + sync_ended, false, false, 0, 0, false)); + } virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( URLRequestContextGetter* getter) { return new browser_sync::TestHttpBridgeFactory; } - virtual void InitCore(const Core::DoInitializeOptions& options); + virtual void InitCore(const Core::DoInitializeOptions& options) { + std::wstring user = L"testuser"; + core_loop()->PostTask(FROM_HERE, + NewRunnableMethod(core_.get(), + &SyncBackendHost::Core::DoInitializeForTest, + user, + options.http_bridge_factory, + options.delete_sync_data_folder)); - static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile); + // TODO(akalin): Figure out a better way to do this. + if (synchronous_init_) { + // The SyncBackend posts a task to the current loop when + // initialization completes. + MessageLoop::current()->Run(); + } + } + + static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile) { + EXPECT_CALL(*profile, GetPasswordStore(testing::_)). + WillOnce(testing::Return((PasswordStore*)NULL)); + EXPECT_CALL(*profile, GetHistoryService(testing::_)). + WillOnce(testing::Return((HistoryService*)NULL)); + } private: Task* initial_condition_setup_task_; bool set_initial_sync_ended_on_init_; bool synchronous_init_; - TestProfileSyncService* test_service_; + }; } // namespace browser_sync @@ -108,16 +186,49 @@ class TestProfileSyncService : public ProfileSyncService { Profile* profile, const std::string& test_user, bool synchronous_backend_initialization, - Task* initial_condition_setup_task); + Task* initial_condition_setup_task) + : ProfileSyncService(factory, profile, + !test_user.empty() ? + test_user : ""), + synchronous_backend_initialization_( + synchronous_backend_initialization), + synchronous_sync_configuration_(false), + num_expected_resumes_(1), + num_expected_pauses_(1), + initial_condition_setup_task_(initial_condition_setup_task), + set_initial_sync_ended_on_init_(true) { + RegisterPreferences(); + SetSyncSetupCompleted(); + } virtual ~TestProfileSyncService() { } - virtual void CreateBackend(); + virtual void CreateBackend() { + backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( + this, profile(), + profile()->GetPath(), data_type_controllers(), + initial_condition_setup_task_.release(), + num_expected_resumes_, num_expected_pauses_, + set_initial_sync_ended_on_init_, + synchronous_backend_initialization_)); + } - virtual void OnBackendInitialized(); + virtual void OnBackendInitialized() { + ProfileSyncService::OnBackendInitialized(); + // TODO(akalin): Figure out a better way to do this. + if (synchronous_backend_initialization_) { + MessageLoop::current()->Quit(); + } + } virtual void Observe(NotificationType type, const NotificationSource& source, - const NotificationDetails& details); + const NotificationDetails& details) { + ProfileSyncService::Observe(type, source, details); + if (type == NotificationType::SYNC_CONFIGURE_DONE && + !synchronous_sync_configuration_) { + MessageLoop::current()->Quit(); + } + } void set_num_expected_resumes(int times) { num_expected_resumes_ = times; @@ -132,8 +243,6 @@ class TestProfileSyncService : public ProfileSyncService { synchronous_sync_configuration_ = true; } - browser_sync::TestIdFactory* id_factory() { return &id_factory_; } - private: // When testing under ChromiumOS, this method must not return an empty // value value in order for the profile sync service to start. @@ -152,8 +261,6 @@ class TestProfileSyncService : public ProfileSyncService { scoped_ptr<Task> initial_condition_setup_task_; bool set_initial_sync_ended_on_init_; - browser_sync::TestIdFactory id_factory_; - }; #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 6af7ca4..522da8e 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1492,7 +1492,6 @@ 'browser/sync/sync_setup_wizard_unittest.cc', 'browser/sync/sync_ui_util_mac_unittest.mm', 'browser/sync/sync_ui_util_unittest.cc', - 'browser/sync/test_profile_sync_service.cc', 'browser/sync/test_profile_sync_service.h', 'browser/sync/util/cryptographer_unittest.cc', 'browser/sync/util/nigori_unittest.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index bdfc7dc..0e6949d 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -290,9 +290,6 @@ const char kDisableSyncBookmarks[] = "disable-sync-bookmarks"; // Disable syncing of extensions. const char kDisableSyncExtensions[] = "disable-sync-extensions"; -// Disable syncing browser passwords. -const char kDisableSyncPasswords[] = "disable-sync-passwords"; - // Disable syncing of preferences. const char kDisableSyncPreferences[] = "disable-sync-preferences"; @@ -497,6 +494,9 @@ const char kEnableSync[] = "enable-sync"; // Enable syncing browser autofill. const char kEnableSyncAutofill[] = "enable-sync-autofill"; +// Enable syncing browser passwords. +const char kEnableSyncPasswords[] = "enable-sync-passwords"; + // Enable syncing browser sessions. const char kEnableSyncSessions[] = "enable-sync-sessions"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 667b603..9f4620f 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -95,7 +95,6 @@ extern const char kDisableSyncApps[]; extern const char kDisableSyncAutofill[]; extern const char kDisableSyncBookmarks[]; extern const char kDisableSyncExtensions[]; -extern const char kDisableSyncPasswords[]; extern const char kDisableSyncPreferences[]; extern const char kDisableSyncThemes[]; extern const char kDisableTabCloseableStateWatcher[]; @@ -152,6 +151,7 @@ extern const char kEnableSnapStart[]; extern const char kEnableStatsTable[]; extern const char kEnableSync[]; extern const char kEnableSyncAutofill[]; +extern const char kEnableSyncPasswords[]; extern const char kEnableSyncPreferences[]; extern const char kEnableSyncSessions[]; extern const char kEnableSyncTypedUrls[]; diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc index 6af591b..2ae08cc 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -123,6 +123,11 @@ void LiveSyncTest::SetUp() { cl->AppendSwitch(switches::kEnableSyncSessions); } + // TODO(sync): Remove this once passwords sync is enabled by default. + if (!cl->HasSwitch(switches::kEnableSyncPasswords)) { + cl->AppendSwitch(switches::kEnableSyncPasswords); + } + // Mock the Mac Keychain service. The real Keychain can block on user input. #if defined(OS_MACOSX) Encryptor::UseMockKeychain(true); |