| 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/signin/signin_manager.h" | 9 #include "chrome/browser/signin/signin_manager.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 SigninManagerFactory::GetForProfile(profile_.get()); | 97 SigninManagerFactory::GetForProfile(profile_.get()); |
| 98 signin->SetAuthenticatedUsername("test"); | 98 signin->SetAuthenticatedUsername("test"); |
| 99 ProfileSyncComponentsFactoryMock* factory = | 99 ProfileSyncComponentsFactoryMock* factory = |
| 100 new ProfileSyncComponentsFactoryMock(); | 100 new ProfileSyncComponentsFactoryMock(); |
| 101 service_.reset(new TestProfileSyncService( | 101 service_.reset(new TestProfileSyncService( |
| 102 factory, | 102 factory, |
| 103 profile_.get(), | 103 profile_.get(), |
| 104 signin, | 104 signin, |
| 105 ProfileSyncService::AUTO_START, | 105 ProfileSyncService::AUTO_START, |
| 106 true, | 106 true, |
| 107 base::Closure())); | 107 TestProfileSyncService::NullCallback())); |
| 108 if (!set_initial_sync_ended) | 108 if (!set_initial_sync_ended) |
| 109 service_->dont_set_initial_sync_ended_on_init(); | 109 service_->dont_set_initial_sync_ended_on_init(); |
| 110 if (synchronous_sync_configuration) | 110 if (synchronous_sync_configuration) |
| 111 service_->set_synchronous_sync_configuration(); | 111 service_->set_synchronous_sync_configuration(); |
| 112 if (use_real_database) | 112 if (use_real_database) |
| 113 service_->set_use_real_database(); | 113 service_->set_use_real_database(); |
| 114 if (!sync_setup_completed) | 114 if (!sync_setup_completed) |
| 115 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); | 115 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); |
| 116 | 116 |
| 117 if (expect_create_dtm) { | 117 if (expect_create_dtm) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 TEST_F(ProfileSyncServiceTest, InitialState) { | 155 TEST_F(ProfileSyncServiceTest, InitialState) { |
| 156 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); | 156 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); |
| 157 service_.reset(new TestProfileSyncService( | 157 service_.reset(new TestProfileSyncService( |
| 158 new ProfileSyncComponentsFactoryMock(), | 158 new ProfileSyncComponentsFactoryMock(), |
| 159 profile_.get(), | 159 profile_.get(), |
| 160 signin, | 160 signin, |
| 161 ProfileSyncService::MANUAL_START, | 161 ProfileSyncService::MANUAL_START, |
| 162 true, | 162 true, |
| 163 base::Closure())); | 163 TestProfileSyncService::NullCallback())); |
| 164 EXPECT_TRUE( | 164 EXPECT_TRUE( |
| 165 service_->sync_service_url().spec() == | 165 service_->sync_service_url().spec() == |
| 166 ProfileSyncService::kSyncServerUrl || | 166 ProfileSyncService::kSyncServerUrl || |
| 167 service_->sync_service_url().spec() == | 167 service_->sync_service_url().spec() == |
| 168 ProfileSyncService::kDevServerUrl); | 168 ProfileSyncService::kDevServerUrl); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(ProfileSyncServiceTest, DisabledByPolicy) { | 171 TEST_F(ProfileSyncServiceTest, DisabledByPolicy) { |
| 172 profile_->GetTestingPrefService()->SetManagedPref( | 172 profile_->GetTestingPrefService()->SetManagedPref( |
| 173 prefs::kSyncManaged, | 173 prefs::kSyncManaged, |
| 174 Value::CreateBooleanValue(true)); | 174 Value::CreateBooleanValue(true)); |
| 175 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); | 175 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); |
| 176 service_.reset(new TestProfileSyncService( | 176 service_.reset(new TestProfileSyncService( |
| 177 new ProfileSyncComponentsFactoryMock(), | 177 new ProfileSyncComponentsFactoryMock(), |
| 178 profile_.get(), | 178 profile_.get(), |
| 179 signin, | 179 signin, |
| 180 ProfileSyncService::MANUAL_START, | 180 ProfileSyncService::MANUAL_START, |
| 181 true, | 181 true, |
| 182 base::Closure())); | 182 TestProfileSyncService::NullCallback())); |
| 183 service_->Initialize(); | 183 service_->Initialize(); |
| 184 EXPECT_TRUE(service_->IsManaged()); | 184 EXPECT_TRUE(service_->IsManaged()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { | 187 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { |
| 188 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); | 188 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); |
| 189 signin->SetAuthenticatedUsername("test"); | 189 signin->SetAuthenticatedUsername("test"); |
| 190 ProfileSyncComponentsFactoryMock* factory = | 190 ProfileSyncComponentsFactoryMock* factory = |
| 191 new ProfileSyncComponentsFactoryMock(); | 191 new ProfileSyncComponentsFactoryMock(); |
| 192 service_.reset(new TestProfileSyncService( | 192 service_.reset(new TestProfileSyncService( |
| 193 factory, | 193 factory, |
| 194 profile_.get(), | 194 profile_.get(), |
| 195 signin, | 195 signin, |
| 196 ProfileSyncService::AUTO_START, | 196 ProfileSyncService::AUTO_START, |
| 197 true, | 197 true, |
| 198 base::Closure())); | 198 TestProfileSyncService::NullCallback())); |
| 199 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).Times(0); | 199 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).Times(0); |
| 200 EXPECT_CALL(*factory, CreateBookmarkSyncComponents(_, _)). | 200 EXPECT_CALL(*factory, CreateBookmarkSyncComponents(_, _)). |
| 201 Times(0); | 201 Times(0); |
| 202 service_->RegisterDataTypeController( | 202 service_->RegisterDataTypeController( |
| 203 new BookmarkDataTypeController(service_->factory(), | 203 new BookmarkDataTypeController(service_->factory(), |
| 204 profile_.get(), | 204 profile_.get(), |
| 205 service_.get())); | 205 service_.get())); |
| 206 | 206 |
| 207 service_->Initialize(); | 207 service_->Initialize(); |
| 208 service_.reset(); | 208 service_.reset(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { | 211 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { |
| 212 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); | 212 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); |
| 213 signin->SetAuthenticatedUsername("test"); | 213 signin->SetAuthenticatedUsername("test"); |
| 214 ProfileSyncComponentsFactoryMock* factory = | 214 ProfileSyncComponentsFactoryMock* factory = |
| 215 new ProfileSyncComponentsFactoryMock(); | 215 new ProfileSyncComponentsFactoryMock(); |
| 216 service_.reset(new TestProfileSyncService( | 216 service_.reset(new TestProfileSyncService( |
| 217 factory, | 217 factory, |
| 218 profile_.get(), | 218 profile_.get(), |
| 219 signin, | 219 signin, |
| 220 ProfileSyncService::AUTO_START, | 220 ProfileSyncService::AUTO_START, |
| 221 true, | 221 true, |
| 222 base::Closure())); | 222 TestProfileSyncService::NullCallback())); |
| 223 // Register the bookmark data type. | 223 // Register the bookmark data type. |
| 224 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)). | 224 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)). |
| 225 WillRepeatedly(ReturnNewDataTypeManager()); | 225 WillRepeatedly(ReturnNewDataTypeManager()); |
| 226 | 226 |
| 227 IssueTestTokens(); | 227 IssueTestTokens(); |
| 228 | 228 |
| 229 service_->Initialize(); | 229 service_->Initialize(); |
| 230 EXPECT_TRUE(service_->sync_initialized()); | 230 EXPECT_TRUE(service_->sync_initialized()); |
| 231 EXPECT_TRUE(service_->GetBackendForTest() != NULL); | 231 EXPECT_TRUE(service_->GetBackendForTest() != NULL); |
| 232 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); | 232 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // The backend is not ready. Ensure the PSS knows this. | 378 // The backend is not ready. Ensure the PSS knows this. |
| 379 EXPECT_FALSE(service_->sync_initialized()); | 379 EXPECT_FALSE(service_->sync_initialized()); |
| 380 | 380 |
| 381 // Ensure we will be prepared to initialize a fresh DB next time. | 381 // Ensure we will be prepared to initialize a fresh DB next time. |
| 382 EXPECT_FALSE(service_->HasSyncSetupCompleted()); | 382 EXPECT_FALSE(service_->HasSyncSetupCompleted()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace | 385 } // namespace |
| 386 | 386 |
| 387 } // namespace browser_sync | 387 } // namespace browser_sync |
| OLD | NEW |