diff options
author | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 21:17:32 +0000 |
---|---|---|
committer | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 21:17:32 +0000 |
commit | daed5ecdf85e983a9ff2aa0d7db5c7fdd34b71ab (patch) | |
tree | 5a4224b03b958b7bf6eece7c9ad92530a77688c3 /chrome | |
parent | 44d8ce76bed0ef853a28dc55164b8e2246f3eddc (diff) | |
download | chromium_src-daed5ecdf85e983a9ff2aa0d7db5c7fdd34b71ab.zip chromium_src-daed5ecdf85e983a9ff2aa0d7db5c7fdd34b71ab.tar.gz chromium_src-daed5ecdf85e983a9ff2aa0d7db5c7fdd34b71ab.tar.bz2 |
Take 3: Refactor, relocate and rename ProfileSyncServiceTestHarness.
ProfileSyncServiceTestHarness is an automation helper class that lives in chrome/test. It contains methods that allow you to wait on various sync events, and is used by the sync integration tests.
We now need to re-use ProfileSyncServiceTestHarness to support sync operations in TestingAutomationProvider, a class that lives in chrome/browser. In order to accomplish this, we do the following things in this patch:
1) Move ProfileSyncServiceTestHarness to chrome/browser, so that TestingAutomationProvider can re-use its functionality, and rename it to ProfileSyncServiceHarness (a less wordy name that reflects the purpose of the class).
2) Since TestingAutomationProvider relies on the fact that the UI message loop is always running, we must change the default behavior of ProfileSyncServiceHarness to not start/stop the UI message loop. We make 2 key wait methods pure virtual: SignalStateComplete() and AwaitStatusChange().
3) The integration tests use a specialization of ProfileSyncServiceHarness that start/stop the UI message loop.
4) TestingAutomationProvider can go on to use a specialization of ProfileSyncServiceHarness that uses WaitableEvents. (coming up in another patch)
NOTE: There were 2 earlier attempts at checking in this patch -- See
http://codereview.chromium.org/3492005/show and
http://codereview.chromium.org/3419029/show.
BUG=56460
TEST=sync_integration_tests
Review URL: http://codereview.chromium.org/4145003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63951 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/sync/profile_sync_service.h | 2 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_harness.cc (renamed from chrome/test/live_sync/profile_sync_service_test_harness.cc) | 161 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_harness.h (renamed from chrome/test/live_sync/profile_sync_service_test_harness.h) | 49 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_test.cc | 31 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_test.h | 8 |
7 files changed, 141 insertions, 114 deletions
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 6e9ac00..65f18f5 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -355,6 +355,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, const GURL& sync_service_url() const { return sync_service_url_; } + SigninManager* signin() { return &signin_; } protected: // Used by ProfileSyncServiceMock only. // @@ -407,7 +408,6 @@ class ProfileSyncService : public browser_sync::SyncFrontend, friend class ProfileSyncServicePasswordTest; friend class ProfileSyncServicePreferenceTest; friend class ProfileSyncServiceSessionTest; - friend class ProfileSyncServiceTestHarness; FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, UnrecoverableErrorSuspendsService); diff --git a/chrome/test/live_sync/profile_sync_service_test_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc index a903fa7..3ecafb7 100644 --- a/chrome/test/live_sync/profile_sync_service_test_harness.cc +++ b/chrome/browser/sync/profile_sync_service_harness.cc @@ -3,34 +3,34 @@ // found in the LICENSE file. #include "base/message_loop.h" -#include "base/test/test_timeouts.h" #include "chrome/browser/browser.h" #include "chrome/browser/defaults.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/sync/glue/sync_backend_host.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/sessions/session_state.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/gaia/google_service_auth_error.h" #include "chrome/common/pref_names.h" -#include "chrome/test/live_sync/profile_sync_service_test_harness.h" -#include "chrome/test/ui_test_utils.h" -#include "testing/gtest/include/gtest/gtest.h" // The default value for min_timestamp_needed_ when we're not in the // WAITING_FOR_UPDATES state. static const int kMinTimestampNeededNone = -1; +// The amount of time for which we wait for a live sync operation to complete. +static const int kLiveSyncOperationTimeoutMs = 30000; + // Simple class to implement a timeout using PostDelayedTask. If it is not // aborted before picked up by a message queue, then it asserts with the message // provided. This class is not thread safe. class StateChangeTimeoutEvent : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { public: - explicit StateChangeTimeoutEvent(ProfileSyncServiceTestHarness* caller, - const std::string& message); + StateChangeTimeoutEvent(ProfileSyncServiceHarness* caller, + const std::string& message); // The entry point to the class from PostDelayedTask. void Callback(); @@ -49,7 +49,7 @@ class StateChangeTimeoutEvent // Due to synchronization of the IO loop, the caller will always be alive // if the class is not aborted. - ProfileSyncServiceTestHarness* caller_; + ProfileSyncServiceHarness* caller_; // Informative message to assert in the case of a timeout. std::string message_; @@ -58,7 +58,7 @@ class StateChangeTimeoutEvent }; StateChangeTimeoutEvent::StateChangeTimeoutEvent( - ProfileSyncServiceTestHarness* caller, + ProfileSyncServiceHarness* caller, const std::string& message) : aborted_(false), did_timeout_(false), caller_(caller), message_(message) { } @@ -71,7 +71,7 @@ void StateChangeTimeoutEvent::Callback() { if (!caller_->RunStateChangeMachine()) { // Report the message. did_timeout_ = true; - EXPECT_FALSE(aborted_) << message_; + DCHECK(!aborted_) << message_; caller_->SignalStateComplete(); } } @@ -83,19 +83,21 @@ bool StateChangeTimeoutEvent::Abort() { return !did_timeout_; } -ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness(Profile* p, - const std::string& username, const std::string& password, int id) +ProfileSyncServiceHarness::ProfileSyncServiceHarness( + Profile* p, + const std::string& username, + const std::string& password, + int id) : wait_state_(WAITING_FOR_ON_BACKEND_INITIALIZED), - profile_(p), service_(NULL), + profile_(p), + service_(NULL), last_timestamp_(0), min_timestamp_needed_(kMinTimestampNeededNone), - username_(username), password_(password), id_(id) { - // Ensure the profile has enough prefs registered for use by sync. - if (!p->GetPrefs()->FindPreference(prefs::kAcceptLanguages)) - TabContents::RegisterUserPrefs(p->GetPrefs()); -} + username_(username), + password_(password), + id_(id) {} -bool ProfileSyncServiceTestHarness::SetupSync() { +bool ProfileSyncServiceHarness::SetupSync() { syncable::ModelTypeSet synced_datatypes; for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; ++i) { @@ -104,7 +106,7 @@ bool ProfileSyncServiceTestHarness::SetupSync() { return SetupSync(synced_datatypes); } -bool ProfileSyncServiceTestHarness::SetupSync( +bool ProfileSyncServiceHarness::SetupSync( const syncable::ModelTypeSet& synced_datatypes) { // Initialize the sync client's profile sync service object. service_ = profile_->GetProfileSyncService(""); @@ -118,14 +120,14 @@ bool ProfileSyncServiceTestHarness::SetupSync( service_->AddObserver(this); // Authenticate sync client using GAIA credentials. - service_->signin_.StartSignIn(username_, password_, "", ""); + service_->signin()->StartSignIn(username_, password_, "", ""); // Wait for the OnBackendInitialized() callback. - EXPECT_EQ(wait_state_, WAITING_FOR_ON_BACKEND_INITIALIZED); - if (!AwaitStatusChangeWithTimeout(TestTimeouts::live_operation_timeout_ms(), + DCHECK_EQ(wait_state_, WAITING_FOR_ON_BACKEND_INITIALIZED); + if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, "Waiting for OnBackendInitialized().")) { LOG(ERROR) << "OnBackendInitialized() not seen after " - << TestTimeouts::live_operation_timeout_ms() / 1000 + << kLiveSyncOperationTimeoutMs / 1000 << " seconds."; return false; } @@ -137,11 +139,11 @@ bool ProfileSyncServiceTestHarness::SetupSync( service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); // Wait for initial sync cycle to complete. - EXPECT_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); - if (!AwaitStatusChangeWithTimeout(TestTimeouts::live_operation_timeout_ms(), + DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); + if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, "Waiting for initial sync cycle to complete.")) { LOG(ERROR) << "Initial sync cycle did not complete after " - << TestTimeouts::live_operation_timeout_ms() / 1000 + << kLiveSyncOperationTimeoutMs / 1000 << " seconds."; return false; } @@ -149,17 +151,13 @@ bool ProfileSyncServiceTestHarness::SetupSync( return true; } -void ProfileSyncServiceTestHarness::SignalStateCompleteWithNextState( +void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( WaitState next_state) { wait_state_ = next_state; SignalStateComplete(); } -void ProfileSyncServiceTestHarness::SignalStateComplete() { - MessageLoopForUI::current()->Quit(); -} - -bool ProfileSyncServiceTestHarness::RunStateChangeMachine() { +bool ProfileSyncServiceHarness::RunStateChangeMachine() { WaitState original_wait_state = wait_state_; switch (wait_state_) { case WAITING_FOR_ON_BACKEND_INITIALIZED: { @@ -237,11 +235,11 @@ bool ProfileSyncServiceTestHarness::RunStateChangeMachine() { return original_wait_state != wait_state_; } -void ProfileSyncServiceTestHarness::OnStateChanged() { +void ProfileSyncServiceHarness::OnStateChanged() { RunStateChangeMachine(); } -bool ProfileSyncServiceTestHarness::AwaitPassphraseAccepted() { +bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { LogClientInfo("AwaitPassphraseAccepted"); if (wait_state_ == SYNC_DISABLED) { LOG(ERROR) << "Sync disabled for Client " << id_ << "."; @@ -250,12 +248,11 @@ bool ProfileSyncServiceTestHarness::AwaitPassphraseAccepted() { if (!service()->observed_passphrase_required()) return true; wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; - return AwaitStatusChangeWithTimeout( - TestTimeouts::live_operation_timeout_ms(), - "Waiting for passphrase accepted."); + return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, + "Waiting for passphrase accepted."); } -bool ProfileSyncServiceTestHarness::AwaitSyncCycleCompletion( +bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( const std::string& reason) { LogClientInfo("AwaitSyncCycleCompletion"); if (wait_state_ == SYNC_DISABLED) { @@ -265,16 +262,13 @@ bool ProfileSyncServiceTestHarness::AwaitSyncCycleCompletion( if (!IsSynced()) { if (wait_state_ == SERVER_UNREACHABLE) { // Client was offline; wait for it to go online, and then wait for sync. - AwaitStatusChangeWithTimeout( - TestTimeouts::live_operation_timeout_ms(), reason); - EXPECT_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); - return AwaitStatusChangeWithTimeout( - TestTimeouts::live_operation_timeout_ms(), reason); + AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); + DCHECK_EQ(wait_state_, WAITING_FOR_SYNC_TO_FINISH); + return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); } else { - EXPECT_TRUE(service()->sync_initialized()); + DCHECK(service()->sync_initialized()); wait_state_ = WAITING_FOR_SYNC_TO_FINISH; - AwaitStatusChangeWithTimeout( - TestTimeouts::live_operation_timeout_ms(), reason); + AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); if (wait_state_ == FULLY_SYNCED) { // Client is online; sync was successful. return true; @@ -293,8 +287,8 @@ bool ProfileSyncServiceTestHarness::AwaitSyncCycleCompletion( } } -bool ProfileSyncServiceTestHarness::AwaitMutualSyncCycleCompletion( - ProfileSyncServiceTestHarness* partner) { +bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( + ProfileSyncServiceHarness* partner) { LogClientInfo("AwaitMutualSyncCycleCompletion"); if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) return false; @@ -302,13 +296,13 @@ bool ProfileSyncServiceTestHarness::AwaitMutualSyncCycleCompletion( "Sync cycle completion on passive client."); } -bool ProfileSyncServiceTestHarness::AwaitGroupSyncCycleCompletion( - std::vector<ProfileSyncServiceTestHarness*>& partners) { +bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( + std::vector<ProfileSyncServiceHarness*>& partners) { LogClientInfo("AwaitGroupSyncCycleCompletion"); if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) return false; bool return_value = true; - for (std::vector<ProfileSyncServiceTestHarness*>::iterator it = + for (std::vector<ProfileSyncServiceHarness*>::iterator it = partners.begin(); it != partners.end(); ++it) { if ((this != *it) && ((*it)->wait_state_ != SYNC_DISABLED)) { return_value = return_value && @@ -320,11 +314,11 @@ bool ProfileSyncServiceTestHarness::AwaitGroupSyncCycleCompletion( } // static -bool ProfileSyncServiceTestHarness::AwaitQuiescence( - std::vector<ProfileSyncServiceTestHarness*>& clients) { +bool ProfileSyncServiceHarness::AwaitQuiescence( + std::vector<ProfileSyncServiceHarness*>& clients) { VLOG(1) << "AwaitQuiescence."; bool return_value = true; - for (std::vector<ProfileSyncServiceTestHarness*>::iterator it = + for (std::vector<ProfileSyncServiceHarness*>::iterator it = clients.begin(); it != clients.end(); ++it) { if ((*it)->wait_state_ != SYNC_DISABLED) return_value = return_value && @@ -333,7 +327,7 @@ bool ProfileSyncServiceTestHarness::AwaitQuiescence( return return_value; } -bool ProfileSyncServiceTestHarness::WaitUntilTimestampIsAtLeast( +bool ProfileSyncServiceHarness::WaitUntilTimestampIsAtLeast( int64 timestamp, const std::string& reason) { LogClientInfo("WaitUntilTimestampIsAtLeast"); if (wait_state_ == SYNC_DISABLED) { @@ -343,14 +337,13 @@ bool ProfileSyncServiceTestHarness::WaitUntilTimestampIsAtLeast( min_timestamp_needed_ = timestamp; if (GetUpdatedTimestamp() < min_timestamp_needed_) { wait_state_ = WAITING_FOR_UPDATES; - return AwaitStatusChangeWithTimeout( - TestTimeouts::live_operation_timeout_ms(), reason); + return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); } else { return true; } } -bool ProfileSyncServiceTestHarness::AwaitStatusChangeWithTimeout( +bool ProfileSyncServiceHarness::AwaitStatusChangeWithTimeout( int timeout_milliseconds, const std::string& reason) { LogClientInfo("AwaitStatusChangeWithTimeout"); @@ -366,18 +359,17 @@ bool ProfileSyncServiceTestHarness::AwaitStatusChangeWithTimeout( NewRunnableMethod(timeout_signal.get(), &StateChangeTimeoutEvent::Callback), timeout_milliseconds); - LogClientInfo("Before RunMessageLoop"); - ui_test_utils::RunMessageLoop(); - LogClientInfo("After RunMessageLoop"); + AwaitStatusChange(); + LogClientInfo("AwaitStatusChangeWithTimeout succeeded"); return timeout_signal->Abort(); } -ProfileSyncService::Status ProfileSyncServiceTestHarness::GetStatus() { - EXPECT_FALSE(service() == NULL) << "GetStatus(): service() is NULL."; +ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { + DCHECK(service() != NULL) << "GetStatus(): service() is NULL."; return service()->QueryDetailedSyncStatus(); } -bool ProfileSyncServiceTestHarness::IsSynced() { +bool ProfileSyncServiceHarness::IsSynced() { const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and // snap->unsynced_count once http://crbug.com/48989 is fixed. @@ -391,26 +383,25 @@ bool ProfileSyncServiceTestHarness::IsSynced() { } const SyncSessionSnapshot* - ProfileSyncServiceTestHarness::GetLastSessionSnapshot() const { - EXPECT_FALSE(service_ == NULL) << "Sync service has not yet been set up."; + ProfileSyncServiceHarness::GetLastSessionSnapshot() const { + DCHECK(service_ != NULL) << "Sync service has not yet been set up."; if (service_->backend()) { return service_->backend()->GetLastSessionSnapshot(); } return NULL; } -void ProfileSyncServiceTestHarness::EnableSyncForDatatype( +void ProfileSyncServiceHarness::EnableSyncForDatatype( syncable::ModelType datatype) { LogClientInfo("EnableSyncForDatatype"); syncable::ModelTypeSet synced_datatypes; if (wait_state_ == SYNC_DISABLED) { wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; synced_datatypes.insert(datatype); - EXPECT_TRUE(SetupSync(synced_datatypes)) - << "Reinitialization of Client " << id_ << " failed."; + DCHECK(SetupSync(synced_datatypes)) << "Reinitialization of Client " << id_ + << " failed."; } else { - EXPECT_FALSE(service() == NULL) - << "EnableSyncForDatatype(): service() is null."; + DCHECK(service() != NULL) << "EnableSyncForDatatype(): service() is null."; service()->GetPreferredDataTypes(&synced_datatypes); syncable::ModelTypeSet::iterator it = synced_datatypes.find( syncable::ModelTypeFromInt(datatype)); @@ -428,12 +419,11 @@ void ProfileSyncServiceTestHarness::EnableSyncForDatatype( } } -void ProfileSyncServiceTestHarness::DisableSyncForDatatype( +void ProfileSyncServiceHarness::DisableSyncForDatatype( syncable::ModelType datatype) { LogClientInfo("DisableSyncForDatatype"); syncable::ModelTypeSet synced_datatypes; - EXPECT_FALSE(service() == NULL) - << "DisableSyncForDatatype(): service() is null."; + DCHECK(service() != NULL) << "DisableSyncForDatatype(): service() is null."; service()->GetPreferredDataTypes(&synced_datatypes); syncable::ModelTypeSet::iterator it = synced_datatypes.find(datatype); if (it != synced_datatypes.end()) { @@ -448,20 +438,19 @@ void ProfileSyncServiceTestHarness::DisableSyncForDatatype( } } -void ProfileSyncServiceTestHarness::EnableSyncForAllDatatypes() { +void ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { LogClientInfo("EnableSyncForAllDatatypes"); if (wait_state_ == SYNC_DISABLED) { wait_state_ = WAITING_FOR_ON_BACKEND_INITIALIZED; - EXPECT_TRUE(SetupSync()) - << "Reinitialization of Client " << id_ << " failed."; + DCHECK(SetupSync()) << "Reinitialization of Client " << id_ << " failed."; } else { syncable::ModelTypeSet synced_datatypes; for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; ++i) { synced_datatypes.insert(syncable::ModelTypeFromInt(i)); } - EXPECT_FALSE(service() == NULL) - << "EnableSyncForAllDatatypes(): service() is null."; + DCHECK(service() != NULL) << "EnableSyncForAllDatatypes(): service() is " + " null."; service()->OnUserChoseDatatypes(true, synced_datatypes); wait_state_ = WAITING_FOR_SYNC_TO_FINISH; AwaitSyncCycleCompletion("Waiting for datatype configuration."); @@ -470,25 +459,25 @@ void ProfileSyncServiceTestHarness::EnableSyncForAllDatatypes() { } } -void ProfileSyncServiceTestHarness::DisableSyncForAllDatatypes() { +void ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { LogClientInfo("DisableSyncForAllDatatypes"); - EXPECT_FALSE(service() == NULL) - << "EnableSyncForAllDatatypes(): service() is null."; + DCHECK(service() != NULL) << "EnableSyncForAllDatatypes(): service() is " + "null."; service()->DisableForUser(); wait_state_ = SYNC_DISABLED; VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " "Client " << id_; } -int64 ProfileSyncServiceTestHarness::GetUpdatedTimestamp() { +int64 ProfileSyncServiceHarness::GetUpdatedTimestamp() { const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); - EXPECT_FALSE(snap == NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; - EXPECT_LE(last_timestamp_, snap->max_local_timestamp); + DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; + DCHECK_LE(last_timestamp_, snap->max_local_timestamp); last_timestamp_ = snap->max_local_timestamp; return last_timestamp_; } -void ProfileSyncServiceTestHarness::LogClientInfo(std::string message) { +void ProfileSyncServiceHarness::LogClientInfo(std::string message) { const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); if (snap) { VLOG(1) << "Client " << id_ << ": " << message diff --git a/chrome/test/live_sync/profile_sync_service_test_harness.h b/chrome/browser/sync/profile_sync_service_harness.h index 495aeed..90f4540 100644 --- a/chrome/test/live_sync/profile_sync_service_test_harness.h +++ b/chrome/browser/sync/profile_sync_service_harness.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ -#define CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ +#ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ +#define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ #pragma once #include <string> @@ -17,14 +17,20 @@ using browser_sync::sessions::SyncSessionSnapshot; class Profile; // An instance of this class is basically our notion of a "sync client" for -// test purposes. It harnesses the ProfileSyncService member of the profile -// passed to it on construction and automates certain things like setup and -// authentication. It provides ways to "wait" adequate periods of time for -// several clients to get to the same state. -class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { +// automation purposes. It harnesses the ProfileSyncService member of the +// profile passed to it on construction and automates certain things like setup +// and authentication. It provides ways to "wait" adequate periods of time for +// several clients to get to the same state. In order to use this class for +// automation, derived classes must implement 2 methods: SignalStateComplete() +// and AwaitStatusChange(). +class ProfileSyncServiceHarness : public ProfileSyncServiceObserver { public: - ProfileSyncServiceTestHarness(Profile* p, const std::string& username, - const std::string& password, int id); + ProfileSyncServiceHarness(Profile* p, + const std::string& username, + const std::string& password, + int id); + + virtual ~ProfileSyncServiceHarness() {} // Creates a ProfileSyncService for the profile passed at construction and // enables sync for all available datatypes. Returns true only after sync has @@ -54,7 +60,7 @@ class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { // from the message queue. Returns true if two sync cycles have completed. // Note: Use this method when exactly one client makes local change(s), and // exactly one client is waiting to receive those changes. - bool AwaitMutualSyncCycleCompletion(ProfileSyncServiceTestHarness* partner); + bool AwaitMutualSyncCycleCompletion(ProfileSyncServiceHarness* partner); // Blocks the caller until |this| completes its ongoing sync cycle and every // other client in |partners| has a timestamp that is greater than or equal to @@ -62,14 +68,14 @@ class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { // makes local change(s), and more than one client is waiting to receive those // changes. bool AwaitGroupSyncCycleCompletion( - std::vector<ProfileSyncServiceTestHarness*>& partners); + std::vector<ProfileSyncServiceHarness*>& partners); // Blocks the caller until every client in |clients| completes its ongoing // sync cycle and all the clients' timestamps match. Note: Use this method // when more than one client makes local change(s), and more than one client // is waiting to receive those changes. static bool AwaitQuiescence( - std::vector<ProfileSyncServiceTestHarness*>& clients); + std::vector<ProfileSyncServiceHarness*>& clients); // If a SetPassphrase call has been issued with a valid passphrase, this // will wait until the Cryptographer broadcasts SYNC_PASSPHRASE_ACCEPTED. @@ -132,15 +138,24 @@ class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { // Called from the observer when the current wait state has been completed. void SignalStateCompleteWithNextState(WaitState next_state); - void SignalStateComplete(); + + // Indicates that the operation being waited on is complete. Derived classes + // may implement this either by quitting the UI message loop, or by signaling + // a WaitableEvent object. + virtual void SignalStateComplete() = 0; // Finite state machine for controlling state. Returns true only if a state // change has taken place. bool RunStateChangeMachine(); // Returns true if a status change took place, false on timeout. - virtual bool AwaitStatusChangeWithTimeout(int timeout_milliseconds, - const std::string& reason); + bool AwaitStatusChangeWithTimeout(int timeout_milliseconds, + const std::string& reason); + + // Waits until the sync client's status changes. Derived classes may implement + // this either by running the UI message loop, or by waiting on a + // WaitableEvent object. + virtual void AwaitStatusChange() = 0; // Returns true if the sync client has no unsynced items. bool IsSynced(); @@ -174,7 +189,7 @@ class ProfileSyncServiceTestHarness : public ProfileSyncServiceObserver { // Client ID, used for logging purposes. int id_; - DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHarness); + DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); }; -#endif // CHROME_TEST_LIVE_SYNC_PROFILE_SYNC_SERVICE_TEST_HARNESS_H_ +#endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 525a84d..6c92179 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2802,6 +2802,8 @@ 'browser/sync/profile_sync_factory_impl.h', 'browser/sync/profile_sync_service.cc', 'browser/sync/profile_sync_service.h', + 'browser/sync/profile_sync_service_harness.cc', + 'browser/sync/profile_sync_service_harness.h', 'browser/sync/profile_sync_service_observer.h', 'browser/sync/signin_manager.cc', 'browser/sync/signin_manager.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index c547c26..b3b031b 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2667,8 +2667,6 @@ 'test/live_sync/multiple_client_live_bookmarks_sync_test.cc', 'test/live_sync/multiple_client_live_passwords_sync_test.cc', 'test/live_sync/multiple_client_live_preferences_sync_test.cc', - 'test/live_sync/profile_sync_service_test_harness.cc', - 'test/live_sync/profile_sync_service_test_harness.h', 'test/live_sync/single_client_live_bookmarks_sync_test.cc', 'test/live_sync/single_client_live_passwords_sync_test.cc', 'test/live_sync/single_client_live_preferences_sync_test.cc', diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc index 07a94d4..8b614be 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -86,6 +86,30 @@ class SetProxyConfigTask : public Task { net::ProxyConfig proxy_config_; }; +// This is a our notion of a sync client for automation purposes. It is a helper +// class that specializes ProfileSyncServiceHarness, and is used to wait on +// various sync operations. +class SyncClient : public ProfileSyncServiceHarness { + public: + SyncClient(Profile* profile, + const std::string& username, + const std::string& password, int id) + : ProfileSyncServiceHarness(profile, username, password, id) {} + + virtual ~SyncClient() {} + + // Indicates that the sync operation being waited on is complete. Overrides + // ProfileSyncServiceHarness::SignalStateComplete(). + virtual void SignalStateComplete() { MessageLoopForUI::current()->Quit(); } + + // Waits until the sync client's status changes. Overrides + // ProfileSyncServiceHarness::AwaitStatusChange(). + virtual void AwaitStatusChange() { ui_test_utils::RunMessageLoop(); } + + private: + DISALLOW_COPY_AND_ASSIGN(SyncClient); +}; + void LiveSyncTest::SetUp() { // At this point, the browser hasn't been launched, and no services are // available. But we can verify our command line parameters and fail @@ -153,7 +177,7 @@ Profile* LiveSyncTest::GetProfile(int index) { return profiles_[index]; } -ProfileSyncServiceTestHarness* LiveSyncTest::GetClient(int index) { +ProfileSyncServiceHarness* LiveSyncTest::GetClient(int index) { if (clients_.empty()) LOG(FATAL) << "SetupClients() has not yet been called."; if (index < 0 || index >= static_cast<int>(clients_.size())) @@ -181,8 +205,7 @@ bool LiveSyncTest::SetupClients() { profiles_.push_back(MakeProfile( StringPrintf(FILE_PATH_LITERAL("Profile%d"), i))); EXPECT_FALSE(GetProfile(i) == NULL) << "GetProfile(" << i << ") failed."; - clients_.push_back(new ProfileSyncServiceTestHarness( - GetProfile(i), username_, password_, i)); + clients_.push_back(new SyncClient(GetProfile(i), username_, password_, i)); EXPECT_FALSE(GetClient(i) == NULL) << "GetClient(" << i << ") failed."; } @@ -383,7 +406,7 @@ void LiveSyncTest::DisableNetwork(Profile* profile) { } bool LiveSyncTest::AwaitQuiescence() { - return ProfileSyncServiceTestHarness::AwaitQuiescence(clients()); + return ProfileSyncServiceHarness::AwaitQuiescence(clients()); } void LiveSyncTest::SetProxyConfig(URLRequestContextGetter* context_getter, diff --git a/chrome/test/live_sync/live_sync_test.h b/chrome/test/live_sync/live_sync_test.h index a7ebe79..1e93b64 100644 --- a/chrome/test/live_sync/live_sync_test.h +++ b/chrome/test/live_sync/live_sync_test.h @@ -13,7 +13,7 @@ #include "base/process_util.h" #include "base/scoped_ptr.h" #include "base/scoped_vector.h" -#include "chrome/test/live_sync/profile_sync_service_test_harness.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "net/base/mock_host_resolver.h" #include "net/test/test_server.h" @@ -101,11 +101,11 @@ class LiveSyncTest : public InProcessBrowserTest { // Returns a pointer to a particular sync client. Callee owns the object // and manages its lifetime. - ProfileSyncServiceTestHarness* GetClient(int index) WARN_UNUSED_RESULT; + ProfileSyncServiceHarness* GetClient(int index) WARN_UNUSED_RESULT; // Returns a reference to the collection of sync clients. Callee owns the // object and manages its lifetime. - std::vector<ProfileSyncServiceTestHarness*>& clients() WARN_UNUSED_RESULT { + std::vector<ProfileSyncServiceHarness*>& clients() WARN_UNUSED_RESULT { return clients_.get(); } @@ -209,7 +209,7 @@ class LiveSyncTest : public InProcessBrowserTest { // Collection of sync clients used by a test. A sync client is associated with // a sync profile, and implements methods that sync the contents of the // profile with the server. - ScopedVector<ProfileSyncServiceTestHarness> clients_; + ScopedVector<ProfileSyncServiceHarness> clients_; // Sync profile against which changes to individual profiles are verified. We // don't need a corresponding verifier sync client because the contents of the |