Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: blimp/client/session/assignment_source_unittest.cc

Issue 1876983002: Use Chromium BUILD to approximate Blimp protocol version, and check it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add disconnection message and unit-tests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/client/session/assignment_source.h" 5 #include "blimp/client/session/assignment_source.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/test/test_simple_task_runner.h" 15 #include "base/test/test_simple_task_runner.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "blimp/client/app/blimp_client_switches.h" 18 #include "blimp/client/app/blimp_client_switches.h"
19 #include "blimp/common/protocol_version.h" 19 #include "blimp/common/version_info.h"
20 #include "components/safe_json/testing_json_parser.h" 20 #include "components/safe_json/testing_json_parser.h"
21 #include "net/base/test_data_directory.h" 21 #include "net/base/test_data_directory.h"
22 #include "net/url_request/test_url_fetcher_factory.h" 22 #include "net/url_request/test_url_fetcher_factory.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 using testing::_; 27 using testing::_;
28 using testing::DoAll; 28 using testing::DoAll;
29 using testing::InSequence; 29 using testing::InSequence;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 TEST_F(AssignmentSourceTest, TestSuccess) { 242 TEST_F(AssignmentSourceTest, TestSuccess) {
243 Assignment assignment = BuildSslAssignment(); 243 Assignment assignment = BuildSslAssignment();
244 244
245 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 245 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
246 AssignmentEquals(assignment))) 246 AssignmentEquals(assignment)))
247 .Times(1); 247 .Times(1);
248 248
249 GetNetworkAssignmentAndWaitForResponse( 249 GetNetworkAssignmentAndWaitForResponse(
250 net::HTTP_OK, net::Error::OK, ValueToString(*BuildAssignerResponse()), 250 net::HTTP_OK, net::Error::OK, ValueToString(*BuildAssignerResponse()),
251 kTestAuthToken, kEngineVersion); 251 kTestAuthToken, GetAssignmentRequestVersion());
252 } 252 }
253 253
254 TEST_F(AssignmentSourceTest, TestValidAfterError) { 254 TEST_F(AssignmentSourceTest, TestValidAfterError) {
255 InSequence sequence; 255 InSequence sequence;
256 Assignment assignment = BuildSslAssignment(); 256 Assignment assignment = BuildSslAssignment();
257 257
258 EXPECT_CALL(*this, AssignmentResponse( 258 EXPECT_CALL(*this, AssignmentResponse(
259 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _)) 259 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _))
260 .Times(1) 260 .Times(1)
261 .RetiresOnSaturation(); 261 .RetiresOnSaturation();
262 262
263 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 263 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
264 AssignmentEquals(assignment))) 264 AssignmentEquals(assignment)))
265 .Times(1) 265 .Times(1)
266 .RetiresOnSaturation(); 266 .RetiresOnSaturation();
267 267
268 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, 268 GetNetworkAssignmentAndWaitForResponse(
269 net::Error::ERR_INSUFFICIENT_RESOURCES, 269 net::HTTP_OK, net::Error::ERR_INSUFFICIENT_RESOURCES, "", kTestAuthToken,
270 "", kTestAuthToken, kEngineVersion); 270 GetAssignmentRequestVersion());
271 271
272 GetNetworkAssignmentAndWaitForResponse( 272 GetNetworkAssignmentAndWaitForResponse(
273 net::HTTP_OK, net::Error::OK, ValueToString(*BuildAssignerResponse()), 273 net::HTTP_OK, net::Error::OK, ValueToString(*BuildAssignerResponse()),
274 kTestAuthToken, kEngineVersion); 274 kTestAuthToken, GetAssignmentRequestVersion());
275 } 275 }
276 276
277 TEST_F(AssignmentSourceTest, TestNetworkFailure) { 277 TEST_F(AssignmentSourceTest, TestNetworkFailure) {
278 EXPECT_CALL(*this, AssignmentResponse( 278 EXPECT_CALL(*this, AssignmentResponse(
279 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _)); 279 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _));
280 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, 280 GetNetworkAssignmentAndWaitForResponse(
281 net::Error::ERR_INSUFFICIENT_RESOURCES, 281 net::HTTP_OK, net::Error::ERR_INSUFFICIENT_RESOURCES, "", kTestAuthToken,
282 "", kTestAuthToken, kEngineVersion); 282 GetAssignmentRequestVersion());
283 } 283 }
284 284
285 TEST_F(AssignmentSourceTest, TestBadRequest) { 285 TEST_F(AssignmentSourceTest, TestBadRequest) {
286 EXPECT_CALL(*this, AssignmentResponse( 286 EXPECT_CALL(*this, AssignmentResponse(
287 AssignmentSource::Result::RESULT_BAD_REQUEST, _)); 287 AssignmentSource::Result::RESULT_BAD_REQUEST, _));
288 GetNetworkAssignmentAndWaitForResponse(net::HTTP_BAD_REQUEST, net::Error::OK, 288 GetNetworkAssignmentAndWaitForResponse(net::HTTP_BAD_REQUEST, net::Error::OK,
289 "", kTestAuthToken, kEngineVersion); 289 "", kTestAuthToken,
290 GetAssignmentRequestVersion());
290 } 291 }
291 292
292 TEST_F(AssignmentSourceTest, TestUnauthorized) { 293 TEST_F(AssignmentSourceTest, TestUnauthorized) {
293 EXPECT_CALL(*this, 294 EXPECT_CALL(*this,
294 AssignmentResponse( 295 AssignmentResponse(
295 AssignmentSource::Result::RESULT_EXPIRED_ACCESS_TOKEN, _)); 296 AssignmentSource::Result::RESULT_EXPIRED_ACCESS_TOKEN, _));
296 GetNetworkAssignmentAndWaitForResponse(net::HTTP_UNAUTHORIZED, net::Error::OK, 297 GetNetworkAssignmentAndWaitForResponse(net::HTTP_UNAUTHORIZED, net::Error::OK,
297 "", kTestAuthToken, kEngineVersion); 298 "", kTestAuthToken,
299 GetAssignmentRequestVersion());
298 } 300 }
299 301
300 TEST_F(AssignmentSourceTest, TestForbidden) { 302 TEST_F(AssignmentSourceTest, TestForbidden) {
301 EXPECT_CALL(*this, AssignmentResponse( 303 EXPECT_CALL(*this, AssignmentResponse(
302 AssignmentSource::Result::RESULT_USER_INVALID, _)); 304 AssignmentSource::Result::RESULT_USER_INVALID, _));
303 GetNetworkAssignmentAndWaitForResponse(net::HTTP_FORBIDDEN, net::Error::OK, 305 GetNetworkAssignmentAndWaitForResponse(net::HTTP_FORBIDDEN, net::Error::OK,
304 "", kTestAuthToken, kEngineVersion); 306 "", kTestAuthToken,
307 GetAssignmentRequestVersion());
305 } 308 }
306 309
307 TEST_F(AssignmentSourceTest, TestTooManyRequests) { 310 TEST_F(AssignmentSourceTest, TestTooManyRequests) {
308 EXPECT_CALL(*this, AssignmentResponse( 311 EXPECT_CALL(*this, AssignmentResponse(
309 AssignmentSource::Result::RESULT_OUT_OF_VMS, _)); 312 AssignmentSource::Result::RESULT_OUT_OF_VMS, _));
310 GetNetworkAssignmentAndWaitForResponse(static_cast<net::HttpStatusCode>(429), 313 GetNetworkAssignmentAndWaitForResponse(static_cast<net::HttpStatusCode>(429),
311 net::Error::OK, "", kTestAuthToken, 314 net::Error::OK, "", kTestAuthToken,
312 kEngineVersion); 315 GetAssignmentRequestVersion());
313 } 316 }
314 317
315 TEST_F(AssignmentSourceTest, TestInternalServerError) { 318 TEST_F(AssignmentSourceTest, TestInternalServerError) {
316 EXPECT_CALL(*this, AssignmentResponse( 319 EXPECT_CALL(*this, AssignmentResponse(
317 AssignmentSource::Result::RESULT_SERVER_ERROR, _)); 320 AssignmentSource::Result::RESULT_SERVER_ERROR, _));
318 GetNetworkAssignmentAndWaitForResponse(net::HTTP_INTERNAL_SERVER_ERROR, 321 GetNetworkAssignmentAndWaitForResponse(net::HTTP_INTERNAL_SERVER_ERROR,
319 net::Error::OK, "", kTestAuthToken, 322 net::Error::OK, "", kTestAuthToken,
320 kEngineVersion); 323 GetAssignmentRequestVersion());
321 } 324 }
322 325
323 TEST_F(AssignmentSourceTest, TestUnexpectedNetCodeFallback) { 326 TEST_F(AssignmentSourceTest, TestUnexpectedNetCodeFallback) {
324 EXPECT_CALL(*this, AssignmentResponse( 327 EXPECT_CALL(*this, AssignmentResponse(
325 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 328 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
326 GetNetworkAssignmentAndWaitForResponse(net::HTTP_NOT_IMPLEMENTED, 329 GetNetworkAssignmentAndWaitForResponse(net::HTTP_NOT_IMPLEMENTED,
327 net::Error::OK, "", kTestAuthToken, 330 net::Error::OK, "", kTestAuthToken,
328 kEngineVersion); 331 GetAssignmentRequestVersion());
329 } 332 }
330 333
331 TEST_F(AssignmentSourceTest, TestInvalidJsonResponse) { 334 TEST_F(AssignmentSourceTest, TestInvalidJsonResponse) {
332 Assignment assignment = BuildSslAssignment(); 335 Assignment assignment = BuildSslAssignment();
333 336
334 // Remove half the response. 337 // Remove half the response.
335 std::string response = ValueToString(*BuildAssignerResponse()); 338 std::string response = ValueToString(*BuildAssignerResponse());
336 response = response.substr(response.size() / 2); 339 response = response.substr(response.size() / 2);
337 340
338 EXPECT_CALL(*this, AssignmentResponse( 341 EXPECT_CALL(*this, AssignmentResponse(
339 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 342 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
340 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response, 343 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
341 kTestAuthToken, kEngineVersion); 344 kTestAuthToken,
345 GetAssignmentRequestVersion());
342 } 346 }
343 347
344 TEST_F(AssignmentSourceTest, TestMissingResponsePort) { 348 TEST_F(AssignmentSourceTest, TestMissingResponsePort) {
345 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse(); 349 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse();
346 response->Remove("port", nullptr); 350 response->Remove("port", nullptr);
347 EXPECT_CALL(*this, AssignmentResponse( 351 EXPECT_CALL(*this, AssignmentResponse(
348 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 352 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
349 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, 353 GetNetworkAssignmentAndWaitForResponse(
350 ValueToString(*response), 354 net::HTTP_OK, net::Error::OK, ValueToString(*response), kTestAuthToken,
351 kTestAuthToken, kEngineVersion); 355 GetAssignmentRequestVersion());
352 } 356 }
353 357
354 TEST_F(AssignmentSourceTest, TestInvalidIPAddress) { 358 TEST_F(AssignmentSourceTest, TestInvalidIPAddress) {
355 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse(); 359 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse();
356 response->SetString("host", "happywhales.test"); 360 response->SetString("host", "happywhales.test");
357 361
358 EXPECT_CALL(*this, AssignmentResponse( 362 EXPECT_CALL(*this, AssignmentResponse(
359 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 363 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
360 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, 364 GetNetworkAssignmentAndWaitForResponse(
361 ValueToString(*response), 365 net::HTTP_OK, net::Error::OK, ValueToString(*response), kTestAuthToken,
362 kTestAuthToken, kEngineVersion); 366 GetAssignmentRequestVersion());
363 } 367 }
364 368
365 TEST_F(AssignmentSourceTest, TestMissingCert) { 369 TEST_F(AssignmentSourceTest, TestMissingCert) {
366 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse(); 370 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse();
367 response->Remove("certificate", nullptr); 371 response->Remove("certificate", nullptr);
368 EXPECT_CALL(*this, AssignmentResponse( 372 EXPECT_CALL(*this, AssignmentResponse(
369 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 373 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
370 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, 374 GetNetworkAssignmentAndWaitForResponse(
371 ValueToString(*response), 375 net::HTTP_OK, net::Error::OK, ValueToString(*response), kTestAuthToken,
372 kTestAuthToken, kEngineVersion); 376 GetAssignmentRequestVersion());
373 } 377 }
374 378
375 TEST_F(AssignmentSourceTest, TestInvalidCert) { 379 TEST_F(AssignmentSourceTest, TestInvalidCert) {
376 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse(); 380 std::unique_ptr<base::DictionaryValue> response = BuildAssignerResponse();
377 response->SetString("certificate", "h4x0rz!"); 381 response->SetString("certificate", "h4x0rz!");
378 EXPECT_CALL(*this, AssignmentResponse( 382 EXPECT_CALL(*this, AssignmentResponse(
379 AssignmentSource::Result::RESULT_INVALID_CERT, _)); 383 AssignmentSource::Result::RESULT_INVALID_CERT, _));
380 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, 384 GetNetworkAssignmentAndWaitForResponse(
381 ValueToString(*response), 385 net::HTTP_OK, net::Error::OK, ValueToString(*response), kTestAuthToken,
382 kTestAuthToken, kEngineVersion); 386 GetAssignmentRequestVersion());
383 } 387 }
384 388
385 } // namespace 389 } // namespace
386 } // namespace client 390 } // namespace client
387 } // namespace blimp 391 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698