| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 12 #include "chrome/browser/sync/managed_user_signin_manager_wrapper.h" |
| 12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 13 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 14 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 17 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 19 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 18 #include "components/sync_driver/data_type_controller.h" | 20 #include "components/sync_driver/data_type_controller.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "google_apis/gaia/gaia_constants.h" |
| 23 #include "google_apis/gaia/oauth2_token_service.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/app_list/app_list_switches.h" | 25 #include "ui/app_list/app_list_switches.h" |
| 22 | 26 |
| 23 using browser_sync::DataTypeController; | 27 using browser_sync::DataTypeController; |
| 24 using content::BrowserThread; | 28 |
| 29 const char kAccountId[] = "testuser@test.com"; |
| 25 | 30 |
| 26 class ProfileSyncComponentsFactoryImplTest : public testing::Test { | 31 class ProfileSyncComponentsFactoryImplTest : public testing::Test { |
| 27 protected: | 32 protected: |
| 28 ProfileSyncComponentsFactoryImplTest() | 33 ProfileSyncComponentsFactoryImplTest() |
| 29 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 34 : thread_bundle_(content::TestBrowserThreadBundle::DEFAULT) {} |
| 30 | 35 |
| 31 virtual void SetUp() { | 36 virtual void SetUp() { |
| 32 profile_.reset(new TestingProfile()); | 37 profile_.reset(new TestingProfile()); |
| 33 base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); | 38 base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); |
| 34 command_line_.reset(new CommandLine(program_path)); | 39 command_line_.reset(new CommandLine(program_path)); |
| 40 scope_set_.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
| 35 } | 41 } |
| 36 | 42 |
| 37 // Returns the collection of default datatypes. | 43 // Returns the collection of default datatypes. |
| 38 static std::vector<syncer::ModelType> DefaultDatatypes() { | 44 static std::vector<syncer::ModelType> DefaultDatatypes() { |
| 39 std::vector<syncer::ModelType> datatypes; | 45 std::vector<syncer::ModelType> datatypes; |
| 40 datatypes.push_back(syncer::APPS); | 46 datatypes.push_back(syncer::APPS); |
| 41 #if defined(ENABLE_APP_LIST) | 47 #if defined(ENABLE_APP_LIST) |
| 42 if (app_list::switches::IsAppListSyncEnabled()) | 48 if (app_list::switches::IsAppListSyncEnabled()) |
| 43 datatypes.push_back(syncer::APP_LIST); | 49 datatypes.push_back(syncer::APP_LIST); |
| 44 #endif | 50 #endif |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 EXPECT_EQ(1U, map->count(*iter)) | 95 EXPECT_EQ(1U, map->count(*iter)) |
| 90 << *iter << " not found in datatypes map"; | 96 << *iter << " not found in datatypes map"; |
| 91 } | 97 } |
| 92 } | 98 } |
| 93 | 99 |
| 94 // Asserts that if you disable types via the command line, all other types | 100 // Asserts that if you disable types via the command line, all other types |
| 95 // are enabled. | 101 // are enabled. |
| 96 void TestSwitchDisablesType(syncer::ModelTypeSet types) { | 102 void TestSwitchDisablesType(syncer::ModelTypeSet types) { |
| 97 command_line_->AppendSwitchASCII(switches::kDisableSyncTypes, | 103 command_line_->AppendSwitchASCII(switches::kDisableSyncTypes, |
| 98 syncer::ModelTypeSetToString(types)); | 104 syncer::ModelTypeSetToString(types)); |
| 99 scoped_ptr<ProfileSyncService> pss( | 105 GURL sync_service_url = |
| 100 new ProfileSyncService( | 106 ProfileSyncService::GetSyncServiceURL(*command_line_); |
| 101 new ProfileSyncComponentsFactoryImpl(profile_.get(), | 107 ProfileOAuth2TokenService* token_service = |
| 102 command_line_.get()), | 108 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
| 109 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |
| 110 new ProfileSyncComponentsFactoryImpl( |
| 103 profile_.get(), | 111 profile_.get(), |
| 104 NULL, | 112 command_line_.get(), |
| 105 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()), | 113 ProfileSyncService::GetSyncServiceURL(*command_line_), |
| 106 browser_sync::MANUAL_START)); | 114 kAccountId, |
| 115 scope_set_, |
| 116 token_service, |
| 117 profile_->GetRequestContext()), |
| 118 profile_.get(), |
| 119 make_scoped_ptr<ManagedUserSigninManagerWrapper>(NULL), |
| 120 token_service, |
| 121 browser_sync::MANUAL_START)); |
| 107 pss->factory()->RegisterDataTypes(pss.get()); | 122 pss->factory()->RegisterDataTypes(pss.get()); |
| 108 DataTypeController::StateMap controller_states; | 123 DataTypeController::StateMap controller_states; |
| 109 pss->GetDataTypeControllerStates(&controller_states); | 124 pss->GetDataTypeControllerStates(&controller_states); |
| 110 EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); | 125 EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); |
| 111 CheckDefaultDatatypesInMapExcept(&controller_states, types); | 126 CheckDefaultDatatypesInMapExcept(&controller_states, types); |
| 112 } | 127 } |
| 113 | 128 |
| 114 base::MessageLoop message_loop_; | 129 content::TestBrowserThreadBundle thread_bundle_; |
| 115 content::TestBrowserThread ui_thread_; | |
| 116 scoped_ptr<Profile> profile_; | 130 scoped_ptr<Profile> profile_; |
| 117 scoped_ptr<CommandLine> command_line_; | 131 scoped_ptr<CommandLine> command_line_; |
| 132 OAuth2TokenService::ScopeSet scope_set_; |
| 118 }; | 133 }; |
| 119 | 134 |
| 120 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { | 135 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { |
| 136 ProfileOAuth2TokenService* token_service = |
| 137 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
| 121 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( | 138 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |
| 122 new ProfileSyncComponentsFactoryImpl(profile_.get(), command_line_.get()), | 139 new ProfileSyncComponentsFactoryImpl( |
| 140 profile_.get(), |
| 141 command_line_.get(), |
| 142 ProfileSyncService::GetSyncServiceURL(*command_line_), |
| 143 kAccountId, |
| 144 scope_set_, |
| 145 token_service, |
| 146 profile_->GetRequestContext()), |
| 123 profile_.get(), | 147 profile_.get(), |
| 124 NULL, | 148 make_scoped_ptr<ManagedUserSigninManagerWrapper>(NULL), |
| 125 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()), | 149 token_service, |
| 126 browser_sync::MANUAL_START)); | 150 browser_sync::MANUAL_START)); |
| 127 pss->factory()->RegisterDataTypes(pss.get()); | 151 pss->factory()->RegisterDataTypes(pss.get()); |
| 128 DataTypeController::StateMap controller_states; | 152 DataTypeController::StateMap controller_states; |
| 129 pss->GetDataTypeControllerStates(&controller_states); | 153 pss->GetDataTypeControllerStates(&controller_states); |
| 130 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); | 154 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |
| 131 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); | 155 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); |
| 132 } | 156 } |
| 133 | 157 |
| 134 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) { | 158 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) { |
| 135 TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL)); | 159 TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL)); |
| 136 } | 160 } |
| 137 | 161 |
| 138 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) { | 162 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) { |
| 139 TestSwitchDisablesType( | 163 TestSwitchDisablesType( |
| 140 syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS)); | 164 syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS)); |
| 141 } | 165 } |
| OLD | NEW |