Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / profile_sync_service_startup_unittest.cc
index cdf0051..8553c3b 100644 (file)
@@ -6,14 +6,14 @@
 #include "base/memory/scoped_ptr.h"
 #include "base/prefs/pref_service.h"
 #include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
+#include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h"
 #include "chrome/browser/signin/fake_signin_manager.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/sync/glue/data_type_manager.h"
-#include "chrome/browser/sync/glue/data_type_manager_mock.h"
 #include "chrome/browser/sync/glue/sync_backend_host_mock.h"
 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
 #include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -21,6 +21,8 @@
 #include "chrome/browser/sync/sync_prefs.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/test/base/testing_profile.h"
+#include "components/sync_driver/data_type_manager.h"
+#include "components/sync_driver/data_type_manager_mock.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/notification_source.h"
 #include "content/public/test/test_browser_thread_bundle.h"
@@ -77,7 +79,7 @@ class ProfileSyncServiceStartupTest : public testing::Test {
                               FakeSigninManagerBase::Build);
     builder.AddTestingFactory(
         ProfileOAuth2TokenServiceFactory::GetInstance(),
-        FakeProfileOAuth2TokenService::BuildAutoIssuingTokenService);
+        FakeProfileOAuth2TokenServiceWrapper::BuildAutoIssuingTokenService);
     builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(),
                               BuildService);
     return builder.Build();
@@ -94,7 +96,8 @@ class ProfileSyncServiceStartupTest : public testing::Test {
     return new ProfileSyncService(
         new ProfileSyncComponentsFactoryMock(),
         profile,
-        SigninManagerFactory::GetForProfile(profile),
+        new ManagedUserSigninManagerWrapper(
+            SigninManagerFactory::GetForProfile(profile)),
         ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
         ProfileSyncService::MANUAL_START);
   }
@@ -136,7 +139,6 @@ class ProfileSyncServiceStartupTest : public testing::Test {
   scoped_ptr<TestingProfile> profile_;
   ProfileSyncService* sync_;
   ProfileSyncServiceObserverMock observer_;
-  ProfileSyncComponentsFactoryMock* mock_components_factory_;
 };
 
 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
@@ -156,14 +158,14 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
         SigninManagerFactory::GetForProfile(profile);
     profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                    "test_user@gmail.com");
+    signin->SetAuthenticatedUsername("test_user@gmail.com");
     ProfileOAuth2TokenService* oauth2_token_service =
         ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
-    signin->Initialize(profile, NULL);
     EXPECT_FALSE(signin->GetAuthenticatedUsername().empty());
     return new ProfileSyncService(
         new ProfileSyncComponentsFactoryMock(),
         profile,
-        signin,
+        new ManagedUserSigninManagerWrapper(signin),
         oauth2_token_service,
         ProfileSyncService::AUTO_START);
   }
@@ -172,8 +174,6 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
   // We've never completed startup.
   profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
-  SigninManagerFactory::GetForProfile(
-      profile_.get())->Initialize(profile_.get(), NULL);
   CreateSyncService();
   SetUpSyncBackendHost();
   DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
@@ -221,8 +221,6 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
   // We've never completed startup.
   profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
-  SigninManagerFactory::GetForProfile(
-      profile_.get())->Initialize(profile_.get(), NULL);
   CreateSyncService();
 
   // Should not actually start, rather just clean things up and wait
@@ -264,8 +262,7 @@ TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) {
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(
-      profile_.get())->Initialize(profile_.get(), NULL);
+  sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com");
   CreateSyncService();
   SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost();
 
@@ -339,8 +336,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartNormal) {
   // Pre load the tokens
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
-      profile_.get(), NULL);
+  SigninManagerFactory::GetForProfile(profile_.get())
+      ->SetAuthenticatedUsername("test_user@gmail.com");
   CreateSyncService();
   sync_->SetSyncSetupCompleted();
   SetUpSyncBackendHost();
@@ -372,8 +369,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
   // Pre load the tokens
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
-      profile_.get(), NULL);
+  SigninManagerFactory::GetForProfile(profile_.get())
+      ->SetAuthenticatedUsername("test_user@gmail.com");
   CreateSyncService();
   sync_->SetSyncSetupCompleted();
   SetUpSyncBackendHost();
@@ -401,8 +398,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) {
   // Pre load the tokens
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
-      profile_.get(), NULL);
+  SigninManagerFactory::GetForProfile(profile_.get())
+      ->SetAuthenticatedUsername("test_user@gmail.com");
   CreateSyncService();
   sync_->SetSyncSetupCompleted();
   SetUpSyncBackendHost();
@@ -423,8 +420,6 @@ TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) {
   // Service should not be started by Initialize() since it's managed.
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
-      profile_.get(), NULL);
   CreateSyncService();
 
   // Disable sync through policy.
@@ -439,8 +434,8 @@ TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) {
 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
-      profile_.get(), NULL);
+  SigninManagerFactory::GetForProfile(profile_.get())
+      ->SetAuthenticatedUsername("test_user@gmail.com");
   CreateSyncService();
   sync_->SetSyncSetupCompleted();
   SetUpSyncBackendHost();
@@ -470,8 +465,8 @@ TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
 TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
-      profile_.get(), NULL);
+  SigninManagerFactory::GetForProfile(profile_.get())
+      ->SetAuthenticatedUsername("test_user@gmail.com");
   CreateSyncService();
   sync_->SetSyncSetupCompleted();
   SetUpSyncBackendHost();
@@ -506,8 +501,8 @@ TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
   // Pre load the tokens
   profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
                                   "test_user@gmail.com");
-  SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
-      profile_.get(), NULL);
+  SigninManagerFactory::GetForProfile(profile_.get())
+      ->SetAuthenticatedUsername("test_user@gmail.com");
   CreateSyncService();
   SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost();
   mock_sbh->set_fail_initial_download(true);