buffet: Persist needed registration data Previously we weren't persisting the device_kind, name, display_name, description, and location of the device. This meant that after stopping and starting buffet it could no longer save device state to GCD. TEST=FEATURES=test emerge buffet BUG=brillo:153 Change-Id: Ica5233ef6e3d50d3456ecd6b18ba750e1bada3cf Reviewed-on: https://chromium-review.googlesource.com/248740 Tested-by: Nathan Bullock <nathanbullock@google.com> Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Nathan Bullock <nathanbullock@google.com>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc index abe130b..a0b684e 100644 --- a/buffet/device_registration_info.cc +++ b/buffet/device_registration_info.cc
@@ -214,6 +214,21 @@ std::string device_robot_account; if (!dict->GetString(storage_keys::kRobotAccount, &device_robot_account)) return false; + std::string device_kind; + if (!dict->GetString(storage_keys::kDeviceKind, &device_kind)) + return false; + std::string name; + if (!dict->GetString(storage_keys::kName, &name)) + return false; + std::string display_name; + if (!dict->GetString(storage_keys::kDisplayName, &display_name)) + return false; + std::string description; + if (!dict->GetString(storage_keys::kDescription, &description)) + return false; + std::string location; + if (!dict->GetString(storage_keys::kLocation, &location)) + return false; client_id_ = client_id; client_secret_ = client_secret; @@ -223,6 +238,11 @@ oauth_url_ = oauth_url; service_url_ = service_url; device_robot_account_ = device_robot_account; + device_kind_ = device_kind; + name_ = name; + display_name_ = display_name; + description_ = description; + location_ = location; return true; } @@ -236,6 +256,12 @@ dict.SetString(storage_keys::kOAuthURL, oauth_url_); dict.SetString(storage_keys::kServiceURL, service_url_); dict.SetString(storage_keys::kRobotAccount, device_robot_account_); + dict.SetString(storage_keys::kDeviceKind, device_kind_); + dict.SetString(storage_keys::kName, name_); + dict.SetString(storage_keys::kDisplayName, display_name_); + dict.SetString(storage_keys::kDescription, description_); + dict.SetString(storage_keys::kLocation, location_); + return storage_->Save(&dict); }
diff --git a/buffet/device_registration_info_unittest.cc b/buffet/device_registration_info_unittest.cc index 56e294a..676048f 100644 --- a/buffet/device_registration_info_unittest.cc +++ b/buffet/device_registration_info_unittest.cc
@@ -67,6 +67,11 @@ data->SetString(storage_keys::kOAuthURL, test_data::kOAuthURL); data->SetString(storage_keys::kServiceURL, test_data::kServiceURL); data->SetString(storage_keys::kRobotAccount, ""); + data->SetString(storage_keys::kDeviceKind, ""); + data->SetString(storage_keys::kName, ""); + data->SetString(storage_keys::kDisplayName, ""); + data->SetString(storage_keys::kDescription, ""); + data->SetString(storage_keys::kLocation, ""); } // Add the test device registration information. @@ -151,14 +156,18 @@ } // anonymous namespace -// This is a helper class that allows the unit tests to set the private -// member DeviceRegistrationInfo::ticket_id_, since TestHelper is declared -// as a friend to DeviceRegistrationInfo. +// This is a helper class that allows the unit tests to access private +// methods and data since TestHelper is declared as a friend to +// DeviceRegistrationInfo. class DeviceRegistrationInfo::TestHelper { public: static void SetTestTicketId(DeviceRegistrationInfo* info) { info->ticket_id_ = test_data::kClaimTicketId; } + + static bool Save(DeviceRegistrationInfo* info) { + return info->Save(); + } }; class DeviceRegistrationInfoTest : public ::testing::Test { @@ -216,6 +225,35 @@ })); } +TEST_F(DeviceRegistrationInfoTest, VerifySave) { + base::DictionaryValue data; + data.SetString(storage_keys::kClientId, "a"); + data.SetString(storage_keys::kClientSecret, "b"); + data.SetString(storage_keys::kApiKey, "c"); + data.SetString(storage_keys::kRefreshToken, "d"); + data.SetString(storage_keys::kDeviceId, "e"); + data.SetString(storage_keys::kOAuthURL, "f"); + data.SetString(storage_keys::kServiceURL, "g"); + data.SetString(storage_keys::kRobotAccount, "h"); + data.SetString(storage_keys::kDeviceKind, "i"); + data.SetString(storage_keys::kName, "j"); + data.SetString(storage_keys::kDisplayName, "k"); + data.SetString(storage_keys::kDescription, "l"); + data.SetString(storage_keys::kLocation, "m"); + + storage_->Save(&data); + + // This test isn't really trying to test Load, it is just the easiest + // way to initialize the properties in dev_reg_. + EXPECT_TRUE(dev_reg_->Load()); + + // Clear the storage to get a clean test. + base::DictionaryValue empty; + storage_->Save(&empty); + EXPECT_TRUE(DeviceRegistrationInfo::TestHelper::Save(dev_reg_.get())); + EXPECT_TRUE(storage_->Load()->Equals(&data)); +} + TEST_F(DeviceRegistrationInfoTest, GetOAuthURL) { EXPECT_TRUE(dev_reg_->Load()); EXPECT_EQ(test_data::kOAuthURL, dev_reg_->GetOAuthURL());