shill: Service: Save service entry when property is set

When individual properties are set on a service that has a
backing profile, save the property to the profile so it is
persisted immediately.

BUG=chromium-os:29745
TEST=New unit test

Change-Id: I19084436d29f39033f5be2d08958aa68297be4d0
Reviewed-on: https://gerrit.chromium.org/gerrit/21026
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/service_unittest.cc b/service_unittest.cc
index 6413166..2d94615 100644
--- a/service_unittest.cc
+++ b/service_unittest.cc
@@ -21,6 +21,7 @@
 #include "shill/mock_adaptors.h"
 #include "shill/mock_control.h"
 #include "shill/mock_manager.h"
+#include "shill/mock_profile.h"
 #include "shill/mock_store.h"
 #include "shill/property_store_unittest.h"
 #include "shill/service_under_test.h"
@@ -419,6 +420,27 @@
   EXPECT_FALSE(service_->auto_connect());
 }
 
+TEST_F(ServiceTest, OnPropertyChanged) {
+  scoped_refptr<MockProfile> profile(
+      new StrictMock<MockProfile>(control_interface(), manager()));
+  service_->set_profile(NULL);
+  // Expect no crash.
+  service_->OnPropertyChanged("");
+
+  // Expect no call to Update if the profile has no storage.
+  service_->set_profile(profile);
+  EXPECT_CALL(*profile, UpdateService(_)).Times(0);
+  EXPECT_CALL(*profile, GetConstStorage())
+      .WillOnce(Return(reinterpret_cast<StoreInterface *>(NULL)));
+  service_->OnPropertyChanged("");
+
+  // Expect call to Update if the profile has storage.
+  EXPECT_CALL(*profile, UpdateService(_)).Times(1);
+  NiceMock<MockStore> storage;
+  EXPECT_CALL(*profile, GetConstStorage()).WillOnce(Return(&storage));
+  service_->OnPropertyChanged("");
+}
+
 // Make sure a property is registered as a write only property
 // by reading and comparing all string properties returned on the store.
 // Subtle: We need to convert the test argument back and forth between