| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #ifdef CHROME_PERSONALIZATION |
| 5 |
| 6 #ifndef CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ |
| 7 #define CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/time.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 |
| 14 class Profile; |
| 15 |
| 16 // An instance of this class is basically our notion of a "sync client" for |
| 17 // test purposes. It harnesses the ProfileSyncService member of the profile |
| 18 // passed to it on construction and automates certain things like setup and |
| 19 // authentication. It provides ways to "wait" adequate periods of time for |
| 20 // several clients to get to the same state. |
| 21 class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { |
| 22 public: |
| 23 ProfileSyncServiceTestHarness(Profile* p, const std::string& username, |
| 24 const std::string& password); |
| 25 |
| 26 // Creates a ProfileSyncService for the profile passed at construction and |
| 27 // enables sync. Returns true only after sync has been fully initialized and |
| 28 // authenticated, and we are ready to process changes. |
| 29 bool SetupSync(); |
| 30 |
| 31 // ProfileSyncServiceObserver implementation. |
| 32 virtual void OnStateChanged(); |
| 33 |
| 34 // Blocks the caller until this harness has completed a single sync cycle |
| 35 // since the previous one. Returns true if a sync cycle has completed. |
| 36 bool AwaitSyncCycleCompletion(const std::string& reason); |
| 37 |
| 38 // Wait an extra 20 seconds to ensure any rebounding updates |
| 39 // due to a conflict are processed and observed by each client. |
| 40 bool AwaitMutualSyncCycleCompletionWithConflict( |
| 41 ProfileSyncServiceTestHarness* partner); |
| 42 |
| 43 // Calling this acts as a barrier and blocks the caller until |this| and |
| 44 // |partner| have both completed a sync cycle. When calling this method, |
| 45 // the |partner| should be the passive responder who responds to the actions |
| 46 // of |this|. This method relies upon the synchronization of callbacks |
| 47 // from the message queue. Returns true if two sync cycles have completed. |
| 48 bool AwaitMutualSyncCycleCompletion(ProfileSyncServiceTestHarness* partner); |
| 49 |
| 50 ProfileSyncService* service() { return service_; } |
| 51 |
| 52 // See ProfileSyncService::ShouldPushChanges(). |
| 53 bool ServiceIsPushingChanges() { return service_->ShouldPushChanges(); } |
| 54 |
| 55 private: |
| 56 friend class StateChangeTimeoutEvent; |
| 57 friend class ConflictTimeoutEvent; |
| 58 |
| 59 enum WaitState { |
| 60 WAITING_FOR_INITIAL_CALLBACK = 0, |
| 61 WAITING_FOR_READY_TO_PROCESS_CHANGES, |
| 62 WAITING_FOR_TIMESTAMP_UPDATE, |
| 63 WAITING_FOR_UPDATES, |
| 64 WAITING_FOR_NOTHING, |
| 65 NUMBER_OF_STATES |
| 66 }; |
| 67 |
| 68 // Called from the observer when the current wait state has been completed. |
| 69 void SignalStateCompleteWithNextState(WaitState next_state); |
| 70 void SignalStateComplete(); |
| 71 |
| 72 // Finite state machine for controlling state. Returns true only if a state |
| 73 // change has taken place. |
| 74 bool RunStateChangeMachine(); |
| 75 |
| 76 // Returns true if a status change took place, false on timeout. |
| 77 virtual bool AwaitStatusChangeWithTimeout(int timeout_seconds, |
| 78 const std::string& reason); |
| 79 |
| 80 // Returns true if the service initialized correctly. |
| 81 bool WaitForServiceInit(); |
| 82 |
| 83 WaitState wait_state_; |
| 84 |
| 85 Profile* profile_; |
| 86 ProfileSyncService* service_; |
| 87 |
| 88 // State tracking. Used for debugging and tracking of state. |
| 89 ProfileSyncService::Status last_status_; |
| 90 |
| 91 // When awaiting quiescence, we are waiting for a change to this value. It |
| 92 // is set to the current (ui-threadsafe) last synced timestamp returned by |
| 93 // the sync service when AwaitQuiescence is called, and then we wait for an |
| 94 // OnStatusChanged event to observe a new, more recent last synced timestamp. |
| 95 base::Time last_timestamp_; |
| 96 |
| 97 // The minimum value of the 'updates_received' member of SyncManager Status |
| 98 // we need to wait to observe in OnStateChanged when told to |
| 99 // WaitForUpdatesReceivedAtLeast. |
| 100 int64 min_updates_needed_; |
| 101 |
| 102 // Credentials used for GAIA authentication. |
| 103 std::string username_; |
| 104 std::string password_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHarness); |
| 107 }; |
| 108 |
| 109 #endif // CHROME_TEST_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ |
| 110 |
| 111 #endif // CHROME_PERSONALIZATION |
| OLD | NEW |