diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-15 01:49:54 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-15 01:49:54 +0000 |
commit | 3fd04f5fba94f0312e1ba5da0aca9fdd56578145 (patch) | |
tree | 09f7c30f34f9f89dd32e0048bd328ab3b7583c57 /chrome/browser | |
parent | 3372d98ec174306ff2beb1942216200ad3c8722b (diff) | |
download | chromium_src-3fd04f5fba94f0312e1ba5da0aca9fdd56578145.zip chromium_src-3fd04f5fba94f0312e1ba5da0aca9fdd56578145.tar.gz chromium_src-3fd04f5fba94f0312e1ba5da0aca9fdd56578145.tar.bz2 |
Turn password sync on by default.
BUG=61252
TEST=none
Review URL: http://codereview.chromium.org/6249006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71534 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
12 files changed, 254 insertions, 231 deletions
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h index b5fc1c2..a0f1276 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.h +++ b/chrome/browser/sync/abstract_profile_sync_service_test.h @@ -52,41 +52,40 @@ 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; + static const std::string GetTagForType(ModelType model_type) { switch (model_type) { case syncable::AUTOFILL: - tag_name = browser_sync::kAutofillTag; - break; + return browser_sync::kAutofillTag; case syncable::AUTOFILL_PROFILE: - tag_name = browser_sync::kAutofillProfileTag; - break; + return browser_sync::kAutofillProfileTag; 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, @@ -117,7 +116,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: @@ -127,7 +127,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 fcfb8fc9..3c3c8d8 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -130,8 +130,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); 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 79864f0..c6e0268 100644 --- a/chrome/browser/sync/profile_sync_factory_impl.cc +++ b/chrome/browser/sync/profile_sync_factory_impl.cc @@ -116,7 +116,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 daf43ae..a3b9e05d 100644 --- a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc +++ b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <vector> + #include "testing/gtest/include/gtest/gtest.h" #include "base/command_line.h" #include "base/file_path.h" @@ -30,6 +32,56 @@ class ProfileSyncFactoryImplTest : public testing::Test { new ProfileSyncFactoryImpl(profile_.get(), command_line_.get())); } + // Returns the collection of default datatypes. + static std::vector<syncable::ModelType> DefaultDatatypes() { + std::vector<syncable::ModelType> datatypes; + datatypes.push_back(syncable::BOOKMARKS); + datatypes.push_back(syncable::PREFERENCES); + datatypes.push_back(syncable::AUTOFILL); + datatypes.push_back(syncable::THEMES); + datatypes.push_back(syncable::EXTENSIONS); + datatypes.push_back(syncable::APPS); + datatypes.push_back(syncable::AUTOFILL_PROFILE); + datatypes.push_back(syncable::PASSWORDS); + return datatypes; + } + + // Returns the number of default datatypes. + static size_t DefaultDatatypesCount() { + return DefaultDatatypes().size(); + } + + // Asserts that all the default datatypes are in |map|, except + // for |exception_type|, which unless it is UNDEFINED, is asserted to + // not be in |map|. + static void CheckDefaultDatatypesInMapExcept( + DataTypeController::StateMap* map, + syncable::ModelType exception_type) { + std::vector<syncable::ModelType> defaults = DefaultDatatypes(); + std::vector<syncable::ModelType>::iterator iter; + for (iter = defaults.begin(); iter != defaults.end(); ++iter) { + if (exception_type != syncable::UNSPECIFIED && exception_type == *iter) + EXPECT_EQ(0U, map->count(*iter)) + << *iter << " found in dataypes map, shouldn't be there."; + else + EXPECT_EQ(1U, map->count(*iter)) + << *iter << " not found in datatypes map"; + } + } + + // Asserts that if you apply the command line switch |cmd_switch|, + // all types are enabled except for |type|, which is disabled. + void TestSwitchDisablesType(const char* cmd_switch, + syncable::ModelType type) { + command_line_->AppendSwitch(cmd_switch); + scoped_ptr<ProfileSyncService> pss( + profile_sync_service_factory_->CreateProfileSyncService("")); + DataTypeController::StateMap controller_states; + pss->GetDataTypeControllerStates(&controller_states); + EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size()); + CheckDefaultDatatypesInMapExcept(&controller_states, type); + } + MessageLoop message_loop_; BrowserThread ui_thread_; scoped_ptr<Profile> profile_; @@ -38,136 +90,50 @@ class ProfileSyncFactoryImplTest : public testing::Test { }; TEST_F(ProfileSyncFactoryImplTest, CreatePSSDefault) { - scoped_ptr<ProfileSyncService> pss; - pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); + scoped_ptr<ProfileSyncService> pss( + profile_sync_service_factory_->CreateProfileSyncService("")); 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(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::AUTOFILL_PROFILE)); + pss->GetDataTypeControllerStates(&controller_states); + EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); + CheckDefaultDatatypesInMapExcept(&controller_states, syncable::UNSPECIFIED); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) { - command_line_->AppendSwitch(switches::kDisableSyncAutofill); - 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(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::AUTOFILL_PROFILE)); + TestSwitchDisablesType(switches::kDisableSyncAutofill, + syncable::AUTOFILL); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) { - command_line_->AppendSwitch(switches::kDisableSyncBookmarks); - 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(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::AUTOFILL_PROFILE)); + TestSwitchDisablesType(switches::kDisableSyncBookmarks, + syncable::BOOKMARKS); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) { - command_line_->AppendSwitch(switches::kDisableSyncPreferences); - 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(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::AUTOFILL_PROFILE)); + TestSwitchDisablesType(switches::kDisableSyncPreferences, + syncable::PREFERENCES); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) { - command_line_->AppendSwitch(switches::kDisableSyncThemes); - 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(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::AUTOFILL_PROFILE)); + TestSwitchDisablesType(switches::kDisableSyncThemes, + syncable::THEMES); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableExtensions) { - command_line_->AppendSwitch(switches::kDisableSyncExtensions); - 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(0U, controller_states_ptr->count(syncable::EXTENSIONS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); + TestSwitchDisablesType(switches::kDisableSyncExtensions, + syncable::EXTENSIONS); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableApps) { - command_line_->AppendSwitch(switches::kDisableSyncApps); - 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(0U, controller_states_ptr->count(syncable::APPS)); - EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); + TestSwitchDisablesType(switches::kDisableSyncApps, + syncable::APPS); } TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofillProfile) { - command_line_->AppendSwitch(switches::kDisableSyncAutofillProfile); - 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::AUTOFILL_PROFILE)); + TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, + syncable::AUTOFILL_PROFILE); +} + +TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePasswords) { + TestSwitchDisablesType(switches::kDisableSyncPasswords, + 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 0342474..b4e8162 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -547,7 +547,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, @@ -600,7 +600,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 632c3d9..3b202d2 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -178,22 +178,21 @@ 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", false, true); - 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", false, true); + MessageLoop::current()->Run(); } } @@ -263,22 +262,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 { @@ -300,10 +283,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()); } @@ -313,7 +293,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); @@ -343,7 +323,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); @@ -395,7 +375,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); @@ -450,7 +430,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); @@ -523,7 +503,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 d235259..3023d6b 100644 --- a/chrome/browser/sync/profile_sync_service_session_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc @@ -59,7 +59,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(); } @@ -133,7 +133,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 98b70c0..2ee601f 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 236c7a5..5c85c1d 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 4e28efa..80d1fbf 100644 --- a/chrome/browser/sync/profile_sync_test_util.h +++ b/chrome/browser/sync/profile_sync_test_util.h @@ -18,11 +18,13 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.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" @@ -51,6 +53,10 @@ 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) { @@ -60,10 +66,33 @@ 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(); + + sync_api::ReadNode root(&trans); + root_exists = root.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 @@ -97,6 +126,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..d93e63b --- /dev/null +++ b/chrome/browser/sync/test_profile_sync_service.cc @@ -0,0 +1,78 @@ +// 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/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::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(); + + if (!dir->initial_sync_ended_for_type(syncable::NIGORI)) { + ProfileSyncServiceTestHelper::CreateRoot( + syncable::NIGORI, test_service_, test_service_->id_factory()); + } + + SetInitialSyncEndedForEnabledTypes(); + } + + SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(); + } + + + +} // namespace diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h index 0866761..0416006 100644 --- a/chrome/browser/sync/test_profile_sync_service.h +++ b/chrome/browser/sync/test_profile_sync_service.h @@ -20,9 +20,11 @@ #include "chrome/browser/sync/syncable/syncable.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" class Profile; +class TestProfileSyncService; using browser_sync::ModelSafeRoutingInfo; using browser_sync::sessions::ErrorCounters; @@ -60,7 +62,8 @@ 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,29 +71,7 @@ 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()); @@ -118,22 +99,6 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { SyncBackendHost::ConfigureDataTypes(types, ready_task); } - 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() { syncable::ModelTypeBitSet sync_ended; @@ -149,6 +114,8 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { sync_ended, download_progress_markers, false, false, 0, 0, false)); } + virtual void HandleInitializationCompletedOnFrontendLoop(); + virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( URLRequestContextGetter* getter) { return new browser_sync::TestHttpBridgeFactory; @@ -185,6 +152,7 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { Task* initial_condition_setup_task_; bool set_initial_sync_ended_on_init_; bool synchronous_init_; + TestProfileSyncService* test_service_; }; } // namespace browser_sync @@ -252,6 +220,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. @@ -270,6 +240,9 @@ 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_ |