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

Side by Side Diff: components/drive/service/fake_drive_service_unittest.cc

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 "components/drive/service/fake_drive_service.h" 5 #include "components/drive/service/fake_drive_service.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <string> 10 #include <string>
8 #include <vector> 11 #include <vector>
9 12
10 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
12 #include "base/md5.h" 15 #include "base/md5.h"
13 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 17 #include "base/run_loop.h"
15 #include "base/stl_util.h" 18 #include "base/stl_util.h"
16 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 scoped_ptr<FileResource> entry = FindEntry(resource_id); 94 scoped_ptr<FileResource> entry = FindEntry(resource_id);
92 if (entry) { 95 if (entry) {
93 for (size_t i = 0; i < entry->parents().size(); ++i) { 96 for (size_t i = 0; i < entry->parents().size(); ++i) {
94 if (entry->parents()[i].file_id() == parent_id) 97 if (entry->parents()[i].file_id() == parent_id)
95 return true; 98 return true;
96 } 99 }
97 } 100 }
98 return false; 101 return false;
99 } 102 }
100 103
101 int64 GetLargestChangeByAboutResource() { 104 int64_t GetLargestChangeByAboutResource() {
102 DriveApiErrorCode error; 105 DriveApiErrorCode error;
103 scoped_ptr<AboutResource> about_resource; 106 scoped_ptr<AboutResource> about_resource;
104 fake_service_.GetAboutResource( 107 fake_service_.GetAboutResource(
105 test_util::CreateCopyResultCallback(&error, &about_resource)); 108 test_util::CreateCopyResultCallback(&error, &about_resource));
106 base::RunLoop().RunUntilIdle(); 109 base::RunLoop().RunUntilIdle();
107 return about_resource->largest_change_id(); 110 return about_resource->largest_change_id();
108 } 111 }
109 112
110 base::MessageLoop message_loop_; 113 base::MessageLoop message_loop_;
111 FakeDriveService fake_service_; 114 FakeDriveService fake_service_;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 change_list->largest_change_id()); 384 change_list->largest_change_id());
382 // This should be empty as the latest changestamp was passed to 385 // This should be empty as the latest changestamp was passed to
383 // GetChangeList(), hence there should be no new entries. 386 // GetChangeList(), hence there should be no new entries.
384 EXPECT_EQ(0U, change_list->items().size()); 387 EXPECT_EQ(0U, change_list->items().size());
385 // It's considered loaded even if the result is empty. 388 // It's considered loaded even if the result is empty.
386 EXPECT_EQ(1, fake_service_.change_list_load_count()); 389 EXPECT_EQ(1, fake_service_.change_list_load_count());
387 } 390 }
388 391
389 TEST_F(FakeDriveServiceTest, GetChangeList_WithNewEntry) { 392 TEST_F(FakeDriveServiceTest, GetChangeList_WithNewEntry) {
390 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 393 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
391 const int64 old_largest_change_id = 394 const int64_t old_largest_change_id =
392 fake_service_.about_resource().largest_change_id(); 395 fake_service_.about_resource().largest_change_id();
393 396
394 // Add a new directory in the root directory. 397 // Add a new directory in the root directory.
395 ASSERT_TRUE(AddNewDirectory( 398 ASSERT_TRUE(AddNewDirectory(
396 fake_service_.GetRootResourceId(), "new directory")); 399 fake_service_.GetRootResourceId(), "new directory"));
397 400
398 // Get the resource list newer than old_largest_change_id. 401 // Get the resource list newer than old_largest_change_id.
399 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 402 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
400 scoped_ptr<ChangeList> change_list; 403 scoped_ptr<ChangeList> change_list;
401 fake_service_.GetChangeList( 404 fake_service_.GetChangeList(
(...skipping 23 matching lines...) Expand all
425 test_util::CreateCopyResultCallback(&error, &change_list)); 428 test_util::CreateCopyResultCallback(&error, &change_list));
426 base::RunLoop().RunUntilIdle(); 429 base::RunLoop().RunUntilIdle();
427 430
428 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 431 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
429 EXPECT_FALSE(change_list); 432 EXPECT_FALSE(change_list);
430 } 433 }
431 434
432 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) { 435 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) {
433 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 436 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
434 ASSERT_TRUE(Exists("2_file_resource_id")); 437 ASSERT_TRUE(Exists("2_file_resource_id"));
435 const int64 old_largest_change_id = 438 const int64_t old_largest_change_id =
436 fake_service_.about_resource().largest_change_id(); 439 fake_service_.about_resource().largest_change_id();
437 440
438 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 441 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
439 fake_service_.DeleteResource("2_file_resource_id", 442 fake_service_.DeleteResource("2_file_resource_id",
440 std::string(), // etag 443 std::string(), // etag
441 test_util::CreateCopyResultCallback(&error)); 444 test_util::CreateCopyResultCallback(&error));
442 base::RunLoop().RunUntilIdle(); 445 base::RunLoop().RunUntilIdle();
443 ASSERT_EQ(HTTP_NO_CONTENT, error); 446 ASSERT_EQ(HTTP_NO_CONTENT, error);
444 ASSERT_FALSE(Exists("2_file_resource_id")); 447 ASSERT_FALSE(Exists("2_file_resource_id"));
445 448
(...skipping 14 matching lines...) Expand all
460 const ChangeResource& item = *change_list->items()[0]; 463 const ChangeResource& item = *change_list->items()[0];
461 EXPECT_EQ("2_file_resource_id", item.file_id()); 464 EXPECT_EQ("2_file_resource_id", item.file_id());
462 EXPECT_FALSE(item.file()); 465 EXPECT_FALSE(item.file());
463 EXPECT_TRUE(item.is_deleted()); 466 EXPECT_TRUE(item.is_deleted());
464 EXPECT_EQ(1, fake_service_.change_list_load_count()); 467 EXPECT_EQ(1, fake_service_.change_list_load_count());
465 } 468 }
466 469
467 TEST_F(FakeDriveServiceTest, GetChangeList_TrashedEntry) { 470 TEST_F(FakeDriveServiceTest, GetChangeList_TrashedEntry) {
468 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 471 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
469 ASSERT_TRUE(Exists("2_file_resource_id")); 472 ASSERT_TRUE(Exists("2_file_resource_id"));
470 const int64 old_largest_change_id = 473 const int64_t old_largest_change_id =
471 fake_service_.about_resource().largest_change_id(); 474 fake_service_.about_resource().largest_change_id();
472 475
473 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 476 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
474 fake_service_.TrashResource("2_file_resource_id", 477 fake_service_.TrashResource("2_file_resource_id",
475 test_util::CreateCopyResultCallback(&error)); 478 test_util::CreateCopyResultCallback(&error));
476 base::RunLoop().RunUntilIdle(); 479 base::RunLoop().RunUntilIdle();
477 ASSERT_EQ(HTTP_SUCCESS, error); 480 ASSERT_EQ(HTTP_SUCCESS, error);
478 ASSERT_FALSE(Exists("2_file_resource_id")); 481 ASSERT_FALSE(Exists("2_file_resource_id"));
479 482
480 // Get the resource list newer than old_largest_change_id. 483 // Get the resource list newer than old_largest_change_id.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 637
635 EXPECT_EQ(HTTP_SUCCESS, error); 638 EXPECT_EQ(HTTP_SUCCESS, error);
636 ASSERT_TRUE(file_list); 639 ASSERT_TRUE(file_list);
637 640
638 EXPECT_EQ(2U, file_list->items().size()); 641 EXPECT_EQ(2U, file_list->items().size());
639 } 642 }
640 643
641 TEST_F(FakeDriveServiceTest, GetRemainingChangeList_GetChangeList) { 644 TEST_F(FakeDriveServiceTest, GetRemainingChangeList_GetChangeList) {
642 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 645 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
643 fake_service_.set_default_max_results(2); 646 fake_service_.set_default_max_results(2);
644 const int64 old_largest_change_id = 647 const int64_t old_largest_change_id =
645 fake_service_.about_resource().largest_change_id(); 648 fake_service_.about_resource().largest_change_id();
646 649
647 // Add 5 new directory in the root directory. 650 // Add 5 new directory in the root directory.
648 for (int i = 0; i < 5; ++i) { 651 for (int i = 0; i < 5; ++i) {
649 ASSERT_TRUE(AddNewDirectory( 652 ASSERT_TRUE(AddNewDirectory(
650 fake_service_.GetRootResourceId(), 653 fake_service_.GetRootResourceId(),
651 base::StringPrintf("new directory %d", i))); 654 base::StringPrintf("new directory %d", i)));
652 } 655 }
653 656
654 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 657 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 base::RunLoop().RunUntilIdle(); 1053 base::RunLoop().RunUntilIdle();
1051 1054
1052 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 1055 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
1053 } 1056 }
1054 1057
1055 TEST_F(FakeDriveServiceTest, CopyResource) { 1058 TEST_F(FakeDriveServiceTest, CopyResource) {
1056 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; 1059 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
1057 1060
1058 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1061 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1059 1062
1060 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1063 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1061 1064
1062 const std::string kResourceId = "2_file_resource_id"; 1065 const std::string kResourceId = "2_file_resource_id";
1063 const std::string kParentResourceId = "2_folder_resource_id"; 1066 const std::string kParentResourceId = "2_folder_resource_id";
1064 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1067 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1065 scoped_ptr<FileResource> entry; 1068 scoped_ptr<FileResource> entry;
1066 fake_service_.CopyResource( 1069 fake_service_.CopyResource(
1067 kResourceId, 1070 kResourceId,
1068 kParentResourceId, 1071 kParentResourceId,
1069 "new title", 1072 "new title",
1070 base::Time::FromUTCExploded(kModifiedDate), 1073 base::Time::FromUTCExploded(kModifiedDate),
(...skipping 26 matching lines...) Expand all
1097 base::Time(), 1100 base::Time(),
1098 test_util::CreateCopyResultCallback(&error, &entry)); 1101 test_util::CreateCopyResultCallback(&error, &entry));
1099 base::RunLoop().RunUntilIdle(); 1102 base::RunLoop().RunUntilIdle();
1100 1103
1101 EXPECT_EQ(HTTP_NOT_FOUND, error); 1104 EXPECT_EQ(HTTP_NOT_FOUND, error);
1102 } 1105 }
1103 1106
1104 TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) { 1107 TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) {
1105 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1108 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1106 1109
1107 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1110 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1108 1111
1109 const std::string kResourceId = "2_file_resource_id"; 1112 const std::string kResourceId = "2_file_resource_id";
1110 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1113 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1111 scoped_ptr<FileResource> entry; 1114 scoped_ptr<FileResource> entry;
1112 fake_service_.CopyResource( 1115 fake_service_.CopyResource(
1113 kResourceId, 1116 kResourceId,
1114 std::string(), 1117 std::string(),
1115 "new title", 1118 "new title",
1116 base::Time(), 1119 base::Time(),
1117 test_util::CreateCopyResultCallback(&error, &entry)); 1120 test_util::CreateCopyResultCallback(&error, &entry));
(...skipping 29 matching lines...) Expand all
1147 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 1150 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
1148 EXPECT_FALSE(entry); 1151 EXPECT_FALSE(entry);
1149 } 1152 }
1150 1153
1151 TEST_F(FakeDriveServiceTest, UpdateResource) { 1154 TEST_F(FakeDriveServiceTest, UpdateResource) {
1152 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; 1155 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
1153 const base::Time::Exploded kViewedDate = {2013, 8, 1, 20, 16, 00, 14, 234}; 1156 const base::Time::Exploded kViewedDate = {2013, 8, 1, 20, 16, 00, 14, 234};
1154 1157
1155 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1158 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1156 1159
1157 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1160 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1158 1161
1159 const std::string kResourceId = "2_file_resource_id"; 1162 const std::string kResourceId = "2_file_resource_id";
1160 const std::string kParentResourceId = "2_folder_resource_id"; 1163 const std::string kParentResourceId = "2_folder_resource_id";
1161 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1164 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1162 scoped_ptr<FileResource> entry; 1165 scoped_ptr<FileResource> entry;
1163 fake_service_.UpdateResource( 1166 fake_service_.UpdateResource(
1164 kResourceId, kParentResourceId, "new title", 1167 kResourceId, kParentResourceId, "new title",
1165 base::Time::FromUTCExploded(kModifiedDate), 1168 base::Time::FromUTCExploded(kModifiedDate),
1166 base::Time::FromUTCExploded(kViewedDate), 1169 base::Time::FromUTCExploded(kViewedDate),
1167 google_apis::drive::Properties(), 1170 google_apis::drive::Properties(),
(...skipping 27 matching lines...) Expand all
1195 base::Time(), google_apis::drive::Properties(), 1198 base::Time(), google_apis::drive::Properties(),
1196 test_util::CreateCopyResultCallback(&error, &entry)); 1199 test_util::CreateCopyResultCallback(&error, &entry));
1197 base::RunLoop().RunUntilIdle(); 1200 base::RunLoop().RunUntilIdle();
1198 1201
1199 EXPECT_EQ(HTTP_NOT_FOUND, error); 1202 EXPECT_EQ(HTTP_NOT_FOUND, error);
1200 } 1203 }
1201 1204
1202 TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) { 1205 TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) {
1203 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1206 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1204 1207
1205 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1208 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1206 1209
1207 const std::string kResourceId = "2_file_resource_id"; 1210 const std::string kResourceId = "2_file_resource_id";
1208 1211
1209 // Just make sure that the resource is under root. 1212 // Just make sure that the resource is under root.
1210 ASSERT_TRUE(HasParent(kResourceId, "fake_root")); 1213 ASSERT_TRUE(HasParent(kResourceId, "fake_root"));
1211 1214
1212 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1215 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1213 scoped_ptr<FileResource> entry; 1216 scoped_ptr<FileResource> entry;
1214 fake_service_.UpdateResource( 1217 fake_service_.UpdateResource(
1215 kResourceId, std::string(), "new title", base::Time(), base::Time(), 1218 kResourceId, std::string(), "new title", base::Time(), base::Time(),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 test_util::CreateCopyResultCallback(&error, &entry)); 1264 test_util::CreateCopyResultCallback(&error, &entry));
1262 base::RunLoop().RunUntilIdle(); 1265 base::RunLoop().RunUntilIdle();
1263 1266
1264 EXPECT_EQ(HTTP_FORBIDDEN, error); 1267 EXPECT_EQ(HTTP_FORBIDDEN, error);
1265 EXPECT_FALSE(entry); 1268 EXPECT_FALSE(entry);
1266 } 1269 }
1267 1270
1268 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { 1271 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) {
1269 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1272 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1270 1273
1271 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1274 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1272 1275
1273 const std::string kResourceId = "2_file_resource_id"; 1276 const std::string kResourceId = "2_file_resource_id";
1274 const std::string kOldParentResourceId = fake_service_.GetRootResourceId(); 1277 const std::string kOldParentResourceId = fake_service_.GetRootResourceId();
1275 const std::string kNewParentResourceId = "1_folder_resource_id"; 1278 const std::string kNewParentResourceId = "1_folder_resource_id";
1276 1279
1277 // Here's the original parent link. 1280 // Here's the original parent link.
1278 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); 1281 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId));
1279 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); 1282 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId));
1280 1283
1281 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1284 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
(...skipping 10 matching lines...) Expand all
1292 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); 1295 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId));
1293 // Should be incremented as a file was moved. 1296 // Should be incremented as a file was moved.
1294 EXPECT_EQ(old_largest_change_id + 1, 1297 EXPECT_EQ(old_largest_change_id + 1,
1295 fake_service_.about_resource().largest_change_id()); 1298 fake_service_.about_resource().largest_change_id());
1296 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 1299 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1297 } 1300 }
1298 1301
1299 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) { 1302 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) {
1300 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1303 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1301 1304
1302 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1305 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1303 1306
1304 const std::string kResourceId = "subdirectory_file_1_id"; 1307 const std::string kResourceId = "subdirectory_file_1_id";
1305 const std::string kOldParentResourceId = "1_folder_resource_id"; 1308 const std::string kOldParentResourceId = "1_folder_resource_id";
1306 const std::string kNewParentResourceId = "2_folder_resource_id"; 1309 const std::string kNewParentResourceId = "2_folder_resource_id";
1307 1310
1308 // Here's the original parent link. 1311 // Here's the original parent link.
1309 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); 1312 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId));
1310 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); 1313 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId));
1311 1314
1312 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1315 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
(...skipping 26 matching lines...) Expand all
1339 kResourceId, 1342 kResourceId,
1340 test_util::CreateCopyResultCallback(&error)); 1343 test_util::CreateCopyResultCallback(&error));
1341 base::RunLoop().RunUntilIdle(); 1344 base::RunLoop().RunUntilIdle();
1342 1345
1343 EXPECT_EQ(HTTP_NOT_FOUND, error); 1346 EXPECT_EQ(HTTP_NOT_FOUND, error);
1344 } 1347 }
1345 1348
1346 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_OrphanFile) { 1349 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_OrphanFile) {
1347 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1350 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1348 1351
1349 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1352 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1350 1353
1351 const std::string kResourceId = "1_orphanfile_resource_id"; 1354 const std::string kResourceId = "1_orphanfile_resource_id";
1352 const std::string kNewParentResourceId = "1_folder_resource_id"; 1355 const std::string kNewParentResourceId = "1_folder_resource_id";
1353 1356
1354 // The file does not belong to any directory, even to the root. 1357 // The file does not belong to any directory, even to the root.
1355 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); 1358 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId));
1356 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); 1359 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId()));
1357 1360
1358 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1361 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1359 fake_service_.AddResourceToDirectory( 1362 fake_service_.AddResourceToDirectory(
(...skipping 26 matching lines...) Expand all
1386 kResourceId, 1389 kResourceId,
1387 test_util::CreateCopyResultCallback(&error)); 1390 test_util::CreateCopyResultCallback(&error));
1388 base::RunLoop().RunUntilIdle(); 1391 base::RunLoop().RunUntilIdle();
1389 1392
1390 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 1393 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
1391 } 1394 }
1392 1395
1393 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { 1396 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) {
1394 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1397 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1395 1398
1396 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1399 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1397 1400
1398 const std::string kResourceId = "subdirectory_file_1_id"; 1401 const std::string kResourceId = "subdirectory_file_1_id";
1399 const std::string kParentResourceId = "1_folder_resource_id"; 1402 const std::string kParentResourceId = "1_folder_resource_id";
1400 1403
1401 scoped_ptr<FileResource> entry = FindEntry(kResourceId); 1404 scoped_ptr<FileResource> entry = FindEntry(kResourceId);
1402 ASSERT_TRUE(entry); 1405 ASSERT_TRUE(entry);
1403 // The entry should have a parent now. 1406 // The entry should have a parent now.
1404 ASSERT_FALSE(entry->parents().empty()); 1407 ASSERT_FALSE(entry->parents().empty());
1405 1408
1406 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1409 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 kResourceId, 1470 kResourceId,
1468 test_util::CreateCopyResultCallback(&error)); 1471 test_util::CreateCopyResultCallback(&error));
1469 base::RunLoop().RunUntilIdle(); 1472 base::RunLoop().RunUntilIdle();
1470 1473
1471 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 1474 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
1472 } 1475 }
1473 1476
1474 TEST_F(FakeDriveServiceTest, AddNewDirectory_EmptyParent) { 1477 TEST_F(FakeDriveServiceTest, AddNewDirectory_EmptyParent) {
1475 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1478 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1476 1479
1477 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1480 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1478 1481
1479 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1482 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1480 scoped_ptr<FileResource> entry; 1483 scoped_ptr<FileResource> entry;
1481 fake_service_.AddNewDirectory( 1484 fake_service_.AddNewDirectory(
1482 std::string(), "new directory", AddNewDirectoryOptions(), 1485 std::string(), "new directory", AddNewDirectoryOptions(),
1483 test_util::CreateCopyResultCallback(&error, &entry)); 1486 test_util::CreateCopyResultCallback(&error, &entry));
1484 base::RunLoop().RunUntilIdle(); 1487 base::RunLoop().RunUntilIdle();
1485 1488
1486 EXPECT_EQ(HTTP_CREATED, error); 1489 EXPECT_EQ(HTTP_CREATED, error);
1487 ASSERT_TRUE(entry); 1490 ASSERT_TRUE(entry);
1488 EXPECT_TRUE(entry->IsDirectory()); 1491 EXPECT_TRUE(entry->IsDirectory());
1489 EXPECT_EQ("resource_id_1", entry->file_id()); 1492 EXPECT_EQ("resource_id_1", entry->file_id());
1490 EXPECT_EQ("new directory", entry->title()); 1493 EXPECT_EQ("new directory", entry->title());
1491 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); 1494 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId()));
1492 // Should be incremented as a new directory was created. 1495 // Should be incremented as a new directory was created.
1493 EXPECT_EQ(old_largest_change_id + 1, 1496 EXPECT_EQ(old_largest_change_id + 1,
1494 fake_service_.about_resource().largest_change_id()); 1497 fake_service_.about_resource().largest_change_id());
1495 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 1498 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1496 } 1499 }
1497 1500
1498 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { 1501 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) {
1499 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1502 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1500 1503
1501 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1504 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1502 1505
1503 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1506 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1504 scoped_ptr<FileResource> entry; 1507 scoped_ptr<FileResource> entry;
1505 fake_service_.AddNewDirectory( 1508 fake_service_.AddNewDirectory(
1506 fake_service_.GetRootResourceId(), "new directory", 1509 fake_service_.GetRootResourceId(), "new directory",
1507 AddNewDirectoryOptions(), 1510 AddNewDirectoryOptions(),
1508 test_util::CreateCopyResultCallback(&error, &entry)); 1511 test_util::CreateCopyResultCallback(&error, &entry));
1509 base::RunLoop().RunUntilIdle(); 1512 base::RunLoop().RunUntilIdle();
1510 1513
1511 EXPECT_EQ(HTTP_CREATED, error); 1514 EXPECT_EQ(HTTP_CREATED, error);
1512 ASSERT_TRUE(entry); 1515 ASSERT_TRUE(entry);
1513 EXPECT_TRUE(entry->IsDirectory()); 1516 EXPECT_TRUE(entry->IsDirectory());
1514 EXPECT_EQ("resource_id_1", entry->file_id()); 1517 EXPECT_EQ("resource_id_1", entry->file_id());
1515 EXPECT_EQ("new directory", entry->title()); 1518 EXPECT_EQ("new directory", entry->title());
1516 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); 1519 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId()));
1517 // Should be incremented as a new directory was created. 1520 // Should be incremented as a new directory was created.
1518 EXPECT_EQ(old_largest_change_id + 1, 1521 EXPECT_EQ(old_largest_change_id + 1,
1519 fake_service_.about_resource().largest_change_id()); 1522 fake_service_.about_resource().largest_change_id());
1520 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 1523 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1521 } 1524 }
1522 1525
1523 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { 1526 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) {
1524 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1527 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1525 1528
1526 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1529 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1527 scoped_ptr<FileResource> entry; 1530 scoped_ptr<FileResource> entry;
1528 fake_service_.AddNewDirectory( 1531 fake_service_.AddNewDirectory(
1529 fake_service_.GetRootResourceId(), "new directory", 1532 fake_service_.GetRootResourceId(), "new directory",
1530 AddNewDirectoryOptions(), 1533 AddNewDirectoryOptions(),
1531 test_util::CreateCopyResultCallback(&error, &entry)); 1534 test_util::CreateCopyResultCallback(&error, &entry));
1532 base::RunLoop().RunUntilIdle(); 1535 base::RunLoop().RunUntilIdle();
1533 1536
1534 EXPECT_EQ(HTTP_CREATED, error); 1537 EXPECT_EQ(HTTP_CREATED, error);
1535 ASSERT_TRUE(entry); 1538 ASSERT_TRUE(entry);
1536 EXPECT_TRUE(entry->IsDirectory()); 1539 EXPECT_TRUE(entry->IsDirectory());
1537 EXPECT_EQ("resource_id_1", entry->file_id()); 1540 EXPECT_EQ("resource_id_1", entry->file_id());
1538 EXPECT_EQ("new directory", entry->title()); 1541 EXPECT_EQ("new directory", entry->title());
1539 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); 1542 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId()));
1540 // Should be incremented as a new directory was created. 1543 // Should be incremented as a new directory was created.
1541 EXPECT_EQ(old_largest_change_id + 1, 1544 EXPECT_EQ(old_largest_change_id + 1,
1542 fake_service_.about_resource().largest_change_id()); 1545 fake_service_.about_resource().largest_change_id());
1543 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 1546 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1544 } 1547 }
1545 1548
1546 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { 1549 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) {
1547 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1550 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1548 1551
1549 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1552 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1550 1553
1551 const std::string kParentResourceId = "1_folder_resource_id"; 1554 const std::string kParentResourceId = "1_folder_resource_id";
1552 1555
1553 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1556 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1554 scoped_ptr<FileResource> entry; 1557 scoped_ptr<FileResource> entry;
1555 fake_service_.AddNewDirectory( 1558 fake_service_.AddNewDirectory(
1556 kParentResourceId, "new directory", AddNewDirectoryOptions(), 1559 kParentResourceId, "new directory", AddNewDirectoryOptions(),
1557 test_util::CreateCopyResultCallback(&error, &entry)); 1560 test_util::CreateCopyResultCallback(&error, &entry));
1558 base::RunLoop().RunUntilIdle(); 1561 base::RunLoop().RunUntilIdle();
1559 1562
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 test_util::CreateCopyResultCallback(&response, &entry), 1837 test_util::CreateCopyResultCallback(&response, &entry),
1835 base::Bind(&test_util::AppendProgressCallbackResult, 1838 base::Bind(&test_util::AppendProgressCallbackResult,
1836 &upload_progress_values)); 1839 &upload_progress_values));
1837 base::RunLoop().RunUntilIdle(); 1840 base::RunLoop().RunUntilIdle();
1838 1841
1839 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1842 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1840 EXPECT_FALSE(entry.get()); 1843 EXPECT_FALSE(entry.get());
1841 ASSERT_TRUE(!upload_progress_values.empty()); 1844 ASSERT_TRUE(!upload_progress_values.empty());
1842 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1845 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1843 EXPECT_LE(0, upload_progress_values.front().first); 1846 EXPECT_LE(0, upload_progress_values.front().first);
1844 EXPECT_GE(static_cast<int64>(contents.size() / 2), 1847 EXPECT_GE(static_cast<int64_t>(contents.size() / 2),
1845 upload_progress_values.back().first); 1848 upload_progress_values.back().first);
1846 1849
1847 upload_progress_values.clear(); 1850 upload_progress_values.clear();
1848 fake_service_.ResumeUpload( 1851 fake_service_.ResumeUpload(
1849 upload_location, 1852 upload_location,
1850 contents.size() / 2, contents.size(), contents.size(), "text/plain", 1853 contents.size() / 2, contents.size(), contents.size(), "text/plain",
1851 local_file_path, 1854 local_file_path,
1852 test_util::CreateCopyResultCallback(&response, &entry), 1855 test_util::CreateCopyResultCallback(&response, &entry),
1853 base::Bind(&test_util::AppendProgressCallbackResult, 1856 base::Bind(&test_util::AppendProgressCallbackResult,
1854 &upload_progress_values)); 1857 &upload_progress_values));
1855 base::RunLoop().RunUntilIdle(); 1858 base::RunLoop().RunUntilIdle();
1856 1859
1857 EXPECT_EQ(HTTP_SUCCESS, response.code); 1860 EXPECT_EQ(HTTP_SUCCESS, response.code);
1858 EXPECT_TRUE(entry.get()); 1861 EXPECT_TRUE(entry.get());
1859 EXPECT_EQ(static_cast<int64>(contents.size()), entry->file_size()); 1862 EXPECT_EQ(static_cast<int64_t>(contents.size()), entry->file_size());
1860 EXPECT_TRUE(Exists(entry->file_id())); 1863 EXPECT_TRUE(Exists(entry->file_id()));
1861 ASSERT_TRUE(!upload_progress_values.empty()); 1864 ASSERT_TRUE(!upload_progress_values.empty());
1862 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1865 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1863 EXPECT_LE(0, upload_progress_values.front().first); 1866 EXPECT_LE(0, upload_progress_values.front().first);
1864 EXPECT_GE(static_cast<int64>(contents.size() - contents.size() / 2), 1867 EXPECT_GE(static_cast<int64_t>(contents.size() - contents.size() / 2),
1865 upload_progress_values.back().first); 1868 upload_progress_values.back().first);
1866 EXPECT_EQ(base::MD5String(contents), entry->md5_checksum()); 1869 EXPECT_EQ(base::MD5String(contents), entry->md5_checksum());
1867 } 1870 }
1868 1871
1869 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { 1872 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
1870 base::ScopedTempDir temp_dir; 1873 base::ScopedTempDir temp_dir;
1871 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1874 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1872 base::FilePath local_file_path = 1875 base::FilePath local_file_path =
1873 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo")); 1876 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo"));
1874 std::string contents("hogefugapiyo"); 1877 std::string contents("hogefugapiyo");
(...skipping 24 matching lines...) Expand all
1899 test_util::CreateCopyResultCallback(&response, &entry), 1902 test_util::CreateCopyResultCallback(&response, &entry),
1900 base::Bind(&test_util::AppendProgressCallbackResult, 1903 base::Bind(&test_util::AppendProgressCallbackResult,
1901 &upload_progress_values)); 1904 &upload_progress_values));
1902 base::RunLoop().RunUntilIdle(); 1905 base::RunLoop().RunUntilIdle();
1903 1906
1904 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1907 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1905 EXPECT_FALSE(entry.get()); 1908 EXPECT_FALSE(entry.get());
1906 ASSERT_TRUE(!upload_progress_values.empty()); 1909 ASSERT_TRUE(!upload_progress_values.empty());
1907 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1910 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1908 EXPECT_LE(0, upload_progress_values.front().first); 1911 EXPECT_LE(0, upload_progress_values.front().first);
1909 EXPECT_GE(static_cast<int64>(contents.size() / 2), 1912 EXPECT_GE(static_cast<int64_t>(contents.size() / 2),
1910 upload_progress_values.back().first); 1913 upload_progress_values.back().first);
1911 1914
1912 upload_progress_values.clear(); 1915 upload_progress_values.clear();
1913 fake_service_.ResumeUpload( 1916 fake_service_.ResumeUpload(
1914 upload_location, 1917 upload_location,
1915 contents.size() / 2, contents.size(), contents.size(), "test/foo", 1918 contents.size() / 2, contents.size(), contents.size(), "test/foo",
1916 local_file_path, 1919 local_file_path,
1917 test_util::CreateCopyResultCallback(&response, &entry), 1920 test_util::CreateCopyResultCallback(&response, &entry),
1918 base::Bind(&test_util::AppendProgressCallbackResult, 1921 base::Bind(&test_util::AppendProgressCallbackResult,
1919 &upload_progress_values)); 1922 &upload_progress_values));
1920 base::RunLoop().RunUntilIdle(); 1923 base::RunLoop().RunUntilIdle();
1921 1924
1922 EXPECT_EQ(HTTP_CREATED, response.code); 1925 EXPECT_EQ(HTTP_CREATED, response.code);
1923 EXPECT_TRUE(entry.get()); 1926 EXPECT_TRUE(entry.get());
1924 EXPECT_EQ(static_cast<int64>(contents.size()), entry->file_size()); 1927 EXPECT_EQ(static_cast<int64_t>(contents.size()), entry->file_size());
1925 EXPECT_TRUE(Exists(entry->file_id())); 1928 EXPECT_TRUE(Exists(entry->file_id()));
1926 ASSERT_TRUE(!upload_progress_values.empty()); 1929 ASSERT_TRUE(!upload_progress_values.empty());
1927 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1930 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1928 EXPECT_LE(0, upload_progress_values.front().first); 1931 EXPECT_LE(0, upload_progress_values.front().first);
1929 EXPECT_GE(static_cast<int64>(contents.size() - contents.size() / 2), 1932 EXPECT_GE(static_cast<int64_t>(contents.size() - contents.size() / 2),
1930 upload_progress_values.back().first); 1933 upload_progress_values.back().first);
1931 EXPECT_EQ(base::MD5String(contents), entry->md5_checksum()); 1934 EXPECT_EQ(base::MD5String(contents), entry->md5_checksum());
1932 } 1935 }
1933 1936
1934 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) { 1937 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) {
1935 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1938 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1936 1939
1937 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1940 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1938 1941
1939 const std::string kContentType = "text/plain"; 1942 const std::string kContentType = "text/plain";
1940 const std::string kContentData = "This is some test content."; 1943 const std::string kContentData = "This is some test content.";
1941 const std::string kTitle = "new file"; 1944 const std::string kTitle = "new file";
1942 1945
1943 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1946 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1944 scoped_ptr<FileResource> entry; 1947 scoped_ptr<FileResource> entry;
1945 fake_service_.AddNewFile( 1948 fake_service_.AddNewFile(
1946 kContentType, 1949 kContentType,
1947 kContentData, 1950 kContentData,
1948 fake_service_.GetRootResourceId(), 1951 fake_service_.GetRootResourceId(),
1949 kTitle, 1952 kTitle,
1950 false, // shared_with_me 1953 false, // shared_with_me
1951 test_util::CreateCopyResultCallback(&error, &entry)); 1954 test_util::CreateCopyResultCallback(&error, &entry));
1952 base::RunLoop().RunUntilIdle(); 1955 base::RunLoop().RunUntilIdle();
1953 1956
1954 EXPECT_EQ(HTTP_CREATED, error); 1957 EXPECT_EQ(HTTP_CREATED, error);
1955 ASSERT_TRUE(entry); 1958 ASSERT_TRUE(entry);
1956 EXPECT_EQ(kContentType, entry->mime_type()); 1959 EXPECT_EQ(kContentType, entry->mime_type());
1957 EXPECT_EQ(static_cast<int64>(kContentData.size()), entry->file_size()); 1960 EXPECT_EQ(static_cast<int64_t>(kContentData.size()), entry->file_size());
1958 EXPECT_EQ("resource_id_1", entry->file_id()); 1961 EXPECT_EQ("resource_id_1", entry->file_id());
1959 EXPECT_EQ(kTitle, entry->title()); 1962 EXPECT_EQ(kTitle, entry->title());
1960 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); 1963 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId()));
1961 // Should be incremented as a new directory was created. 1964 // Should be incremented as a new directory was created.
1962 EXPECT_EQ(old_largest_change_id + 1, 1965 EXPECT_EQ(old_largest_change_id + 1,
1963 fake_service_.about_resource().largest_change_id()); 1966 fake_service_.about_resource().largest_change_id());
1964 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 1967 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1965 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); 1968 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum());
1966 } 1969 }
1967 1970
1968 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) { 1971 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) {
1969 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1972 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
1970 1973
1971 const std::string kContentType = "text/plain"; 1974 const std::string kContentType = "text/plain";
1972 const std::string kContentData = "This is some test content."; 1975 const std::string kContentData = "This is some test content.";
1973 const std::string kTitle = "new file"; 1976 const std::string kTitle = "new file";
1974 1977
1975 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 1978 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
1976 scoped_ptr<FileResource> entry; 1979 scoped_ptr<FileResource> entry;
1977 fake_service_.AddNewFile( 1980 fake_service_.AddNewFile(
1978 kContentType, 1981 kContentType,
1979 kContentData, 1982 kContentData,
1980 fake_service_.GetRootResourceId(), 1983 fake_service_.GetRootResourceId(),
1981 kTitle, 1984 kTitle,
1982 false, // shared_with_me 1985 false, // shared_with_me
1983 test_util::CreateCopyResultCallback(&error, &entry)); 1986 test_util::CreateCopyResultCallback(&error, &entry));
1984 base::RunLoop().RunUntilIdle(); 1987 base::RunLoop().RunUntilIdle();
1985 1988
1986 EXPECT_EQ(HTTP_CREATED, error); 1989 EXPECT_EQ(HTTP_CREATED, error);
1987 ASSERT_TRUE(entry); 1990 ASSERT_TRUE(entry);
1988 EXPECT_EQ(kContentType, entry->mime_type()); 1991 EXPECT_EQ(kContentType, entry->mime_type());
1989 EXPECT_EQ(static_cast<int64>(kContentData.size()), entry->file_size()); 1992 EXPECT_EQ(static_cast<int64_t>(kContentData.size()), entry->file_size());
1990 EXPECT_EQ("resource_id_1", entry->file_id()); 1993 EXPECT_EQ("resource_id_1", entry->file_id());
1991 EXPECT_EQ(kTitle, entry->title()); 1994 EXPECT_EQ(kTitle, entry->title());
1992 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); 1995 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId()));
1993 // Should be incremented as a new directory was created. 1996 // Should be incremented as a new directory was created.
1994 EXPECT_EQ(old_largest_change_id + 1, 1997 EXPECT_EQ(old_largest_change_id + 1,
1995 fake_service_.about_resource().largest_change_id()); 1998 fake_service_.about_resource().largest_change_id());
1996 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 1999 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1997 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); 2000 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum());
1998 } 2001 }
1999 2002
2000 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) { 2003 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) {
2001 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 2004 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
2002 2005
2003 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 2006 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
2004 2007
2005 const std::string kContentType = "text/plain"; 2008 const std::string kContentType = "text/plain";
2006 const std::string kContentData = "This is some test content."; 2009 const std::string kContentData = "This is some test content.";
2007 const std::string kTitle = "new file"; 2010 const std::string kTitle = "new file";
2008 const std::string kParentResourceId = "1_folder_resource_id"; 2011 const std::string kParentResourceId = "1_folder_resource_id";
2009 2012
2010 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 2013 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
2011 scoped_ptr<FileResource> entry; 2014 scoped_ptr<FileResource> entry;
2012 fake_service_.AddNewFile( 2015 fake_service_.AddNewFile(
2013 kContentType, 2016 kContentType,
2014 kContentData, 2017 kContentData,
2015 kParentResourceId, 2018 kParentResourceId,
2016 kTitle, 2019 kTitle,
2017 false, // shared_with_me 2020 false, // shared_with_me
2018 test_util::CreateCopyResultCallback(&error, &entry)); 2021 test_util::CreateCopyResultCallback(&error, &entry));
2019 base::RunLoop().RunUntilIdle(); 2022 base::RunLoop().RunUntilIdle();
2020 2023
2021 EXPECT_EQ(HTTP_CREATED, error); 2024 EXPECT_EQ(HTTP_CREATED, error);
2022 ASSERT_TRUE(entry); 2025 ASSERT_TRUE(entry);
2023 EXPECT_EQ(kContentType, entry->mime_type()); 2026 EXPECT_EQ(kContentType, entry->mime_type());
2024 EXPECT_EQ(static_cast<int64>(kContentData.size()), entry->file_size()); 2027 EXPECT_EQ(static_cast<int64_t>(kContentData.size()), entry->file_size());
2025 EXPECT_EQ("resource_id_1", entry->file_id()); 2028 EXPECT_EQ("resource_id_1", entry->file_id());
2026 EXPECT_EQ(kTitle, entry->title()); 2029 EXPECT_EQ(kTitle, entry->title());
2027 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); 2030 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId));
2028 // Should be incremented as a new directory was created. 2031 // Should be incremented as a new directory was created.
2029 EXPECT_EQ(old_largest_change_id + 1, 2032 EXPECT_EQ(old_largest_change_id + 1,
2030 fake_service_.about_resource().largest_change_id()); 2033 fake_service_.about_resource().largest_change_id());
2031 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 2034 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
2032 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); 2035 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum());
2033 } 2036 }
2034 2037
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 EXPECT_FALSE(entry); 2081 EXPECT_FALSE(entry);
2079 } 2082 }
2080 2083
2081 TEST_F(FakeDriveServiceTest, AddNewFile_SharedWithMeLabel) { 2084 TEST_F(FakeDriveServiceTest, AddNewFile_SharedWithMeLabel) {
2082 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 2085 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
2083 2086
2084 const std::string kContentType = "text/plain"; 2087 const std::string kContentType = "text/plain";
2085 const std::string kContentData = "This is some test content."; 2088 const std::string kContentData = "This is some test content.";
2086 const std::string kTitle = "new file"; 2089 const std::string kTitle = "new file";
2087 2090
2088 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 2091 int64_t old_largest_change_id = GetLargestChangeByAboutResource();
2089 2092
2090 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 2093 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
2091 scoped_ptr<FileResource> entry; 2094 scoped_ptr<FileResource> entry;
2092 fake_service_.AddNewFile( 2095 fake_service_.AddNewFile(
2093 kContentType, 2096 kContentType,
2094 kContentData, 2097 kContentData,
2095 fake_service_.GetRootResourceId(), 2098 fake_service_.GetRootResourceId(),
2096 kTitle, 2099 kTitle,
2097 true, // shared_with_me 2100 true, // shared_with_me
2098 test_util::CreateCopyResultCallback(&error, &entry)); 2101 test_util::CreateCopyResultCallback(&error, &entry));
2099 base::RunLoop().RunUntilIdle(); 2102 base::RunLoop().RunUntilIdle();
2100 2103
2101 EXPECT_EQ(HTTP_CREATED, error); 2104 EXPECT_EQ(HTTP_CREATED, error);
2102 ASSERT_TRUE(entry); 2105 ASSERT_TRUE(entry);
2103 EXPECT_EQ(kContentType, entry->mime_type()); 2106 EXPECT_EQ(kContentType, entry->mime_type());
2104 EXPECT_EQ(static_cast<int64>(kContentData.size()), entry->file_size()); 2107 EXPECT_EQ(static_cast<int64_t>(kContentData.size()), entry->file_size());
2105 EXPECT_EQ("resource_id_1", entry->file_id()); 2108 EXPECT_EQ("resource_id_1", entry->file_id());
2106 EXPECT_EQ(kTitle, entry->title()); 2109 EXPECT_EQ(kTitle, entry->title());
2107 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); 2110 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId()));
2108 EXPECT_FALSE(entry->shared_with_me_date().is_null()); 2111 EXPECT_FALSE(entry->shared_with_me_date().is_null());
2109 // Should be incremented as a new directory was created. 2112 // Should be incremented as a new directory was created.
2110 EXPECT_EQ(old_largest_change_id + 1, 2113 EXPECT_EQ(old_largest_change_id + 1,
2111 fake_service_.about_resource().largest_change_id()); 2114 fake_service_.about_resource().largest_change_id());
2112 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 2115 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
2113 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); 2116 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum());
2114 } 2117 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 test_util::CreateCopyResultCallback(&error, &entry)); 2171 test_util::CreateCopyResultCallback(&error, &entry));
2169 base::RunLoop().RunUntilIdle(); 2172 base::RunLoop().RunUntilIdle();
2170 2173
2171 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 2174 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
2172 EXPECT_FALSE(entry); 2175 EXPECT_FALSE(entry);
2173 } 2176 }
2174 2177
2175 } // namespace 2178 } // namespace
2176 2179
2177 } // namespace drive 2180 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/service/fake_drive_service.cc ('k') | components/drive/sync/entry_revert_performer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698