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

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

Issue 12210031: Implement fake drive service upload methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: properly rebased Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/google_apis/fake_drive_service.h" 5 #include "chrome/browser/google_apis/fake_drive_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/google_apis/drive_api_parser.h" 13 #include "chrome/browser/google_apis/drive_api_parser.h"
14 #include "chrome/browser/google_apis/gdata_wapi_operations.h"
14 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 15 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
15 #include "chrome/browser/google_apis/test_util.h" 16 #include "chrome/browser/google_apis/test_util.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace google_apis { 21 namespace google_apis {
21 22
23 namespace {
24
22 class FakeDriveServiceTest : public testing::Test { 25 class FakeDriveServiceTest : public testing::Test {
23 protected: 26 protected:
24 FakeDriveServiceTest() 27 FakeDriveServiceTest()
25 : ui_thread_(content::BrowserThread::UI, &message_loop_) { 28 : ui_thread_(content::BrowserThread::UI, &message_loop_) {
26 } 29 }
27 30
28 // Returns the resource entry that matches |resource_id|. 31 // Returns the resource entry that matches |resource_id|.
29 scoped_ptr<ResourceEntry> FindEntry(const std::string& resource_id) { 32 scoped_ptr<ResourceEntry> FindEntry(const std::string& resource_id) {
30 GDataErrorCode error = GDATA_OTHER_ERROR; 33 GDataErrorCode error = GDATA_OTHER_ERROR;
31 scoped_ptr<ResourceEntry> resource_entry; 34 scoped_ptr<ResourceEntry> resource_entry;
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 "new directory", 1032 "new directory",
1030 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, 1033 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback,
1031 &error, 1034 &error,
1032 &resource_entry)); 1035 &resource_entry));
1033 message_loop_.RunUntilIdle(); 1036 message_loop_.RunUntilIdle();
1034 1037
1035 EXPECT_EQ(GDATA_NO_CONNECTION, error); 1038 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1036 EXPECT_FALSE(resource_entry); 1039 EXPECT_FALSE(resource_entry);
1037 } 1040 }
1038 1041
1042 TEST_F(FakeDriveServiceTest, InitiateUpload_Offline) {
1043 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1044 fake_service_.set_offline(true);
1045
1046 GDataErrorCode error = GDATA_OTHER_ERROR;
1047 GURL upload_location;
1048 fake_service_.InitiateUpload(
1049 InitiateUploadParams(
1050 UPLOAD_NEW_FILE,
1051 "new file.foo",
1052 "test/foo",
1053 13,
1054 GURL("https://1_folder_resumable_create_media_link"),
1055 FilePath(FILE_PATH_LITERAL("drive/Directory 1")),
1056 "etag_ignored"),
1057 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1058 &error,
1059 &upload_location));
1060 message_loop_.RunUntilIdle();
1061
1062 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1063 EXPECT_TRUE(upload_location.is_empty());
1064 }
1065
1066 TEST_F(FakeDriveServiceTest, InitiateUpload_NotFound) {
1067 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1068
1069 GDataErrorCode error = GDATA_OTHER_ERROR;
1070 GURL upload_location;
1071 fake_service_.InitiateUpload(
1072 InitiateUploadParams(
1073 UPLOAD_NEW_FILE,
1074 "new file.foo",
1075 "test/foo",
1076 13,
1077 GURL("https://non_existent"),
1078 FilePath(FILE_PATH_LITERAL("drive/Directory 1")),
1079 "etag_ignored"),
1080 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1081 &error,
1082 &upload_location));
1083 message_loop_.RunUntilIdle();
1084
1085 EXPECT_EQ(HTTP_NOT_FOUND, error);
1086 EXPECT_TRUE(upload_location.is_empty());
1087 }
1088
1089 TEST_F(FakeDriveServiceTest, InitiateUpload_NewFile) {
1090 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1091
1092 GDataErrorCode error = GDATA_OTHER_ERROR;
1093 GURL upload_location;
1094 fake_service_.InitiateUpload(
1095 InitiateUploadParams(
1096 UPLOAD_NEW_FILE,
1097 "new file.foo",
1098 "test/foo",
1099 13,
1100 GURL("https://1_folder_resumable_create_media_link"),
1101 FilePath(FILE_PATH_LITERAL("drive/Directory 1")),
1102 "etag_ignored"),
1103 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1104 &error,
1105 &upload_location));
1106 message_loop_.RunUntilIdle();
1107
1108 EXPECT_EQ(HTTP_SUCCESS, error);
1109 EXPECT_FALSE(upload_location.is_empty());
1110 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
1111 upload_location);
1112 }
1113
1114 TEST_F(FakeDriveServiceTest, InitiateUpload_WrongETag) {
1115 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1116
1117 GDataErrorCode error = GDATA_OTHER_ERROR;
1118 GURL upload_location;
1119 fake_service_.InitiateUpload(
1120 InitiateUploadParams(
1121 UPLOAD_EXISTING_FILE,
1122 "name_ignored",
1123 "text/plain",
1124 13,
1125 GURL("https://2_file_link_resumable_create_media"),
1126 FilePath(FILE_PATH_LITERAL("drive/File 1.txt")),
1127 "invalid_etag"),
1128 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1129 &error,
1130 &upload_location));
1131 message_loop_.RunUntilIdle();
1132
1133 EXPECT_EQ(HTTP_PRECONDITION, error);
1134 EXPECT_TRUE(upload_location.is_empty());
1135 }
1136
1137 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) {
1138 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1139
1140 GDataErrorCode error = GDATA_OTHER_ERROR;
1141 GURL upload_location;
1142 fake_service_.InitiateUpload(
1143 InitiateUploadParams(
1144 UPLOAD_EXISTING_FILE,
1145 "name_ignored",
1146 "text/plain",
1147 13,
1148 GURL("https://2_file_link_resumable_create_media"),
1149 FilePath(FILE_PATH_LITERAL("drive/File 1.txt")),
1150 "\"HhMOFgxXHit7ImBr\""),
1151 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1152 &error,
1153 &upload_location));
1154 message_loop_.RunUntilIdle();
1155
1156 EXPECT_EQ(HTTP_SUCCESS, error);
1157 EXPECT_EQ(GURL("https://2_file_link_resumable_create_media"),
1158 upload_location);
1159 }
1160
1161 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) {
1162 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1163
1164 GDataErrorCode error = GDATA_OTHER_ERROR;
1165 GURL upload_location;
1166 fake_service_.InitiateUpload(
1167 InitiateUploadParams(
1168 UPLOAD_NEW_FILE,
1169 "new file.foo",
1170 "test/foo",
1171 15,
1172 GURL("https://1_folder_resumable_create_media_link"),
1173 FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")),
1174 "etag_ignored"),
1175 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1176 &error,
1177 &upload_location));
1178 message_loop_.RunUntilIdle();
1179
1180 EXPECT_EQ(HTTP_SUCCESS, error);
1181 EXPECT_FALSE(upload_location.is_empty());
1182 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
1183 upload_location);
1184
1185 fake_service_.set_offline(true);
1186
1187 UploadRangeResponse response;
1188 scoped_ptr<ResourceEntry> entry;
1189 fake_service_.ResumeUpload(
1190 ResumeUploadParams(UPLOAD_NEW_FILE,
1191 0, 13, 15, "test/foo",
1192 scoped_refptr<net::IOBuffer>(),
1193 upload_location,
1194 FilePath(FILE_PATH_LITERAL(
1195 "drive/Directory 1/new file.foo"))),
1196 base::Bind(&test_util::CopyResultsFromUploadRangeCallback,
1197 &response, &entry));
1198 message_loop_.RunUntilIdle();
1199
1200 EXPECT_EQ(GDATA_NO_CONNECTION, response.code);
1201 EXPECT_FALSE(entry.get());
1202 }
1203
1204 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) {
1205 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1206
1207 GDataErrorCode error = GDATA_OTHER_ERROR;
1208 GURL upload_location;
1209 fake_service_.InitiateUpload(
1210 InitiateUploadParams(
1211 UPLOAD_NEW_FILE,
1212 "new file.foo",
1213 "test/foo",
1214 15,
1215 GURL("https://1_folder_resumable_create_media_link"),
1216 FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")),
1217 "etag_ignored"),
1218 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1219 &error,
1220 &upload_location));
1221 message_loop_.RunUntilIdle();
1222
1223 ASSERT_EQ(HTTP_SUCCESS, error);
1224
1225 UploadRangeResponse response;
1226 scoped_ptr<ResourceEntry> entry;
1227 fake_service_.ResumeUpload(
1228 ResumeUploadParams(UPLOAD_NEW_FILE,
1229 0, 13, 15, "test/foo",
1230 scoped_refptr<net::IOBuffer>(),
1231 GURL("https://foo.com/"),
1232 FilePath(FILE_PATH_LITERAL(
1233 "drive/Directory 1/new file.foo"))),
1234 base::Bind(&test_util::CopyResultsFromUploadRangeCallback,
1235 &response, &entry));
1236 message_loop_.RunUntilIdle();
1237
1238 EXPECT_EQ(HTTP_NOT_FOUND, response.code);
1239 EXPECT_FALSE(entry.get());
1240 }
1241
1242 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) {
1243 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1244
1245 GDataErrorCode error = GDATA_OTHER_ERROR;
1246 GURL upload_location;
1247 fake_service_.InitiateUpload(
1248 InitiateUploadParams(
1249 UPLOAD_EXISTING_FILE,
1250 "name_ignored",
1251 "text/plain",
1252 15,
1253 GURL("https://2_file_link_resumable_create_media"),
1254 FilePath(FILE_PATH_LITERAL("drive/File 1.txt")),
1255 "\"HhMOFgxXHit7ImBr\""),
1256 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1257 &error,
1258 &upload_location));
1259 message_loop_.RunUntilIdle();
1260
1261 ASSERT_EQ(HTTP_SUCCESS, error);
1262
1263 UploadRangeResponse response;
1264 scoped_ptr<ResourceEntry> entry;
1265 fake_service_.ResumeUpload(
1266 ResumeUploadParams(UPLOAD_EXISTING_FILE,
1267 0, 13, 15, "text/plain",
1268 scoped_refptr<net::IOBuffer>(),
1269 upload_location,
1270 FilePath(FILE_PATH_LITERAL(
1271 "drive/File 1.txt"))),
1272 base::Bind(&test_util::CopyResultsFromUploadRangeCallback,
1273 &response, &entry));
1274 message_loop_.RunUntilIdle();
1275
1276 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1277 EXPECT_FALSE(entry.get());
1278
1279 fake_service_.ResumeUpload(
1280 ResumeUploadParams(UPLOAD_EXISTING_FILE,
1281 14, 15, 15, "text/plain",
1282 scoped_refptr<net::IOBuffer>(),
1283 upload_location,
1284 FilePath(FILE_PATH_LITERAL(
1285 "drive/File 1.txt"))),
1286 base::Bind(&test_util::CopyResultsFromUploadRangeCallback,
1287 &response, &entry));
1288 message_loop_.RunUntilIdle();
1289
1290 EXPECT_EQ(HTTP_SUCCESS, response.code);
1291 EXPECT_TRUE(entry.get());
1292 EXPECT_EQ(15L, entry->file_size());
1293 EXPECT_TRUE(Exists(entry->resource_id()));
1294 }
1295
1296 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
1297 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
1298
1299 GDataErrorCode error = GDATA_OTHER_ERROR;
1300 GURL upload_location;
1301 fake_service_.InitiateUpload(
1302 InitiateUploadParams(
1303 UPLOAD_NEW_FILE,
1304 "new file.foo",
1305 "test/foo",
1306 15,
1307 GURL("https://1_folder_resumable_create_media_link"),
1308 FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")),
1309 "etag_ignored"),
1310 base::Bind(&test_util::CopyResultsFromInitiateUploadCallback,
1311 &error,
1312 &upload_location));
1313 message_loop_.RunUntilIdle();
1314
1315 EXPECT_EQ(HTTP_SUCCESS, error);
1316 EXPECT_FALSE(upload_location.is_empty());
1317 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
1318 upload_location);
1319
1320 UploadRangeResponse response;
1321 scoped_ptr<ResourceEntry> entry;
1322 fake_service_.ResumeUpload(
1323 ResumeUploadParams(UPLOAD_NEW_FILE,
1324 0, 13, 15, "test/foo",
1325 scoped_refptr<net::IOBuffer>(),
1326 upload_location,
1327 FilePath(FILE_PATH_LITERAL(
1328 "drive/Directory 1/new file.foo"))),
1329 base::Bind(&test_util::CopyResultsFromUploadRangeCallback,
1330 &response, &entry));
1331 message_loop_.RunUntilIdle();
1332
1333 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1334 EXPECT_FALSE(entry.get());
1335
1336 fake_service_.ResumeUpload(
1337 ResumeUploadParams(UPLOAD_NEW_FILE,
1338 14, 15, 15, "test/foo",
1339 scoped_refptr<net::IOBuffer>(),
1340 upload_location,
1341 FilePath(FILE_PATH_LITERAL(
1342 "drive/Directory 1/new file.foo"))),
1343 base::Bind(&test_util::CopyResultsFromUploadRangeCallback,
1344 &response, &entry));
1345 message_loop_.RunUntilIdle();
1346
1347 EXPECT_EQ(HTTP_CREATED, response.code);
1348 EXPECT_TRUE(entry.get());
1349 EXPECT_EQ(15L, entry->file_size());
1350 EXPECT_TRUE(Exists(entry->resource_id()));
1351 }
1352
1353 } // namespace
1354
1039 } // namespace google_apis 1355 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/fake_drive_service.cc ('k') | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698