Commit 9a6dc8bc authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[DeviceSync v2] Add Delegate class to fakes

Add Delegate classes to FakeCryptAuthFeatureStatusSetter and
FakeCryptAuthDeviceNotifier that are alerted when SetFeatureStatus() and
NotifyDevices(), respectively, are called. This is analogous to
the behavior of FakeSoftwareFeatureManager.

These delegates are used to make the DeviceSync service unit tests more
robust to asynchronous behavior.

Bug: 951969
Change-Id: Idcc1fe95a1b70fad0d99e67216bf40fd61af0ef8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893517
Commit-Queue: Josh Nohle <nohle@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Auto-Submit: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711379}
parent b73af798
......@@ -44,6 +44,9 @@ void FakeCryptAuthDeviceNotifier::NotifyDevices(
requests_.emplace_back(device_ids, target_service, feature_type,
std::move(success_callback),
std::move(error_callback));
if (delegate_)
delegate_->OnNotifyDevicesCalled();
}
FakeCryptAuthDeviceNotifierFactory::FakeCryptAuthDeviceNotifierFactory() =
......
......@@ -28,6 +28,12 @@ class CryptAuthGCMManager;
class FakeCryptAuthDeviceNotifier : public CryptAuthDeviceNotifier {
public:
class Delegate {
public:
virtual ~Delegate() = default;
virtual void OnNotifyDevicesCalled() {}
};
struct Request {
Request(const base::flat_set<std::string>& device_ids,
cryptauthv2::TargetService target_service,
......@@ -49,6 +55,8 @@ class FakeCryptAuthDeviceNotifier : public CryptAuthDeviceNotifier {
FakeCryptAuthDeviceNotifier();
~FakeCryptAuthDeviceNotifier() override;
void set_delegate(Delegate* delegate) { delegate_ = delegate; }
std::vector<Request>& requests() { return requests_; }
private:
......@@ -60,6 +68,7 @@ class FakeCryptAuthDeviceNotifier : public CryptAuthDeviceNotifier {
base::OnceClosure success_callback,
base::OnceCallback<void(NetworkRequestError)> error_callback) override;
Delegate* delegate_ = nullptr;
std::vector<Request> requests_;
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthDeviceNotifier);
......
......@@ -42,6 +42,9 @@ void FakeCryptAuthFeatureStatusSetter::SetFeatureStatus(
requests_.emplace_back(device_id, feature, status_change,
std::move(success_callback),
std::move(error_callback));
if (delegate_)
delegate_->OnSetFeatureStatusCalled();
}
FakeCryptAuthFeatureStatusSetterFactory::
......
......@@ -27,6 +27,12 @@ class CryptAuthGCMManager;
class FakeCryptAuthFeatureStatusSetter : public CryptAuthFeatureStatusSetter {
public:
class Delegate {
public:
virtual ~Delegate() = default;
virtual void OnSetFeatureStatusCalled() {}
};
struct Request {
Request(const std::string& device_id,
multidevice::SoftwareFeature feature,
......@@ -48,6 +54,8 @@ class FakeCryptAuthFeatureStatusSetter : public CryptAuthFeatureStatusSetter {
FakeCryptAuthFeatureStatusSetter();
~FakeCryptAuthFeatureStatusSetter() override;
void set_delegate(Delegate* delegate) { delegate_ = delegate; }
std::vector<Request>& requests() { return requests_; }
private:
......@@ -59,6 +67,7 @@ class FakeCryptAuthFeatureStatusSetter : public CryptAuthFeatureStatusSetter {
base::OnceClosure success_callback,
base::OnceCallback<void(NetworkRequestError)> error_callback) override;
Delegate* delegate_ = nullptr;
std::vector<Request> requests_;
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthFeatureStatusSetter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment