Chromium Code Reviews| Index: chromeos/dbus/test_upstart_client.h |
| diff --git a/chromeos/dbus/test_upstart_client.h b/chromeos/dbus/test_upstart_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2c200a2c4a469418cc9b04cf238ee2a76dad6ae6 |
| --- /dev/null |
| +++ b/chromeos/dbus/test_upstart_client.h |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2017 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 CHROMEOS_DBUS_TEST_UPSTART_CLIENT_H_ |
| +#define CHROMEOS_DBUS_TEST_UPSTART_CLIENT_H_ |
| + |
| +#include <queue> |
| + |
| +#include "chromeos/dbus/fake_upstart_client.h" |
|
tbarzic
2017/05/18 21:39:15
can you make this class private to the test that u
Luke Sorenson
2017/05/19 00:56:43
Done.
|
| + |
| +namespace chromeos { |
| + |
| +class CHROMEOS_EXPORT TestUpstartClient : public FakeUpstartClient { |
| + public: |
| + TestUpstartClient(); |
| + ~TestUpstartClient() override; |
| + |
| + // Overrides behavior to queue start requests. |
| + void StartMediaAnalytics(const UpstartCallback& callback) override; |
| + |
| + // Triggers the next queue'd start request to succeed or fail. |
| + bool HandleNextUpstartRequest(bool should_succeed) { |
| + if (pending_upstart_request_callbacks_.empty()) |
| + return false; |
| + |
| + UpstartCallback callback = pending_upstart_request_callbacks_.front(); |
| + pending_upstart_request_callbacks_.pop(); |
| + |
| + if (!should_succeed) { |
| + callback.Run(false); |
| + return true; |
| + } |
| + |
| + FakeUpstartClient::StartMediaAnalytics(callback); |
| + return true; |
| + } |
| + |
| + private: |
| + std::queue<UpstartCallback> pending_upstart_request_callbacks_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestUpstartClient); |
| +}; |
| + |
| +TestUpstartClient::TestUpstartClient() {} |
| +TestUpstartClient::~TestUpstartClient() {} |
| + |
| +void TestUpstartClient::StartMediaAnalytics(const UpstartCallback& callback) { |
| + pending_upstart_request_callbacks_.push(callback); |
| +} |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROMEOS_DBUS_TEST_UPSTART_CLIENT_H_ |