| 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 // Move the file to the directory |parent_resource_id| with new name |
| 690 // "new title". |
| 691 { |
| 692 base::RunLoop run_loop; |
| 693 drive::MoveResourceRequest* request = |
| 694 new drive::MoveResourceRequest( |
| 695 request_sender_.get(), |
| 696 *url_generator_, |
| 697 "resource_id", |
| 698 "parent_resource_id", |
| 699 "new title", |
| 700 test_util::CreateQuitCallback( |
| 701 &run_loop, |
| 702 test_util::CreateCopyResultCallback(&error, &file_resource))); |
| 703 request_sender_->StartRequestWithRetry(request); |
| 704 run_loop.Run(); |
| 705 } |
| 706 |
| 707 EXPECT_EQ(HTTP_SUCCESS, error); |
| 708 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); |
| 709 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); |
| 710 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 711 |
| 712 EXPECT_TRUE(http_request_.has_content); |
| 713 EXPECT_EQ( |
| 714 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new title\"}", |
| 715 http_request_.content); |
| 716 EXPECT_TRUE(file_resource); |
| 717 } |
| 718 |
| 719 TEST_F(DriveApiRequestsTest, MoveResourceRequest_EmptyParentResourceId) { |
| 720 // Set an expected data file containing the directory's entry data. |
| 721 // It'd be returned if we rename a directory. |
| 722 expected_data_file_path_ = |
| 723 test_util::GetTestFilePath("drive/file_entry.json"); |
| 724 |
| 725 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 726 scoped_ptr<FileResource> file_resource; |
| 727 |
| 728 // Rename the file to "new title," but keep the parent directory as is. |
| 729 { |
| 730 base::RunLoop run_loop; |
| 731 drive::MoveResourceRequest* request = |
| 732 new drive::MoveResourceRequest( |
| 733 request_sender_.get(), |
| 734 *url_generator_, |
| 735 "resource_id", |
| 736 std::string(), |
| 737 "new title", |
| 738 test_util::CreateQuitCallback( |
| 739 &run_loop, |
| 740 test_util::CreateCopyResultCallback(&error, &file_resource))); |
| 741 request_sender_->StartRequestWithRetry(request); |
| 742 run_loop.Run(); |
| 743 } |
| 744 |
| 745 EXPECT_EQ(HTTP_SUCCESS, error); |
| 746 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); |
| 747 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); |
| 748 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 749 |
| 750 EXPECT_TRUE(http_request_.has_content); |
| 751 EXPECT_EQ("{\"title\":\"new title\"}", http_request_.content); |
| 752 EXPECT_TRUE(file_resource); |
| 753 } |
| 754 |
| 713 TEST_F(DriveApiRequestsTest, TrashResourceRequest) { | 755 TEST_F(DriveApiRequestsTest, TrashResourceRequest) { |
| 714 // Set data for the expected result. Directory entry should be returned | 756 // 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. | 757 // if the trashing entry is a directory, so using it here should be fine. |
| 716 expected_data_file_path_ = | 758 expected_data_file_path_ = |
| 717 test_util::GetTestFilePath("drive/directory_entry.json"); | 759 test_util::GetTestFilePath("drive/directory_entry.json"); |
| 718 | 760 |
| 719 GDataErrorCode error = GDATA_OTHER_ERROR; | 761 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 720 | 762 |
| 721 // Trash a resource with the given resource id. | 763 // Trash a resource with the given resource id. |
| 722 { | 764 { |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1549 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1508 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 1550 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 1509 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); | 1551 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); |
| 1510 EXPECT_EQ(kDownloadedFilePath, temp_file); | 1552 EXPECT_EQ(kDownloadedFilePath, temp_file); |
| 1511 | 1553 |
| 1512 const std::string expected_contents = kTestId + kTestId + kTestId; | 1554 const std::string expected_contents = kTestId + kTestId + kTestId; |
| 1513 EXPECT_EQ(expected_contents, contents); | 1555 EXPECT_EQ(expected_contents, contents); |
| 1514 } | 1556 } |
| 1515 | 1557 |
| 1516 } // namespace google_apis | 1558 } // namespace google_apis |
| OLD | NEW |