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

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

Issue 17415007: Get rid of RequestRegistry (part 3): remove Drive path from request objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 6 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/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 GDataErrorCode error = GDATA_OTHER_ERROR; 751 GDataErrorCode error = GDATA_OTHER_ERROR;
752 GURL upload_url; 752 GURL upload_url;
753 753
754 // Initiate uploading a new file to the directory with 754 // Initiate uploading a new file to the directory with
755 // "parent_resource_id". 755 // "parent_resource_id".
756 drive::InitiateUploadNewFileRequest* request = 756 drive::InitiateUploadNewFileRequest* request =
757 new drive::InitiateUploadNewFileRequest( 757 new drive::InitiateUploadNewFileRequest(
758 request_sender_.get(), 758 request_sender_.get(),
759 request_context_getter_.get(), 759 request_context_getter_.get(),
760 *url_generator_, 760 *url_generator_,
761 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
762 kTestContentType, 761 kTestContentType,
763 kTestContent.size(), 762 kTestContent.size(),
764 "parent_resource_id", // The resource id of the parent directory. 763 "parent_resource_id", // The resource id of the parent directory.
765 "new file title", // The title of the file being uploaded. 764 "new file title", // The title of the file being uploaded.
766 CreateComposedCallback( 765 CreateComposedCallback(
767 base::Bind(&test_util::RunAndQuit), 766 base::Bind(&test_util::RunAndQuit),
768 test_util::CreateCopyResultCallback(&error, &upload_url))); 767 test_util::CreateCopyResultCallback(&error, &upload_url)));
769 request_sender_->StartRequestWithRetry(request); 768 request_sender_->StartRequestWithRetry(request);
770 base::MessageLoop::current()->Run(); 769 base::MessageLoop::current()->Run();
771 770
(...skipping 16 matching lines...) Expand all
788 http_request_.content); 787 http_request_.content);
789 788
790 // Upload the content to the upload URL. 789 // Upload the content to the upload URL.
791 UploadRangeResponse response; 790 UploadRangeResponse response;
792 scoped_ptr<FileResource> new_entry; 791 scoped_ptr<FileResource> new_entry;
793 792
794 drive::ResumeUploadRequest* resume_request = 793 drive::ResumeUploadRequest* resume_request =
795 new drive::ResumeUploadRequest( 794 new drive::ResumeUploadRequest(
796 request_sender_.get(), 795 request_sender_.get(),
797 request_context_getter_.get(), 796 request_context_getter_.get(),
798 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
799 upload_url, 797 upload_url,
800 0, // start_position 798 0, // start_position
801 kTestContent.size(), // end_position (exclusive) 799 kTestContent.size(), // end_position (exclusive)
802 kTestContent.size(), // content_length, 800 kTestContent.size(), // content_length,
803 kTestContentType, 801 kTestContentType,
804 kTestFilePath, 802 kTestFilePath,
805 CreateComposedCallback( 803 CreateComposedCallback(
806 base::Bind(&test_util::RunAndQuit), 804 base::Bind(&test_util::RunAndQuit),
807 test_util::CreateCopyResultCallback(&response, &new_entry)), 805 test_util::CreateCopyResultCallback(&response, &new_entry)),
808 ProgressCallback()); 806 ProgressCallback());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 839
842 GDataErrorCode error = GDATA_OTHER_ERROR; 840 GDataErrorCode error = GDATA_OTHER_ERROR;
843 GURL upload_url; 841 GURL upload_url;
844 842
845 // Initiate uploading a new file to the directory with "parent_resource_id". 843 // Initiate uploading a new file to the directory with "parent_resource_id".
846 drive::InitiateUploadNewFileRequest* request = 844 drive::InitiateUploadNewFileRequest* request =
847 new drive::InitiateUploadNewFileRequest( 845 new drive::InitiateUploadNewFileRequest(
848 request_sender_.get(), 846 request_sender_.get(),
849 request_context_getter_.get(), 847 request_context_getter_.get(),
850 *url_generator_, 848 *url_generator_,
851 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
852 kTestContentType, 849 kTestContentType,
853 0, 850 0,
854 "parent_resource_id", // The resource id of the parent directory. 851 "parent_resource_id", // The resource id of the parent directory.
855 "new file title", // The title of the file being uploaded. 852 "new file title", // The title of the file being uploaded.
856 CreateComposedCallback( 853 CreateComposedCallback(
857 base::Bind(&test_util::RunAndQuit), 854 base::Bind(&test_util::RunAndQuit),
858 test_util::CreateCopyResultCallback(&error, &upload_url))); 855 test_util::CreateCopyResultCallback(&error, &upload_url)));
859 request_sender_->StartRequestWithRetry(request); 856 request_sender_->StartRequestWithRetry(request);
860 base::MessageLoop::current()->Run(); 857 base::MessageLoop::current()->Run();
861 858
(...skipping 15 matching lines...) Expand all
877 http_request_.content); 874 http_request_.content);
878 875
879 // Upload the content to the upload URL. 876 // Upload the content to the upload URL.
880 UploadRangeResponse response; 877 UploadRangeResponse response;
881 scoped_ptr<FileResource> new_entry; 878 scoped_ptr<FileResource> new_entry;
882 879
883 drive::ResumeUploadRequest* resume_request = 880 drive::ResumeUploadRequest* resume_request =
884 new drive::ResumeUploadRequest( 881 new drive::ResumeUploadRequest(
885 request_sender_.get(), 882 request_sender_.get(),
886 request_context_getter_.get(), 883 request_context_getter_.get(),
887 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
888 upload_url, 884 upload_url,
889 0, // start_position 885 0, // start_position
890 0, // end_position (exclusive) 886 0, // end_position (exclusive)
891 0, // content_length, 887 0, // content_length,
892 kTestContentType, 888 kTestContentType,
893 kTestFilePath, 889 kTestFilePath,
894 CreateComposedCallback( 890 CreateComposedCallback(
895 base::Bind(&test_util::RunAndQuit), 891 base::Bind(&test_util::RunAndQuit),
896 test_util::CreateCopyResultCallback(&response, &new_entry)), 892 test_util::CreateCopyResultCallback(&response, &new_entry)),
897 ProgressCallback()); 893 ProgressCallback());
(...skipping 10 matching lines...) Expand all
908 EXPECT_TRUE(http_request_.has_content); 904 EXPECT_TRUE(http_request_.has_content);
909 EXPECT_EQ(kTestContent, http_request_.content); 905 EXPECT_EQ(kTestContent, http_request_.content);
910 906
911 // Check the response. 907 // Check the response.
912 EXPECT_EQ(HTTP_CREATED, response.code); // Because it's a new file 908 EXPECT_EQ(HTTP_CREATED, response.code); // Because it's a new file
913 // The start and end positions should be set to -1, if an upload is complete. 909 // The start and end positions should be set to -1, if an upload is complete.
914 EXPECT_EQ(-1, response.start_position_received); 910 EXPECT_EQ(-1, response.start_position_received);
915 EXPECT_EQ(-1, response.end_position_received); 911 EXPECT_EQ(-1, response.end_position_received);
916 } 912 }
917 913
918 // TODO(kinaba): crbug.com/{241241,164098} Re-enable the test.
919 #define NO_GET_UPLOAD_STATUS_TEST
920
921 TEST_F(DriveApiRequestsTest, UploadNewLargeFileRequest) { 914 TEST_F(DriveApiRequestsTest, UploadNewLargeFileRequest) {
922 // Set an expected url for uploading. 915 // Set an expected url for uploading.
923 expected_upload_path_ = kTestUploadNewFilePath; 916 expected_upload_path_ = kTestUploadNewFilePath;
924 917
925 const char kTestContentType[] = "text/plain"; 918 const char kTestContentType[] = "text/plain";
926 const size_t kNumChunkBytes = 10; // Num bytes in a chunk. 919 const size_t kNumChunkBytes = 10; // Num bytes in a chunk.
927 const std::string kTestContent(100, 'a'); 920 const std::string kTestContent(100, 'a');
928 const base::FilePath kTestFilePath = 921 const base::FilePath kTestFilePath =
929 temp_dir_.path().AppendASCII("upload_file.txt"); 922 temp_dir_.path().AppendASCII("upload_file.txt");
930 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); 923 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent));
931 924
932 GDataErrorCode error = GDATA_OTHER_ERROR; 925 GDataErrorCode error = GDATA_OTHER_ERROR;
933 GURL upload_url; 926 GURL upload_url;
934 927
935 // Initiate uploading a new file to the directory with "parent_resource_id". 928 // Initiate uploading a new file to the directory with "parent_resource_id".
936 drive::InitiateUploadNewFileRequest* request = 929 drive::InitiateUploadNewFileRequest* request =
937 new drive::InitiateUploadNewFileRequest( 930 new drive::InitiateUploadNewFileRequest(
938 request_sender_.get(), 931 request_sender_.get(),
939 request_context_getter_.get(), 932 request_context_getter_.get(),
940 *url_generator_, 933 *url_generator_,
941 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
942 kTestContentType, 934 kTestContentType,
943 kTestContent.size(), 935 kTestContent.size(),
944 "parent_resource_id", // The resource id of the parent directory. 936 "parent_resource_id", // The resource id of the parent directory.
945 "new file title", // The title of the file being uploaded. 937 "new file title", // The title of the file being uploaded.
946 CreateComposedCallback( 938 CreateComposedCallback(
947 base::Bind(&test_util::RunAndQuit), 939 base::Bind(&test_util::RunAndQuit),
948 test_util::CreateCopyResultCallback(&error, &upload_url))); 940 test_util::CreateCopyResultCallback(&error, &upload_url)));
949 request_sender_->StartRequestWithRetry(request); 941 request_sender_->StartRequestWithRetry(request);
950 base::MessageLoop::current()->Run(); 942 base::MessageLoop::current()->Run();
951 943
952 EXPECT_EQ(HTTP_SUCCESS, error); 944 EXPECT_EQ(HTTP_SUCCESS, error);
953 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); 945 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
954 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 946 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
955 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 947 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
956 http_request_.headers["X-Upload-Content-Length"]); 948 http_request_.headers["X-Upload-Content-Length"]);
957 949
958 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 950 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
959 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", 951 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
960 http_request_.relative_url); 952 http_request_.relative_url);
961 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 953 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
962 EXPECT_TRUE(http_request_.has_content); 954 EXPECT_TRUE(http_request_.has_content);
963 EXPECT_EQ("{\"parents\":[{" 955 EXPECT_EQ("{\"parents\":[{"
964 "\"id\":\"parent_resource_id\"," 956 "\"id\":\"parent_resource_id\","
965 "\"kind\":\"drive#fileLink\"" 957 "\"kind\":\"drive#fileLink\""
966 "}]," 958 "}],"
967 "\"title\":\"new file title\"}", 959 "\"title\":\"new file title\"}",
968 http_request_.content); 960 http_request_.content);
969 961
970 #if !defined(NO_GET_UPLOAD_STATUS_TEST)
971 // Before sending any data, check the current status. 962 // Before sending any data, check the current status.
972 // This is an edge case test for GetUploadStatusRequest. 963 // This is an edge case test for GetUploadStatusRequest.
973 { 964 {
974 UploadRangeResponse response; 965 UploadRangeResponse response;
975 scoped_ptr<FileResource> new_entry; 966 scoped_ptr<FileResource> new_entry;
976 967
977 // Check the response by GetUploadStatusRequest. 968 // Check the response by GetUploadStatusRequest.
978 drive::GetUploadStatusRequest* get_upload_status_request = 969 drive::GetUploadStatusRequest* get_upload_status_request =
979 new drive::GetUploadStatusRequest( 970 new drive::GetUploadStatusRequest(
980 request_sender_.get(), 971 request_sender_.get(),
981 request_context_getter_.get(), 972 request_context_getter_.get(),
982 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
983 upload_url, 973 upload_url,
984 kTestContent.size(), 974 kTestContent.size(),
985 CreateComposedCallback( 975 CreateComposedCallback(
986 base::Bind(&test_util::RunAndQuit), 976 base::Bind(&test_util::RunAndQuit),
987 test_util::CreateCopyResultCallback(&response, &new_entry))); 977 test_util::CreateCopyResultCallback(&response, &new_entry)));
988 request_sender_->StartRequestWithRetry(get_upload_status_request); 978 request_sender_->StartRequestWithRetry(get_upload_status_request);
989 base::MessageLoop::current()->Run(); 979 base::MessageLoop::current()->Run();
990 980
991 // METHOD_PUT should be used to upload data. 981 // METHOD_PUT should be used to upload data.
992 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 982 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
993 // Request should go to the upload URL. 983 // Request should go to the upload URL.
994 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 984 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
995 // Content-Range header should be added. 985 // Content-Range header should be added.
996 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), 986 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()),
997 http_request_.headers["Content-Range"]); 987 http_request_.headers["Content-Range"]);
998 EXPECT_TRUE(http_request_.has_content); 988 EXPECT_TRUE(http_request_.has_content);
999 EXPECT_TRUE(http_request_.content.empty()); 989 EXPECT_TRUE(http_request_.content.empty());
1000 990
1001 // Check the response. 991 // Check the response.
1002 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 992 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1003 EXPECT_EQ(0, response.start_position_received); 993 EXPECT_EQ(0, response.start_position_received);
1004 EXPECT_EQ(0, response.end_position_received); 994 EXPECT_EQ(0, response.end_position_received);
1005 } 995 }
1006 #endif // NO_GET_UPLOAD_STATUS_TEST
1007 996
1008 // Upload the content to the upload URL. 997 // Upload the content to the upload URL.
1009 for (size_t start_position = 0; start_position < kTestContent.size(); 998 for (size_t start_position = 0; start_position < kTestContent.size();
1010 start_position += kNumChunkBytes) { 999 start_position += kNumChunkBytes) {
1011 const std::string payload = kTestContent.substr( 1000 const std::string payload = kTestContent.substr(
1012 start_position, 1001 start_position,
1013 std::min(kNumChunkBytes, kTestContent.size() - start_position)); 1002 std::min(kNumChunkBytes, kTestContent.size() - start_position));
1014 const size_t end_position = start_position + payload.size(); 1003 const size_t end_position = start_position + payload.size();
1015 1004
1016 UploadRangeResponse response; 1005 UploadRangeResponse response;
1017 scoped_ptr<FileResource> new_entry; 1006 scoped_ptr<FileResource> new_entry;
1018 1007
1019 drive::ResumeUploadRequest* resume_request = 1008 drive::ResumeUploadRequest* resume_request =
1020 new drive::ResumeUploadRequest( 1009 new drive::ResumeUploadRequest(
1021 request_sender_.get(), 1010 request_sender_.get(),
1022 request_context_getter_.get(), 1011 request_context_getter_.get(),
1023 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1024 upload_url, 1012 upload_url,
1025 start_position, 1013 start_position,
1026 end_position, 1014 end_position,
1027 kTestContent.size(), // content_length, 1015 kTestContent.size(), // content_length,
1028 kTestContentType, 1016 kTestContentType,
1029 kTestFilePath, 1017 kTestFilePath,
1030 CreateComposedCallback( 1018 CreateComposedCallback(
1031 base::Bind(&test_util::RunAndQuit), 1019 base::Bind(&test_util::RunAndQuit),
1032 test_util::CreateCopyResultCallback(&response, &new_entry)), 1020 test_util::CreateCopyResultCallback(&response, &new_entry)),
1033 ProgressCallback()); 1021 ProgressCallback());
(...skipping 22 matching lines...) Expand all
1056 EXPECT_EQ(-1, response.start_position_received); 1044 EXPECT_EQ(-1, response.start_position_received);
1057 EXPECT_EQ(-1, response.end_position_received); 1045 EXPECT_EQ(-1, response.end_position_received);
1058 break; 1046 break;
1059 } 1047 }
1060 1048
1061 // Check the response. 1049 // Check the response.
1062 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1050 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1063 EXPECT_EQ(0, response.start_position_received); 1051 EXPECT_EQ(0, response.start_position_received);
1064 EXPECT_EQ(static_cast<int64>(end_position), response.end_position_received); 1052 EXPECT_EQ(static_cast<int64>(end_position), response.end_position_received);
1065 1053
1066 #if !defined(NO_GET_UPLOAD_STATUS_TEST)
1067 // Check the response by GetUploadStatusRequest. 1054 // Check the response by GetUploadStatusRequest.
1068 drive::GetUploadStatusRequest* get_upload_status_request = 1055 drive::GetUploadStatusRequest* get_upload_status_request =
1069 new drive::GetUploadStatusRequest( 1056 new drive::GetUploadStatusRequest(
1070 request_sender_.get(), 1057 request_sender_.get(),
1071 request_context_getter_.get(), 1058 request_context_getter_.get(),
1072 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1073 upload_url, 1059 upload_url,
1074 kTestContent.size(), 1060 kTestContent.size(),
1075 CreateComposedCallback( 1061 CreateComposedCallback(
1076 base::Bind(&test_util::RunAndQuit), 1062 base::Bind(&test_util::RunAndQuit),
1077 test_util::CreateCopyResultCallback(&response, &new_entry))); 1063 test_util::CreateCopyResultCallback(&response, &new_entry)));
1078 request_sender_->StartRequestWithRetry(get_upload_status_request); 1064 request_sender_->StartRequestWithRetry(get_upload_status_request);
1079 base::MessageLoop::current()->Run(); 1065 base::MessageLoop::current()->Run();
1080 1066
1081 // METHOD_PUT should be used to upload data. 1067 // METHOD_PUT should be used to upload data.
1082 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1068 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1083 // Request should go to the upload URL. 1069 // Request should go to the upload URL.
1084 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1070 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1085 // Content-Range header should be added. 1071 // Content-Range header should be added.
1086 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), 1072 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()),
1087 http_request_.headers["Content-Range"]); 1073 http_request_.headers["Content-Range"]);
1088 EXPECT_TRUE(http_request_.has_content); 1074 EXPECT_TRUE(http_request_.has_content);
1089 EXPECT_TRUE(http_request_.content.empty()); 1075 EXPECT_TRUE(http_request_.content.empty());
1090 1076
1091 // Check the response. 1077 // Check the response.
1092 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1078 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1093 EXPECT_EQ(0, response.start_position_received); 1079 EXPECT_EQ(0, response.start_position_received);
1094 EXPECT_EQ(static_cast<int64>(end_position), 1080 EXPECT_EQ(static_cast<int64>(end_position),
1095 response.end_position_received); 1081 response.end_position_received);
1096 #endif // NO_GET_UPLOAD_STATUS_TEST
1097 } 1082 }
1098 } 1083 }
1099 1084
1100 TEST_F(DriveApiRequestsTest, UploadExistingFileRequest) { 1085 TEST_F(DriveApiRequestsTest, UploadExistingFileRequest) {
1101 // Set an expected url for uploading. 1086 // Set an expected url for uploading.
1102 expected_upload_path_ = kTestUploadExistingFilePath; 1087 expected_upload_path_ = kTestUploadExistingFilePath;
1103 1088
1104 const char kTestContentType[] = "text/plain"; 1089 const char kTestContentType[] = "text/plain";
1105 const std::string kTestContent(100, 'a'); 1090 const std::string kTestContent(100, 'a');
1106 const base::FilePath kTestFilePath = 1091 const base::FilePath kTestFilePath =
1107 temp_dir_.path().AppendASCII("upload_file.txt"); 1092 temp_dir_.path().AppendASCII("upload_file.txt");
1108 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); 1093 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent));
1109 1094
1110 GDataErrorCode error = GDATA_OTHER_ERROR; 1095 GDataErrorCode error = GDATA_OTHER_ERROR;
1111 GURL upload_url; 1096 GURL upload_url;
1112 1097
1113 // Initiate uploading a new file to the directory with "parent_resource_id". 1098 // Initiate uploading a new file to the directory with "parent_resource_id".
1114 drive::InitiateUploadExistingFileRequest* request = 1099 drive::InitiateUploadExistingFileRequest* request =
1115 new drive::InitiateUploadExistingFileRequest( 1100 new drive::InitiateUploadExistingFileRequest(
1116 request_sender_.get(), 1101 request_sender_.get(),
1117 request_context_getter_.get(), 1102 request_context_getter_.get(),
1118 *url_generator_, 1103 *url_generator_,
1119 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1120 kTestContentType, 1104 kTestContentType,
1121 kTestContent.size(), 1105 kTestContent.size(),
1122 "resource_id", // The resource id of the file to be overwritten. 1106 "resource_id", // The resource id of the file to be overwritten.
1123 std::string(), // No etag. 1107 std::string(), // No etag.
1124 CreateComposedCallback( 1108 CreateComposedCallback(
1125 base::Bind(&test_util::RunAndQuit), 1109 base::Bind(&test_util::RunAndQuit),
1126 test_util::CreateCopyResultCallback(&error, &upload_url))); 1110 test_util::CreateCopyResultCallback(&error, &upload_url)));
1127 request_sender_->StartRequestWithRetry(request); 1111 request_sender_->StartRequestWithRetry(request);
1128 base::MessageLoop::current()->Run(); 1112 base::MessageLoop::current()->Run();
1129 1113
(...skipping 11 matching lines...) Expand all
1141 EXPECT_TRUE(http_request_.content.empty()); 1125 EXPECT_TRUE(http_request_.content.empty());
1142 1126
1143 // Upload the content to the upload URL. 1127 // Upload the content to the upload URL.
1144 UploadRangeResponse response; 1128 UploadRangeResponse response;
1145 scoped_ptr<FileResource> new_entry; 1129 scoped_ptr<FileResource> new_entry;
1146 1130
1147 drive::ResumeUploadRequest* resume_request = 1131 drive::ResumeUploadRequest* resume_request =
1148 new drive::ResumeUploadRequest( 1132 new drive::ResumeUploadRequest(
1149 request_sender_.get(), 1133 request_sender_.get(),
1150 request_context_getter_.get(), 1134 request_context_getter_.get(),
1151 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1152 upload_url, 1135 upload_url,
1153 0, // start_position 1136 0, // start_position
1154 kTestContent.size(), // end_position (exclusive) 1137 kTestContent.size(), // end_position (exclusive)
1155 kTestContent.size(), // content_length, 1138 kTestContent.size(), // content_length,
1156 kTestContentType, 1139 kTestContentType,
1157 kTestFilePath, 1140 kTestFilePath,
1158 CreateComposedCallback( 1141 CreateComposedCallback(
1159 base::Bind(&test_util::RunAndQuit), 1142 base::Bind(&test_util::RunAndQuit),
1160 test_util::CreateCopyResultCallback(&response, &new_entry)), 1143 test_util::CreateCopyResultCallback(&response, &new_entry)),
1161 ProgressCallback()); 1144 ProgressCallback());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 1177
1195 GDataErrorCode error = GDATA_OTHER_ERROR; 1178 GDataErrorCode error = GDATA_OTHER_ERROR;
1196 GURL upload_url; 1179 GURL upload_url;
1197 1180
1198 // Initiate uploading a new file to the directory with "parent_resource_id". 1181 // Initiate uploading a new file to the directory with "parent_resource_id".
1199 drive::InitiateUploadExistingFileRequest* request = 1182 drive::InitiateUploadExistingFileRequest* request =
1200 new drive::InitiateUploadExistingFileRequest( 1183 new drive::InitiateUploadExistingFileRequest(
1201 request_sender_.get(), 1184 request_sender_.get(),
1202 request_context_getter_.get(), 1185 request_context_getter_.get(),
1203 *url_generator_, 1186 *url_generator_,
1204 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1205 kTestContentType, 1187 kTestContentType,
1206 kTestContent.size(), 1188 kTestContent.size(),
1207 "resource_id", // The resource id of the file to be overwritten. 1189 "resource_id", // The resource id of the file to be overwritten.
1208 kTestETag, 1190 kTestETag,
1209 CreateComposedCallback( 1191 CreateComposedCallback(
1210 base::Bind(&test_util::RunAndQuit), 1192 base::Bind(&test_util::RunAndQuit),
1211 test_util::CreateCopyResultCallback(&error, &upload_url))); 1193 test_util::CreateCopyResultCallback(&error, &upload_url)));
1212 request_sender_->StartRequestWithRetry(request); 1194 request_sender_->StartRequestWithRetry(request);
1213 base::MessageLoop::current()->Run(); 1195 base::MessageLoop::current()->Run();
1214 1196
(...skipping 11 matching lines...) Expand all
1226 EXPECT_TRUE(http_request_.content.empty()); 1208 EXPECT_TRUE(http_request_.content.empty());
1227 1209
1228 // Upload the content to the upload URL. 1210 // Upload the content to the upload URL.
1229 UploadRangeResponse response; 1211 UploadRangeResponse response;
1230 scoped_ptr<FileResource> new_entry; 1212 scoped_ptr<FileResource> new_entry;
1231 1213
1232 drive::ResumeUploadRequest* resume_request = 1214 drive::ResumeUploadRequest* resume_request =
1233 new drive::ResumeUploadRequest( 1215 new drive::ResumeUploadRequest(
1234 request_sender_.get(), 1216 request_sender_.get(),
1235 request_context_getter_.get(), 1217 request_context_getter_.get(),
1236 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1237 upload_url, 1218 upload_url,
1238 0, // start_position 1219 0, // start_position
1239 kTestContent.size(), // end_position (exclusive) 1220 kTestContent.size(), // end_position (exclusive)
1240 kTestContent.size(), // content_length, 1221 kTestContent.size(), // content_length,
1241 kTestContentType, 1222 kTestContentType,
1242 kTestFilePath, 1223 kTestFilePath,
1243 CreateComposedCallback( 1224 CreateComposedCallback(
1244 base::Bind(&test_util::RunAndQuit), 1225 base::Bind(&test_util::RunAndQuit),
1245 test_util::CreateCopyResultCallback(&response, &new_entry)), 1226 test_util::CreateCopyResultCallback(&response, &new_entry)),
1246 ProgressCallback()); 1227 ProgressCallback());
(...skipping 29 matching lines...) Expand all
1276 1257
1277 GDataErrorCode error = GDATA_OTHER_ERROR; 1258 GDataErrorCode error = GDATA_OTHER_ERROR;
1278 GURL upload_url; 1259 GURL upload_url;
1279 1260
1280 // Initiate uploading a new file to the directory with "parent_resource_id". 1261 // Initiate uploading a new file to the directory with "parent_resource_id".
1281 drive::InitiateUploadExistingFileRequest* request = 1262 drive::InitiateUploadExistingFileRequest* request =
1282 new drive::InitiateUploadExistingFileRequest( 1263 new drive::InitiateUploadExistingFileRequest(
1283 request_sender_.get(), 1264 request_sender_.get(),
1284 request_context_getter_.get(), 1265 request_context_getter_.get(),
1285 *url_generator_, 1266 *url_generator_,
1286 base::FilePath(FILE_PATH_LITERAL("drive/file/path")),
1287 kTestContentType, 1267 kTestContentType,
1288 kTestContent.size(), 1268 kTestContent.size(),
1289 "resource_id", // The resource id of the file to be overwritten. 1269 "resource_id", // The resource id of the file to be overwritten.
1290 "Conflicting-etag", 1270 "Conflicting-etag",
1291 CreateComposedCallback( 1271 CreateComposedCallback(
1292 base::Bind(&test_util::RunAndQuit), 1272 base::Bind(&test_util::RunAndQuit),
1293 test_util::CreateCopyResultCallback(&error, &upload_url))); 1273 test_util::CreateCopyResultCallback(&error, &upload_url)));
1294 request_sender_->StartRequestWithRetry(request); 1274 request_sender_->StartRequestWithRetry(request);
1295 base::MessageLoop::current()->Run(); 1275 base::MessageLoop::current()->Run();
1296 1276
1297 EXPECT_EQ(HTTP_PRECONDITION, error); 1277 EXPECT_EQ(HTTP_PRECONDITION, error);
1298 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1278 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1299 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1279 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1300 http_request_.headers["X-Upload-Content-Length"]); 1280 http_request_.headers["X-Upload-Content-Length"]);
1301 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); 1281 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]);
1302 1282
1303 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1283 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1304 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", 1284 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1305 http_request_.relative_url); 1285 http_request_.relative_url);
1306 EXPECT_TRUE(http_request_.has_content); 1286 EXPECT_TRUE(http_request_.has_content);
1307 EXPECT_TRUE(http_request_.content.empty()); 1287 EXPECT_TRUE(http_request_.content.empty());
1308 } 1288 }
1309 1289
1310 } // namespace google_apis 1290 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_requests.cc ('k') | chrome/browser/google_apis/gdata_wapi_requests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698