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; | |
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 break; | 324 break; |
321 } | 325 } |
322 case WAITING_FOR_SYNC_DISABLED: { | 326 case WAITING_FOR_SYNC_DISABLED: { |
323 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); | 327 VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); |
324 if (service()->HasSyncSetupCompleted() == false) { | 328 if (service()->HasSyncSetupCompleted() == false) { |
325 // Sync has been disabled. | 329 // Sync has been disabled. |
326 SignalStateCompleteWithNextState(SYNC_DISABLED); | 330 SignalStateCompleteWithNextState(SYNC_DISABLED); |
327 } | 331 } |
328 break; | 332 break; |
329 } | 333 } |
334 case WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION: { | |
335 VLOG(1) << GetClientInfoString( | |
336 "WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION"); | |
337 const browser_sync::sessions::SyncSessionSnapshot *snap = | |
338 GetLastSessionSnapshot(); | |
339 CHECK(snap); | |
340 retry_verifier_.VerifyRetryInterval(*snap); | |
341 if (retry_verifier_.Done()) | |
342 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | |
343 break; | |
344 } | |
330 case SERVER_UNREACHABLE: { | 345 case SERVER_UNREACHABLE: { |
331 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); | 346 VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); |
332 if (GetStatus().server_reachable) { | 347 if (GetStatus().server_reachable) { |
333 // The client was offline due to the network being disabled, but is now | 348 // The client was offline due to the network being disabled, but is now |
334 // back online. Wait for the pending sync cycle to complete. | 349 // back online. Wait for the pending sync cycle to complete. |
335 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 350 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
336 } | 351 } |
337 break; | 352 break; |
338 } | 353 } |
339 case SET_PASSPHRASE_FAILED: { | 354 case SET_PASSPHRASE_FAILED: { |
340 // A passphrase is required for decryption. There is nothing the sync | 355 // A passphrase is required for decryption. There is nothing the sync |
341 // client can do until SetPassphrase() is called. | 356 // client can do until SetPassphrase() is called. |
342 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); | 357 VLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); |
343 break; | 358 break; |
344 } | 359 } |
345 case FULLY_SYNCED: { | 360 case FULLY_SYNCED: { |
346 // The client is online and fully synced. There is nothing to do. | 361 // The client is online and fully synced. There is nothing to do. |
347 VLOG(1) << GetClientInfoString("FULLY_SYNCED"); | 362 VLOG(1) << GetClientInfoString("FULLY_SYNCED"); |
348 break; | 363 break; |
349 } | 364 } |
350 case SYNC_DISABLED: { | 365 case SYNC_DISABLED: { |
351 // Syncing is disabled for the client. There is nothing to do. | 366 // Syncing is disabled for the client. There is nothing to do. |
352 VLOG(1) << GetClientInfoString("SYNC_DISABLED"); | 367 VLOG(1) << GetClientInfoString("SYNC_DISABLED"); |
353 break; | 368 break; |
354 } | 369 } |
370 case WAITING_FOR_NOTHING: { | |
371 // We don't care about the state of the syncer for the rest of the test | |
372 // case. | |
373 VLOG(1) << GetClientInfoString("WAIT_FOR_NOTHING"); | |
Raghu Simha
2011/08/05 23:23:58
s/WAIT_FOR_NOTHING/WAITING_FOR_NOTHING/
lipalani1
2011/08/09 01:39:02
Done.
| |
374 break; | |
375 } | |
355 default: | 376 default: |
356 // Invalid state during observer callback which may be triggered by other | 377 // Invalid state during observer callback which may be triggered by other |
357 // classes using the the UI message loop. Defer to their handling. | 378 // classes using the the UI message loop. Defer to their handling. |
358 break; | 379 break; |
359 } | 380 } |
360 return original_wait_state != wait_state_; | 381 return original_wait_state != wait_state_; |
361 } | 382 } |
362 | 383 |
363 void ProfileSyncServiceHarness::OnStateChanged() { | 384 void ProfileSyncServiceHarness::OnStateChanged() { |
364 RunStateChangeMachine(); | 385 RunStateChangeMachine(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 } | 491 } |
471 | 492 |
472 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { | 493 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { |
473 DCHECK(service()->HasSyncSetupCompleted()); | 494 DCHECK(service()->HasSyncSetupCompleted()); |
474 DCHECK_NE(wait_state_, SYNC_DISABLED); | 495 DCHECK_NE(wait_state_, SYNC_DISABLED); |
475 wait_state_ = WAITING_FOR_SYNC_DISABLED; | 496 wait_state_ = WAITING_FOR_SYNC_DISABLED; |
476 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 497 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
477 return wait_state_ == SYNC_DISABLED; | 498 return wait_state_ == SYNC_DISABLED; |
478 } | 499 } |
479 | 500 |
501 bool ProfileSyncServiceHarness::AwaitExponentialBackoffVerification() { | |
502 retry_verifier_.Initialize(*GetLastSessionSnapshot()); | |
503 wait_state_ = WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION; | |
504 AwaitStatusChangeWithTimeout(kExponentialBackoffVerificationTimeoutMs, | |
505 "Verify Exponential backoff"); | |
506 return (retry_verifier_.Success()); | |
507 } | |
508 | |
480 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 509 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
481 ProfileSyncServiceHarness* partner) { | 510 ProfileSyncServiceHarness* partner) { |
482 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); | 511 VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); |
483 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 512 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
484 return false; | 513 return false; |
485 return partner->WaitUntilTimestampMatches(this, | 514 return partner->WaitUntilTimestampMatches(this, |
486 "Sync cycle completion on passive client."); | 515 "Sync cycle completion on passive client."); |
487 } | 516 } |
488 | 517 |
489 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( | 518 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
832 return true; | 861 return true; |
833 } | 862 } |
834 | 863 |
835 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 864 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
836 DictionaryValue value; | 865 DictionaryValue value; |
837 sync_ui_util::ConstructAboutInformation(service_, &value); | 866 sync_ui_util::ConstructAboutInformation(service_, &value); |
838 std::string service_status; | 867 std::string service_status; |
839 base::JSONWriter::Write(&value, true, &service_status); | 868 base::JSONWriter::Write(&value, true, &service_status); |
840 return service_status; | 869 return service_status; |
841 } | 870 } |
OLD | NEW |