| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ | 5 #ifndef CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ |
| 6 #define CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ | 6 #define CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { | 24 class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { |
| 25 public: | 25 public: |
| 26 ProfileSyncServiceTestHarness(Profile* p, const std::string& username, | 26 ProfileSyncServiceTestHarness(Profile* p, const std::string& username, |
| 27 const std::string& password, int id); | 27 const std::string& password, int id); |
| 28 | 28 |
| 29 // Creates a ProfileSyncService for the profile passed at construction and | 29 // Creates a ProfileSyncService for the profile passed at construction and |
| 30 // enables sync. Returns true only after sync has been fully initialized and | 30 // enables sync. Returns true only after sync has been fully initialized and |
| 31 // authenticated, and we are ready to process changes. | 31 // authenticated, and we are ready to process changes. |
| 32 bool SetupSync(); | 32 bool SetupSync(); |
| 33 | 33 |
| 34 // Retries a sync setup when the previous attempt was aborted by an | |
| 35 // authentication failure. | |
| 36 bool RetryAuthentication(); | |
| 37 | |
| 38 // ProfileSyncServiceObserver implementation. | 34 // ProfileSyncServiceObserver implementation. |
| 39 virtual void OnStateChanged(); | 35 virtual void OnStateChanged(); |
| 40 | 36 |
| 41 // Blocks the caller until this harness has completed a single sync cycle | 37 // Blocks the caller until this harness has completed a single sync cycle |
| 42 // since the previous one. Returns true if a sync cycle has completed. | 38 // since the previous one. Returns true if a sync cycle has completed. |
| 43 bool AwaitSyncCycleCompletion(const std::string& reason); | 39 bool AwaitSyncCycleCompletion(const std::string& reason); |
| 44 | 40 |
| 45 // Blocks the caller until this harness has observed that the sync engine | 41 // Blocks the caller until this harness has observed that the sync engine |
| 46 // has "synced" up to at least the specified local timestamp. | 42 // has "synced" up to at least the specified local timestamp. |
| 47 bool WaitUntilTimestampIsAtLeast(int64 timestamp, const std::string& reason); | 43 bool WaitUntilTimestampIsAtLeast(int64 timestamp, const std::string& reason); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 72 | 68 |
| 73 ProfileSyncService* service() { return service_; } | 69 ProfileSyncService* service() { return service_; } |
| 74 | 70 |
| 75 // See ProfileSyncService::ShouldPushChanges(). | 71 // See ProfileSyncService::ShouldPushChanges(). |
| 76 bool ServiceIsPushingChanges() { return service_->ShouldPushChanges(); } | 72 bool ServiceIsPushingChanges() { return service_->ShouldPushChanges(); } |
| 77 | 73 |
| 78 private: | 74 private: |
| 79 friend class StateChangeTimeoutEvent; | 75 friend class StateChangeTimeoutEvent; |
| 80 | 76 |
| 81 enum WaitState { | 77 enum WaitState { |
| 82 // The sync client awaits the OnAuthError() callback. | |
| 83 WAITING_FOR_ON_AUTH_ERROR = 0, | |
| 84 // The sync client awaits the OnBackendInitialized() callback. | 78 // The sync client awaits the OnBackendInitialized() callback. |
| 85 WAITING_FOR_ON_BACKEND_INITIALIZED, | 79 WAITING_FOR_ON_BACKEND_INITIALIZED = 0, |
| 86 // The sync client is waiting for notifications_enabled to become true. | 80 // The sync client is waiting for notifications_enabled to become true. |
| 87 WAITING_FOR_NOTIFICATIONS_ENABLED, | 81 WAITING_FOR_NOTIFICATIONS_ENABLED, |
| 88 // The sync client is waiting for an ongoing sync cycle to complete. | 82 // The sync client is waiting for an ongoing sync cycle to complete. |
| 89 WAITING_FOR_SYNC_TO_FINISH, | 83 WAITING_FOR_SYNC_TO_FINISH, |
| 90 // The sync client anticipates incoming updates leading to a new sync cycle. | 84 // The sync client anticipates incoming updates leading to a new sync cycle. |
| 91 WAITING_FOR_UPDATES, | 85 WAITING_FOR_UPDATES, |
| 86 // The sync client is waiting for server_reachable to become true. |
| 87 WAITING_FOR_SERVER_REACHABLE, |
| 92 // The sync client is fully synced and there are no pending updates. | 88 // The sync client is fully synced and there are no pending updates. |
| 93 FULLY_SYNCED, | 89 FULLY_SYNCED, |
| 94 // An authentication error has occurred. | 90 // An authentication error has occurred. |
| 95 AUTH_ERROR, | 91 AUTH_ERROR, |
| 96 NUMBER_OF_STATES, | 92 NUMBER_OF_STATES, |
| 97 }; | 93 }; |
| 98 | 94 |
| 99 // Called from the observer when the current wait state has been completed. | 95 // Called from the observer when the current wait state has been completed. |
| 100 void SignalStateCompleteWithNextState(WaitState next_state); | 96 void SignalStateCompleteWithNextState(WaitState next_state); |
| 101 void SignalStateComplete(); | 97 void SignalStateComplete(); |
| 102 | 98 |
| 103 // Finite state machine for controlling state. Returns true only if a state | 99 // Finite state machine for controlling state. Returns true only if a state |
| 104 // change has taken place. | 100 // change has taken place. |
| 105 bool RunStateChangeMachine(); | 101 bool RunStateChangeMachine(); |
| 106 | 102 |
| 107 // Returns true if a status change took place, false on timeout. | 103 // Returns true if a status change took place, false on timeout. |
| 108 virtual bool AwaitStatusChangeWithTimeout(int timeout_seconds, | 104 virtual bool AwaitStatusChangeWithTimeout(int timeout_seconds, |
| 109 const std::string& reason); | 105 const std::string& reason); |
| 110 | 106 |
| 111 // Returns true if the service initialized correctly. Set is_auth_retry to | 107 // Returns true if the service initialized correctly. Set is_auth_retry to |
| 112 // true when calling this method second time after an authentication failure. | 108 // true when calling this method second time after an authentication failure. |
| 113 bool WaitForServiceInit(bool is_auth_retry); | 109 bool WaitForServiceInit(); |
| 114 | 110 |
| 115 // Logs message with relevant info about client's sync state (if available). | 111 // Logs message with relevant info about client's sync state (if available). |
| 116 void LogClientInfo(std::string message); | 112 void LogClientInfo(std::string message); |
| 117 | 113 |
| 118 WaitState wait_state_; | 114 WaitState wait_state_; |
| 119 | 115 |
| 120 Profile* profile_; | 116 Profile* profile_; |
| 121 ProfileSyncService* service_; | 117 ProfileSyncService* service_; |
| 122 | 118 |
| 123 // Returns a snapshot of the current sync session. | 119 // Returns a snapshot of the current sync session. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 140 std::string username_; | 136 std::string username_; |
| 141 std::string password_; | 137 std::string password_; |
| 142 | 138 |
| 143 // Client ID, used for logging purposes. | 139 // Client ID, used for logging purposes. |
| 144 int id_; | 140 int id_; |
| 145 | 141 |
| 146 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHarness); | 142 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHarness); |
| 147 }; | 143 }; |
| 148 | 144 |
| 149 #endif // CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ | 145 #endif // CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ |
| OLD | NEW |