blob: f3330786542cc32f2802e3bc493fb6c0f88cdbce [file] [log] [blame]
Alex Vakulenko8e34d392014-04-29 11:02:56 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <base/json/json_reader.h>
6#include <base/values.h>
Alex Vakulenkocf0b33a2014-08-20 15:02:10 -07007#include <chromeos/bind_lambda.h>
Alex Vakulenkoa8b95bc2014-08-27 11:00:57 -07008#include <chromeos/http/http_request.h>
9#include <chromeos/http/http_transport_fake.h>
Alex Vakulenko3aeea1c2014-08-20 16:33:12 -070010#include <chromeos/mime_utils.h>
Alex Vakulenko8e34d392014-04-29 11:02:56 -070011#include <gtest/gtest.h>
12
Alex Vakulenko1f30a622014-07-23 11:13:15 -070013#include "buffet/commands/command_manager.h"
Alex Vakulenko45109442014-07-29 11:07:10 -070014#include "buffet/commands/unittest_utils.h"
Alex Vakulenko8e34d392014-04-29 11:02:56 -070015#include "buffet/device_registration_info.h"
16#include "buffet/device_registration_storage_keys.h"
Alex Vakulenko57123b22014-10-28 13:50:16 -070017#include "buffet/states/mock_state_change_queue_interface.h"
Alex Vakulenko07216fe2014-09-19 15:31:09 -070018#include "buffet/states/state_manager.h"
Christopher Wiley006e94e2014-05-02 13:44:48 -070019#include "buffet/storage_impls.h"
Alex Vakulenko8e34d392014-04-29 11:02:56 -070020
Alex Vakulenkocca20932014-08-20 17:35:12 -070021using chromeos::http::request_header::kAuthorization;
22using chromeos::http::fake::ServerRequest;
23using chromeos::http::fake::ServerResponse;
24
25namespace buffet {
Alex Vakulenko8e34d392014-04-29 11:02:56 -070026
27namespace {
Alex Vakulenko8e34d392014-04-29 11:02:56 -070028
29namespace test_data {
30
31const char kServiceURL[] = "http://gcd.server.com/";
32const char kOAuthURL[] = "http://oauth.server.com/";
33const char kApiKey[] = "GOadRdTf9FERf0k4w6EFOof56fUJ3kFDdFL3d7f";
34const char kClientId[] = "123543821385-sfjkjshdkjhfk234sdfsdfkskd"
35 "fkjh7f.apps.googleusercontent.com";
36const char kClientSecret[] = "5sdGdGlfolGlrFKfdFlgP6FG";
37const char kDeviceId[] = "4a7ea2d1-b331-1e1f-b206-e863c7635196";
38const char kClaimTicketId[] = "RTcUE";
39const char kAccessToken[] = "ya29.1.AADtN_V-dLUM-sVZ0qVjG9Dxm5NgdS9J"
40 "Mx_JLUqhC9bED_YFjzHZtYt65ZzXCS35NMAeaVZ"
41 "Dei530-w0yE2urpQ";
42const char kRefreshToken[] = "1/zQmxR6PKNvhcxf9SjXUrCjcmCrcqRKXctc6cp"
43 "1nI-GQ";
44const char kRobotAccountAuthCode[] = "4/Mf_ujEhPejVhOq-OxW9F5cSOnWzx."
45 "YgciVjTYGscRshQV0ieZDAqiTIjMigI";
46const char kRobotAccountEmail[] = "6ed0b3f54f9bd619b942f4ad2441c252@"
47 "clouddevices.gserviceaccount.com";
48const char kUserAccountAuthCode[] = "2/sd_GD1TGFKpJOLJ34-0g5fK0fflp.GlT"
49 "I0F5g7hNtFgj5HFGOf8FlGK9eflO";
50const char kUserAccessToken[] = "sd56.4.FGDjG_F-gFGF-dFG6gGOG9Dxm5NgdS9"
51 "JMx_JLUqhC9bED_YFjLKjlkjLKJlkjLKjlKJea"
52 "VZDei530-w0yE2urpQ";
53const char kUserRefreshToken[] = "1/zQLKjlKJlkLkLKjLkjLKjLkjLjLkjl0ftc6"
54 "cp1nI-GQ";
55
56} // namespace test_data
57
58// Fill in the storage with default environment information (URLs, etc).
59void InitDefaultStorage(base::DictionaryValue* data) {
60 data->SetString(storage_keys::kClientId, test_data::kClientId);
61 data->SetString(storage_keys::kClientSecret, test_data::kClientSecret);
62 data->SetString(storage_keys::kApiKey, test_data::kApiKey);
63 data->SetString(storage_keys::kRefreshToken, "");
64 data->SetString(storage_keys::kDeviceId, "");
65 data->SetString(storage_keys::kOAuthURL, test_data::kOAuthURL);
66 data->SetString(storage_keys::kServiceURL, test_data::kServiceURL);
67 data->SetString(storage_keys::kRobotAccount, "");
68}
69
70// Add the test device registration information.
71void SetDefaultDeviceRegistration(base::DictionaryValue* data) {
72 data->SetString(storage_keys::kRefreshToken, test_data::kRefreshToken);
73 data->SetString(storage_keys::kDeviceId, test_data::kDeviceId);
74 data->SetString(storage_keys::kRobotAccount, test_data::kRobotAccountEmail);
75}
76
Alex Vakulenkocca20932014-08-20 17:35:12 -070077void OAuth2Handler(const ServerRequest& request, ServerResponse* response) {
Alex Vakulenko8e34d392014-04-29 11:02:56 -070078 base::DictionaryValue json;
79 if (request.GetFormField("grant_type") == "refresh_token") {
80 // Refresh device access token.
81 EXPECT_EQ(test_data::kRefreshToken, request.GetFormField("refresh_token"));
82 EXPECT_EQ(test_data::kClientId, request.GetFormField("client_id"));
83 EXPECT_EQ(test_data::kClientSecret, request.GetFormField("client_secret"));
84 json.SetString("access_token", test_data::kAccessToken);
85 } else if (request.GetFormField("grant_type") == "authorization_code") {
86 // Obtain access token.
87 std::string code = request.GetFormField("code");
88 if (code == test_data::kUserAccountAuthCode) {
89 // Get user access token.
90 EXPECT_EQ(test_data::kClientId, request.GetFormField("client_id"));
91 EXPECT_EQ(test_data::kClientSecret,
92 request.GetFormField("client_secret"));
93 EXPECT_EQ("urn:ietf:wg:oauth:2.0:oob",
94 request.GetFormField("redirect_uri"));
95 json.SetString("access_token", test_data::kUserAccessToken);
96 json.SetString("token_type", "Bearer");
97 json.SetString("refresh_token", test_data::kUserRefreshToken);
98 } else if (code == test_data::kRobotAccountAuthCode) {
99 // Get device access token.
100 EXPECT_EQ(test_data::kClientId, request.GetFormField("client_id"));
101 EXPECT_EQ(test_data::kClientSecret,
102 request.GetFormField("client_secret"));
103 EXPECT_EQ("oob", request.GetFormField("redirect_uri"));
104 EXPECT_EQ("https://www.googleapis.com/auth/clouddevices",
105 request.GetFormField("scope"));
106 json.SetString("access_token", test_data::kAccessToken);
107 json.SetString("token_type", "Bearer");
108 json.SetString("refresh_token", test_data::kRefreshToken);
109 } else {
Alex Vakulenkob3aac252014-05-07 17:35:24 -0700110 FAIL() << "Unexpected authorization code";
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700111 }
112 } else {
Alex Vakulenkob3aac252014-05-07 17:35:24 -0700113 FAIL() << "Unexpected grant type";
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700114 }
115 json.SetInteger("expires_in", 3600);
Alex Vakulenkocca20932014-08-20 17:35:12 -0700116 response->ReplyJson(chromeos::http::status_code::Ok, &json);
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700117}
118
Alex Vakulenkocca20932014-08-20 17:35:12 -0700119void DeviceInfoHandler(const ServerRequest& request, ServerResponse* response) {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700120 std::string auth = "Bearer ";
121 auth += test_data::kAccessToken;
Alex Vakulenkocca20932014-08-20 17:35:12 -0700122 EXPECT_EQ(auth,
123 request.GetHeader(chromeos::http::request_header::kAuthorization));
124 response->ReplyJson(chromeos::http::status_code::Ok, {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700125 {"channel.supportedType", "xmpp"},
126 {"deviceKind", "vendor"},
127 {"id", test_data::kDeviceId},
128 {"kind", "clouddevices#device"},
129 });
130}
131
Alex Vakulenkocca20932014-08-20 17:35:12 -0700132void FinalizeTicketHandler(const ServerRequest& request,
133 ServerResponse* response) {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700134 EXPECT_EQ(test_data::kApiKey, request.GetFormField("key"));
135 EXPECT_TRUE(request.GetData().empty());
136
Alex Vakulenkocca20932014-08-20 17:35:12 -0700137 response->ReplyJson(chromeos::http::status_code::Ok, {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700138 {"id", test_data::kClaimTicketId},
139 {"kind", "clouddevices#registrationTicket"},
140 {"oauthClientId", test_data::kClientId},
141 {"userEmail", "user@email.com"},
142 {"deviceDraft.id", test_data::kDeviceId},
143 {"deviceDraft.kind", "clouddevices#device"},
144 {"deviceDraft.channel.supportedType", "xmpp"},
145 {"robotAccountEmail", test_data::kRobotAccountEmail},
146 {"robotAccountAuthorizationCode", test_data::kRobotAccountAuthCode},
147 });
148}
149
150} // anonymous namespace
151
152// This is a helper class that allows the unit tests to set the private
153// member DeviceRegistrationInfo::ticket_id_, since TestHelper is declared
154// as a friend to DeviceRegistrationInfo.
155class DeviceRegistrationInfo::TestHelper {
156 public:
157 static void SetTestTicketId(DeviceRegistrationInfo* info) {
158 info->ticket_id_ = test_data::kClaimTicketId;
159 }
160};
161
162class DeviceRegistrationInfoTest : public ::testing::Test {
163 protected:
Alex Vakulenko5a9e7182014-08-11 15:59:58 -0700164 void SetUp() override {
Alex Vakulenko45109442014-07-29 11:07:10 -0700165 InitDefaultStorage(&data_);
166 storage_ = std::make_shared<MemStorage>();
167 storage_->Save(&data_);
Alex Vakulenkocca20932014-08-20 17:35:12 -0700168 transport_ = std::make_shared<chromeos::http::fake::Transport>();
Alex Vakulenko45109442014-07-29 11:07:10 -0700169 command_manager_ = std::make_shared<CommandManager>();
Alex Vakulenko57123b22014-10-28 13:50:16 -0700170 state_manager_ = std::make_shared<StateManager>(&mock_state_change_queue_);
Alex Vakulenko45109442014-07-29 11:07:10 -0700171 dev_reg_ = std::unique_ptr<DeviceRegistrationInfo>(
Alex Vakulenko07216fe2014-09-19 15:31:09 -0700172 new DeviceRegistrationInfo(command_manager_, state_manager_,
173 transport_, storage_));
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700174 }
175
Alex Vakulenko45109442014-07-29 11:07:10 -0700176 base::DictionaryValue data_;
177 std::shared_ptr<MemStorage> storage_;
Alex Vakulenkocca20932014-08-20 17:35:12 -0700178 std::shared_ptr<chromeos::http::fake::Transport> transport_;
Alex Vakulenko45109442014-07-29 11:07:10 -0700179 std::unique_ptr<DeviceRegistrationInfo> dev_reg_;
180 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenko57123b22014-10-28 13:50:16 -0700181 testing::NiceMock<MockStateChangeQueueInterface> mock_state_change_queue_;
Alex Vakulenko07216fe2014-09-19 15:31:09 -0700182 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700183};
184
185////////////////////////////////////////////////////////////////////////////////
186TEST_F(DeviceRegistrationInfoTest, GetServiceURL) {
Alex Vakulenko45109442014-07-29 11:07:10 -0700187 EXPECT_TRUE(dev_reg_->Load());
188 EXPECT_EQ(test_data::kServiceURL, dev_reg_->GetServiceURL());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700189 std::string url = test_data::kServiceURL;
190 url += "registrationTickets";
Alex Vakulenko45109442014-07-29 11:07:10 -0700191 EXPECT_EQ(url, dev_reg_->GetServiceURL("registrationTickets"));
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700192 url += "?key=";
193 url += test_data::kApiKey;
Alex Vakulenko45109442014-07-29 11:07:10 -0700194 EXPECT_EQ(url, dev_reg_->GetServiceURL("registrationTickets", {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700195 {"key", test_data::kApiKey}
196 }));
197 url += "&restart=true";
Alex Vakulenko45109442014-07-29 11:07:10 -0700198 EXPECT_EQ(url, dev_reg_->GetServiceURL("registrationTickets", {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700199 {"key", test_data::kApiKey},
200 {"restart", "true"},
201 }));
202}
203
204TEST_F(DeviceRegistrationInfoTest, GetOAuthURL) {
Alex Vakulenko45109442014-07-29 11:07:10 -0700205 EXPECT_TRUE(dev_reg_->Load());
206 EXPECT_EQ(test_data::kOAuthURL, dev_reg_->GetOAuthURL());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700207 std::string url = test_data::kOAuthURL;
208 url += "auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fclouddevices&";
209 url += "redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&";
210 url += "response_type=code&";
211 url += "client_id=";
212 url += test_data::kClientId;
Alex Vakulenko45109442014-07-29 11:07:10 -0700213 EXPECT_EQ(url, dev_reg_->GetOAuthURL("auth", {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700214 {"scope", "https://www.googleapis.com/auth/clouddevices"},
215 {"redirect_uri", "urn:ietf:wg:oauth:2.0:oob"},
216 {"response_type", "code"},
217 {"client_id", test_data::kClientId}
218 }));
219}
220
221TEST_F(DeviceRegistrationInfoTest, CheckRegistration) {
Alex Vakulenko45109442014-07-29 11:07:10 -0700222 EXPECT_TRUE(dev_reg_->Load());
223 EXPECT_FALSE(dev_reg_->CheckRegistration(nullptr));
224 EXPECT_EQ(0, transport_->GetRequestCount());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700225
Alex Vakulenko45109442014-07-29 11:07:10 -0700226 SetDefaultDeviceRegistration(&data_);
227 storage_->Save(&data_);
228 EXPECT_TRUE(dev_reg_->Load());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700229
Alex Vakulenkocca20932014-08-20 17:35:12 -0700230 transport_->AddHandler(dev_reg_->GetOAuthURL("token"),
231 chromeos::http::request_type::kPost,
Alex Vakulenko45109442014-07-29 11:07:10 -0700232 base::Bind(OAuth2Handler));
233 transport_->ResetRequestCount();
234 EXPECT_TRUE(dev_reg_->CheckRegistration(nullptr));
235 EXPECT_EQ(1, transport_->GetRequestCount());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700236}
237
238TEST_F(DeviceRegistrationInfoTest, GetDeviceInfo) {
Alex Vakulenko45109442014-07-29 11:07:10 -0700239 SetDefaultDeviceRegistration(&data_);
240 storage_->Save(&data_);
241 EXPECT_TRUE(dev_reg_->Load());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700242
Alex Vakulenkocca20932014-08-20 17:35:12 -0700243 transport_->AddHandler(dev_reg_->GetOAuthURL("token"),
244 chromeos::http::request_type::kPost,
Alex Vakulenko45109442014-07-29 11:07:10 -0700245 base::Bind(OAuth2Handler));
Alex Vakulenkocca20932014-08-20 17:35:12 -0700246 transport_->AddHandler(dev_reg_->GetDeviceURL(),
247 chromeos::http::request_type::kGet,
Alex Vakulenko45109442014-07-29 11:07:10 -0700248 base::Bind(DeviceInfoHandler));
249 transport_->ResetRequestCount();
250 auto device_info = dev_reg_->GetDeviceInfo(nullptr);
251 EXPECT_EQ(2, transport_->GetRequestCount());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700252 EXPECT_NE(nullptr, device_info.get());
253 base::DictionaryValue* dict = nullptr;
254 EXPECT_TRUE(device_info->GetAsDictionary(&dict));
255 std::string id;
256 EXPECT_TRUE(dict->GetString("id", &id));
257 EXPECT_EQ(test_data::kDeviceId, id);
258}
259
260TEST_F(DeviceRegistrationInfoTest, GetDeviceId) {
Alex Vakulenko45109442014-07-29 11:07:10 -0700261 SetDefaultDeviceRegistration(&data_);
262 storage_->Save(&data_);
263 EXPECT_TRUE(dev_reg_->Load());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700264
Alex Vakulenkocca20932014-08-20 17:35:12 -0700265 transport_->AddHandler(dev_reg_->GetOAuthURL("token"),
266 chromeos::http::request_type::kPost,
Alex Vakulenko45109442014-07-29 11:07:10 -0700267 base::Bind(OAuth2Handler));
Alex Vakulenkocca20932014-08-20 17:35:12 -0700268 transport_->AddHandler(dev_reg_->GetDeviceURL(),
269 chromeos::http::request_type::kGet,
Alex Vakulenko45109442014-07-29 11:07:10 -0700270 base::Bind(DeviceInfoHandler));
271 std::string id = dev_reg_->GetDeviceId(nullptr);
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700272 EXPECT_EQ(test_data::kDeviceId, id);
273}
274
Anton Muhinbeb1c5b2014-10-16 18:59:57 +0400275TEST_F(DeviceRegistrationInfoTest, RegisterDevice) {
Alex Vakulenko45109442014-07-29 11:07:10 -0700276 EXPECT_TRUE(dev_reg_->Load());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700277
Anton Muhina4803142014-09-24 19:30:45 +0400278 auto update_ticket = [](const ServerRequest& request,
Alex Vakulenkocca20932014-08-20 17:35:12 -0700279 ServerResponse* response) {
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700280 EXPECT_EQ(test_data::kApiKey, request.GetFormField("key"));
281 auto json = request.GetDataAsJson();
282 EXPECT_NE(nullptr, json.get());
283 std::string value;
Anton Muhina4803142014-09-24 19:30:45 +0400284 EXPECT_TRUE(json->GetString("id", &value));
285 EXPECT_EQ(test_data::kClaimTicketId, value);
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700286 EXPECT_TRUE(json->GetString("deviceDraft.channel.supportedType", &value));
287 EXPECT_EQ("xmpp", value);
288 EXPECT_TRUE(json->GetString("oauthClientId", &value));
289 EXPECT_EQ(test_data::kClientId, value);
290 EXPECT_TRUE(json->GetString("deviceDraft.deviceKind", &value));
291 EXPECT_EQ("vendor", value);
Alex Vakulenko45109442014-07-29 11:07:10 -0700292 base::DictionaryValue* commandDefs = nullptr;
293 EXPECT_TRUE(json->GetDictionary("deviceDraft.commandDefs", &commandDefs));
294 EXPECT_FALSE(commandDefs->empty());
295 EXPECT_EQ("{'base':{'reboot':{'parameters':{"
296 "'delay':{'minimum':10,'type':'integer'}}}},"
297 "'robot':{'_jump':{'parameters':{"
298 "'_height':{'type':'integer'}}}}}",
299 buffet::unittests::ValueToString(commandDefs));
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700300
301 base::DictionaryValue json_resp;
302 json_resp.SetString("id", test_data::kClaimTicketId);
303 json_resp.SetString("kind", "clouddevices#registrationTicket");
304 json_resp.SetString("oauthClientId", test_data::kClientId);
305 base::DictionaryValue* device_draft = nullptr;
306 EXPECT_TRUE(json->GetDictionary("deviceDraft", &device_draft));
307 device_draft = device_draft->DeepCopy();
308 device_draft->SetString("id", test_data::kDeviceId);
309 device_draft->SetString("kind", "clouddevices#device");
310 json_resp.Set("deviceDraft", device_draft);
311
Alex Vakulenkocca20932014-08-20 17:35:12 -0700312 response->ReplyJson(chromeos::http::status_code::Ok, &json_resp);
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700313 };
314
Alex Vakulenko45109442014-07-29 11:07:10 -0700315 auto json_base = buffet::unittests::CreateDictionaryValue(R"({
316 'base': {
317 'reboot': {
318 'parameters': {'delay': 'integer'}
319 },
320 'shutdown': {
321 'parameters': {}
322 }
323 }
324 })");
325 EXPECT_TRUE(command_manager_->LoadBaseCommands(*json_base, nullptr));
326 auto json_cmds = buffet::unittests::CreateDictionaryValue(R"({
327 'base': {
328 'reboot': {
329 'parameters': {'delay': {'minimum': 10}}
330 }
331 },
332 'robot': {
333 '_jump': {
334 'parameters': {'_height': 'integer'}
335 }
336 }
337 })");
338 EXPECT_TRUE(command_manager_->LoadCommands(*json_cmds, "", nullptr));
339
Anton Muhina4803142014-09-24 19:30:45 +0400340 transport_->AddHandler(dev_reg_->GetServiceURL(
341 std::string("registrationTickets/") + test_data::kClaimTicketId),
342 chromeos::http::request_type::kPatch,
343 base::Bind(update_ticket));
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700344 std::string ticket_url =
Alex Vakulenko45109442014-07-29 11:07:10 -0700345 dev_reg_->GetServiceURL("registrationTickets/" +
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700346 std::string(test_data::kClaimTicketId));
Alex Vakulenkocca20932014-08-20 17:35:12 -0700347 transport_->AddHandler(ticket_url + "/finalize",
348 chromeos::http::request_type::kPost,
Alex Vakulenko45109442014-07-29 11:07:10 -0700349 base::Bind(FinalizeTicketHandler));
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700350
Alex Vakulenkocca20932014-08-20 17:35:12 -0700351 transport_->AddHandler(dev_reg_->GetOAuthURL("token"),
352 chromeos::http::request_type::kPost,
Alex Vakulenko45109442014-07-29 11:07:10 -0700353 base::Bind(OAuth2Handler));
Alex Vakulenko45109442014-07-29 11:07:10 -0700354 storage_->reset_save_count();
355 DeviceRegistrationInfo::TestHelper::SetTestTicketId(dev_reg_.get());
Anton Muhinbeb1c5b2014-10-16 18:59:57 +0400356
357 std::map<std::string, std::string> params;
358 params["ticket_id"] = test_data::kClaimTicketId;
359 std::string device_id = dev_reg_->RegisterDevice(params, nullptr);
360
361 EXPECT_EQ(test_data::kDeviceId, device_id);
Alex Vakulenko45109442014-07-29 11:07:10 -0700362 EXPECT_EQ(1,
363 storage_->save_count()); // The device info must have been saved.
Anton Muhinbeb1c5b2014-10-16 18:59:57 +0400364 EXPECT_EQ(3, transport_->GetRequestCount());
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700365
366 // Validate the device info saved to storage...
Alex Vakulenko45109442014-07-29 11:07:10 -0700367 auto storage_data = storage_->Load();
Alex Vakulenko8e34d392014-04-29 11:02:56 -0700368 base::DictionaryValue* dict = nullptr;
369 EXPECT_TRUE(storage_data->GetAsDictionary(&dict));
370 std::string value;
371 EXPECT_TRUE(dict->GetString(storage_keys::kApiKey, &value));
372 EXPECT_EQ(test_data::kApiKey, value);
373 EXPECT_TRUE(dict->GetString(storage_keys::kClientId, &value));
374 EXPECT_EQ(test_data::kClientId, value);
375 EXPECT_TRUE(dict->GetString(storage_keys::kClientSecret, &value));
376 EXPECT_EQ(test_data::kClientSecret, value);
377 EXPECT_TRUE(dict->GetString(storage_keys::kDeviceId, &value));
378 EXPECT_EQ(test_data::kDeviceId, value);
379 EXPECT_TRUE(dict->GetString(storage_keys::kOAuthURL, &value));
380 EXPECT_EQ(test_data::kOAuthURL, value);
381 EXPECT_TRUE(dict->GetString(storage_keys::kRefreshToken, &value));
382 EXPECT_EQ(test_data::kRefreshToken, value);
383 EXPECT_TRUE(dict->GetString(storage_keys::kRobotAccount, &value));
384 EXPECT_EQ(test_data::kRobotAccountEmail, value);
385 EXPECT_TRUE(dict->GetString(storage_keys::kServiceURL, &value));
386 EXPECT_EQ(test_data::kServiceURL, value);
387}
388
Alex Vakulenkocca20932014-08-20 17:35:12 -0700389} // namespace buffet