shill: cellular: Make StopModem call disconnect for MM1 modems

Fix StopModem so that it makes a DBus call to disconnect the modem for
modems using the MM1 interfaces.  Add unit tests for StopModem.

BUG=none
TEST=run unittests
Change-Id: I6b084ab1928a241e1dfc261747ae361769a83d88
Reviewed-on: https://gerrit.chromium.org/gerrit/22894
Reviewed-by: Ben Chan <benchan@chromium.org>
Tested-by: Jason Glasgow <jglasgow@chromium.org>
Commit-Ready: Jason Glasgow <jglasgow@chromium.org>
diff --git a/cellular_capability_universal_unittest.cc b/cellular_capability_universal_unittest.cc
index 65b1ba3..b504943 100644
--- a/cellular_capability_universal_unittest.cc
+++ b/cellular_capability_universal_unittest.cc
@@ -288,6 +288,59 @@
   EXPECT_TRUE(error.IsSuccess());
 }
 
+TEST_F(CellularCapabilityUniversalTest, StopModem) {
+  // Save pointers to proxies before they are lost by the call to InitProxies
+  mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
+  SetUp();
+  EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
+  capability_->InitProxies();
+
+  Error error;
+  ResultCallback callback =
+      Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
+  capability_->StopModem(&error, callback);
+  EXPECT_TRUE(error.IsSuccess());
+
+  ResultCallback disable_callback;
+  EXPECT_CALL(*modem_proxy,
+              Enable(false, _, _, CellularCapability::kTimeoutEnable))
+      .WillOnce(SaveArg<2>(&disable_callback));
+  dispatcher_.DispatchPendingEvents();
+
+  EXPECT_CALL(*this, TestCallback(IsSuccess()));
+  disable_callback.Run(Error(Error::kSuccess));
+}
+
+TEST_F(CellularCapabilityUniversalTest, StopModemConnected) {
+  // Save pointers to proxies before they are lost by the call to InitProxies
+  mm1::MockModemProxy *modem_proxy = modem_proxy_.get();
+  mm1::MockModemSimpleProxy *modem_simple_proxy = modem_simple_proxy_.get();
+  SetUp();
+  EXPECT_CALL(*modem_proxy, set_state_changed_callback(_));
+  capability_->InitProxies();
+
+  ResultCallback disconnect_callback;
+  Error error;
+  ResultCallback callback =
+      Bind(&CellularCapabilityUniversalTest::TestCallback, Unretained(this));
+  EXPECT_CALL(*modem_simple_proxy,
+              Disconnect(::DBus::Path("/"), _, _,
+                         CellularCapability::kTimeoutDefault))
+      .WillOnce(SaveArg<2>(&disconnect_callback));
+  capability_->cellular()->state_ = Cellular::kStateConnected;
+  capability_->StopModem(&error, callback);
+  EXPECT_TRUE(error.IsSuccess());
+
+  ResultCallback disable_callback;
+  EXPECT_CALL(*modem_proxy,
+              Enable(false, _, _, CellularCapability::kTimeoutEnable))
+      .WillOnce(SaveArg<2>(&disable_callback));
+  disconnect_callback.Run(Error(Error::kSuccess));
+
+  EXPECT_CALL(*this, TestCallback(IsSuccess()));
+  disable_callback.Run(Error(Error::kSuccess));
+}
+
 TEST_F(CellularCapabilityUniversalTest, PropertiesChanged) {
   // Set up mock modem properties
   DBusPropertiesMap modem_properties;