OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <ostream> | 10 #include <ostream> |
11 #include <set> | 11 #include <set> |
12 #include <sstream> | 12 #include <sstream> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/task.h" | 19 #include "base/task.h" |
20 #include "base/tracked.h" | 20 #include "base/tracked.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/sync/sessions/session_state.h" | 22 #include "chrome/browser/sync/sessions/session_state.h" |
23 #include "chrome/browser/sync/signin_manager.h" | 23 #include "chrome/browser/sync/signin_manager.h" |
24 #include "chrome/browser/sync/sync_ui_util.h" | 24 #include "chrome/browser/sync/sync_ui_util.h" |
25 | 25 |
26 using browser_sync::sessions::SyncSessionSnapshot; | 26 using browser_sync::sessions::SyncSessionSnapshot; |
27 | 27 |
28 // TODO(rsimha): Remove the following lines once crbug.com/91863 is fixed. | |
28 // The amount of time for which we wait for a live sync operation to complete. | 29 // The amount of time for which we wait for a live sync operation to complete. |
29 static const int kLiveSyncOperationTimeoutMs = 45000; | 30 static const int kLiveSyncOperationTimeoutMs = 45000; |
30 | 31 |
32 // The amount of time we wait for test cases that verify exponential backoff. | |
33 static const int kExponentialBackoffVerificationTimeoutMs = 60000; | |
tim (not reviewing)
2011/08/10 00:08:29
couldn't we use the TestTimeouts value rather than
| |
34 | |
31 // Simple class to implement a timeout using PostDelayedTask. If it is not | 35 // Simple class to implement a timeout using PostDelayedTask. If it is not |
32 // aborted before picked up by a message queue, then it asserts with the message | 36 // aborted before picked up by a message queue, then it asserts with the message |
33 // provided. This class is not thread safe. | 37 // provided. This class is not thread safe. |
34 class StateChangeTimeoutEvent | 38 class StateChangeTimeoutEvent |
35 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { | 39 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { |
36 public: | 40 public: |
37 StateChangeTimeoutEvent(ProfileSyncServiceHarness* caller, | 41 StateChangeTimeoutEvent(ProfileSyncServiceHarness* caller, |
38 const std::string& message); | 42 const std::string& message); |
39 | 43 |
40 // The entry point to the class from PostDelayedTask. | 44 // The entry point to the class from PostDelayedTask. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 username_(username), | 104 username_(username), |
101 password_(password), | 105 password_(password), |
102 profile_debug_name_(profile->GetDebugName()) { | 106 profile_debug_name_(profile->GetDebugName()) { |
103 if (IsSyncAlreadySetup()) { | 107 if (IsSyncAlreadySetup()) { |
104 service_ = profile_->GetProfileSyncService(); | 108 service_ = profile_->GetProfileSyncService(); |
105 service_->AddObserver(this); | 109 service_->AddObserver(this); |
106 wait_state_ = FULLY_SYNCED; | 110 wait_state_ = FULLY_SYNCED; |
107 } | 111 } |
108 } | 112 } |
109 | 113 |
114 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() {} | |
115 | |
110 // static | 116 // static |
111 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( | 117 ProfileSyncServiceHarness* ProfileSyncServiceHarness::CreateAndAttach( |
112 Profile* profile) { | 118 Profile* profile) { |
113 if (!profile->HasProfileSyncService()) { | 119 if (!profile->HasProfileSyncService()) { |
114 NOTREACHED() << "Profile has never signed into sync."; | 120 NOTREACHED() << "Profile has never signed into sync."; |
115 return NULL; | 121 return NULL; |
116 } | 122 } |
117 return new ProfileSyncServiceHarness(profile, "", ""); | 123 return new ProfileSyncServiceHarness(profile, "", ""); |
118 } | 124 } |
119 | 125 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 break; | 326 break; |
321 } | 327 } |
322 case WAITING_FOR_SYNC_DISABLED: { | 328 case WAITING_FOR_SYNC_DISABLED: { |
323 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); | 329 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); |
324 if (service()->HasSyncSetupCompleted() == false) { | 330 if (service()->HasSyncSetupCompleted() == false) { |
325 // Sync has been disabled. | 331 // Sync has been disabled. |
326 SignalStateCompleteWithNextState(SYNC_DISABLED); | 332 SignalStateCompleteWithNextState(SYNC_DISABLED); |
327 } | 333 } |
328 break; | 334 break; |
329 } | 335 } |
336 case WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION: { | |
337 VLOG(1) << GetClientInfoString( | |
338 "WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION"); | |
339 const browser_sync::sessions::SyncSessionSnapshot *snap = | |
340 GetLastSessionSnapshot(); | |
341 CHECK(snap); | |
tim (not reviewing)
2011/08/10 00:08:29
the deref below is probably more useful than this
| |
342 retry_verifier_.VerifyRetryInterval(*snap); | |
343 if (retry_verifier_.done()) | |
344 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | |
tim (not reviewing)
2011/08/10 00:08:29
nit - indent
| |
345 break; | |
346 } | |
330 case SERVER_UNREACHABLE: { | 347 case SERVER_UNREACHABLE: { |
331 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); | 348 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); |
332 if (GetStatus().server_reachable) { | 349 if (GetStatus().server_reachable) { |
333 // The client was offline due to the network being disabled, but is now | 350 // The client was offline due to the network being disabled, but is now |
334 // back online. Wait for the pending sync cycle to complete. | 351 // back online. Wait for the pending sync cycle to complete. |
335 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 352 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
336 } | 353 } |
337 break; | 354 break; |
338 } | 355 } |
339 case SET_PASSPHRASE_FAILED: { | 356 case SET_PASSPHRASE_FAILED: { |
340 // A passphrase is required for decryption. There is nothing the sync | 357 // A passphrase is required for decryption. There is nothing the sync |
341 // client can do until SetPassphrase() is called. | 358 // client can do until SetPassphrase() is called. |
342 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); | 359 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); |
343 break; | 360 break; |
344 } | 361 } |
345 case FULLY_SYNCED: { | 362 case FULLY_SYNCED: { |
346 // The client is online and fully synced. There is nothing to do. | 363 // The client is online and fully synced. There is nothing to do. |
347 VLOG(1) << GetClientInfoString("FULLY_SYNCED"); | 364 VLOG(1) << GetClientInfoString("FULLY_SYNCED"); |
348 break; | 365 break; |
349 } | 366 } |
350 case SYNC_DISABLED: { | 367 case SYNC_DISABLED: { |
351 // Syncing is disabled for the client. There is nothing to do. | 368 // Syncing is disabled for the client. There is nothing to do. |
352 VLOG(1) << GetClientInfoString("SYNC_DISABLED"); | 369 VLOG(1) << GetClientInfoString("SYNC_DISABLED"); |
353 break; | 370 break; |
354 } | 371 } |
372 case WAITING_FOR_NOTHING: { | |
373 // We don't care about the state of the syncer for the rest of the test | |
374 // case. | |
375 VLOG(1) << GetClientInfoString("WAITING_FOR_NOTHING"); | |
376 break; | |
377 } | |
355 default: | 378 default: |
356 // Invalid state during observer callback which may be triggered by other | 379 // Invalid state during observer callback which may be triggered by other |
357 // classes using the the UI message loop. Defer to their handling. | 380 // classes using the the UI message loop. Defer to their handling. |
358 break; | 381 break; |
359 } | 382 } |
360 return original_wait_state != wait_state_; | 383 return original_wait_state != wait_state_; |
361 } | 384 } |
362 | 385 |
363 void ProfileSyncServiceHarness::OnStateChanged() { | 386 void ProfileSyncServiceHarness::OnStateChanged() { |
364 RunStateChangeMachine(); | 387 RunStateChangeMachine(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 } | 493 } |
471 | 494 |
472 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { | 495 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { |
473 DCHECK(service()->HasSyncSetupCompleted()); | 496 DCHECK(service()->HasSyncSetupCompleted()); |
474 DCHECK_NE(wait_state_, SYNC_DISABLED); | 497 DCHECK_NE(wait_state_, SYNC_DISABLED); |
475 wait_state_ = WAITING_FOR_SYNC_DISABLED; | 498 wait_state_ = WAITING_FOR_SYNC_DISABLED; |
476 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 499 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
477 return wait_state_ == SYNC_DISABLED; | 500 return wait_state_ == SYNC_DISABLED; |
478 } | 501 } |
479 | 502 |
503 bool ProfileSyncServiceHarness::AwaitExponentialBackoffVerification() { | |
504 const browser_sync::sessions::SyncSessionSnapshot *snap = | |
505 GetLastSessionSnapshot(); | |
506 CHECK(snap); | |
507 retry_verifier_.Initialize(*snap); | |
508 wait_state_ = WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION; | |
509 AwaitStatusChangeWithTimeout(kExponentialBackoffVerificationTimeoutMs, | |
510 "Verify Exponential backoff"); | |
511 return (retry_verifier_.Succeeded()); | |
512 } | |
513 | |
480 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 514 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
481 ProfileSyncServiceHarness* partner) { | 515 ProfileSyncServiceHarness* partner) { |
482 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); | 516 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); |
483 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 517 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
484 return false; | 518 return false; |
485 return partner->WaitUntilTimestampMatches(this, | 519 return partner->WaitUntilTimestampMatches(this, |
486 "Sync cycle completion on passive client."); | 520 "Sync cycle completion on passive client."); |
487 } | 521 } |
488 | 522 |
489 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 523 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 return true; | 875 return true; |
842 } | 876 } |
843 | 877 |
844 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 878 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
845 DictionaryValue value; | 879 DictionaryValue value; |
846 sync_ui_util::ConstructAboutInformation(service_, &value); | 880 sync_ui_util::ConstructAboutInformation(service_, &value); |
847 std::string service_status; | 881 std::string service_status; |
848 base::JSONWriter::Write(&value, true, &service_status); | 882 base::JSONWriter::Write(&value, true, &service_status); |
849 return service_status; | 883 return service_status; |
850 } | 884 } |
OLD | NEW |