shill: Update all mock proxies to fail DBus methods synchronously by default.

CL:215790 introduced a new mock action that allows mock dbus proxies to specify
default behaviour for DBus calls. That CL also updated some of the proxies
to fail all DBus calls synchronously. This is a follow up CL that sets similar
expectations for the remaining DBus proxies.

Also, set non-default expectations on one of the proxies in WiFiMainTest and
WiMaxTest.

BUG=chromium:411018
TEST=Run shill_unittest.

Change-Id: Ib5a605ae58750d91f714a33d0e1a3e4479b72154
Reviewed-on: https://chromium-review.googlesource.com/218726
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
diff --git a/mock_crypto_util_proxy.cc b/mock_crypto_util_proxy.cc
index 55cd46f..18601fc 100644
--- a/mock_crypto_util_proxy.cc
+++ b/mock_crypto_util_proxy.cc
@@ -10,12 +10,24 @@
 #include "shill/callbacks.h"
 #include "shill/error.h"
 #include "shill/event_dispatcher.h"
+#include "shill/testing.h"
+
+using testing::_;
+using testing::DoAll;
+using testing::Return;
 
 namespace shill {
 
 MockCryptoUtilProxy::MockCryptoUtilProxy(
     EventDispatcher *dispatcher, GLib *glib)
-    : CryptoUtilProxy(dispatcher, glib) {}
+    : CryptoUtilProxy(dispatcher, glib) {
+  ON_CALL(*this, VerifyDestination(_, _, _, _, _, _, _, _, _))
+      .WillByDefault(DoAll(SetOperationFailedInArgumentAndWarn<8>(),
+                           Return(false)));
+  ON_CALL(*this, EncryptData(_, _, _, _))
+      .WillByDefault(DoAll(SetOperationFailedInArgumentAndWarn<3>(),
+                           Return(false)));
+}
 
 MockCryptoUtilProxy::~MockCryptoUtilProxy() {}
 
diff --git a/mock_dbus_objectmanager_proxy.cc b/mock_dbus_objectmanager_proxy.cc
index 30b6238..81ca236 100644
--- a/mock_dbus_objectmanager_proxy.cc
+++ b/mock_dbus_objectmanager_proxy.cc
@@ -4,11 +4,16 @@
 
 #include "shill/mock_dbus_objectmanager_proxy.h"
 
+#include "shill/testing.h"
+
 using ::testing::_;
 using ::testing::AnyNumber;
 
 namespace shill {
-MockDBusObjectManagerProxy::MockDBusObjectManagerProxy() {}
+MockDBusObjectManagerProxy::MockDBusObjectManagerProxy() {
+  ON_CALL(*this, GetManagedObjects(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+}
 
 MockDBusObjectManagerProxy::~MockDBusObjectManagerProxy() {}
 
diff --git a/mock_dbus_service_proxy.cc b/mock_dbus_service_proxy.cc
index ed91443..caa6aac 100644
--- a/mock_dbus_service_proxy.cc
+++ b/mock_dbus_service_proxy.cc
@@ -4,9 +4,16 @@
 
 #include "shill/mock_dbus_service_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 
-MockDBusServiceProxy::MockDBusServiceProxy() {}
+MockDBusServiceProxy::MockDBusServiceProxy() {
+  ON_CALL(*this, GetNameOwner(_, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<1>());
+}
 
 MockDBusServiceProxy::~MockDBusServiceProxy() {}
 
diff --git a/mock_mm1_bearer_proxy.cc b/mock_mm1_bearer_proxy.cc
index 498465c..6544abf 100644
--- a/mock_mm1_bearer_proxy.cc
+++ b/mock_mm1_bearer_proxy.cc
@@ -4,10 +4,19 @@
 
 #include "shill/mock_mm1_bearer_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 namespace mm1 {
 
-MockBearerProxy::MockBearerProxy() {}
+MockBearerProxy::MockBearerProxy() {
+  ON_CALL(*this, Connect(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+  ON_CALL(*this, Disconnect(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+}
 
 MockBearerProxy::~MockBearerProxy() {}
 
diff --git a/mock_mm1_modem_location_proxy.cc b/mock_mm1_modem_location_proxy.cc
index 2acfe0c..3701936 100644
--- a/mock_mm1_modem_location_proxy.cc
+++ b/mock_mm1_modem_location_proxy.cc
@@ -4,10 +4,19 @@
 
 #include "shill/mock_mm1_modem_location_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 namespace mm1 {
 
-MockModemLocationProxy::MockModemLocationProxy() {}
+MockModemLocationProxy::MockModemLocationProxy() {
+  ON_CALL(*this, Setup(_, _, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<2>());
+  ON_CALL(*this, GetLocation(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+}
 
 MockModemLocationProxy::~MockModemLocationProxy() {}
 
diff --git a/mock_mm1_modem_modemcdma_proxy.cc b/mock_mm1_modem_modemcdma_proxy.cc
index be3a9c7..b660fff 100644
--- a/mock_mm1_modem_modemcdma_proxy.cc
+++ b/mock_mm1_modem_modemcdma_proxy.cc
@@ -4,10 +4,19 @@
 
 #include "shill/mock_mm1_modem_modemcdma_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 namespace mm1 {
 
-MockModemModemCdmaProxy::MockModemModemCdmaProxy() {}
+MockModemModemCdmaProxy::MockModemModemCdmaProxy() {
+  ON_CALL(*this, Activate(_, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<1>());
+  ON_CALL(*this, ActivateManual(_, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<1>());
+}
 
 MockModemModemCdmaProxy::~MockModemModemCdmaProxy() {}
 
diff --git a/mock_mm1_modem_time_proxy.cc b/mock_mm1_modem_time_proxy.cc
index 7cc0200..f4efe8c 100644
--- a/mock_mm1_modem_time_proxy.cc
+++ b/mock_mm1_modem_time_proxy.cc
@@ -4,10 +4,17 @@
 
 #include "shill/mock_mm1_modem_time_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 namespace mm1 {
 
-MockModemTimeProxy::MockModemTimeProxy() {}
+MockModemTimeProxy::MockModemTimeProxy() {
+  ON_CALL(*this, GetNetworkTime(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+}
 
 MockModemTimeProxy::~MockModemTimeProxy() {}
 
diff --git a/mock_mm1_sim_proxy.cc b/mock_mm1_sim_proxy.cc
index 4a117f9..d18fde0 100644
--- a/mock_mm1_sim_proxy.cc
+++ b/mock_mm1_sim_proxy.cc
@@ -4,10 +4,23 @@
 
 #include "shill/mock_mm1_sim_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 namespace mm1 {
 
-MockSimProxy::MockSimProxy() {}
+MockSimProxy::MockSimProxy() {
+  ON_CALL(*this, SendPin(_, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<1>());
+  ON_CALL(*this, SendPuk(_, _, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<2>());
+  ON_CALL(*this, EnablePin(_, _, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<2>());
+  ON_CALL(*this, ChangePin(_, _, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<2>());
+}
 
 MockSimProxy::~MockSimProxy() {}
 
diff --git a/mock_modem_gobi_proxy.cc b/mock_modem_gobi_proxy.cc
index 203110f..820673c 100644
--- a/mock_modem_gobi_proxy.cc
+++ b/mock_modem_gobi_proxy.cc
@@ -4,9 +4,16 @@
 
 #include "shill/mock_modem_gobi_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 
-MockModemGobiProxy::MockModemGobiProxy() {}
+MockModemGobiProxy::MockModemGobiProxy() {
+  ON_CALL(*this, SetCarrier(_, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<1>());
+}
 
 MockModemGobiProxy::~MockModemGobiProxy() {}
 
diff --git a/mock_power_manager_proxy.cc b/mock_power_manager_proxy.cc
index 9836374..dc806d8 100644
--- a/mock_power_manager_proxy.cc
+++ b/mock_power_manager_proxy.cc
@@ -4,6 +4,10 @@
 
 #include "shill/mock_power_manager_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 
 MockPowerManagerProxy::MockPowerManagerProxy() {}
diff --git a/mock_wimax_device_proxy.cc b/mock_wimax_device_proxy.cc
index 5eb7025..c6cf366 100644
--- a/mock_wimax_device_proxy.cc
+++ b/mock_wimax_device_proxy.cc
@@ -4,9 +4,24 @@
 
 #include "shill/mock_wimax_device_proxy.h"
 
+#include "shill/testing.h"
+
+using testing::_;
+
 namespace shill {
 
-MockWiMaxDeviceProxy::MockWiMaxDeviceProxy() {}
+MockWiMaxDeviceProxy::MockWiMaxDeviceProxy() {
+  ON_CALL(*this, Enable(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+  ON_CALL(*this, Disable(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+  ON_CALL(*this, ScanNetworks(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+  ON_CALL(*this, Connect(_, _, _, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<2>());
+  ON_CALL(*this, Disconnect(_, _, _))
+      .WillByDefault(SetOperationFailedInArgumentAndWarn<0>());
+}
 
 MockWiMaxDeviceProxy::~MockWiMaxDeviceProxy() {}
 
diff --git a/wifi_unittest.cc b/wifi_unittest.cc
index b31faa2..307c6d8 100644
--- a/wifi_unittest.cc
+++ b/wifi_unittest.cc
@@ -24,6 +24,7 @@
 #include <dbus-c++/dbus.h>
 
 #include "shill/dbus_adaptor.h"
+#include "shill/error.h"
 #include "shill/event_dispatcher.h"
 #include "shill/geolocation_info.h"
 #include "shill/ieee80211.h"
@@ -117,6 +118,7 @@
 const uint16_t kRandomScanFrequency2 = 5560;
 const uint16_t kRandomScanFrequency3 = 2422;
 const int kInterfaceIndex = 1234;
+const char kSupplicantNameOwner[] = "9999";
 
 }  // namespace
 
@@ -743,9 +745,19 @@
     EXPECT_CALL(netlink_manager_, SendNl80211Message(
         IsNl80211Command(kNl80211FamilyId, NL80211_CMD_GET_WIPHY), _, _, _));
 
+    StringCallback supplicant_name_owner_callback;
+    if (supplicant_present)
+      EXPECT_CALL(*dbus_service_proxy_.get(),
+                  GetNameOwner(WPASupplicant::kDBusAddr, _, _, _))
+          .WillOnce(DoAll(SetErrorTypeInArgument<1>(Error::kOperationInitiated),
+                          SaveArg<2>(&supplicant_name_owner_callback)));
+
     dbus_manager_->Start();
     wifi_->supplicant_present_ = supplicant_present;
     wifi_->SetEnabled(true);  // Start(NULL, ResultCallback());
+    if (supplicant_present)
+      // Mimick the callback from |dbus_service_proxy_->GetNameOwner|.
+      supplicant_name_owner_callback.Run(kSupplicantNameOwner, Error());
   }
   void StartWiFi() {
     StartWiFi(true);
@@ -1158,8 +1170,6 @@
 TEST_F(WiFiMainTest, OnSupplicantAppearStarted) {
   EXPECT_TRUE(GetSupplicantProcessProxy() == NULL);
 
-  EXPECT_CALL(*dbus_service_proxy_.get(),
-              GetNameOwner(WPASupplicant::kDBusAddr, _, _, _));
   StartWiFi(false);  // No supplicant present.
   EXPECT_TRUE(GetSupplicantProcessProxy() == NULL);
 
diff --git a/wimax_unittest.cc b/wimax_unittest.cc
index 01d2161..b1714f7 100644
--- a/wimax_unittest.cc
+++ b/wimax_unittest.cc
@@ -294,7 +294,8 @@
   EXPECT_CALL(*service, SetState(Service::kStateAssociating));
   device_->status_ = wimax_manager::kDeviceStatusScanning;
   EXPECT_CALL(*service, GetNetworkObjectPath()).WillOnce(Return(kPath));
-  EXPECT_CALL(*proxy_, Connect(kPath, _, _, _, _));
+  EXPECT_CALL(*proxy_, Connect(kPath, _, _, _, _))
+      .WillOnce(SetErrorTypeInArgument<2>(Error::kSuccess));
   device_->proxy_.reset(proxy_.release());
   Error error;
   device_->ConnectTo(service, &error);