shill: Emit more property change notifications for Services.

Add property change notifications for all the Service properties that
Chrome currently pays attention to. Also add unit tests for these
property change notifications.

While there:
- add some more tips to TESTING
- update service-api documentation for AutoConnect
  (it is settable for non-favorite services, and has been for
   some time)
- update some ServiceTests to no longer set_favorite before
  changing AutoConnect (set_favorite is no longer necessary,
  as noted above)
- clarify service-api documentation for Device property
- make the security_ field of WiFiService const (it is only
  set in the ctor, and designating it const makes it obvious
  why there's no property change for it)
- fix bug where VPNService would change the Favorite property,
  but not signal the change

BUG=chromium:230329
TEST=new unit tests

Change-Id: Ia387b1ab90fa80fd218cd69e0fd8126ff4c5a2ae
Reviewed-on: https://gerrit.chromium.org/gerrit/48459
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/service_property_change_test.cc b/service_property_change_test.cc
new file mode 100644
index 0000000..9e08e6f
--- /dev/null
+++ b/service_property_change_test.cc
@@ -0,0 +1,119 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shill/service_property_change_test.h"
+
+#include <string>
+
+#include <chromeos/dbus/service_constants.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "shill/error.h"
+#include "shill/mock_adaptors.h"
+#include "shill/service.h"
+
+using std::string;
+using testing::_;
+using testing::AnyNumber;
+using testing::Mock;
+
+namespace shill {
+
+// Some of these tests are duplicative, as we also have broader tests
+// for specific setters. However, it's convenient to have all the property
+// change notifications documented (and tested) in one place.
+
+void TestCommonPropertyChanges(ServiceRefPtr service,
+                               ServiceMockAdaptor *adaptor) {
+  Error error;
+
+  EXPECT_EQ(Service::kStateIdle, service->state());
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _));
+  service->SetState(Service::kStateConnected);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  // TODO(quiche): Once crosbug.com/34528 is resolved, add a test
+  // that service->SetConnection emits kIPConfigProperty changed.
+
+  bool connectable = service->connectable();
+  EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kConnectableProperty, _));
+  service->SetConnectable(!connectable);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_EQ(string(), service->guid());
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kGuidProperty, _));
+  service->SetGuid("some garbage", &error);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_FALSE(service->favorite());
+  EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kAutoConnectProperty, _))
+      .Times(AnyNumber());
+  EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kFavoriteProperty, _));
+  service->MakeFavorite();
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_EQ(0, service->priority());
+  EXPECT_CALL(*adaptor, EmitIntChanged(flimflam::kPriorityProperty, _));
+  service->SetPriority(1, &error);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_EQ(string(), service->GetProxyConfig(&error));
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kProxyConfigProperty, _));
+  service->SetProxyConfig("some garbage", &error);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  uint8 strength = service->strength();
+  EXPECT_CALL(*adaptor,
+              EmitUint8Changed(flimflam::kSignalStrengthProperty, _));
+  service->SetStrength(strength+1);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_EQ(string(), service->error_details());
+  EXPECT_CALL(*adaptor, EmitStringChanged(kErrorDetailsProperty, _));
+  service->SetErrorDetails("some garbage");
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_EQ(Service::kFailureUnknown, service->failure());
+  EXPECT_EQ(Service::ConnectFailureToString(Service::kFailureUnknown),
+            service->error());
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _));
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _));
+  service->SetFailure(Service::kFailureAAA);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_NE(Service::ConnectFailureToString(Service::kFailureUnknown),
+            service->error());
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _));
+  EXPECT_CALL(*adaptor, EmitStringChanged(kErrorDetailsProperty, _));
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _));
+  service->SetState(Service::kStateConnected);
+  Mock::VerifyAndClearExpectations(adaptor);
+
+  EXPECT_EQ(Service::ConnectFailureToString(Service::kFailureUnknown),
+            service->error());
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _));
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _));
+  service->SetFailureSilent(Service::kFailureAAA);
+  Mock::VerifyAndClearExpectations(adaptor);
+}
+
+void TestAutoConnectPropertyChange(ServiceRefPtr service,
+                                   ServiceMockAdaptor *adaptor) {
+  bool auto_connect = service->auto_connect();
+  EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kAutoConnectProperty, _));
+  service->SetAutoConnect(!auto_connect);
+  Mock::VerifyAndClearExpectations(adaptor);
+}
+
+void TestNamePropertyChange(ServiceRefPtr service,
+                            ServiceMockAdaptor *adaptor) {
+  Error error;
+  string name = service->GetNameProperty(&error);
+  EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kNameProperty, _));
+  service->SetNameProperty(name + " and some new stuff", &error);
+  Mock::VerifyAndClearExpectations(adaptor);
+}
+
+} // namespace shill