OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/sync_file_system/drive_backend_v1/api_util.h" | 5 #include "chrome/browser/sync_file_system/drive_backend_v1/api_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 origin_root_id, | 108 origin_root_id, |
109 title, | 109 title, |
110 content_data, | 110 content_data, |
111 &file_resource_id)); | 111 &file_resource_id)); |
112 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 112 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
113 fake_drive_helper_->GetFileResource( | 113 fake_drive_helper_->GetFileResource( |
114 file_resource_id, | 114 file_resource_id, |
115 entry)); | 115 entry)); |
116 } | 116 } |
117 | 117 |
118 void VerifyTitleUniqueness(const std::string& parent_resource_id, | 118 void VerifyTitleUniqueness( |
119 const std::string& title, | 119 const std::string& parent_resource_id, |
120 const std::string& resource_id, | 120 const std::string& title, |
121 google_apis::DriveEntryKind kind) { | 121 const std::string& resource_id, |
| 122 google_apis::ResourceEntry::ResourceEntryKind kind) { |
122 ScopedVector<ResourceEntry> entries; | 123 ScopedVector<ResourceEntry> entries; |
123 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 124 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
124 fake_drive_helper_->SearchByTitle( | 125 fake_drive_helper_->SearchByTitle( |
125 parent_resource_id, title, &entries)); | 126 parent_resource_id, title, &entries)); |
126 ASSERT_EQ(1u, entries.size()); | 127 ASSERT_EQ(1u, entries.size()); |
127 EXPECT_EQ(resource_id, entries[0]->resource_id()); | 128 EXPECT_EQ(resource_id, entries[0]->resource_id()); |
128 EXPECT_EQ(kind, entries[0]->kind()); | 129 EXPECT_EQ(kind, entries[0]->kind()); |
129 } | 130 } |
130 | 131 |
131 void VerifyFileDeletion(const std::string& parent_resource_id, | 132 void VerifyFileDeletion(const std::string& parent_resource_id, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 api_util()->GetDriveDirectoryForSyncRoot( | 250 api_util()->GetDriveDirectoryForSyncRoot( |
250 base::Bind(&DidGetResourceID, &output)); | 251 base::Bind(&DidGetResourceID, &output)); |
251 base::MessageLoop::current()->RunUntilIdle(); | 252 base::MessageLoop::current()->RunUntilIdle(); |
252 | 253 |
253 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); | 254 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); |
254 EXPECT_FALSE(output.resource_id.empty()); | 255 EXPECT_FALSE(output.resource_id.empty()); |
255 | 256 |
256 VerifyTitleUniqueness(std::string(), // directory_resource_id | 257 VerifyTitleUniqueness(std::string(), // directory_resource_id |
257 APIUtil::GetSyncRootDirectoryName(), | 258 APIUtil::GetSyncRootDirectoryName(), |
258 output.resource_id, | 259 output.resource_id, |
259 google_apis::ENTRY_KIND_FOLDER); | 260 google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
260 } | 261 } |
261 | 262 |
262 void APIUtilTest::TestCreateSyncRoot_Conflict() { | 263 void APIUtilTest::TestCreateSyncRoot_Conflict() { |
263 fake_drive_service()->set_make_directory_conflict(true); | 264 fake_drive_service()->set_make_directory_conflict(true); |
264 | 265 |
265 Output output; | 266 Output output; |
266 api_util()->GetDriveDirectoryForSyncRoot( | 267 api_util()->GetDriveDirectoryForSyncRoot( |
267 base::Bind(&DidGetResourceID, &output)); | 268 base::Bind(&DidGetResourceID, &output)); |
268 base::MessageLoop::current()->RunUntilIdle(); | 269 base::MessageLoop::current()->RunUntilIdle(); |
269 | 270 |
270 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); | 271 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); |
271 EXPECT_FALSE(output.resource_id.empty()); | 272 EXPECT_FALSE(output.resource_id.empty()); |
272 | 273 |
273 // Verify that there is no duplicated directory on the remote side. | 274 // Verify that there is no duplicated directory on the remote side. |
274 VerifyTitleUniqueness(std::string(), // directory_resource_id | 275 VerifyTitleUniqueness(std::string(), // directory_resource_id |
275 APIUtil::GetSyncRootDirectoryName(), | 276 APIUtil::GetSyncRootDirectoryName(), |
276 output.resource_id, | 277 output.resource_id, |
277 google_apis::ENTRY_KIND_FOLDER); | 278 google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
278 } | 279 } |
279 | 280 |
280 void APIUtilTest::TestGetOriginDirectory() { | 281 void APIUtilTest::TestGetOriginDirectory() { |
281 const std::string sync_root_id = SetUpSyncRootDirectory(); | 282 const std::string sync_root_id = SetUpSyncRootDirectory(); |
282 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); | 283 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); |
283 | 284 |
284 Output output; | 285 Output output; |
285 api_util()->GetDriveDirectoryForOrigin( | 286 api_util()->GetDriveDirectoryForOrigin( |
286 sync_root_id, | 287 sync_root_id, |
287 GURL(kOrigin), | 288 GURL(kOrigin), |
(...skipping 13 matching lines...) Expand all Loading... |
301 GURL(kOrigin), | 302 GURL(kOrigin), |
302 base::Bind(&DidGetResourceID, &output)); | 303 base::Bind(&DidGetResourceID, &output)); |
303 base::MessageLoop::current()->RunUntilIdle(); | 304 base::MessageLoop::current()->RunUntilIdle(); |
304 | 305 |
305 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); | 306 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); |
306 EXPECT_FALSE(output.resource_id.empty()); | 307 EXPECT_FALSE(output.resource_id.empty()); |
307 | 308 |
308 VerifyTitleUniqueness(sync_root_id, | 309 VerifyTitleUniqueness(sync_root_id, |
309 kOriginDirectoryName, | 310 kOriginDirectoryName, |
310 output.resource_id, | 311 output.resource_id, |
311 google_apis::ENTRY_KIND_FOLDER); | 312 google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
312 } | 313 } |
313 | 314 |
314 void APIUtilTest::TestCreateOriginDirectory_Conflict() { | 315 void APIUtilTest::TestCreateOriginDirectory_Conflict() { |
315 fake_drive_service()->set_make_directory_conflict(true); | 316 fake_drive_service()->set_make_directory_conflict(true); |
316 const std::string sync_root_id = SetUpSyncRootDirectory(); | 317 const std::string sync_root_id = SetUpSyncRootDirectory(); |
317 | 318 |
318 Output output; | 319 Output output; |
319 api_util()->GetDriveDirectoryForOrigin( | 320 api_util()->GetDriveDirectoryForOrigin( |
320 sync_root_id, | 321 sync_root_id, |
321 GURL(kOrigin), | 322 GURL(kOrigin), |
322 base::Bind(&DidGetResourceID, &output)); | 323 base::Bind(&DidGetResourceID, &output)); |
323 base::MessageLoop::current()->RunUntilIdle(); | 324 base::MessageLoop::current()->RunUntilIdle(); |
324 | 325 |
325 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); | 326 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); |
326 EXPECT_FALSE(output.resource_id.empty()); | 327 EXPECT_FALSE(output.resource_id.empty()); |
327 | 328 |
328 // Verify that there is no duplicated directory on the remote side. | 329 // Verify that there is no duplicated directory on the remote side. |
329 VerifyTitleUniqueness(sync_root_id, | 330 VerifyTitleUniqueness(sync_root_id, |
330 kOriginDirectoryName, | 331 kOriginDirectoryName, |
331 output.resource_id, | 332 output.resource_id, |
332 google_apis::ENTRY_KIND_FOLDER); | 333 google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
333 } | 334 } |
334 | 335 |
335 void APIUtilTest::TestGetLargestChangeStamp() { | 336 void APIUtilTest::TestGetLargestChangeStamp() { |
336 Output output; | 337 Output output; |
337 api_util()->GetLargestChangeStamp( | 338 api_util()->GetLargestChangeStamp( |
338 base::Bind(&DidGetLargestChangeStamp, &output)); | 339 base::Bind(&DidGetLargestChangeStamp, &output)); |
339 base::MessageLoop::current()->RunUntilIdle(); | 340 base::MessageLoop::current()->RunUntilIdle(); |
340 | 341 |
341 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); | 342 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); |
342 EXPECT_EQ(fake_drive_service()->about_resource().largest_change_id(), | 343 EXPECT_EQ(fake_drive_service()->about_resource().largest_change_id(), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 kFileTitle, | 476 kFileTitle, |
476 base::Bind(&DidUploadFile, &output)); | 477 base::Bind(&DidUploadFile, &output)); |
477 base::MessageLoop::current()->RunUntilIdle(); | 478 base::MessageLoop::current()->RunUntilIdle(); |
478 | 479 |
479 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); | 480 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); |
480 EXPECT_TRUE(!output.resource_id.empty()); | 481 EXPECT_TRUE(!output.resource_id.empty()); |
481 | 482 |
482 VerifyTitleUniqueness(origin_root_id, | 483 VerifyTitleUniqueness(origin_root_id, |
483 kFileTitle, | 484 kFileTitle, |
484 output.resource_id, | 485 output.resource_id, |
485 google_apis::ENTRY_KIND_FILE); | 486 google_apis::ResourceEntry::ENTRY_KIND_FILE); |
486 } | 487 } |
487 | 488 |
488 void APIUtilTest::TestUploadNewFile_ConflictWithFile() { | 489 void APIUtilTest::TestUploadNewFile_ConflictWithFile() { |
489 const std::string kFileTitle = "test.txt"; | 490 const std::string kFileTitle = "test.txt"; |
490 const base::FilePath kLocalFilePath(FPL("/tmp/dir/file")); | 491 const base::FilePath kLocalFilePath(FPL("/tmp/dir/file")); |
491 const std::string sync_root_id = SetUpSyncRootDirectory(); | 492 const std::string sync_root_id = SetUpSyncRootDirectory(); |
492 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); | 493 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); |
493 | 494 |
494 fake_drive_uploader()->set_make_file_conflict(true); | 495 fake_drive_uploader()->set_make_file_conflict(true); |
495 | 496 |
496 Output output; | 497 Output output; |
497 api_util()->UploadNewFile( | 498 api_util()->UploadNewFile( |
498 origin_root_id, | 499 origin_root_id, |
499 kLocalFilePath, | 500 kLocalFilePath, |
500 kFileTitle, | 501 kFileTitle, |
501 base::Bind(&DidUploadFile, &output)); | 502 base::Bind(&DidUploadFile, &output)); |
502 base::MessageLoop::current()->RunUntilIdle(); | 503 base::MessageLoop::current()->RunUntilIdle(); |
503 | 504 |
504 // HTTP_CONFLICT error must be returned with empty resource_id. | 505 // HTTP_CONFLICT error must be returned with empty resource_id. |
505 EXPECT_EQ(google_apis::HTTP_CONFLICT, output.error); | 506 EXPECT_EQ(google_apis::HTTP_CONFLICT, output.error); |
506 EXPECT_TRUE(!output.resource_id.empty()); | 507 EXPECT_TRUE(!output.resource_id.empty()); |
507 | 508 |
508 // Verify that there is no duplicated file on the remote side. | 509 // Verify that there is no duplicated file on the remote side. |
509 VerifyTitleUniqueness(origin_root_id, | 510 VerifyTitleUniqueness(origin_root_id, |
510 kFileTitle, | 511 kFileTitle, |
511 output.resource_id, | 512 output.resource_id, |
512 google_apis::ENTRY_KIND_FILE); | 513 google_apis::ResourceEntry::ENTRY_KIND_FILE); |
513 } | 514 } |
514 | 515 |
515 void APIUtilTest::TestUploadExistingFile() { | 516 void APIUtilTest::TestUploadExistingFile() { |
516 const base::FilePath kLocalFilePath(FPL("/tmp/dir/file")); | 517 const base::FilePath kLocalFilePath(FPL("/tmp/dir/file")); |
517 const std::string kFileContent = "test content"; | 518 const std::string kFileContent = "test content"; |
518 const std::string kFileTitle = "test.txt"; | 519 const std::string kFileTitle = "test.txt"; |
519 const std::string sync_root_id = SetUpSyncRootDirectory(); | 520 const std::string sync_root_id = SetUpSyncRootDirectory(); |
520 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); | 521 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); |
521 | 522 |
522 scoped_ptr<FileResource> file; | 523 scoped_ptr<FileResource> file; |
523 SetUpFile(origin_root_id, kFileContent, kFileTitle, &file); | 524 SetUpFile(origin_root_id, kFileContent, kFileTitle, &file); |
524 | 525 |
525 Output output; | 526 Output output; |
526 api_util()->UploadExistingFile( | 527 api_util()->UploadExistingFile( |
527 file->file_id(), | 528 file->file_id(), |
528 file->md5_checksum(), | 529 file->md5_checksum(), |
529 kLocalFilePath, | 530 kLocalFilePath, |
530 base::Bind(&DidUploadFile, &output)); | 531 base::Bind(&DidUploadFile, &output)); |
531 base::MessageLoop::current()->RunUntilIdle(); | 532 base::MessageLoop::current()->RunUntilIdle(); |
532 | 533 |
533 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); | 534 EXPECT_EQ(google_apis::HTTP_SUCCESS, output.error); |
534 EXPECT_EQ(file->file_id(), output.resource_id); | 535 EXPECT_EQ(file->file_id(), output.resource_id); |
535 | 536 |
536 VerifyTitleUniqueness(origin_root_id, | 537 VerifyTitleUniqueness(origin_root_id, |
537 file->title(), | 538 file->title(), |
538 file->file_id(), | 539 file->file_id(), |
539 google_apis::ENTRY_KIND_FILE); | 540 google_apis::ResourceEntry::ENTRY_KIND_FILE); |
540 } | 541 } |
541 | 542 |
542 void APIUtilTest::TestUploadExistingFileInConflict() { | 543 void APIUtilTest::TestUploadExistingFileInConflict() { |
543 const base::FilePath kLocalFilePath(FPL("/tmp/dir/file")); | 544 const base::FilePath kLocalFilePath(FPL("/tmp/dir/file")); |
544 const std::string kFileContent = "test content"; | 545 const std::string kFileContent = "test content"; |
545 const std::string kFileTitle = "test.txt"; | 546 const std::string kFileTitle = "test.txt"; |
546 const std::string sync_root_id = SetUpSyncRootDirectory(); | 547 const std::string sync_root_id = SetUpSyncRootDirectory(); |
547 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); | 548 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); |
548 | 549 |
549 scoped_ptr<FileResource> file; | 550 scoped_ptr<FileResource> file; |
(...skipping 11 matching lines...) Expand all Loading... |
561 base::Bind(&DidUploadFile, &output)); | 562 base::Bind(&DidUploadFile, &output)); |
562 base::MessageLoop::current()->RunUntilIdle(); | 563 base::MessageLoop::current()->RunUntilIdle(); |
563 | 564 |
564 EXPECT_EQ(google_apis::HTTP_CONFLICT, output.error); | 565 EXPECT_EQ(google_apis::HTTP_CONFLICT, output.error); |
565 EXPECT_TRUE(output.resource_id.empty()); | 566 EXPECT_TRUE(output.resource_id.empty()); |
566 | 567 |
567 // Verify that there is no duplicated file on the remote side. | 568 // Verify that there is no duplicated file on the remote side. |
568 VerifyTitleUniqueness(origin_root_id, | 569 VerifyTitleUniqueness(origin_root_id, |
569 file->title(), | 570 file->title(), |
570 file->file_id(), | 571 file->file_id(), |
571 google_apis::ENTRY_KIND_FILE); | 572 google_apis::ResourceEntry::ENTRY_KIND_FILE); |
572 } | 573 } |
573 | 574 |
574 void APIUtilTest::TestDeleteFile() { | 575 void APIUtilTest::TestDeleteFile() { |
575 const std::string kFileContent = "test content"; | 576 const std::string kFileContent = "test content"; |
576 const std::string kFileTitle = "test.txt"; | 577 const std::string kFileTitle = "test.txt"; |
577 const std::string sync_root_id = SetUpSyncRootDirectory(); | 578 const std::string sync_root_id = SetUpSyncRootDirectory(); |
578 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); | 579 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); |
579 | 580 |
580 scoped_ptr<FileResource> file; | 581 scoped_ptr<FileResource> file; |
581 SetUpFile(origin_root_id, kFileContent, kFileTitle, &file); | 582 SetUpFile(origin_root_id, kFileContent, kFileTitle, &file); |
(...skipping 27 matching lines...) Expand all Loading... |
609 kExpectedRemoteFileMD5, | 610 kExpectedRemoteFileMD5, |
610 base::Bind(&DidDeleteFile, &error)); | 611 base::Bind(&DidDeleteFile, &error)); |
611 base::MessageLoop::current()->RunUntilIdle(); | 612 base::MessageLoop::current()->RunUntilIdle(); |
612 | 613 |
613 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); | 614 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); |
614 | 615 |
615 // Verify that the conflict file was not deleted on the remote side. | 616 // Verify that the conflict file was not deleted on the remote side. |
616 VerifyTitleUniqueness(origin_root_id, | 617 VerifyTitleUniqueness(origin_root_id, |
617 file->title(), | 618 file->title(), |
618 file->file_id(), | 619 file->file_id(), |
619 google_apis::ENTRY_KIND_FILE); | 620 google_apis::ResourceEntry::ENTRY_KIND_FILE); |
620 } | 621 } |
621 | 622 |
622 void APIUtilTest::TestCreateDirectory() { | 623 void APIUtilTest::TestCreateDirectory() { |
623 const std::string kDirectoryTitle("directory"); | 624 const std::string kDirectoryTitle("directory"); |
624 const std::string sync_root_id = SetUpSyncRootDirectory(); | 625 const std::string sync_root_id = SetUpSyncRootDirectory(); |
625 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); | 626 const std::string origin_root_id = SetUpOriginRootDirectory(sync_root_id); |
626 | 627 |
627 Output output; | 628 Output output; |
628 api_util()->CreateDirectory( | 629 api_util()->CreateDirectory( |
629 origin_root_id, | 630 origin_root_id, |
630 kDirectoryTitle, | 631 kDirectoryTitle, |
631 base::Bind(&DidGetResourceID, &output)); | 632 base::Bind(&DidGetResourceID, &output)); |
632 base::MessageLoop::current()->RunUntilIdle(); | 633 base::MessageLoop::current()->RunUntilIdle(); |
633 | 634 |
634 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); | 635 EXPECT_EQ(google_apis::HTTP_CREATED, output.error); |
635 EXPECT_FALSE(output.resource_id.empty()); | 636 EXPECT_FALSE(output.resource_id.empty()); |
636 | 637 |
637 VerifyTitleUniqueness(origin_root_id, | 638 VerifyTitleUniqueness(origin_root_id, |
638 kDirectoryTitle, | 639 kDirectoryTitle, |
639 output.resource_id, | 640 output.resource_id, |
640 google_apis::ENTRY_KIND_FOLDER); | 641 google_apis::ResourceEntry::ENTRY_KIND_FOLDER); |
641 } | 642 } |
642 | 643 |
643 TEST_F(APIUtilTest, GetSyncRoot) { | 644 TEST_F(APIUtilTest, GetSyncRoot) { |
644 ASSERT_FALSE(IsDriveAPIDisabled()); | 645 ASSERT_FALSE(IsDriveAPIDisabled()); |
645 TestGetSyncRoot(); | 646 TestGetSyncRoot(); |
646 } | 647 } |
647 | 648 |
648 TEST_F(APIUtilTest, GetSyncRoot_WAPI) { | 649 TEST_F(APIUtilTest, GetSyncRoot_WAPI) { |
649 ScopedDisableDriveAPI disable_drive_api; | 650 ScopedDisableDriveAPI disable_drive_api; |
650 TestGetSyncRoot(); | 651 TestGetSyncRoot(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 TestCreateDirectory(); | 816 TestCreateDirectory(); |
816 } | 817 } |
817 | 818 |
818 TEST_F(APIUtilTest, CreateDirectory_WAPI) { | 819 TEST_F(APIUtilTest, CreateDirectory_WAPI) { |
819 ScopedDisableDriveAPI disable_drive_api; | 820 ScopedDisableDriveAPI disable_drive_api; |
820 TestCreateDirectory(); | 821 TestCreateDirectory(); |
821 } | 822 } |
822 | 823 |
823 } // namespace drive_backend | 824 } // namespace drive_backend |
824 } // namespace sync_file_system | 825 } // namespace sync_file_system |
OLD | NEW |