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

Side by Side Diff: chrome/browser/sync/profile_sync_service_startup_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments. merge to ToT. Murder a DB thread and more TestBrowserThreads. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/run_loop.h"
10 #include "chrome/browser/signin/fake_signin_manager.h" 11 #include "chrome/browser/signin/fake_signin_manager.h"
11 #include "chrome/browser/signin/oauth2_token_service.h" 12 #include "chrome/browser/signin/oauth2_token_service.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service.h" 13 #include "chrome/browser/signin/profile_oauth2_token_service.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager.h" 15 #include "chrome/browser/signin/signin_manager.h"
15 #include "chrome/browser/signin/signin_manager_factory.h" 16 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/signin/token_service.h" 17 #include "chrome/browser/signin/token_service.h"
17 #include "chrome/browser/signin/token_service_factory.h" 18 #include "chrome/browser/signin/token_service_factory.h"
18 #include "chrome/browser/sync/glue/data_type_manager.h" 19 #include "chrome/browser/sync/glue/data_type_manager.h"
19 #include "chrome/browser/sync/glue/data_type_manager_mock.h" 20 #include "chrome/browser/sync/glue/data_type_manager_mock.h"
20 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 21 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
21 #include "chrome/browser/sync/profile_sync_service_factory.h" 22 #include "chrome/browser/sync/profile_sync_service_factory.h"
22 #include "chrome/browser/sync/profile_sync_test_util.h" 23 #include "chrome/browser/sync/profile_sync_test_util.h"
23 #include "chrome/browser/sync/sync_prefs.h" 24 #include "chrome/browser/sync/sync_prefs.h"
24 #include "chrome/browser/sync/test_profile_sync_service.h" 25 #include "chrome/browser/sync/test_profile_sync_service.h"
25 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
30 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "content/public/test/test_utils.h"
31 #include "google_apis/gaia/gaia_auth_consumer.h" 33 #include "google_apis/gaia/gaia_auth_consumer.h"
32 #include "google_apis/gaia/gaia_constants.h" 34 #include "google_apis/gaia/gaia_constants.h"
33 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
34 36
35 using browser_sync::DataTypeManager; 37 using browser_sync::DataTypeManager;
36 using browser_sync::DataTypeManagerMock; 38 using browser_sync::DataTypeManagerMock;
37 using content::BrowserThread; 39 using content::BrowserThread;
38 using testing::_; 40 using testing::_;
39 using testing::AnyNumber; 41 using testing::AnyNumber;
40 using testing::DoAll; 42 using testing::DoAll;
(...skipping 23 matching lines...) Expand all
64 content::NotificationService::current()->Notify( 66 content::NotificationService::current()->Notify(
65 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, 67 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
66 content::Source<TokenService>(this), 68 content::Source<TokenService>(this),
67 content::NotificationService::NoDetails()); 69 content::NotificationService::NoDetails());
68 } 70 }
69 }; 71 };
70 72
71 class ProfileSyncServiceStartupTest : public testing::Test { 73 class ProfileSyncServiceStartupTest : public testing::Test {
72 public: 74 public:
73 ProfileSyncServiceStartupTest() 75 ProfileSyncServiceStartupTest()
74 : ui_thread_(BrowserThread::UI, &ui_loop_), 76 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
75 db_thread_(BrowserThread::DB), 77 content::TestBrowserThreadBundle::REAL_FILE_THREAD |
76 file_thread_(BrowserThread::FILE), 78 content::TestBrowserThreadBundle::REAL_IO_THREAD),
77 io_thread_(BrowserThread::IO),
78 profile_(new TestingProfile), 79 profile_(new TestingProfile),
79 sync_(NULL) {} 80 sync_(NULL) {}
80 81
81 virtual ~ProfileSyncServiceStartupTest() { 82 virtual ~ProfileSyncServiceStartupTest() {
82 } 83 }
83 84
84 virtual void SetUp() { 85 virtual void SetUp() {
85 file_thread_.Start();
86 io_thread_.StartIOThread();
87 db_thread_.Start();
88 profile_->CreateRequestContext();
89 #if defined(OS_CHROMEOS) 86 #if defined(OS_CHROMEOS)
90 SigninManagerFactory::GetInstance()->SetTestingFactory( 87 SigninManagerFactory::GetInstance()->SetTestingFactory(
91 profile_.get(), FakeSigninManagerBase::Build); 88 profile_.get(), FakeSigninManagerBase::Build);
92 #else 89 #else
93 SigninManagerFactory::GetInstance()->SetTestingFactory( 90 SigninManagerFactory::GetInstance()->SetTestingFactory(
94 profile_.get(), FakeSigninManager::Build); 91 profile_.get(), FakeSigninManager::Build);
95 #endif 92 #endif
96 } 93 }
97 94
98 virtual void TearDown() { 95 virtual void TearDown() {
99 sync_->RemoveObserver(&observer_); 96 sync_->RemoveObserver(&observer_);
100 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( 97 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
101 profile_.get(), NULL); 98 profile_.get(), NULL);
102 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( 99 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
103 profile_.get(), NULL); 100 profile_.get(), NULL);
104 profile_.reset(); 101 profile_.reset();
105 102
106 // Pump messages posted by the sync core thread (which may end up 103 // Pump messages posted by the sync core thread (which may end up
107 // posting on the IO thread). 104 // posting on the IO thread).
108 ui_loop_.RunUntilIdle(); 105 base::RunLoop().RunUntilIdle();
109 file_thread_.Stop(); 106 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
110 db_thread_.Stop(); 107 base::RunLoop().RunUntilIdle();
111 io_thread_.Stop();
112 ui_loop_.RunUntilIdle();
113 } 108 }
114 109
115 static BrowserContextKeyedService* BuildService( 110 static BrowserContextKeyedService* BuildService(
116 content::BrowserContext* profile) { 111 content::BrowserContext* profile) {
117 return new TestProfileSyncService( 112 return new TestProfileSyncService(
118 new ProfileSyncComponentsFactoryMock(), 113 new ProfileSyncComponentsFactoryMock(),
119 static_cast<Profile*>(profile), 114 static_cast<Profile*>(profile),
120 SigninManagerFactory::GetForProfile(static_cast<Profile*>(profile)), 115 SigninManagerFactory::GetForProfile(static_cast<Profile*>(profile)),
121 ProfileSyncService::MANUAL_START, 116 ProfileSyncService::MANUAL_START,
122 true); 117 true);
(...skipping 11 matching lines...) Expand all
134 129
135 protected: 130 protected:
136 DataTypeManagerMock* SetUpDataTypeManager() { 131 DataTypeManagerMock* SetUpDataTypeManager() {
137 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock(); 132 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock();
138 EXPECT_CALL(*sync_->components_factory_mock(), 133 EXPECT_CALL(*sync_->components_factory_mock(),
139 CreateDataTypeManager(_, _, _, _, _, _)). 134 CreateDataTypeManager(_, _, _, _, _, _)).
140 WillOnce(Return(data_type_manager)); 135 WillOnce(Return(data_type_manager));
141 return data_type_manager; 136 return data_type_manager;
142 } 137 }
143 138
144 base::MessageLoop ui_loop_; 139 content::TestBrowserThreadBundle thread_bundle_;
145 content::TestBrowserThread ui_thread_;
146 content::TestBrowserThread db_thread_;
147 content::TestBrowserThread file_thread_;
148 content::TestBrowserThread io_thread_;
149 scoped_ptr<TestingProfile> profile_; 140 scoped_ptr<TestingProfile> profile_;
150 TestProfileSyncService* sync_; 141 TestProfileSyncService* sync_;
151 ProfileSyncServiceObserverMock observer_; 142 ProfileSyncServiceObserverMock observer_;
152 }; 143 };
153 144
154 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { 145 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
155 public: 146 public:
156 virtual void SetUp() { 147 virtual void SetUp() {
157 ProfileSyncServiceStartupTest::SetUp(); 148 ProfileSyncServiceStartupTest::SetUp();
158 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( 149 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 549 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
559 GaiaConstants::kSyncService, "token"); 550 GaiaConstants::kSyncService, "token");
560 sync_->fail_initial_download(); 551 sync_->fail_initial_download();
561 552
562 sync_->SetSetupInProgress(true); 553 sync_->SetSetupInProgress(true);
563 sync_->Initialize(); 554 sync_->Initialize();
564 sync_->SetSetupInProgress(false); 555 sync_->SetSetupInProgress(false);
565 EXPECT_FALSE(sync_->sync_initialized()); 556 EXPECT_FALSE(sync_->sync_initialized());
566 EXPECT_TRUE(sync_->GetBackendForTest()); 557 EXPECT_TRUE(sync_->GetBackendForTest());
567 } 558 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698