shill: service: Do active checks on PortalCheck and ProxyConfig

Change both properties to be derived strings.  Validate the various
values of the PortalCheck parameter.  Force a restart of portal
detection if either parameter changes, so that we can switch from
Portal to Online or vice vesa if by changing this parameter we are
changing the behavior of portal check.

BUG=chromium-os:29745
TEST=New unit tests.  Manual: Set Proxy configuration on a service
in portal state while on the login screen.

Change-Id: I86c386e61396a23103f99382c568372b4774f452
Reviewed-on: https://gerrit.chromium.org/gerrit/21027
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 56f6034..62e8832 100644
--- a/service_unittest.cc
+++ b/service_unittest.cc
@@ -79,7 +79,7 @@
   Error error(Error::kInvalidProperty, "");
   {
     ::DBus::Error dbus_error;
-    string expected("portal_list");
+    string expected("true");
     service_->mutable_store()->SetStringProperty(flimflam::kCheckPortalProperty,
                                                  expected,
                                                  &error);
@@ -444,6 +444,59 @@
   service_->OnPropertyChanged("");
 }
 
+
+TEST_F(ServiceTest, RecheckPortal) {
+  ServiceRefPtr service_ref(service_);
+  service_->state_ = Service::kStateIdle;
+  EXPECT_CALL(mock_manager_, RecheckPortalOnService(_)).Times(0);
+  service_->OnPropertyChanged(flimflam::kCheckPortalProperty);
+
+  service_->state_ = Service::kStatePortal;
+  EXPECT_CALL(mock_manager_, RecheckPortalOnService(service_ref)).Times(1);
+  service_->OnPropertyChanged(flimflam::kCheckPortalProperty);
+
+  service_->state_ = Service::kStateConnected;
+  EXPECT_CALL(mock_manager_, RecheckPortalOnService(service_ref)).Times(1);
+  service_->OnPropertyChanged(flimflam::kProxyConfigProperty);
+
+  service_->state_ = Service::kStateOnline;
+  EXPECT_CALL(mock_manager_, RecheckPortalOnService(service_ref)).Times(1);
+  service_->OnPropertyChanged(flimflam::kCheckPortalProperty);
+
+  service_->state_ = Service::kStatePortal;
+  EXPECT_CALL(mock_manager_, RecheckPortalOnService(_)).Times(0);
+  service_->OnPropertyChanged(flimflam::kEAPKeyIDProperty);
+}
+
+TEST_F(ServiceTest, SetCheckPortal) {
+  ServiceRefPtr service_ref(service_);
+  {
+    Error error;
+    service_->SetCheckPortal("false", &error);
+    EXPECT_TRUE(error.IsSuccess());
+    EXPECT_EQ(Service::kCheckPortalFalse, service_->check_portal_);
+  }
+  {
+    Error error;
+    service_->SetCheckPortal("true", &error);
+    EXPECT_TRUE(error.IsSuccess());
+    EXPECT_EQ(Service::kCheckPortalTrue, service_->check_portal_);
+  }
+  {
+    Error error;
+    service_->SetCheckPortal("auto", &error);
+    EXPECT_TRUE(error.IsSuccess());
+    EXPECT_EQ(Service::kCheckPortalAuto, service_->check_portal_);
+  }
+  {
+    Error error;
+    service_->SetCheckPortal("xxx", &error);
+    EXPECT_FALSE(error.IsSuccess());
+    EXPECT_EQ(Error::kInvalidArguments, error.type());
+    EXPECT_EQ(Service::kCheckPortalAuto, service_->check_portal_);
+  }
+}
+
 // 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