Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1041)

Unified Diff: chrome/browser/sync/profile_sync_service_startup_unittest.cc

Issue 11348220: sync: centralize sync startup decisions in TryStart. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ui review Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/profile_sync_service_mock.h ('k') | chrome/browser/ui/webui/sync_setup_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/profile_sync_service_startup_unittest.cc
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
index e926df478bc37a3c49ca7bf356a7d4b1fca604ec..af9925adeb0c2ecf2bc98314600059d2ccd9176b 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -48,6 +48,20 @@ ACTION_P2(InvokeOnConfigureDone, pss, result) {
service->OnConfigureDone(configure_result);
}
+class FakeTokenService : public TokenService {
+ public:
+ FakeTokenService() {}
+ virtual ~FakeTokenService() {}
+
+ virtual void LoadTokensFromDB() OVERRIDE {
+ set_tokens_loaded(true);
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
+ content::Source<TokenService>(this),
+ content::NotificationService::NoDetails());
+ }
+};
+
// TODO(chron): Test not using cros_user flag and use signin_
class ProfileSyncServiceStartupTest : public testing::Test {
public:
@@ -176,9 +190,16 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
EXPECT_TRUE(service_->ShouldPushChanges());
}
+ProfileKeyedService* BuildFakeTokenService(Profile* profile) {
+ return new FakeTokenService();
+}
+
TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) {
DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
+ TokenService* token_service = static_cast<TokenService*>(
+ TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_.get(), BuildFakeTokenService));
// We've never completed startup.
profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
@@ -208,11 +229,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) {
service_->SetSetupInProgress(true);
service_->signin()->StartSignIn("test_user", "", "", "");
// NOTE: Unlike StartFirstTime, this test does not issue any auth tokens.
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
- content::Source<TokenService>(
- TokenServiceFactory::GetForProfile(profile_.get())),
- content::NotificationService::NoDetails());
+ token_service->LoadTokensFromDB();
service_->SetSetupInProgress(false);
// Backend should initialize using a bogus GAIA token for credentials.
EXPECT_TRUE(service_->ShouldPushChanges());
@@ -222,16 +239,15 @@ TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) {
EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _, _)).Times(0);
profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
+ TokenService* token_service = static_cast<TokenService*>(
+ TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_.get(), BuildFakeTokenService));
service_->Initialize();
// Sync should not start because there are no tokens yet.
EXPECT_FALSE(service_->ShouldPushChanges());
EXPECT_FALSE(service_->GetBackendForTest());
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
- content::Source<TokenService>(
- TokenServiceFactory::GetForProfile(profile_.get())),
- content::NotificationService::NoDetails());
+ token_service->LoadTokensFromDB();
service_->SetSetupInProgress(false);
// Sync should not start because there are still no tokens.
EXPECT_FALSE(service_->ShouldPushChanges());
« no previous file with comments | « chrome/browser/sync/profile_sync_service_mock.h ('k') | chrome/browser/ui/webui/sync_setup_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698