diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-21 23:11:57 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-21 23:11:57 +0000 |
commit | 3a8d2de3be5629f532f4b26a4ddb7c0961cb25d7 (patch) | |
tree | 267401c3af60f1cb901af38708318e5be2b4dfc0 | |
parent | 45e9e90c4c7b6cb70f1cfdb647b726fcdbd5e9fa (diff) | |
download | chromium_src-3a8d2de3be5629f532f4b26a4ddb7c0961cb25d7.zip chromium_src-3a8d2de3be5629f532f4b26a4ddb7c0961cb25d7.tar.gz chromium_src-3a8d2de3be5629f532f4b26a4ddb7c0961cb25d7.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63447 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, 319 insertions, 223 deletions
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h index 57b3791..d13a3f8 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.h +++ b/chrome/browser/sync/abstract_profile_sync_service_test.h @@ -51,39 +51,38 @@ using syncable::WriteTransaction; class ProfileSyncServiceTestHelper { public: - static bool CreateRoot(ModelType model_type, ProfileSyncService* service, - TestIdFactory* ids) { - UserShare* user_share = service->backend()->GetUserShareHandle(); - DirectoryManager* dir_manager = user_share->dir_manager.get(); - - ScopedDirLookup dir(dir_manager, user_share->name); - if (!dir.good()) - return false; - - std::string tag_name; - switch (model_type) { + static const std::string GetTagForType(ModelType type) { + switch (type) { case syncable::AUTOFILL: - tag_name = browser_sync::kAutofillTag; - break; + return browser_sync::kAutofillTag; case syncable::PREFERENCES: - tag_name = browser_sync::kPreferencesTag; - break; + return browser_sync::kPreferencesTag; case syncable::PASSWORDS: - tag_name = browser_sync::kPasswordTag; - break; + return browser_sync::kPasswordTag; case syncable::NIGORI: - tag_name = browser_sync::kNigoriTag; - break; + return browser_sync::kNigoriTag; case syncable::TYPED_URLS: - tag_name = browser_sync::kTypedUrlTag; - break; + return browser_sync::kTypedUrlTag; case syncable::SESSIONS: - tag_name = browser_sync::kSessionsTag; - break; + return browser_sync::kSessionsTag; + case syncable::BOOKMARKS: + return "google_chrome_bookmarks"; default: - return false; + NOTREACHED(); + return std::string(); } + } + + static bool CreateRoot(ModelType model_type, ProfileSyncService* service, + TestIdFactory* ids) { + UserShare* user_share = service->backend()->GetUserShareHandle(); + DirectoryManager* dir_manager = user_share->dir_manager.get(); + + ScopedDirLookup dir(dir_manager, user_share->name); + if (!dir.good()) + return false; + std::string tag_name = GetTagForType(model_type); WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); MutableEntry node(&wtrans, CREATE, @@ -97,7 +96,7 @@ class ProfileSyncServiceTestHelper { node.Put(SERVER_VERSION, 20); node.Put(BASE_VERSION, 20); node.Put(IS_DEL, false); - node.Put(syncable::ID, ids->MakeServer(tag_name)); + EXPECT_TRUE(node.Put(syncable::ID, ids->MakeServer(tag_name))); sync_pb::EntitySpecifics specifics; syncable::AddDefaultExtensionValue(model_type, &specifics); node.Put(SPECIFICS, specifics); @@ -113,7 +112,8 @@ class AbstractProfileSyncServiceTest : public testing::Test { bool CreateRoot(ModelType model_type) { return ProfileSyncServiceTestHelper::CreateRoot(model_type, - service_.get(), &ids_); + service_.get(), + service_->id_factory()); } protected: @@ -123,7 +123,6 @@ 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 7d833bd..0637850 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::kEnableSyncPasswords) || types.count(syncable::PASSWORDS); + bool enable_encryption = !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableSyncPasswords) || types.count(syncable::PASSWORDS) > 0; 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 ed8f429..2585f71 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::kEnableSyncPasswords)) { + if (!command_line_->HasSwitch(switches::kDisableSyncPasswords)) { 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 f622ef4..2e1a708 100644 --- a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc +++ b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc @@ -43,13 +43,14 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDefault) { 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(7U, 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) { @@ -59,13 +60,14 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(5U, 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(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) { @@ -75,13 +77,14 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(5U, controller_states_ptr->size()); + EXPECT_EQ(6U, 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) { @@ -91,13 +94,14 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(5U, controller_states_ptr->size()); + EXPECT_EQ(6U, 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) { @@ -107,13 +111,14 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(5U, 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(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) { @@ -123,13 +128,14 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableExtensions) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(5U, 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(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) { @@ -139,11 +145,29 @@ TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableApps) { DataTypeController::StateMap controller_states; DataTypeController::StateMap* controller_states_ptr = &controller_states; pss->GetDataTypeControllerStates(controller_states_ptr); - EXPECT_EQ(5U, 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(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 e541380..536c5a8 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -420,7 +420,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 = ids_.NewServerId(); + syncable::Id server_parent_id = service_->id_factory()->NewServerId(); item.Put(syncable::ID, server_parent_id); syncable::Id new_predecessor = SyncerUtil::ComputePrevIdFromServerPosition(&trans, &item, @@ -473,7 +473,6 @@ 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 43ee1fb..fede8a5 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -185,22 +185,20 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { service_->Initialize(); 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(); - } + + 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(); + } } @@ -270,22 +268,6 @@ 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 { @@ -307,10 +289,7 @@ class AddPasswordEntriesTask : public Task { }; TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { - // 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); + StartSyncService(NULL, NULL, 1, 2); EXPECT_TRUE(service_->unrecoverable_error_detected()); } @@ -320,7 +299,7 @@ TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) .WillOnce(Return(true)); SetIdleChangeProcessorExpectations(); - CreatePasswordRootTask task(this); + CreateRootTask task(this, syncable::PASSWORDS); StartSyncService(&task, NULL); std::vector<PasswordForm> sync_entries; GetPasswordEntriesFromSyncDB(&sync_entries); @@ -350,7 +329,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) .WillOnce(Return(true)); SetIdleChangeProcessorExpectations(); - CreatePasswordRootTask task(this); + CreateRootTask task(this, syncable::PASSWORDS); StartSyncService(&task, NULL); std::vector<PasswordForm> sync_forms; GetPasswordEntriesFromSyncDB(&sync_forms); @@ -402,7 +381,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) .WillOnce(Return(true)); SetIdleChangeProcessorExpectations(); - CreatePasswordRootTask task(this); + CreateRootTask task(this, syncable::PASSWORDS); StartSyncService(&task, NULL); std::vector<PasswordForm> sync_forms; GetPasswordEntriesFromSyncDB(&sync_forms); @@ -457,7 +436,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); - CreatePasswordRootTask root_task(this); + CreateRootTask root_task(this, syncable::PASSWORDS); AddPasswordEntriesTask node_task(this, sync_forms); StartSyncService(&root_task, &node_task); @@ -530,7 +509,7 @@ TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncMergeEntry) { EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); - CreatePasswordRootTask root_task(this); + CreateRootTask root_task(this, syncable::PASSWORDS); 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 0a5ee55..77790e4 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 &ids_; } + TestIdFactory* ids() { return sync_service_->id_factory(); } protected: SessionService* service() { return helper_.service(); } @@ -134,7 +134,6 @@ 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 f913433..0224291 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -279,8 +279,6 @@ 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 d34c5e6..2db71ad 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -54,10 +54,10 @@ using testing::Invoke; class TestBookmarkModelAssociator : public BookmarkModelAssociator { public: - TestBookmarkModelAssociator(ProfileSyncService* service, + TestBookmarkModelAssociator(TestProfileSyncService* service, UnrecoverableErrorHandler* persist_ids_error_handler) : BookmarkModelAssociator(service, persist_ids_error_handler), - helper_(new TestModelAssociatorHelper()) { + helper_(new TestModelAssociatorHelper(service->id_factory())) { } 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 aa8584e..6e9b77a 100644 --- a/chrome/browser/sync/profile_sync_test_util.h +++ b/chrome/browser/sync/profile_sync_test_util.h @@ -19,11 +19,13 @@ #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" @@ -52,6 +54,8 @@ 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) { @@ -61,10 +65,32 @@ class TestModelAssociatorHelper { return false; } - sync_api::WriteTransaction trans( + browser_sync::SyncBackendHost::UserShareHandle share( 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); - root.InitByRootLookup(); + EXPECT_TRUE(root.InitByTagLookup( + ProfileSyncServiceTestHelper::GetTagForType(type))); // 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 @@ -98,6 +124,8 @@ 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 new file mode 100644 index 0000000..1ef298f --- /dev/null +++ b/chrome/browser/sync/test_profile_sync_service.cc @@ -0,0 +1,181 @@ +// 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 3cad8dc..b4115ad 100644 --- a/chrome/browser/sync/test_profile_sync_service.h +++ b/chrome/browser/sync/test_profile_sync_service.h @@ -22,6 +22,7 @@ #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; @@ -33,6 +34,8 @@ using syncable::DirectoryManager; using syncable::ModelType; using syncable::ScopedDirLookup; +class TestProfileSyncService; + ACTION_P(CallOnPaused, core) { core->OnPaused(); }; @@ -60,7 +63,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(SyncFrontend* frontend, + SyncBackendHostForProfileSyncTest(TestProfileSyncService* service, Profile* profile, const FilePath& profile_path, const DataTypeController::TypeMap& data_type_controllers, @@ -68,114 +71,33 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { int num_expected_resumes, int num_expected_pauses, bool set_initial_sync_ended_on_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); - } + bool synchronous_init); MOCK_METHOD0(RequestPause, bool()); MOCK_METHOD0(RequestResume, bool()); MOCK_METHOD0(RequestNudge, void()); - 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); - } - } + void SetInitialSyncEndedForEnabledTypes(); - 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(); - } + virtual void HandleInitializationCompletedOnFrontendLoop(); // Called when a nudge comes in. - 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)); - } + void SimulateSyncCycleCompletedInitialSyncEnded(); virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( URLRequestContextGetter* getter) { return new browser_sync::TestHttpBridgeFactory; } - 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)); + virtual void InitCore(const Core::DoInitializeOptions& options); - // 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)); - } + static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile); private: Task* initial_condition_setup_task_; bool set_initial_sync_ended_on_init_; bool synchronous_init_; - + TestProfileSyncService* test_service_; }; } // namespace browser_sync @@ -186,49 +108,16 @@ class TestProfileSyncService : public ProfileSyncService { 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(); - } + Task* initial_condition_setup_task); virtual ~TestProfileSyncService() { } - 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 CreateBackend(); - virtual void OnBackendInitialized() { - ProfileSyncService::OnBackendInitialized(); - // TODO(akalin): Figure out a better way to do this. - if (synchronous_backend_initialization_) { - MessageLoop::current()->Quit(); - } - } + virtual void OnBackendInitialized(); virtual void 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(); - } - } + const NotificationDetails& details); void set_num_expected_resumes(int times) { num_expected_resumes_ = times; @@ -243,6 +132,8 @@ 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. @@ -261,6 +152,8 @@ 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 704171d..acdd862 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1470,6 +1470,7 @@ '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 987a460..e2e36b5 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -293,6 +293,9 @@ 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"; @@ -489,9 +492,6 @@ 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 faf7797..14e3ae3 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -96,6 +96,7 @@ 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[]; @@ -150,7 +151,6 @@ 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 eca363e..7c0bc51 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -118,11 +118,6 @@ void LiveSyncTest::SetUp() { cl->AppendSwitch(switches::kSyncUseSslTcp); } - // 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); |