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

Side by Side Diff: chrome/browser/sync/test/integration/profile_sync_service_harness.cc

Issue 2716413003: Initial clear server data impl (Closed)
Patch Set: Addressing newlines, and unused arguments Created 3 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 5 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <iterator> 8 #include <iterator>
9 #include <ostream> 9 #include <ostream>
10 #include <sstream> 10 #include <sstream>
11 11
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h" 17 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h" 18 #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h"
19 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" 19 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
22 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" 24 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
23 #include "chrome/common/channel_info.h" 25 #include "chrome/common/channel_info.h"
24 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
25 #include "components/browser_sync/profile_sync_service.h" 27 #include "components/browser_sync/profile_sync_service.h"
26 #include "components/invalidation/impl/p2p_invalidation_service.h" 28 #include "components/invalidation/impl/p2p_invalidation_service.h"
27 #include "components/signin/core/browser/profile_oauth2_token_service.h" 29 #include "components/signin/core/browser/profile_oauth2_token_service.h"
28 #include "components/signin/core/browser/signin_manager_base.h" 30 #include "components/signin/core/browser/signin_manager_base.h"
29 #include "components/sync/base/progress_marker_map.h" 31 #include "components/sync/base/progress_marker_map.h"
30 #include "components/sync/driver/about_sync_util.h" 32 #include "components/sync/driver/about_sync_util.h"
31 #include "components/sync/engine/sync_string_conversions.h" 33 #include "components/sync/engine/sync_string_conversions.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 125
124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { } 126 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { }
125 127
126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, 128 void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
127 const std::string& password) { 129 const std::string& password) {
128 username_ = username; 130 username_ = username;
129 password_ = password; 131 password_ = password;
130 } 132 }
131 133
132 bool ProfileSyncServiceHarness::SetupSync() { 134 bool ProfileSyncServiceHarness::SetupSync() {
133 bool result = SetupSync(syncer::UserSelectableTypes()); 135 bool result = SetupSync(syncer::UserSelectableTypes(), false);
134 if (result == false) { 136 if (!result) {
135 std::string status = GetServiceStatus(); 137 LOG(ERROR) << profile_debug_name_ << ": SetupSync failed. Syncer status:\n"
136 LOG(ERROR) << profile_debug_name_ 138 << GetServiceStatus();
137 << ": SetupSync failed. Syncer status:\n" << status;
138 } else { 139 } else {
139 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; 140 DVLOG(1) << profile_debug_name_ << ": SetupSync successful.";
140 } 141 }
141 return result; 142 return result;
142 } 143 }
143 144
144 bool ProfileSyncServiceHarness::SetupSync( 145 bool ProfileSyncServiceHarness::SetupSyncForClearingServerData() {
145 syncer::ModelTypeSet synced_datatypes) { 146 bool result = SetupSync(syncer::UserSelectableTypes(), true);
147 if (!result) {
148 LOG(ERROR) << profile_debug_name_
149 << ": SetupSyncForClear failed. Syncer status:\n"
150 << GetServiceStatus();
151 } else {
152 DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful.";
153 }
154 return result;
155 }
156
157 bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes,
158 bool skip_passphrase_verification) {
146 DCHECK(!profile_->IsLegacySupervised()) 159 DCHECK(!profile_->IsLegacySupervised())
147 << "SetupSync should not be used for legacy supervised users."; 160 << "SetupSync should not be used for legacy supervised users.";
148 161
149 // Initialize the sync client's profile sync service object. 162 // Initialize the sync client's profile sync service object.
150 if (service() == nullptr) { 163 if (service() == nullptr) {
151 LOG(ERROR) << "SetupSync(): service() is null."; 164 LOG(ERROR) << "SetupSync(): service() is null.";
152 return false; 165 return false;
153 } 166 }
154 167
155 // Tell the sync service that setup is in progress so we don't start syncing 168 // Tell the sync service that setup is in progress so we don't start syncing
(...skipping 16 matching lines...) Expand all
172 service()->GoogleSigninSucceeded(account_id, username_, password_); 185 service()->GoogleSigninSucceeded(account_id, username_, password_);
173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 186 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
174 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); 187 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString());
175 } else { 188 } else {
176 LOG(ERROR) << "Unsupported profile signin type."; 189 LOG(ERROR) << "Unsupported profile signin type.";
177 } 190 }
178 191
179 // Now that auth is completed, request that sync actually start. 192 // Now that auth is completed, request that sync actually start.
180 service()->RequestStart(); 193 service()->RequestStart();
181 194
182 if (!AwaitEngineInitialization()) { 195 if (!AwaitEngineInitialization(skip_passphrase_verification)) {
183 return false; 196 return false;
184 } 197 }
185
186 // Choose the datatypes to be synced. If all datatypes are to be synced, 198 // Choose the datatypes to be synced. If all datatypes are to be synced,
187 // set sync_everything to true; otherwise, set it to false. 199 // set sync_everything to true; otherwise, set it to false.
188 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); 200 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes());
189 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); 201 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes);
190 202
191 // Notify ProfileSyncService that we are done with configuration. 203 // Notify ProfileSyncService that we are done with configuration.
192 FinishSyncSetup(); 204 if (skip_passphrase_verification) {
205 sync_blocker_.reset();
206 } else {
207 FinishSyncSetup();
208 }
193 209
194 if ((signin_type_ == SigninType::UI_SIGNIN) && 210 if ((signin_type_ == SigninType::UI_SIGNIN) &&
195 !login_ui_test_utils::DismissSyncConfirmationDialog( 211 !login_ui_test_utils::DismissSyncConfirmationDialog(
196 chrome::FindBrowserWithProfile(profile_), 212 chrome::FindBrowserWithProfile(profile_),
197 base::TimeDelta::FromSeconds(30))) { 213 base::TimeDelta::FromSeconds(30))) {
198 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; 214 LOG(ERROR) << "Failed to dismiss sync confirmation dialog.";
199 return false; 215 return false;
200 } 216 }
201 217
218 // OneClickSigninSyncStarter observer is created with a real user sign in.
219 // It is deleted on certain conditions which are not satisfied by our tests,
220 // and this causes the SigninTracker observer to stay hanging at shutdown.
221 // Calling LoginUIService::SyncConfirmationUIClosed forces the observer to
222 // be removed. http://crbug.com/484388
223 if (signin_type_ == SigninType::UI_SIGNIN) {
224 LoginUIServiceFactory::GetForProfile(profile_)->SyncConfirmationUIClosed(
225 LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
226 }
227
228 if (skip_passphrase_verification) {
229 return true;
230 }
231
202 // Set an implicit passphrase for encryption if an explicit one hasn't already 232 // Set an implicit passphrase for encryption if an explicit one hasn't already
203 // been set. If an explicit passphrase has been set, immediately return false, 233 // been set. If an explicit passphrase has been set, immediately return false,
204 // since a decryption passphrase is required. 234 // since a decryption passphrase is required.
205 if (!service()->IsUsingSecondaryPassphrase()) { 235 if (!service()->IsUsingSecondaryPassphrase()) {
206 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); 236 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
207 } else { 237 } else {
208 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 238 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
209 " until SetDecryptionPassphrase is called."; 239 " until SetDecryptionPassphrase is called.";
210 return false; 240 return false;
211 } 241 }
212 242
213 // Wait for initial sync cycle to be completed. 243 // Wait for initial sync cycle to be completed.
214 if (!AwaitSyncSetupCompletion()) { 244 if (!AwaitSyncSetupCompletion()) {
215 LOG(ERROR) << "Initial sync cycle timed out.";
216 return false; 245 return false;
217 } 246 }
218 247
248 return true;
249 }
250
251 bool ProfileSyncServiceHarness::RestartSyncService() {
252 DVLOG(1) << "Requesting stop for service.";
253 service()->RequestStop(ProfileSyncService::CLEAR_DATA);
254
255 std::unique_ptr<syncer::SyncSetupInProgressHandle> blocker =
256 service()->GetSetupInProgressHandle();
257 DVLOG(1) << "Requesting start for service";
258 service()->RequestStart();
259
260 if (!AwaitEngineInitialization()) {
261 LOG(ERROR) << "AwaitEngineInitialization failed.";
262 return false;
263 }
264 DVLOG(1) << "Engine Initialized successfully.";
265
266 // This passphrase should be implicit because ClearServerData should be called
267 // prior.
268 if (!service()->IsUsingSecondaryPassphrase()) {
269 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
270 } else {
271 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
272 " until SetDecryptionPassphrase is called.";
273 return false;
274 }
275 DVLOG(1) << "Passphrase decryption success.";
276
277 blocker.reset();
278 service()->SetFirstSetupComplete();
279
280 if (!AwaitSyncSetupCompletion()) {
281 LOG(FATAL) << "AwaitSyncSetupCompletion failed.";
282 return false;
283 }
284
219 return true; 285 return true;
220 } 286 }
221 287
222 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( 288 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
223 ProfileSyncServiceHarness* partner) { 289 ProfileSyncServiceHarness* partner) {
224 std::vector<ProfileSyncServiceHarness*> harnesses; 290 std::vector<ProfileSyncServiceHarness*> harnesses;
225 harnesses.push_back(this); 291 harnesses.push_back(this);
226 harnesses.push_back(partner); 292 harnesses.push_back(partner);
227 return AwaitQuiescence(harnesses); 293 return AwaitQuiescence(harnesses);
228 } 294 }
(...skipping 10 matching lines...) Expand all
239 if (clients.empty()) { 305 if (clients.empty()) {
240 return true; 306 return true;
241 } 307 }
242 308
243 for (const ProfileSyncServiceHarness* harness : clients) { 309 for (const ProfileSyncServiceHarness* harness : clients) {
244 services.push_back(harness->service()); 310 services.push_back(harness->service());
245 } 311 }
246 return QuiesceStatusChangeChecker(services).Wait(); 312 return QuiesceStatusChangeChecker(services).Wait();
247 } 313 }
248 314
249 bool ProfileSyncServiceHarness::AwaitEngineInitialization() { 315 bool ProfileSyncServiceHarness::AwaitEngineInitialization(
316 bool skip_passphrase_verification) {
250 if (!EngineInitializeChecker(service()).Wait()) { 317 if (!EngineInitializeChecker(service()).Wait()) {
251 LOG(ERROR) << "EngineInitializeChecker timed out."; 318 LOG(ERROR) << "EngineInitializeChecker timed out.";
252 return false; 319 return false;
253 } 320 }
254 321
255 if (!service()->IsEngineInitialized()) { 322 if (!service()->IsEngineInitialized()) {
256 LOG(ERROR) << "Service engine not initialized."; 323 LOG(ERROR) << "Service engine not initialized.";
257 return false; 324 return false;
258 } 325 }
259 326
260 // Make sure that initial sync wasn't blocked by a missing passphrase. 327 // Make sure that initial sync wasn't blocked by a missing passphrase.
261 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { 328 if (!skip_passphrase_verification &&
329 service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) {
262 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 330 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
263 " until SetDecryptionPassphrase is called."; 331 " until SetDecryptionPassphrase is called.";
264 return false; 332 return false;
265 } 333 }
266 334
267 if (HasAuthError(service())) { 335 if (HasAuthError(service())) {
268 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; 336 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed.";
269 return false; 337 return false;
270 } 338 }
271 339
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 544
477 std::string ProfileSyncServiceHarness::GetServiceStatus() { 545 std::string ProfileSyncServiceHarness::GetServiceStatus() {
478 std::unique_ptr<base::DictionaryValue> value( 546 std::unique_ptr<base::DictionaryValue> value(
479 syncer::sync_ui_util::ConstructAboutInformation( 547 syncer::sync_ui_util::ConstructAboutInformation(
480 service(), service()->signin(), chrome::GetChannel())); 548 service(), service()->signin(), chrome::GetChannel()));
481 std::string service_status; 549 std::string service_status;
482 base::JSONWriter::WriteWithOptions( 550 base::JSONWriter::WriteWithOptions(
483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); 551 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status);
484 return service_status; 552 return service_status;
485 } 553 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/profile_sync_service_harness.h ('k') | chrome/browser/sync/test/integration/sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698