| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_PROFILE_SYNC_SERVICE_HARNESS_H_ | 5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_PROFILE_SYNC_SERVICE_HARNESS_H_ |
| 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_PROFILE_SYNC_SERVICE_HARNESS_H_ | 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_PROFILE_SYNC_SERVICE_HARNESS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/browser/sync/profile_sync_service_observer.h" | 14 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 15 #include "sync/internal_api/public/base/model_type.h" | 15 #include "sync/internal_api/public/base/model_type.h" |
| 16 | 16 |
| 17 class Profile; | 17 class Profile; |
| 18 class StatusChangeChecker; | 18 class StatusChangeChecker; |
| 19 class P2PInvalidationForwarder; |
| 19 | 20 |
| 20 namespace invalidation { | 21 namespace invalidation { |
| 21 class P2PInvalidationService; | 22 class P2PInvalidationService; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace browser_sync { | 25 namespace browser_sync { |
| 25 namespace sessions { | 26 namespace sessions { |
| 26 class SyncSessionSnapshot; | 27 class SyncSessionSnapshot; |
| 27 } | 28 } |
| 28 } | 29 } |
| 29 | 30 |
| 30 // An instance of this class is basically our notion of a "sync client" for | 31 // An instance of this class is basically our notion of a "sync client" for |
| 31 // automation purposes. It harnesses the ProfileSyncService member of the | 32 // automation purposes. It harnesses the ProfileSyncService member of the |
| 32 // profile passed to it on construction and automates certain things like setup | 33 // profile passed to it on construction and automates certain things like setup |
| 33 // and authentication. It provides ways to "wait" adequate periods of time for | 34 // and authentication. It provides ways to "wait" adequate periods of time for |
| 34 // several clients to get to the same state. | 35 // several clients to get to the same state. |
| 35 class ProfileSyncServiceHarness | 36 class ProfileSyncServiceHarness { |
| 36 : public ProfileSyncServiceObserver { | |
| 37 public: | 37 public: |
| 38 static ProfileSyncServiceHarness* Create( | 38 static ProfileSyncServiceHarness* Create( |
| 39 Profile* profile, | 39 Profile* profile, |
| 40 const std::string& username, | 40 const std::string& username, |
| 41 const std::string& password); | 41 const std::string& password); |
| 42 | 42 |
| 43 static ProfileSyncServiceHarness* CreateForIntegrationTest( | 43 static ProfileSyncServiceHarness* CreateForIntegrationTest( |
| 44 Profile* profile, | 44 Profile* profile, |
| 45 const std::string& username, | 45 const std::string& username, |
| 46 const std::string& password, | 46 const std::string& password, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 60 // Creates a ProfileSyncService for the profile passed at construction and | 60 // Creates a ProfileSyncService for the profile passed at construction and |
| 61 // enables sync for all available datatypes. Returns true only after sync has | 61 // enables sync for all available datatypes. Returns true only after sync has |
| 62 // been fully initialized and authenticated, and we are ready to process | 62 // been fully initialized and authenticated, and we are ready to process |
| 63 // changes. | 63 // changes. |
| 64 bool SetupSync(); | 64 bool SetupSync(); |
| 65 | 65 |
| 66 // Same as the above method, but enables sync only for the datatypes contained | 66 // Same as the above method, but enables sync only for the datatypes contained |
| 67 // in |synced_datatypes|. | 67 // in |synced_datatypes|. |
| 68 bool SetupSync(syncer::ModelTypeSet synced_datatypes); | 68 bool SetupSync(syncer::ModelTypeSet synced_datatypes); |
| 69 | 69 |
| 70 // ProfileSyncServiceObserver implementation. | |
| 71 virtual void OnStateChanged() OVERRIDE; | |
| 72 virtual void OnSyncCycleCompleted() OVERRIDE; | |
| 73 | |
| 74 // Blocks the caller until the sync backend host associated with this harness | 70 // Blocks the caller until the sync backend host associated with this harness |
| 75 // has been initialized. Returns true if the wait was successful. | 71 // has been initialized. Returns true if the wait was successful. |
| 76 bool AwaitBackendInitialized(); | 72 bool AwaitBackendInitialized(); |
| 77 | 73 |
| 78 // Blocks the caller until the client has nothing left to commit and its | 74 // Blocks the caller until the client has nothing left to commit and its |
| 79 // progress markers are up to date. Returns true if successful. | 75 // progress markers are up to date. Returns true if successful. |
| 80 bool AwaitCommitActivityCompletion(); | 76 bool AwaitCommitActivityCompletion(); |
| 81 | 77 |
| 82 // Blocks the caller until sync has been disabled for this client. Returns | 78 // Blocks the caller until sync has been disabled for this client. Returns |
| 83 // true if sync is disabled. | 79 // true if sync is disabled. |
| 84 bool AwaitSyncDisabled(); | 80 bool AwaitSyncDisabled(); |
| 85 | 81 |
| 86 // Blocks the caller until sync setup is complete for this client. Returns | 82 // Blocks the caller until sync setup is complete for this client. Returns |
| 87 // true if sync setup is complete. | 83 // true if sync setup is complete. |
| 88 bool AwaitSyncSetupCompletion(); | 84 bool AwaitSyncSetupCompletion(); |
| 89 | 85 |
| 90 // Blocks the caller until this harness has observed that the sync engine | |
| 91 // has downloaded all the changes seen by the |partner| harness's client. | |
| 92 bool WaitUntilProgressMarkersMatch(ProfileSyncServiceHarness* partner); | |
| 93 | |
| 94 // Calling this acts as a barrier and blocks the caller until |this| and | 86 // Calling this acts as a barrier and blocks the caller until |this| and |
| 95 // |partner| have both completed a sync cycle. When calling this method, | 87 // |partner| have both completed a sync cycle. When calling this method, |
| 96 // the |partner| should be the passive responder who responds to the actions | 88 // the |partner| should be the passive responder who responds to the actions |
| 97 // of |this|. This method relies upon the synchronization of callbacks | 89 // of |this|. This method relies upon the synchronization of callbacks |
| 98 // from the message queue. Returns true if two sync cycles have completed. | 90 // from the message queue. Returns true if two sync cycles have completed. |
| 99 // Note: Use this method when exactly one client makes local change(s), and | 91 // Note: Use this method when exactly one client makes local change(s), and |
| 100 // exactly one client is waiting to receive those changes. | 92 // exactly one client is waiting to receive those changes. |
| 101 bool AwaitMutualSyncCycleCompletion(ProfileSyncServiceHarness* partner); | 93 bool AwaitMutualSyncCycleCompletion(ProfileSyncServiceHarness* partner); |
| 102 | 94 |
| 103 // Blocks the caller until |this| completes its ongoing sync cycle and every | 95 // Blocks the caller until |this| completes its ongoing sync cycle and every |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // Returns true if encryption is complete for all datatypes, and false | 152 // Returns true if encryption is complete for all datatypes, and false |
| 161 // otherwise. | 153 // otherwise. |
| 162 bool IsEncryptionComplete() const; | 154 bool IsEncryptionComplete() const; |
| 163 | 155 |
| 164 // Check if |type| is registered and the controller is running. | 156 // Check if |type| is registered and the controller is running. |
| 165 bool IsTypeRunning(syncer::ModelType type); | 157 bool IsTypeRunning(syncer::ModelType type); |
| 166 | 158 |
| 167 // Check if |type| is being synced. | 159 // Check if |type| is being synced. |
| 168 bool IsTypePreferred(syncer::ModelType type); | 160 bool IsTypePreferred(syncer::ModelType type); |
| 169 | 161 |
| 170 // Get the number of sync entries this client has. This includes all top | |
| 171 // level or permanent items, and can include recently deleted entries. | |
| 172 size_t GetNumEntries() const; | |
| 173 | |
| 174 // Get the number of sync datatypes registered (ignoring whatever state | |
| 175 // they're in). | |
| 176 size_t GetNumDatatypes() const; | |
| 177 | |
| 178 // Gets the |auto_start_enabled_| variable from the |service_|. | 162 // Gets the |auto_start_enabled_| variable from the |service_|. |
| 179 bool AutoStartEnabled(); | 163 bool AutoStartEnabled(); |
| 180 | 164 |
| 181 // Runs the UI message loop and waits until the Run() method of |checker| | 165 // Runs the UI message loop and waits until the Run() method of |checker| |
| 182 // returns true, indicating that the status change we are waiting for has | 166 // returns true, indicating that the status change we are waiting for has |
| 183 // taken place. Caller retains ownership of |checker|, which must outlive this | 167 // taken place. Caller retains ownership of |checker|, which must outlive this |
| 184 // method. Returns true if the status change was observed. In case of a | 168 // method. Returns true if the status change was observed. In case of a |
| 185 // timeout, we log the |source| of the call to this method, and return false. | 169 // timeout, we CHECK(false). |
| 186 bool AwaitStatusChange(StatusChangeChecker* checker, | 170 bool AwaitStatusChange(StatusChangeChecker* checker); |
| 187 const std::string& source); | |
| 188 | 171 |
| 189 // Returns a string that can be used as the value of an oauth2 refresh token. | 172 // Returns a string that can be used as the value of an oauth2 refresh token. |
| 190 // This function guarantees that a different string is returned each time | 173 // This function guarantees that a different string is returned each time |
| 191 // it is called. | 174 // it is called. |
| 192 std::string GenerateFakeOAuth2RefreshTokenString(); | 175 std::string GenerateFakeOAuth2RefreshTokenString(); |
| 193 | 176 |
| 194 // Returns a string with relevant info about client's sync state (if | 177 // Returns a string with relevant info about client's sync state (if |
| 195 // available), annotated with |message|. Useful for logging. | 178 // available), annotated with |message|. Useful for logging. |
| 196 std::string GetClientInfoString(const std::string& message) const; | 179 std::string GetClientInfoString(const std::string& message) const; |
| 197 | 180 |
| 198 // Returns true if this client has downloaded all the items that the | |
| 199 // other client has. | |
| 200 bool MatchesPartnerClient() const; | |
| 201 | |
| 202 private: | 181 private: |
| 203 ProfileSyncServiceHarness( | 182 ProfileSyncServiceHarness( |
| 204 Profile* profile, | 183 Profile* profile, |
| 205 const std::string& username, | 184 const std::string& username, |
| 206 const std::string& password, | 185 const std::string& password, |
| 207 invalidation::P2PInvalidationService* invalidation_service); | 186 invalidation::P2PInvalidationService* invalidation_service); |
| 208 | 187 |
| 209 // Quits the current message loop. Called when the status change being waited | 188 // Quits the current message loop. Called when the status change being waited |
| 210 // on has occurred, or in the event of a timeout. | 189 // on has occurred, or in the event of a timeout. |
| 211 void QuitMessageLoop(); | 190 void QuitMessageLoop(); |
| 212 | 191 |
| 213 // Signals that sync setup is complete, and that PSS may begin syncing. | 192 // Signals that sync setup is complete, and that PSS may begin syncing. |
| 214 void FinishSyncSetup(); | 193 void FinishSyncSetup(); |
| 215 | 194 |
| 216 // Gets the current progress marker of the current sync session for a | |
| 217 // particular datatype. Returns an empty string if the progress marker isn't | |
| 218 // found. | |
| 219 std::string GetSerializedProgressMarker(syncer::ModelType model_type) const; | |
| 220 | |
| 221 // Returns true if a client has nothing left to commit and its progress | 195 // Returns true if a client has nothing left to commit and its progress |
| 222 // markers are up to date. | 196 // markers are up to date. |
| 223 bool HasLatestProgressMarkers() const; | 197 bool HasLatestProgressMarkers() const; |
| 224 | 198 |
| 225 // Gets detailed status from |service_| in pretty-printable form. | 199 // Gets detailed status from |service_| in pretty-printable form. |
| 226 std::string GetServiceStatus(); | 200 std::string GetServiceStatus(); |
| 227 | 201 |
| 228 // Sync profile associated with this sync client. | 202 // Sync profile associated with this sync client. |
| 229 Profile* profile_; | 203 Profile* profile_; |
| 230 | 204 |
| 231 // ProfileSyncService object associated with |profile_|. | 205 // ProfileSyncService object associated with |profile_|. |
| 232 ProfileSyncService* service_; | 206 ProfileSyncService* service_; |
| 233 | 207 |
| 234 // P2PInvalidationService associated with |profile_|. | 208 // P2PInvalidationService associated with |profile_|. |
| 235 invalidation::P2PInvalidationService* p2p_invalidation_service_; | 209 invalidation::P2PInvalidationService* p2p_invalidation_service_; |
| 236 | 210 |
| 211 // An bridge between the ProfileSyncService and P2PInvalidationService. |
| 212 scoped_ptr<P2PInvalidationForwarder> p2p_invalidation_forwarder_; |
| 213 |
| 237 // The harness of the client whose update progress marker we're expecting | 214 // The harness of the client whose update progress marker we're expecting |
| 238 // eventually match. | 215 // eventually match. |
| 239 ProfileSyncServiceHarness* progress_marker_partner_; | 216 ProfileSyncServiceHarness* progress_marker_partner_; |
| 240 | 217 |
| 241 // Credentials used for GAIA authentication. | 218 // Credentials used for GAIA authentication. |
| 242 std::string username_; | 219 std::string username_; |
| 243 std::string password_; | 220 std::string password_; |
| 244 | 221 |
| 245 // Number used by GenerateFakeOAuth2RefreshTokenString() to make sure that | 222 // Number used by GenerateFakeOAuth2RefreshTokenString() to make sure that |
| 246 // all refresh tokens used in the tests are different. | 223 // all refresh tokens used in the tests are different. |
| 247 int oauth2_refesh_token_number_; | 224 int oauth2_refesh_token_number_; |
| 248 | 225 |
| 249 // Used for logging. | 226 // Used for logging. |
| 250 const std::string profile_debug_name_; | 227 const std::string profile_debug_name_; |
| 251 | 228 |
| 252 // Keeps track of the state change on which we are waiting. PSSHarness can | |
| 253 // wait on only one status change at a time. | |
| 254 StatusChangeChecker* status_change_checker_; | |
| 255 | |
| 256 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); | 229 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); |
| 257 }; | 230 }; |
| 258 | 231 |
| 259 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_PROFILE_SYNC_SERVICE_HARNESS_H_ | 232 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_PROFILE_SYNC_SERVICE_HARNESS_H_ |
| OLD | NEW |