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_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());