buffet: Expose RegistrationStatus over DBus

This new property lets applications monitor Buffet's connection to
cloud services.

BUG=brillo:16
TEST=Unittests, buffet_Registration has been expanded appropriately.
CQ-DEPEND=CL:*199337
Change-Id: I30253e8199cb65068a74dd8b780a8ab0954bf9fa
Reviewed-on: https://chromium-review.googlesource.com/250011
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/buffet/device_registration_info_unittest.cc b/buffet/device_registration_info_unittest.cc
index ee49b0a..dee5614 100644
--- a/buffet/device_registration_info_unittest.cc
+++ b/buffet/device_registration_info_unittest.cc
@@ -189,12 +189,18 @@
     config_store->SetString("model_id", "AAA");
     config_store->SetString("oauth_url", test_data::kOAuthURL);
     config_store->SetString("service_url", test_data::kServiceURL);
+    auto mock_callback = base::Bind(
+        &DeviceRegistrationInfoTest::OnRegistrationStatusChange,
+        base::Unretained(this));
     dev_reg_ = std::unique_ptr<DeviceRegistrationInfo>(
         new DeviceRegistrationInfo(command_manager_, state_manager_,
                                    std::move(config_store),
-                                   transport_, storage_));
+                                   transport_, storage_,
+                                   mock_callback));
   }
 
+  MOCK_METHOD1(OnRegistrationStatusChange, void(RegistrationStatus));
+
   base::DictionaryValue data_;
   std::shared_ptr<MemStorage> storage_;
   std::shared_ptr<chromeos::http::fake::Transport> transport_;
@@ -425,6 +431,7 @@
   EXPECT_EQ(1,
             storage_->save_count());  // The device info must have been saved.
   EXPECT_EQ(3, transport_->GetRequestCount());
+  EXPECT_EQ(RegistrationStatus::kRegistered, dev_reg_->GetRegistrationStatus());
 
   // Validate the device info saved to storage...
   auto storage_data = storage_->Load();
@@ -449,4 +456,17 @@
   EXPECT_EQ(test_data::kServiceURL, value);
 }
 
+TEST_F(DeviceRegistrationInfoTest, OOBRegistrationStatus) {
+  // After we've been initialized, we should be either offline or unregistered,
+  // depending on whether or not we've found credentials.
+  EXPECT_TRUE(dev_reg_->Load());
+  EXPECT_EQ(RegistrationStatus::kUnregistered,
+            dev_reg_->GetRegistrationStatus());
+  // Put some credentials into our state, make sure we call that offline.
+  SetDefaultDeviceRegistration(&data_);
+  storage_->Save(&data_);
+  EXPECT_TRUE(dev_reg_->Load());
+  EXPECT_EQ(RegistrationStatus::kOffline, dev_reg_->GetRegistrationStatus());
+}
+
 }  // namespace buffet