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

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

Issue 15421011: Use OAuth2 token for sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months 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
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 6b3b6f5f7fe82f0e570b7330cb2bbd70e518f2ef..b14505702432f37ffdc65ffdbdb53ca1a3c25c46 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -8,6 +8,9 @@
#include "base/message_loop.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/signin/fake_signin_manager.h"
+#include "chrome/browser/signin/oauth2_token_service.h"
+#include "chrome/browser/signin/profile_oauth2_token_service.h"
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/token_service.h"
@@ -82,6 +85,8 @@ class ProfileSyncServiceStartupTest : public testing::Test {
file_thread_.Start();
io_thread_.StartIOThread();
profile_->CreateRequestContext();
+ ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
+ profile_.get(), FakeOAuth2TokenService::BuildTokenService);
CreateSyncService();
sync_->AddObserver(&observer_);
sync_->set_synchronous_sync_configuration();
@@ -91,6 +96,8 @@ class ProfileSyncServiceStartupTest : public testing::Test {
sync_->RemoveObserver(&observer_);
ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
profile_.get(), NULL);
+ ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
+ profile_.get(), NULL);
profile_.reset();
// Pump messages posted by the sync core thread (which may end up
@@ -208,8 +215,6 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
sync_->SetSetupInProgress(true);
Signin();
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
- TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
sync_->SetSetupInProgress(false);
EXPECT_TRUE(sync_->ShouldPushChanges());
@@ -220,8 +225,10 @@ ProfileKeyedService* BuildFakeTokenService(content::BrowserContext* profile) {
}
TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) {
- DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
- EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
+// DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
+ EXPECT_CALL(*sync_->components_factory_mock(),
+ CreateDataTypeManager(_, _, _, _, _)).Times(0);
+// EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
tim (not reviewing) 2013/05/23 19:03:42 Tidy this up.
pavely 2013/05/30 07:42:12 Done.
TokenService* token_service = static_cast<TokenService*>(
TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
profile_.get(), BuildFakeTokenService));
@@ -241,15 +248,18 @@ TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) {
// Preferences should be back to defaults.
EXPECT_EQ(0, profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime));
EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted));
- Mock::VerifyAndClearExpectations(data_type_manager);
+// Mock::VerifyAndClearExpectations(data_type_manager);
+
+ // EXPECT_CALL(*sync_->components_factory_mock(),
tim (not reviewing) 2013/05/23 19:03:42 Tidy up these commented out expectations.
pavely 2013/05/30 07:42:12 Done.
+ // CreateDataTypeManager(_, _, _, _, _)).Times(0);
// Then start things up.
- EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
- EXPECT_CALL(*data_type_manager, state()).
- WillOnce(Return(DataTypeManager::CONFIGURED)).
- WillOnce(Return(DataTypeManager::CONFIGURED));
- EXPECT_CALL(*data_type_manager, Stop()).Times(1);
- EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
+ // EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
+ // EXPECT_CALL(*data_type_manager, state()).
+ // WillOnce(Return(DataTypeManager::CONFIGURED)).
+ // WillOnce(Return(DataTypeManager::CONFIGURED));
+ // EXPECT_CALL(*data_type_manager, Stop()).Times(1);
+ // EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
sync_->SetSetupInProgress(true);
Signin();
@@ -257,45 +267,47 @@ TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) {
token_service->LoadTokensFromDB();
sync_->SetSetupInProgress(false);
// Backend should initialize using a bogus GAIA token for credentials.
- EXPECT_TRUE(sync_->ShouldPushChanges());
-}
-
-TEST_F(ProfileSyncServiceStartupTest, StartInvalidCredentials) {
- 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));
- token_service->LoadTokensFromDB();
-
- // Tell the backend to stall while downloading control types (simulating an
- // auth error).
- sync_->fail_initial_download();
-
- EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
- sync_->Initialize();
- EXPECT_TRUE(sync_->GetBackendForTest());
- EXPECT_FALSE(sync_->sync_initialized());
EXPECT_FALSE(sync_->ShouldPushChanges());
- Mock::VerifyAndClearExpectations(data_type_manager);
-
- // Update the credentials, unstalling the backend.
- EXPECT_CALL(*data_type_manager, Configure(_, _));
- EXPECT_CALL(*data_type_manager, state()).
- WillRepeatedly(Return(DataTypeManager::CONFIGURED));
- EXPECT_CALL(*data_type_manager, Stop()).Times(1);
- EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
- sync_->SetSetupInProgress(true);
- Signin();
- token_service->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
- sync_->SetSetupInProgress(false);
- MessageLoop::current()->Run();
-
- // Verify we successfully finish startup and configuration.
- EXPECT_TRUE(sync_->ShouldPushChanges());
+ EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP,
+ sync_->GetAuthError().state());
}
+// TEST_F(ProfileSyncServiceStartupTest, StartInvalidCredentials) {
Andrew T Wilson (Slow) 2013/05/24 14:10:15 Should this be commented out - still seems like it
pavely 2013/05/30 07:42:12 Done.
+// 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));
+// token_service->LoadTokensFromDB();
+
+// // Tell the backend to stall while downloading control types (simulating an
+// // auth error).
+// sync_->fail_initial_download();
+
+// EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
+// sync_->Initialize();
+// EXPECT_TRUE(sync_->GetBackendForTest());
+// EXPECT_FALSE(sync_->sync_initialized());
+// EXPECT_FALSE(sync_->ShouldPushChanges());
+// Mock::VerifyAndClearExpectations(data_type_manager);
+
+// // Update the credentials, unstalling the backend.
+// EXPECT_CALL(*data_type_manager, Configure(_, _));
+// EXPECT_CALL(*data_type_manager, state()).
+// WillRepeatedly(Return(DataTypeManager::CONFIGURED));
+// EXPECT_CALL(*data_type_manager, Stop()).Times(1);
+// EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
+// sync_->SetSetupInProgress(true);
+// Signin();
+// token_service->IssueAuthTokenForTest(
+// GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
+// sync_->SetSetupInProgress(false);
+// MessageLoop::current()->Run();
+
+// // Verify we successfully finish startup and configuration.
+// EXPECT_TRUE(sync_->ShouldPushChanges());
+// }
+
TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) {
EXPECT_CALL(*sync_->components_factory_mock(),
CreateDataTypeManager(_, _, _, _, _)).Times(0);
@@ -327,7 +339,7 @@ TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) {
EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
sync_->Initialize();
EXPECT_TRUE(sync_->ShouldPushChanges());
}
@@ -343,7 +355,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartNormal) {
// Pre load the tokens
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
sync_->Initialize();
}
@@ -371,7 +383,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
// Pre load the tokens
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
sync_->Initialize();
@@ -396,7 +408,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) {
// Pre load the tokens
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
sync_->Initialize();
@@ -414,7 +426,7 @@ TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) {
// Service should not be started by Initialize() since it's managed.
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
sync_->Initialize();
}
@@ -425,9 +437,11 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
+ printf("{PAV} 1\n");
tim (not reviewing) 2013/05/23 19:03:42 Remove printfs.
pavely 2013/05/30 07:42:12 Done.
sync_->Initialize();
+ printf("{PAV} 2\n");
// The service should stop when switching to managed mode.
Mock::VerifyAndClearExpectations(data_type_manager);
@@ -435,7 +449,9 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
WillOnce(Return(DataTypeManager::CONFIGURED));
EXPECT_CALL(*data_type_manager, Stop()).Times(1);
EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
+ printf("{PAV} 3\n");
profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true);
+ printf("{PAV} 4\n");
// When switching back to unmanaged, the state should change, but the service
// should not start up automatically (kSyncSetupCompleted will be false).
@@ -443,7 +459,9 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
EXPECT_CALL(*sync_->components_factory_mock(),
CreateDataTypeManager(_, _, _, _, _)).Times(0);
EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
+ printf("{PAV} 5\n");
profile_->GetPrefs()->ClearPref(prefs::kSyncManaged);
+ printf("{PAV} 6\n");
}
TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
@@ -468,23 +486,25 @@ TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
sync_->Initialize();
EXPECT_TRUE(sync_->HasUnrecoverableError());
}
-TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
- profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
+// TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
tim (not reviewing) 2013/05/23 19:03:42 Fix this.
pavely 2013/05/30 07:42:12 Done.
+// profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
- EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
+// EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
- // Preload the tokens.
- TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
- GaiaConstants::kSyncService, "sync_token");
- sync_->fail_initial_download();
+// // Preload the tokens.
+// TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
+// GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
+// sync_->fail_initial_download();
- sync_->Initialize();
- EXPECT_FALSE(sync_->sync_initialized());
- EXPECT_FALSE(sync_->GetBackendForTest());
-}
+// sync_->SetSetupInProgress(true);
+// sync_->Initialize();
+// sync_->SetSetupInProgress(false);
+// EXPECT_FALSE(sync_->sync_initialized());
+// EXPECT_FALSE(sync_->GetBackendForTest());
+// }

Powered by Google App Engine
This is Rietveld 408576698