| // Copyright 2019 The Chromium OS 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 ARC_NETWORK_FAKE_SHILL_CLIENT_H_ |
| #define ARC_NETWORK_FAKE_SHILL_CLIENT_H_ |
| |
| #include <memory> |
| #include <string> |
| #include <utility> |
| |
| #include <base/memory/ref_counted.h> |
| #include <dbus/mock_bus.h> |
| #include <dbus/mock_object_proxy.h> |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| #include "arc/network/shill_client.h" |
| |
| using testing::_; |
| using testing::AnyNumber; |
| using testing::Return; |
| |
| namespace arc_networkd { |
| |
| class FakeShillClient : public ShillClient { |
| public: |
| explicit FakeShillClient(scoped_refptr<dbus::Bus> bus) : ShillClient(bus) {} |
| |
| std::string GetDefaultInterface() override { return fake_default_ifname_; } |
| |
| void SetFakeDefaultInterface(const std::string& ifname) { |
| fake_default_ifname_ = ifname; |
| } |
| |
| void NotifyManagerPropertyChange(const std::string& name, |
| const brillo::Any& value) { |
| OnManagerPropertyChange(name, value); |
| } |
| |
| private: |
| std::string fake_default_ifname_; |
| }; |
| |
| class FakeShillClientHelper { |
| public: |
| FakeShillClientHelper() { |
| mock_proxy_ = new dbus::MockObjectProxy( |
| mock_bus_.get(), "org.chromium.flimflam", dbus::ObjectPath("/path")); |
| // Set these expectations rather than just ignoring them to confirm |
| // the ShillClient obtains the expected proxy and registers for |
| // property changes. |
| EXPECT_CALL(*mock_bus_, GetObjectProxy("org.chromium.flimflam", _)) |
| .WillRepeatedly(Return(mock_proxy_.get())); |
| EXPECT_CALL(*mock_proxy_, ConnectToSignal("org.chromium.flimflam.Manager", |
| "PropertyChanged", _, _)) |
| .Times(AnyNumber()); |
| |
| client_ = std::make_unique<FakeShillClient>(mock_bus_); |
| } |
| |
| std::unique_ptr<ShillClient> Client() { return std::move(client_); } |
| |
| std::unique_ptr<FakeShillClient> FakeClient() { return std::move(client_); } |
| |
| private: |
| scoped_refptr<dbus::MockBus> mock_bus_{ |
| new dbus::MockBus{dbus::Bus::Options{}}}; |
| scoped_refptr<dbus::MockObjectProxy> mock_proxy_; |
| |
| std::unique_ptr<FakeShillClient> client_; |
| }; |
| |
| } // namespace arc_networkd |
| |
| #endif // ARC_NETWORK_FAKE_SHILL_CLIENT_H_ |