forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync: Prepare for integration test refactoring
Adds an optional virtual method to sync tests to control whether or not self-notifications should be enabled for a specific test. Defaults to on. Introduces the multi-client status change checker. This can be used to wait for a specific condition while waiting listening to change events emitted by several different ProfileSyncServices. Adds some helper functions to SyncTest that can be used to fetch the active ProfileSyncServices. This functions are helpful for initializing StatusChangeCheckers. These changes should have no effect on existing tests. They will be used to implement a new style of integration test that does not rely on sync-cycle concepts like "quiescence" or the self-notifications that those concepts depend on. BUG=97780,95742 Review URL: https://codereview.chromium.org/215583002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260616 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
rlarocque@chromium.org
committed
Mar 31, 2014
1 parent
bf3f459
commit 1fdd4f4
Showing
41 changed files
with
344 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
chrome/browser/sync/test/integration/multi_client_status_change_checker.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h" | ||
|
||
#include "base/logging.h" | ||
#include "base/scoped_observer.h" | ||
#include "chrome/browser/sync/profile_sync_service.h" | ||
|
||
MultiClientStatusChangeChecker::MultiClientStatusChangeChecker( | ||
std::vector<ProfileSyncService*> services) | ||
: services_(services), timed_out_(false) {} | ||
|
||
MultiClientStatusChangeChecker::~MultiClientStatusChangeChecker() {} | ||
|
||
base::TimeDelta MultiClientStatusChangeChecker::GetTimeoutDuration() { | ||
return base::TimeDelta::FromSeconds(45); | ||
} | ||
void MultiClientStatusChangeChecker::OnTimeout() { | ||
DVLOG(1) << "Await -> Timed out: " << GetDebugMessage(); | ||
timed_out_ = true; | ||
base::MessageLoop::current()->QuitWhenIdle(); | ||
} | ||
|
||
void MultiClientStatusChangeChecker::Wait() { | ||
DVLOG(1) << "Await: " << GetDebugMessage(); | ||
|
||
if (IsExitConditionSatisfied()) { | ||
DVLOG(1) << "Await -> Exit before waiting: " << GetDebugMessage(); | ||
return; | ||
} | ||
|
||
ScopedObserver<ProfileSyncService, MultiClientStatusChangeChecker> obs(this); | ||
for (std::vector<ProfileSyncService*>::iterator it = services_.begin(); | ||
it != services_.end(); ++it) { | ||
obs.Add(*it); | ||
} | ||
|
||
base::OneShotTimer<MultiClientStatusChangeChecker> timer; | ||
timer.Start(FROM_HERE, | ||
GetTimeoutDuration(), | ||
base::Bind(&MultiClientStatusChangeChecker::OnTimeout, | ||
base::Unretained(this))); | ||
|
||
{ | ||
base::MessageLoop* loop = base::MessageLoop::current(); | ||
base::MessageLoop::ScopedNestableTaskAllower allow(loop); | ||
loop->Run(); | ||
} | ||
} | ||
|
||
void MultiClientStatusChangeChecker::OnStateChanged() { | ||
DVLOG(1) << "Await -> Checking Condition: " << GetDebugMessage(); | ||
if (IsExitConditionSatisfied()) { | ||
DVLOG(1) << "Await -> Condition met: " << GetDebugMessage(); | ||
base::MessageLoop::current()->QuitWhenIdle(); | ||
} | ||
} | ||
|
||
bool MultiClientStatusChangeChecker::TimedOut() { | ||
return timed_out_; | ||
} |
55 changes: 55 additions & 0 deletions
55
chrome/browser/sync/test/integration/multi_client_status_change_checker.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_MULTI_CLIENT_STATUS_CHANGE_CHECKER_H_ | ||
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_MULTI_CLIENT_STATUS_CHANGE_CHECKER_H_ | ||
|
||
#include <vector> | ||
|
||
#include "base/compiler_specific.h" | ||
#include "base/time/time.h" | ||
#include "chrome/browser/sync/profile_sync_service_observer.h" | ||
#include "chrome/browser/sync/test/integration/status_change_checker.h" | ||
|
||
class ProfileSyncService; | ||
|
||
// This class provides some common functionality for StatusChangeCheckers that | ||
// observe many ProfileSyncServices. This class is abstract. Its descendants | ||
// are expected to provide additional functionality. | ||
class MultiClientStatusChangeChecker | ||
: public StatusChangeChecker, | ||
public ProfileSyncServiceObserver { | ||
public: | ||
explicit MultiClientStatusChangeChecker( | ||
std::vector<ProfileSyncService*> services); | ||
virtual ~MultiClientStatusChangeChecker(); | ||
|
||
// Timeout length for this operation. Default is 45s. | ||
virtual base::TimeDelta GetTimeoutDuration(); | ||
|
||
// Called when waiting times out. | ||
void OnTimeout(); | ||
|
||
// Blocks until the exit condition is satisfied or a timeout occurs. | ||
void Wait(); | ||
|
||
// ProfileSyncServiceObserver implementation. | ||
virtual void OnStateChanged() OVERRIDE; | ||
|
||
// Returns true if the checker timed out. | ||
bool TimedOut(); | ||
|
||
// StatusChangeChecker implementations and stubs. | ||
virtual bool IsExitConditionSatisfied() = 0; | ||
virtual std::string GetDebugMessage() const = 0; | ||
|
||
protected: | ||
const std::vector<ProfileSyncService*>& services() { return services_; } | ||
|
||
private: | ||
std::vector<ProfileSyncService*> services_; | ||
bool timed_out_; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_MULTI_CLIENT_STATUS_CHANGE_CHECKER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.