| 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> |
| 11 | 11 |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 | 14 |
| 15 using browser_sync::sessions::SyncSessionSnapshot; | 15 using browser_sync::sessions::SyncSessionSnapshot; |
| 16 | 16 |
| 17 class Profile; | 17 class Profile; |
| 18 | 18 |
| 19 // An instance of this class is basically our notion of a "sync client" for | 19 // An instance of this class is basically our notion of a "sync client" for |
| 20 // test purposes. It harnesses the ProfileSyncService member of the profile | 20 // test purposes. It harnesses the ProfileSyncService member of the profile |
| 21 // passed to it on construction and automates certain things like setup and | 21 // passed to it on construction and automates certain things like setup and |
| 22 // authentication. It provides ways to "wait" adequate periods of time for | 22 // authentication. It provides ways to "wait" adequate periods of time for |
| 23 // several clients to get to the same state. | 23 // several clients to get to the same state. |
| 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); | 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 | 34 // Retries a sync setup when the previous attempt was aborted by an |
| 35 // authentication failure. | 35 // authentication failure. |
| 36 bool RetryAuthentication(); | 36 bool RetryAuthentication(); |
| 37 | 37 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void SignalStateComplete(); | 101 void SignalStateComplete(); |
| 102 | 102 |
| 103 // Finite state machine for controlling state. Returns true only if a state | 103 // Finite state machine for controlling state. Returns true only if a state |
| 104 // change has taken place. | 104 // change has taken place. |
| 105 bool RunStateChangeMachine(); | 105 bool RunStateChangeMachine(); |
| 106 | 106 |
| 107 // Returns true if a status change took place, false on timeout. | 107 // Returns true if a status change took place, false on timeout. |
| 108 virtual bool AwaitStatusChangeWithTimeout(int timeout_seconds, | 108 virtual bool AwaitStatusChangeWithTimeout(int timeout_seconds, |
| 109 const std::string& reason); | 109 const std::string& reason); |
| 110 | 110 |
| 111 // Returns true if the service initialized correctly. Set | 111 // Returns true if the service initialized correctly. Set is_auth_retry to |
| 112 // is_auth_retry to true when calling this method second time after | 112 // true when calling this method second time after an authentication failure. |
| 113 // an autentication failure. | |
| 114 bool WaitForServiceInit(bool is_auth_retry); | 113 bool WaitForServiceInit(bool is_auth_retry); |
| 115 | 114 |
| 115 // Logs message with relevant info about client's sync state (if available). |
| 116 void LogClientInfo(std::string message); |
| 117 |
| 116 WaitState wait_state_; | 118 WaitState wait_state_; |
| 117 | 119 |
| 118 Profile* profile_; | 120 Profile* profile_; |
| 119 ProfileSyncService* service_; | 121 ProfileSyncService* service_; |
| 120 | 122 |
| 121 // Returns a snapshot of the current sync session. | 123 // Returns a snapshot of the current sync session. |
| 122 const SyncSessionSnapshot* GetLastSessionSnapshot() const; | 124 const SyncSessionSnapshot* GetLastSessionSnapshot() const; |
| 123 | 125 |
| 124 // State tracking. Used for debugging and tracking of state. | 126 // State tracking. Used for debugging and tracking of state. |
| 125 ProfileSyncService::Status last_status_; | 127 ProfileSyncService::Status last_status_; |
| 126 | 128 |
| 127 // This value tracks the max sync timestamp (e.g. synced-to revision) inside | 129 // This value tracks the max sync timestamp (e.g. synced-to revision) inside |
| 128 // the sync engine. It gets updated when a sync cycle ends and the session | 130 // the sync engine. It gets updated when a sync cycle ends and the session |
| 129 // snapshot implies syncing is "done". | 131 // snapshot implies syncing is "done". |
| 130 int64 last_timestamp_; | 132 int64 last_timestamp_; |
| 131 | 133 |
| 132 // The minimum value of the 'max_local_timestamp' member of a | 134 // The minimum value of the 'max_local_timestamp' member of a |
| 133 // SyncSessionSnapshot we need to wait to observe in OnStateChanged when told | 135 // SyncSessionSnapshot we need to wait to observe in OnStateChanged when told |
| 134 // to WaitUntilTimestampIsAtLeast(...). | 136 // to WaitUntilTimestampIsAtLeast(...). |
| 135 int64 min_timestamp_needed_; | 137 int64 min_timestamp_needed_; |
| 136 | 138 |
| 137 // Credentials used for GAIA authentication. | 139 // Credentials used for GAIA authentication. |
| 138 std::string username_; | 140 std::string username_; |
| 139 std::string password_; | 141 std::string password_; |
| 140 | 142 |
| 143 // Client ID, used for logging purposes. |
| 144 int id_; |
| 145 |
| 141 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHarness); | 146 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHarness); |
| 142 }; | 147 }; |
| 143 | 148 |
| 144 #endif // CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ | 149 #endif // CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ |
| OLD | NEW |