PM: Shift to signal-based inference of network connection.
Instead of making DBus calls to shill on-demand, and estimating the time
a connection has changed, the RealShillProvider now listens to the
appropriate DBus signal and update its internal state accordingly. Note
that checking for the connection type still requires a DBus call, if the
connection has changed since its type was last checked.
In order to pass all unit tests (including those of PolicyManager and
RealState), there's a substantial portion of DBus mock set up code that
was added. This code will be removed very soon, once we begin injecting
providers into RealState, instead of low-level DBus and/or clock
interfaces.
BUG=chromium:338585
TEST=Unit tests.
Change-Id: Ia7a2f9db18f905f1b7a2cc1234acb31eaa60009e
Reviewed-on: https://chromium-review.googlesource.com/189692
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/policy_manager_unittest.cc b/policy_manager/policy_manager_unittest.cc
index fd43045..e2f3218 100644
--- a/policy_manager/policy_manager_unittest.cc
+++ b/policy_manager/policy_manager_unittest.cc
@@ -8,6 +8,8 @@
#include <base/bind.h>
#include <base/memory/scoped_ptr.h>
+// TODO(garnold) Remove once shill DBus constants not needed.
+#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
@@ -17,23 +19,32 @@
#include "update_engine/policy_manager/mock_policy.h"
#include "update_engine/policy_manager/pmtest_utils.h"
#include "update_engine/policy_manager/policy_manager.h"
+// TODO(garnold) Remove once we stop mocking DBus.
#include "update_engine/test_utils.h"
using base::Bind;
using base::Callback;
using chromeos_update_engine::FakeClock;
+using chromeos_update_engine::GValueNewString;
+using chromeos_update_engine::GValueFree;
using chromeos_update_engine::MockDBusWrapper;
using std::pair;
using std::string;
using std::vector;
using testing::NiceMock;
using testing::Return;
+using testing::SetArgPointee;
using testing::StrictMock;
using testing::_;
namespace {
+// TODO(garnold) This whole section gets removed once we mock the shill provider
+// itself in tests.
+
+// Fake dbus-glib objects.
DBusGConnection* const kFakeConnection = reinterpret_cast<DBusGConnection*>(1);
+DBusGProxy* const kFakeManagerProxy = reinterpret_cast<DBusGProxy*>(2);
} // namespace
@@ -42,8 +53,28 @@
class PmPolicyManagerTest : public ::testing::Test {
protected:
virtual void SetUp() {
- EXPECT_CALL(mock_dbus_, BusGet(_, _)).WillOnce(Return(kFakeConnection));
+ // TODO(garnold) Replace this low-level DBus injection with a high-level
+ // mock shill provider.
+ EXPECT_CALL(mock_dbus_, BusGet(_, _))
+ .WillOnce(Return(kFakeConnection));
+ EXPECT_CALL(mock_dbus_, ProxyNewForName(_, _, _, _))
+ .WillOnce(Return(kFakeManagerProxy));
+ EXPECT_CALL(mock_dbus_, ProxyAddSignal_2(_, _, _, _))
+ .WillOnce(Return());
+ EXPECT_CALL(mock_dbus_, ProxyConnectSignal(_, _, _, _, _))
+ .WillOnce(Return());
+ auto properties = g_hash_table_new_full(g_str_hash, g_str_equal, free,
+ GValueFree);
+ g_hash_table_insert(properties, strdup(shill::kDefaultServiceProperty),
+ GValueNewString("/"));
+ EXPECT_CALL(mock_dbus_, ProxyCall_0_1(_, _, _, _))
+ .WillOnce(DoAll(SetArgPointee<3>(g_hash_table_ref(properties)),
+ Return(true)));
+
EXPECT_TRUE(pmut_.Init(&mock_dbus_, &fake_clock_));
+
+ // TODO(garnold) Remove this, too.
+ g_hash_table_unref(properties);
}
NiceMock<MockDBusWrapper> mock_dbus_;