| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/request_manager.h" | 5 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 333 |
| 334 EXPECT_EQ(0, request_id); | 334 EXPECT_EQ(0, request_id); |
| 335 EXPECT_EQ(0u, logger.success_events().size()); | 335 EXPECT_EQ(0u, logger.success_events().size()); |
| 336 EXPECT_EQ(0u, logger.error_events().size()); | 336 EXPECT_EQ(0u, logger.error_events().size()); |
| 337 | 337 |
| 338 EXPECT_EQ(1u, observer.created().size()); | 338 EXPECT_EQ(1u, observer.created().size()); |
| 339 EXPECT_EQ(TESTING, observer.created()[0].type()); | 339 EXPECT_EQ(TESTING, observer.created()[0].type()); |
| 340 EXPECT_EQ(1u, observer.destroyed().size()); | 340 EXPECT_EQ(1u, observer.destroyed().size()); |
| 341 EXPECT_EQ(0u, observer.executed().size()); | 341 EXPECT_EQ(0u, observer.executed().size()); |
| 342 | 342 |
| 343 const std::vector<int> active_request_ids = |
| 344 request_manager_->GetActiveRequestIds(); |
| 345 EXPECT_EQ(0u, active_request_ids.size()); |
| 346 |
| 343 request_manager_->RemoveObserver(&observer); | 347 request_manager_->RemoveObserver(&observer); |
| 344 } | 348 } |
| 345 | 349 |
| 346 TEST_F(FileSystemProviderRequestManagerTest, CreateAndFulFill) { | 350 TEST_F(FileSystemProviderRequestManagerTest, CreateAndFulFill) { |
| 347 EventLogger logger; | 351 EventLogger logger; |
| 348 RequestObserver observer; | 352 RequestObserver observer; |
| 349 request_manager_->AddObserver(&observer); | 353 request_manager_->AddObserver(&observer); |
| 350 | 354 |
| 351 const int request_id = request_manager_->CreateRequest( | 355 const int request_id = request_manager_->CreateRequest( |
| 352 TESTING, | 356 TESTING, |
| 353 make_scoped_ptr<RequestManager::HandlerInterface>( | 357 make_scoped_ptr<RequestManager::HandlerInterface>( |
| 354 new FakeHandler(logger.GetWeakPtr(), true /* execute_reply */))); | 358 new FakeHandler(logger.GetWeakPtr(), true /* execute_reply */))); |
| 355 | 359 |
| 356 EXPECT_EQ(1, request_id); | 360 EXPECT_EQ(1, request_id); |
| 357 EXPECT_EQ(0u, logger.success_events().size()); | 361 EXPECT_EQ(0u, logger.success_events().size()); |
| 358 EXPECT_EQ(0u, logger.error_events().size()); | 362 EXPECT_EQ(0u, logger.error_events().size()); |
| 359 | 363 |
| 360 ASSERT_EQ(1u, observer.created().size()); | 364 ASSERT_EQ(1u, observer.created().size()); |
| 361 EXPECT_EQ(request_id, observer.created()[0].request_id()); | 365 EXPECT_EQ(request_id, observer.created()[0].request_id()); |
| 362 EXPECT_EQ(TESTING, observer.created()[0].type()); | 366 EXPECT_EQ(TESTING, observer.created()[0].type()); |
| 363 | 367 |
| 364 ASSERT_EQ(1u, observer.executed().size()); | 368 ASSERT_EQ(1u, observer.executed().size()); |
| 365 EXPECT_EQ(request_id, observer.executed()[0].request_id()); | 369 EXPECT_EQ(request_id, observer.executed()[0].request_id()); |
| 366 | 370 |
| 371 const std::vector<int> active_request_ids = |
| 372 request_manager_->GetActiveRequestIds(); |
| 373 ASSERT_EQ(1u, active_request_ids.size()); |
| 374 EXPECT_EQ(request_id, active_request_ids[0]); |
| 375 |
| 367 scoped_ptr<RequestValue> response( | 376 scoped_ptr<RequestValue> response( |
| 368 RequestValue::CreateForTesting("i-like-vanilla")); | 377 RequestValue::CreateForTesting("i-like-vanilla")); |
| 369 const bool has_more = false; | 378 const bool has_more = false; |
| 370 | 379 |
| 371 bool result = | 380 bool result = |
| 372 request_manager_->FulfillRequest(request_id, response.Pass(), has_more); | 381 request_manager_->FulfillRequest(request_id, response.Pass(), has_more); |
| 373 EXPECT_TRUE(result); | 382 EXPECT_TRUE(result); |
| 374 | 383 |
| 375 ASSERT_EQ(1u, observer.fulfilled().size()); | 384 ASSERT_EQ(1u, observer.fulfilled().size()); |
| 376 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id()); | 385 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id()); |
| 377 EXPECT_FALSE(observer.fulfilled()[0].has_more()); | 386 EXPECT_FALSE(observer.fulfilled()[0].has_more()); |
| 378 | 387 |
| 379 // Validate if the callback has correct arguments. | 388 // Validate if the callback has correct arguments. |
| 380 ASSERT_EQ(1u, logger.success_events().size()); | 389 ASSERT_EQ(1u, logger.success_events().size()); |
| 381 EXPECT_EQ(0u, logger.error_events().size()); | 390 EXPECT_EQ(0u, logger.error_events().size()); |
| 382 EventLogger::SuccessEvent* event = logger.success_events()[0]; | 391 EventLogger::SuccessEvent* event = logger.success_events()[0]; |
| 383 ASSERT_TRUE(event->result()); | 392 ASSERT_TRUE(event->result()); |
| 384 const std::string* response_test_string = event->result()->testing_params(); | 393 const std::string* response_test_string = event->result()->testing_params(); |
| 385 ASSERT_TRUE(response_test_string); | 394 ASSERT_TRUE(response_test_string); |
| 386 EXPECT_EQ("i-like-vanilla", *response_test_string); | 395 EXPECT_EQ("i-like-vanilla", *response_test_string); |
| 387 EXPECT_FALSE(event->has_more()); | 396 EXPECT_FALSE(event->has_more()); |
| 388 | 397 |
| 389 // Confirm, that the request is removed. Basically, fulfilling again for the | 398 // Confirm, that the request is removed. Basically, fulfilling again for the |
| 390 // same request, should fail. | 399 // same request, should fail. |
| 391 { | 400 { |
| 401 const std::vector<int> active_request_ids = |
| 402 request_manager_->GetActiveRequestIds(); |
| 403 EXPECT_EQ(0u, active_request_ids.size()); |
| 404 |
| 392 bool retry = request_manager_->FulfillRequest( | 405 bool retry = request_manager_->FulfillRequest( |
| 393 request_id, scoped_ptr<RequestValue>(new RequestValue), has_more); | 406 request_id, scoped_ptr<RequestValue>(new RequestValue), has_more); |
| 394 EXPECT_FALSE(retry); | 407 EXPECT_FALSE(retry); |
| 395 EXPECT_EQ(1u, observer.fulfilled().size()); | 408 EXPECT_EQ(1u, observer.fulfilled().size()); |
| 396 } | 409 } |
| 397 | 410 |
| 398 // Rejecting should also fail. | 411 // Rejecting should also fail. |
| 399 { | 412 { |
| 400 bool retry = request_manager_->RejectRequest( | 413 bool retry = request_manager_->RejectRequest( |
| 401 request_id, | 414 request_id, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 EXPECT_TRUE(event->result()); | 459 EXPECT_TRUE(event->result()); |
| 447 EXPECT_TRUE(event->has_more()); | 460 EXPECT_TRUE(event->has_more()); |
| 448 | 461 |
| 449 ASSERT_EQ(1u, observer.fulfilled().size()); | 462 ASSERT_EQ(1u, observer.fulfilled().size()); |
| 450 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id()); | 463 EXPECT_EQ(request_id, observer.fulfilled()[0].request_id()); |
| 451 EXPECT_TRUE(observer.fulfilled()[0].has_more()); | 464 EXPECT_TRUE(observer.fulfilled()[0].has_more()); |
| 452 | 465 |
| 453 // Confirm, that the request is not removed (since it has has_more == true). | 466 // Confirm, that the request is not removed (since it has has_more == true). |
| 454 // Basically, fulfilling again for the same request, should not fail. | 467 // Basically, fulfilling again for the same request, should not fail. |
| 455 { | 468 { |
| 469 const std::vector<int> active_request_ids = |
| 470 request_manager_->GetActiveRequestIds(); |
| 471 ASSERT_EQ(1u, active_request_ids.size()); |
| 472 EXPECT_EQ(request_id, active_request_ids[0]); |
| 473 |
| 456 bool new_has_more = false; | 474 bool new_has_more = false; |
| 457 bool retry = request_manager_->FulfillRequest( | 475 bool retry = request_manager_->FulfillRequest( |
| 458 request_id, scoped_ptr<RequestValue>(new RequestValue), new_has_more); | 476 request_id, scoped_ptr<RequestValue>(new RequestValue), new_has_more); |
| 459 EXPECT_TRUE(retry); | 477 EXPECT_TRUE(retry); |
| 460 | 478 |
| 461 ASSERT_EQ(2u, observer.fulfilled().size()); | 479 ASSERT_EQ(2u, observer.fulfilled().size()); |
| 462 EXPECT_EQ(request_id, observer.fulfilled()[1].request_id()); | 480 EXPECT_EQ(request_id, observer.fulfilled()[1].request_id()); |
| 463 EXPECT_FALSE(observer.fulfilled()[1].has_more()); | 481 EXPECT_FALSE(observer.fulfilled()[1].has_more()); |
| 464 } | 482 } |
| 465 | 483 |
| 466 // Since |new_has_more| is false, then the request should be removed. To check | 484 // Since |new_has_more| is false, then the request should be removed. To check |
| 467 // it, try to fulfill again, what should fail. | 485 // it, try to fulfill again, what should fail. |
| 468 { | 486 { |
| 487 const std::vector<int> active_request_ids = |
| 488 request_manager_->GetActiveRequestIds(); |
| 489 EXPECT_EQ(0u, active_request_ids.size()); |
| 490 |
| 469 bool new_has_more = false; | 491 bool new_has_more = false; |
| 470 bool retry = request_manager_->FulfillRequest( | 492 bool retry = request_manager_->FulfillRequest( |
| 471 request_id, scoped_ptr<RequestValue>(new RequestValue), new_has_more); | 493 request_id, scoped_ptr<RequestValue>(new RequestValue), new_has_more); |
| 472 EXPECT_FALSE(retry); | 494 EXPECT_FALSE(retry); |
| 473 EXPECT_EQ(0u, observer.rejected().size()); | 495 EXPECT_EQ(0u, observer.rejected().size()); |
| 474 } | 496 } |
| 475 | 497 |
| 476 ASSERT_EQ(1u, observer.destroyed().size()); | 498 ASSERT_EQ(1u, observer.destroyed().size()); |
| 477 EXPECT_EQ(request_id, observer.destroyed()[0].request_id()); | 499 EXPECT_EQ(request_id, observer.destroyed()[0].request_id()); |
| 478 EXPECT_EQ(0u, observer.timeouted().size()); | 500 EXPECT_EQ(0u, observer.timeouted().size()); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 799 |
| 778 // Wait until the request is timeouted again. | 800 // Wait until the request is timeouted again. |
| 779 base::RunLoop().RunUntilIdle(); | 801 base::RunLoop().RunUntilIdle(); |
| 780 EXPECT_EQ(1u, notification_manager_->size()); | 802 EXPECT_EQ(1u, notification_manager_->size()); |
| 781 | 803 |
| 782 request_manager_->RemoveObserver(&observer); | 804 request_manager_->RemoveObserver(&observer); |
| 783 } | 805 } |
| 784 | 806 |
| 785 } // namespace file_system_provider | 807 } // namespace file_system_provider |
| 786 } // namespace chromeos | 808 } // namespace chromeos |
| OLD | NEW |