shill: Fix crash when service is disabled after receiving IP config.

BUG=chromium-os:34127
TEST=Unit tests, network_3GSmokeTest

Change-Id: Ie3cfdcfec4906b089248a357826473e1ec237941
Reviewed-on: https://gerrit.chromium.org/gerrit/32973
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Thieu Le <thieule@chromium.org>
Tested-by: Thieu Le <thieule@chromium.org>
diff --git a/device_unittest.cc b/device_unittest.cc
index 42ee525..bc1fdc9 100644
--- a/device_unittest.cc
+++ b/device_unittest.cc
@@ -350,6 +350,15 @@
   OnIPConfigUpdated(ipconfig.get(), true);
 }
 
+TEST_F(DeviceTest, IPConfigUpdatedSuccessNoSelectedService) {
+  // Make sure shill doesn't crash if a service is disabled immediately
+  // after receiving its IP config (selected_service_ is NULL in this case).
+  scoped_refptr<MockIPConfig> ipconfig = new MockIPConfig(control_interface(),
+                                                          kDeviceName);
+  SelectService(NULL);
+  OnIPConfigUpdated(ipconfig.get(), true);
+}
+
 TEST_F(DeviceTest, SetEnabledPersistent) {
   EXPECT_FALSE(device_->enabled_);
   EXPECT_FALSE(device_->enabled_pending_);