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

Side by Side Diff: chrome/browser/google_apis/drive_api_requests_unittest.cc

Issue 23514007: Refactor TrashResourceRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 request_sender_->StartRequestWithRetry(request); 674 request_sender_->StartRequestWithRetry(request);
675 run_loop.Run(); 675 run_loop.Run();
676 } 676 }
677 677
678 EXPECT_EQ(HTTP_SUCCESS, error); 678 EXPECT_EQ(HTTP_SUCCESS, error);
679 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 679 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
680 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url); 680 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url);
681 EXPECT_TRUE(result); 681 EXPECT_TRUE(result);
682 } 682 }
683 683
684 TEST_F(DriveApiRequestsTest, FilesTrashRequest) {
685 // Set data for the expected result. Directory entry should be returned
686 // if the trashing entry is a directory, so using it here should be fine.
687 expected_data_file_path_ =
688 test_util::GetTestFilePath("drive/directory_entry.json");
689
690 GDataErrorCode error = GDATA_OTHER_ERROR;
691 scoped_ptr<FileResource> file_resource;
692
693 // Trash a resource with the given resource id.
694 {
695 base::RunLoop run_loop;
696 drive::FilesTrashRequest* request = new drive::FilesTrashRequest(
697 request_sender_.get(),
698 *url_generator_,
699 test_util::CreateQuitCallback(
700 &run_loop,
701 test_util::CreateCopyResultCallback(&error, &file_resource)));
702 request->set_file_id("resource_id");
703 request_sender_->StartRequestWithRetry(request);
704 run_loop.Run();
705 }
706
707 EXPECT_EQ(HTTP_SUCCESS, error);
708 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
709 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url);
710 EXPECT_TRUE(http_request_.has_content);
711 EXPECT_TRUE(http_request_.content.empty());
712 }
713
684 TEST_F(DriveApiRequestsTest, TouchResourceRequest) { 714 TEST_F(DriveApiRequestsTest, TouchResourceRequest) {
685 // Set an expected data file containing the directory's entry data. 715 // Set an expected data file containing the directory's entry data.
686 // It'd be returned if we rename a directory. 716 // It'd be returned if we rename a directory.
687 expected_data_file_path_ = 717 expected_data_file_path_ =
688 test_util::GetTestFilePath("drive/directory_entry.json"); 718 test_util::GetTestFilePath("drive/directory_entry.json");
689 719
690 GDataErrorCode error = GDATA_OTHER_ERROR; 720 GDataErrorCode error = GDATA_OTHER_ERROR;
691 scoped_ptr<FileResource> file_resource; 721 scoped_ptr<FileResource> file_resource;
692 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; 722 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
693 const base::Time::Exploded kLastViewedByMeDate = 723 const base::Time::Exploded kLastViewedByMeDate =
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 EXPECT_EQ(HTTP_SUCCESS, error); 820 EXPECT_EQ(HTTP_SUCCESS, error);
791 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); 821 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method);
792 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); 822 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url);
793 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 823 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
794 824
795 EXPECT_TRUE(http_request_.has_content); 825 EXPECT_TRUE(http_request_.has_content);
796 EXPECT_EQ("{\"title\":\"new title\"}", http_request_.content); 826 EXPECT_EQ("{\"title\":\"new title\"}", http_request_.content);
797 EXPECT_TRUE(file_resource); 827 EXPECT_TRUE(file_resource);
798 } 828 }
799 829
800 TEST_F(DriveApiRequestsTest, TrashResourceRequest) {
801 // Set data for the expected result. Directory entry should be returned
802 // if the trashing entry is a directory, so using it here should be fine.
803 expected_data_file_path_ =
804 test_util::GetTestFilePath("drive/directory_entry.json");
805
806 GDataErrorCode error = GDATA_OTHER_ERROR;
807
808 // Trash a resource with the given resource id.
809 {
810 base::RunLoop run_loop;
811 drive::TrashResourceRequest* request =
812 new drive::TrashResourceRequest(
813 request_sender_.get(),
814 *url_generator_,
815 "resource_id",
816 test_util::CreateQuitCallback(
817 &run_loop,
818 test_util::CreateCopyResultCallback(&error)));
819 request_sender_->StartRequestWithRetry(request);
820 run_loop.Run();
821 }
822
823 EXPECT_EQ(HTTP_SUCCESS, error);
824 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
825 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url);
826 EXPECT_TRUE(http_request_.has_content);
827 EXPECT_TRUE(http_request_.content.empty());
828 }
829
830 TEST_F(DriveApiRequestsTest, InsertResourceRequest) { 830 TEST_F(DriveApiRequestsTest, InsertResourceRequest) {
831 // Set an expected data file containing the children entry. 831 // Set an expected data file containing the children entry.
832 expected_content_type_ = "application/json"; 832 expected_content_type_ = "application/json";
833 expected_content_ = kTestChildrenResponse; 833 expected_content_ = kTestChildrenResponse;
834 834
835 GDataErrorCode error = GDATA_OTHER_ERROR; 835 GDataErrorCode error = GDATA_OTHER_ERROR;
836 836
837 // Add a resource with "resource_id" to a directory with 837 // Add a resource with "resource_id" to a directory with
838 // "parent_resource_id". 838 // "parent_resource_id".
839 { 839 {
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 EXPECT_EQ(HTTP_SUCCESS, result_code); 1594 EXPECT_EQ(HTTP_SUCCESS, result_code);
1595 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 1595 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
1596 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); 1596 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url);
1597 EXPECT_EQ(kDownloadedFilePath, temp_file); 1597 EXPECT_EQ(kDownloadedFilePath, temp_file);
1598 1598
1599 const std::string expected_contents = kTestId + kTestId + kTestId; 1599 const std::string expected_contents = kTestId + kTestId + kTestId;
1600 EXPECT_EQ(expected_contents, contents); 1600 EXPECT_EQ(expected_contents, contents);
1601 } 1601 }
1602 1602
1603 } // namespace google_apis 1603 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_requests.cc ('k') | chrome/browser/google_apis/drive_api_url_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698