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

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

Issue 9232011: sync: Make ProfileSyncService a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 11 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) 2011 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/net/gaia/token_service.h" 9 #include "chrome/browser/net/gaia/token_service.h"
10 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" 10 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h"
11 #include "chrome/browser/sync/glue/data_type_controller.h" 11 #include "chrome/browser/sync/glue/data_type_controller.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void StartSyncServiceAndSetInitialSyncEnded( 87 void StartSyncServiceAndSetInitialSyncEnded(
88 bool set_initial_sync_ended, 88 bool set_initial_sync_ended,
89 bool issue_auth_token, 89 bool issue_auth_token,
90 bool synchronous_sync_configuration, 90 bool synchronous_sync_configuration,
91 bool sync_setup_completed, 91 bool sync_setup_completed,
92 bool expect_create_dtm) { 92 bool expect_create_dtm) {
93 if (!service_.get()) { 93 if (!service_.get()) {
94 SigninManager* signin = new SigninManager(); 94 SigninManager* signin = new SigninManager();
95 signin->SetAuthenticatedUsername("test"); 95 signin->SetAuthenticatedUsername("test");
96 service_.reset(new TestProfileSyncService(&factory_, 96 ProfileSyncComponentsFactoryMock* factory =
97 profile_.get(), 97 new ProfileSyncComponentsFactoryMock();
98 signin, 98 service_.reset(new TestProfileSyncService(
99 ProfileSyncService::AUTO_START, 99 factory,
100 true, 100 profile_.get(),
101 base::Closure())); 101 signin,
102 ProfileSyncService::AUTO_START,
103 true,
104 base::Closure()));
102 if (!set_initial_sync_ended) 105 if (!set_initial_sync_ended)
103 service_->dont_set_initial_sync_ended_on_init(); 106 service_->dont_set_initial_sync_ended_on_init();
104 if (synchronous_sync_configuration) 107 if (synchronous_sync_configuration)
105 service_->set_synchronous_sync_configuration(); 108 service_->set_synchronous_sync_configuration();
106 if (!sync_setup_completed) 109 if (!sync_setup_completed)
107 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); 110 profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false);
108 111
109 if (expect_create_dtm) { 112 if (expect_create_dtm) {
110 // Register the bookmark data type. 113 // Register the bookmark data type.
111 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). 114 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).
112 WillOnce(ReturnNewDataTypeManager()); 115 WillOnce(ReturnNewDataTypeManager());
113 } else { 116 } else {
114 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0); 117 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).
118 Times(0);
115 } 119 }
116 120
117 if (issue_auth_token) { 121 if (issue_auth_token) {
118 IssueTestTokens(); 122 IssueTestTokens();
119 } 123 }
120 service_->Initialize(); 124 service_->Initialize();
121 } 125 }
122 } 126 }
123 127
124 void IssueTestTokens() { 128 void IssueTestTokens() {
125 profile_->GetTokenService()->IssueAuthTokenForTest( 129 profile_->GetTokenService()->IssueAuthTokenForTest(
126 GaiaConstants::kSyncService, "token1"); 130 GaiaConstants::kSyncService, "token1");
127 profile_->GetTokenService()->IssueAuthTokenForTest( 131 profile_->GetTokenService()->IssueAuthTokenForTest(
128 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "token2"); 132 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "token2");
129 } 133 }
130 134
131 MessageLoop ui_loop_; 135 MessageLoop ui_loop_;
132 // Needed by |service_|. 136 // Needed by |service_|.
133 content::TestBrowserThread ui_thread_; 137 content::TestBrowserThread ui_thread_;
134 // Needed by DisableAndEnableSyncTemporarily test case. 138 // Needed by DisableAndEnableSyncTemporarily test case.
135 content::TestBrowserThread file_thread_; 139 content::TestBrowserThread file_thread_;
136 // Needed by |service| and |profile_|'s request context. 140 // Needed by |service| and |profile_|'s request context.
137 content::TestBrowserThread io_thread_; 141 content::TestBrowserThread io_thread_;
138 142
139 scoped_ptr<TestProfileSyncService> service_; 143 scoped_ptr<TestProfileSyncService> service_;
140 scoped_ptr<TestingProfile> profile_; 144 scoped_ptr<TestingProfile> profile_;
141 ProfileSyncComponentsFactoryMock factory_;
142 }; 145 };
143 146
144 TEST_F(ProfileSyncServiceTest, InitialState) { 147 TEST_F(ProfileSyncServiceTest, InitialState) {
145 service_.reset(new TestProfileSyncService(&factory_, 148 service_.reset(new TestProfileSyncService(
146 profile_.get(), 149 new ProfileSyncComponentsFactoryMock(),
147 new SigninManager(), 150 profile_.get(),
148 ProfileSyncService::MANUAL_START, 151 new SigninManager(),
149 true, 152 ProfileSyncService::MANUAL_START,
150 base::Closure())); 153 true,
154 base::Closure()));
151 EXPECT_TRUE( 155 EXPECT_TRUE(
152 service_->sync_service_url().spec() == 156 service_->sync_service_url().spec() ==
153 ProfileSyncService::kSyncServerUrl || 157 ProfileSyncService::kSyncServerUrl ||
154 service_->sync_service_url().spec() == 158 service_->sync_service_url().spec() ==
155 ProfileSyncService::kDevServerUrl); 159 ProfileSyncService::kDevServerUrl);
156 } 160 }
157 161
158 TEST_F(ProfileSyncServiceTest, DisabledByPolicy) { 162 TEST_F(ProfileSyncServiceTest, DisabledByPolicy) {
159 profile_->GetTestingPrefService()->SetManagedPref( 163 profile_->GetTestingPrefService()->SetManagedPref(
160 prefs::kSyncManaged, 164 prefs::kSyncManaged,
161 Value::CreateBooleanValue(true)); 165 Value::CreateBooleanValue(true));
162 service_.reset(new TestProfileSyncService(&factory_, 166 service_.reset(new TestProfileSyncService(
163 profile_.get(), 167 new ProfileSyncComponentsFactoryMock(),
164 new SigninManager(), 168 profile_.get(),
165 ProfileSyncService::MANUAL_START, 169 new SigninManager(),
166 true, 170 ProfileSyncService::MANUAL_START,
167 base::Closure())); 171 true,
172 base::Closure()));
168 service_->Initialize(); 173 service_->Initialize();
169 EXPECT_TRUE(service_->IsManaged()); 174 EXPECT_TRUE(service_->IsManaged());
170 } 175 }
171 176
172 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { 177 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
173 SigninManager* signin = new SigninManager(); 178 SigninManager* signin = new SigninManager();
174 signin->SetAuthenticatedUsername("test"); 179 signin->SetAuthenticatedUsername("test");
175 service_.reset(new TestProfileSyncService(&factory_, 180 ProfileSyncComponentsFactoryMock* factory =
176 profile_.get(), 181 new ProfileSyncComponentsFactoryMock();
177 signin, 182 service_.reset(new TestProfileSyncService(
178 ProfileSyncService::AUTO_START, 183 factory,
179 true, 184 profile_.get(),
180 base::Closure())); 185 signin,
181 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0); 186 ProfileSyncService::AUTO_START,
182 EXPECT_CALL(factory_, CreateBookmarkSyncComponents(_, _)).Times(0); 187 true,
188 base::Closure()));
189 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).Times(0);
190 EXPECT_CALL(*factory, CreateBookmarkSyncComponents(_, _)).
191 Times(0);
183 service_->RegisterDataTypeController( 192 service_->RegisterDataTypeController(
184 new BookmarkDataTypeController(&factory_, 193 new BookmarkDataTypeController(service_->factory(),
185 profile_.get(), 194 profile_.get(),
186 service_.get())); 195 service_.get()));
187 196
188 service_->Initialize(); 197 service_->Initialize();
189 service_.reset(); 198 service_.reset();
190 } 199 }
191 200
192 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { 201 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
193 SigninManager* signin = new SigninManager(); 202 SigninManager* signin = new SigninManager();
194 signin->SetAuthenticatedUsername("test"); 203 signin->SetAuthenticatedUsername("test");
195 service_.reset(new TestProfileSyncService(&factory_, 204 ProfileSyncComponentsFactoryMock* factory =
196 profile_.get(), 205 new ProfileSyncComponentsFactoryMock();
197 signin, 206 service_.reset(new TestProfileSyncService(
198 ProfileSyncService::AUTO_START, 207 factory,
199 true, 208 profile_.get(),
200 base::Closure())); 209 signin,
210 ProfileSyncService::AUTO_START,
211 true,
212 base::Closure()));
201 // Register the bookmark data type. 213 // Register the bookmark data type.
202 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). 214 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).
203 WillRepeatedly(ReturnNewDataTypeManager()); 215 WillRepeatedly(ReturnNewDataTypeManager());
204 216
205 IssueTestTokens(); 217 IssueTestTokens();
206 218
207 service_->Initialize(); 219 service_->Initialize();
208 EXPECT_TRUE(service_->sync_initialized()); 220 EXPECT_TRUE(service_->sync_initialized());
209 EXPECT_TRUE(service_->GetBackendForTest() != NULL); 221 EXPECT_TRUE(service_->GetBackendForTest() != NULL);
210 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); 222 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
211 223
212 service_->StopAndSuppress(); 224 service_->StopAndSuppress();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // The backend is not ready. Ensure the PSS knows this. 368 // The backend is not ready. Ensure the PSS knows this.
357 EXPECT_FALSE(service_->sync_initialized()); 369 EXPECT_FALSE(service_->sync_initialized());
358 370
359 // Ensure we will be prepared to initialize a fresh DB next time. 371 // Ensure we will be prepared to initialize a fresh DB next time.
360 EXPECT_FALSE(service_->HasSyncSetupCompleted()); 372 EXPECT_FALSE(service_->HasSyncSetupCompleted());
361 } 373 }
362 374
363 } // namespace 375 } // namespace
364 376
365 } // namespace browser_sync 377 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_typed_url_unittest.cc ('k') | chrome/browser/sync/sync_setup_wizard_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698