Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 | 555 |
| 556 // Sanity check. | 556 // Sanity check. |
| 557 ASSERT_TRUE(file_resource.get()); | 557 ASSERT_TRUE(file_resource.get()); |
| 558 | 558 |
| 559 EXPECT_EQ(expected->file_id(), file_resource->file_id()); | 559 EXPECT_EQ(expected->file_id(), file_resource->file_id()); |
| 560 EXPECT_EQ(expected->title(), file_resource->title()); | 560 EXPECT_EQ(expected->title(), file_resource->title()); |
| 561 EXPECT_EQ(expected->mime_type(), file_resource->mime_type()); | 561 EXPECT_EQ(expected->mime_type(), file_resource->mime_type()); |
| 562 EXPECT_EQ(expected->parents().size(), file_resource->parents().size()); | 562 EXPECT_EQ(expected->parents().size(), file_resource->parents().size()); |
| 563 } | 563 } |
| 564 | 564 |
| 565 TEST_F(DriveApiRequestsTest, RenameResourceRequest) { | |
| 566 // Set an expected data file containing the directory's entry data. | |
| 567 // It'd be returned if we rename a directory. | |
| 568 expected_data_file_path_ = | |
| 569 test_util::GetTestFilePath("drive/directory_entry.json"); | |
| 570 | |
| 571 GDataErrorCode error = GDATA_OTHER_ERROR; | |
| 572 | |
| 573 // Create "new directory" in the root directory. | |
| 574 { | |
| 575 base::RunLoop run_loop; | |
| 576 drive::RenameResourceRequest* request = | |
| 577 new drive::RenameResourceRequest( | |
| 578 request_sender_.get(), | |
| 579 *url_generator_, | |
| 580 "resource_id", | |
| 581 "new title", | |
| 582 test_util::CreateQuitCallback( | |
| 583 &run_loop, | |
| 584 test_util::CreateCopyResultCallback(&error))); | |
| 585 request_sender_->StartRequestWithRetry(request); | |
| 586 run_loop.Run(); | |
| 587 } | |
| 588 | |
| 589 EXPECT_EQ(HTTP_SUCCESS, error); | |
| 590 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); | |
| 591 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); | |
| 592 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | |
| 593 | |
| 594 EXPECT_TRUE(http_request_.has_content); | |
| 595 EXPECT_EQ("{\"title\":\"new title\"}", http_request_.content); | |
| 596 } | |
| 597 | |
| 598 TEST_F(DriveApiRequestsTest, TouchResourceRequest) { | 565 TEST_F(DriveApiRequestsTest, TouchResourceRequest) { |
| 599 // Set an expected data file containing the directory's entry data. | 566 // Set an expected data file containing the directory's entry data. |
| 600 // It'd be returned if we rename a directory. | 567 // It'd be returned if we rename a directory. |
| 601 expected_data_file_path_ = | 568 expected_data_file_path_ = |
| 602 test_util::GetTestFilePath("drive/directory_entry.json"); | 569 test_util::GetTestFilePath("drive/directory_entry.json"); |
| 603 | 570 |
| 604 GDataErrorCode error = GDATA_OTHER_ERROR; | 571 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 605 scoped_ptr<FileResource> file_resource; | 572 scoped_ptr<FileResource> file_resource; |
| 606 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 573 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 607 const base::Time::Exploded kLastViewedByMeDate = | 574 const base::Time::Exploded kLastViewedByMeDate = |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 EXPECT_EQ(HTTP_SUCCESS, error); | 670 EXPECT_EQ(HTTP_SUCCESS, error); |
| 704 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 671 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 705 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); | 672 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); |
| 706 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 673 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 707 | 674 |
| 708 EXPECT_TRUE(http_request_.has_content); | 675 EXPECT_TRUE(http_request_.has_content); |
| 709 EXPECT_EQ("{\"title\":\"new title\"}", http_request_.content); | 676 EXPECT_EQ("{\"title\":\"new title\"}", http_request_.content); |
| 710 EXPECT_TRUE(file_resource); | 677 EXPECT_TRUE(file_resource); |
| 711 } | 678 } |
| 712 | 679 |
| 680 TEST_F(DriveApiRequestsTest, MoveResourceRequest) { | |
| 681 // Set an expected data file containing the dummy file entry data. | |
| 682 // It'd be returned if we move a file. | |
| 683 expected_data_file_path_ = | |
| 684 test_util::GetTestFilePath("drive/file_entry.json"); | |
| 685 | |
| 686 GDataErrorCode error = GDATA_OTHER_ERROR; | |
| 687 scoped_ptr<FileResource> file_resource; | |
| 688 | |
| 689 // Copy the file to a new file named "new title". | |
| 690 { | |
| 691 base::RunLoop run_loop; | |
| 692 drive::MoveResourceRequest* request = | |
| 693 new drive::MoveResourceRequest( | |
| 694 request_sender_.get(), | |
| 695 *url_generator_, | |
| 696 "resource_id", | |
| 697 "parent_resource_id", | |
| 698 "new title", | |
| 699 test_util::CreateQuitCallback( | |
| 700 &run_loop, | |
| 701 test_util::CreateCopyResultCallback(&error, &file_resource))); | |
| 702 request_sender_->StartRequestWithRetry(request); | |
| 703 run_loop.Run(); | |
| 704 } | |
| 705 | |
| 706 EXPECT_EQ(HTTP_SUCCESS, error); | |
| 707 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); | |
| 708 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); | |
| 709 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | |
| 710 | |
| 711 EXPECT_TRUE(http_request_.has_content); | |
| 712 EXPECT_EQ( | |
| 713 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new title\"}", | |
| 714 http_request_.content); | |
| 715 EXPECT_TRUE(file_resource); | |
| 716 } | |
| 717 | |
| 718 TEST_F(DriveApiRequestsTest, MoveResourceRequest_EmptyParentResourceId) { | |
| 719 // Set an expected data file containing the directory's entry data. | |
| 720 // It'd be returned if we rename a directory. | |
| 721 expected_data_file_path_ = | |
| 722 test_util::GetTestFilePath("drive/file_entry.json"); | |
| 723 | |
| 724 GDataErrorCode error = GDATA_OTHER_ERROR; | |
| 725 scoped_ptr<FileResource> file_resource; | |
| 726 | |
| 727 // Create "new directory" in the root directory. | |
|
kinaba
2013/08/16 07:59:52
Update the comment.
hidehiko
2013/08/16 08:33:19
Done.
| |
| 728 { | |
| 729 base::RunLoop run_loop; | |
| 730 drive::MoveResourceRequest* request = | |
| 731 new drive::MoveResourceRequest( | |
| 732 request_sender_.get(), | |
| 733 *url_generator_, | |
| 734 "resource_id", | |
| 735 std::string(), | |
| 736 "new title", | |
| 737 test_util::CreateQuitCallback( | |
| 738 &run_loop, | |
| 739 test_util::CreateCopyResultCallback(&error, &file_resource))); | |
| 740 request_sender_->StartRequestWithRetry(request); | |
| 741 run_loop.Run(); | |
| 742 } | |
| 743 | |
| 744 EXPECT_EQ(HTTP_SUCCESS, error); | |
| 745 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); | |
| 746 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); | |
| 747 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | |
| 748 | |
| 749 EXPECT_TRUE(http_request_.has_content); | |
| 750 EXPECT_EQ("{\"title\":\"new title\"}", http_request_.content); | |
| 751 EXPECT_TRUE(file_resource); | |
| 752 } | |
| 753 | |
| 713 TEST_F(DriveApiRequestsTest, TrashResourceRequest) { | 754 TEST_F(DriveApiRequestsTest, TrashResourceRequest) { |
| 714 // Set data for the expected result. Directory entry should be returned | 755 // Set data for the expected result. Directory entry should be returned |
| 715 // if the trashing entry is a directory, so using it here should be fine. | 756 // if the trashing entry is a directory, so using it here should be fine. |
| 716 expected_data_file_path_ = | 757 expected_data_file_path_ = |
| 717 test_util::GetTestFilePath("drive/directory_entry.json"); | 758 test_util::GetTestFilePath("drive/directory_entry.json"); |
| 718 | 759 |
| 719 GDataErrorCode error = GDATA_OTHER_ERROR; | 760 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 720 | 761 |
| 721 // Trash a resource with the given resource id. | 762 // Trash a resource with the given resource id. |
| 722 { | 763 { |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1507 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1548 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1508 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 1549 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 1509 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); | 1550 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); |
| 1510 EXPECT_EQ(kDownloadedFilePath, temp_file); | 1551 EXPECT_EQ(kDownloadedFilePath, temp_file); |
| 1511 | 1552 |
| 1512 const std::string expected_contents = kTestId + kTestId + kTestId; | 1553 const std::string expected_contents = kTestId + kTestId + kTestId; |
| 1513 EXPECT_EQ(expected_contents, contents); | 1554 EXPECT_EQ(expected_contents, contents); |
| 1514 } | 1555 } |
| 1515 | 1556 |
| 1516 } // namespace google_apis | 1557 } // namespace google_apis |
| OLD | NEW |