OLD | NEW |
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/drive/fake_drive_service.h" | 5 #include "chrome/browser/drive/fake_drive_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 EXPECT_EQ(8U, file_list->items().size()); | 158 EXPECT_EQ(8U, file_list->items().size()); |
159 EXPECT_EQ(1, fake_service_.directory_load_count()); | 159 EXPECT_EQ(1, fake_service_.directory_load_count()); |
160 } | 160 } |
161 | 161 |
162 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_InNonRootDirectory) { | 162 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_InNonRootDirectory) { |
163 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 163 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
164 | 164 |
165 GDataErrorCode error = GDATA_OTHER_ERROR; | 165 GDataErrorCode error = GDATA_OTHER_ERROR; |
166 scoped_ptr<FileList> file_list; | 166 scoped_ptr<FileList> file_list; |
167 fake_service_.GetFileListInDirectory( | 167 fake_service_.GetFileListInDirectory( |
168 "folder:1_folder_resource_id", | 168 "1_folder_resource_id", |
169 test_util::CreateCopyResultCallback(&error, &file_list)); | 169 test_util::CreateCopyResultCallback(&error, &file_list)); |
170 base::RunLoop().RunUntilIdle(); | 170 base::RunLoop().RunUntilIdle(); |
171 | 171 |
172 EXPECT_EQ(HTTP_SUCCESS, error); | 172 EXPECT_EQ(HTTP_SUCCESS, error); |
173 ASSERT_TRUE(file_list); | 173 ASSERT_TRUE(file_list); |
174 // Do some sanity check. There is three entries in 1_folder_resource_id | 174 // Do some sanity check. There is three entries in 1_folder_resource_id |
175 // directory. | 175 // directory. |
176 EXPECT_EQ(3U, file_list->items().size()); | 176 EXPECT_EQ(3U, file_list->items().size()); |
177 EXPECT_EQ(1, fake_service_.directory_load_count()); | 177 EXPECT_EQ(1, fake_service_.directory_load_count()); |
178 } | 178 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 base::RunLoop().RunUntilIdle(); | 264 base::RunLoop().RunUntilIdle(); |
265 | 265 |
266 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 266 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
267 EXPECT_FALSE(file_list); | 267 EXPECT_FALSE(file_list); |
268 } | 268 } |
269 | 269 |
270 TEST_F(FakeDriveServiceTest, Search_Deleted) { | 270 TEST_F(FakeDriveServiceTest, Search_Deleted) { |
271 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 271 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
272 | 272 |
273 GDataErrorCode error = GDATA_OTHER_ERROR; | 273 GDataErrorCode error = GDATA_OTHER_ERROR; |
274 fake_service_.DeleteResource("file:2_file_resource_id", | 274 fake_service_.DeleteResource("2_file_resource_id", |
275 std::string(), // etag | 275 std::string(), // etag |
276 test_util::CreateCopyResultCallback(&error)); | 276 test_util::CreateCopyResultCallback(&error)); |
277 base::RunLoop().RunUntilIdle(); | 277 base::RunLoop().RunUntilIdle(); |
278 EXPECT_EQ(HTTP_NO_CONTENT, error); | 278 EXPECT_EQ(HTTP_NO_CONTENT, error); |
279 | 279 |
280 error = GDATA_OTHER_ERROR; | 280 error = GDATA_OTHER_ERROR; |
281 scoped_ptr<FileList> file_list; | 281 scoped_ptr<FileList> file_list; |
282 fake_service_.Search( | 282 fake_service_.Search( |
283 "File", // search_query | 283 "File", // search_query |
284 test_util::CreateCopyResultCallback(&error, &file_list)); | 284 test_util::CreateCopyResultCallback(&error, &file_list)); |
285 base::RunLoop().RunUntilIdle(); | 285 base::RunLoop().RunUntilIdle(); |
286 | 286 |
287 EXPECT_EQ(HTTP_SUCCESS, error); | 287 EXPECT_EQ(HTTP_SUCCESS, error); |
288 ASSERT_TRUE(file_list); | 288 ASSERT_TRUE(file_list); |
289 // Do some sanity check. There are 4 entries that contain "File" in their | 289 // Do some sanity check. There are 4 entries that contain "File" in their |
290 // titles and one of them is deleted. | 290 // titles and one of them is deleted. |
291 EXPECT_EQ(3U, file_list->items().size()); | 291 EXPECT_EQ(3U, file_list->items().size()); |
292 } | 292 } |
293 | 293 |
294 TEST_F(FakeDriveServiceTest, Search_Trashed) { | 294 TEST_F(FakeDriveServiceTest, Search_Trashed) { |
295 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 295 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
296 | 296 |
297 GDataErrorCode error = GDATA_OTHER_ERROR; | 297 GDataErrorCode error = GDATA_OTHER_ERROR; |
298 fake_service_.TrashResource("file:2_file_resource_id", | 298 fake_service_.TrashResource("2_file_resource_id", |
299 test_util::CreateCopyResultCallback(&error)); | 299 test_util::CreateCopyResultCallback(&error)); |
300 base::RunLoop().RunUntilIdle(); | 300 base::RunLoop().RunUntilIdle(); |
301 EXPECT_EQ(HTTP_SUCCESS, error); | 301 EXPECT_EQ(HTTP_SUCCESS, error); |
302 | 302 |
303 error = GDATA_OTHER_ERROR; | 303 error = GDATA_OTHER_ERROR; |
304 scoped_ptr<FileList> file_list; | 304 scoped_ptr<FileList> file_list; |
305 fake_service_.Search( | 305 fake_service_.Search( |
306 "File", // search_query | 306 "File", // search_query |
307 test_util::CreateCopyResultCallback(&error, &file_list)); | 307 test_util::CreateCopyResultCallback(&error, &file_list)); |
308 base::RunLoop().RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 654321, // start_changestamp | 425 654321, // start_changestamp |
426 test_util::CreateCopyResultCallback(&error, &change_list)); | 426 test_util::CreateCopyResultCallback(&error, &change_list)); |
427 base::RunLoop().RunUntilIdle(); | 427 base::RunLoop().RunUntilIdle(); |
428 | 428 |
429 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 429 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
430 EXPECT_FALSE(change_list); | 430 EXPECT_FALSE(change_list); |
431 } | 431 } |
432 | 432 |
433 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) { | 433 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) { |
434 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 434 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
435 ASSERT_TRUE(Exists("file:2_file_resource_id")); | 435 ASSERT_TRUE(Exists("2_file_resource_id")); |
436 const int64 old_largest_change_id = | 436 const int64 old_largest_change_id = |
437 fake_service_.about_resource().largest_change_id(); | 437 fake_service_.about_resource().largest_change_id(); |
438 | 438 |
439 GDataErrorCode error = GDATA_OTHER_ERROR; | 439 GDataErrorCode error = GDATA_OTHER_ERROR; |
440 fake_service_.DeleteResource("file:2_file_resource_id", | 440 fake_service_.DeleteResource("2_file_resource_id", |
441 std::string(), // etag | 441 std::string(), // etag |
442 test_util::CreateCopyResultCallback(&error)); | 442 test_util::CreateCopyResultCallback(&error)); |
443 base::RunLoop().RunUntilIdle(); | 443 base::RunLoop().RunUntilIdle(); |
444 ASSERT_EQ(HTTP_NO_CONTENT, error); | 444 ASSERT_EQ(HTTP_NO_CONTENT, error); |
445 ASSERT_FALSE(Exists("file:2_file_resource_id")); | 445 ASSERT_FALSE(Exists("2_file_resource_id")); |
446 | 446 |
447 // Get the resource list newer than old_largest_change_id. | 447 // Get the resource list newer than old_largest_change_id. |
448 error = GDATA_OTHER_ERROR; | 448 error = GDATA_OTHER_ERROR; |
449 scoped_ptr<ChangeList> change_list; | 449 scoped_ptr<ChangeList> change_list; |
450 fake_service_.GetChangeList( | 450 fake_service_.GetChangeList( |
451 old_largest_change_id + 1, | 451 old_largest_change_id + 1, |
452 test_util::CreateCopyResultCallback(&error, &change_list)); | 452 test_util::CreateCopyResultCallback(&error, &change_list)); |
453 base::RunLoop().RunUntilIdle(); | 453 base::RunLoop().RunUntilIdle(); |
454 | 454 |
455 EXPECT_EQ(HTTP_SUCCESS, error); | 455 EXPECT_EQ(HTTP_SUCCESS, error); |
456 ASSERT_TRUE(change_list); | 456 ASSERT_TRUE(change_list); |
457 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), | 457 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), |
458 change_list->largest_change_id()); | 458 change_list->largest_change_id()); |
459 // The result should only contain the deleted file. | 459 // The result should only contain the deleted file. |
460 ASSERT_EQ(1U, change_list->items().size()); | 460 ASSERT_EQ(1U, change_list->items().size()); |
461 const ChangeResource& item = *change_list->items()[0]; | 461 const ChangeResource& item = *change_list->items()[0]; |
462 EXPECT_EQ("file:2_file_resource_id", item.file_id()); | 462 EXPECT_EQ("2_file_resource_id", item.file_id()); |
463 EXPECT_FALSE(item.file()); | 463 EXPECT_FALSE(item.file()); |
464 EXPECT_TRUE(item.is_deleted()); | 464 EXPECT_TRUE(item.is_deleted()); |
465 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 465 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
466 } | 466 } |
467 | 467 |
468 TEST_F(FakeDriveServiceTest, GetChangeList_TrashedEntry) { | 468 TEST_F(FakeDriveServiceTest, GetChangeList_TrashedEntry) { |
469 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 469 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
470 ASSERT_TRUE(Exists("file:2_file_resource_id")); | 470 ASSERT_TRUE(Exists("2_file_resource_id")); |
471 const int64 old_largest_change_id = | 471 const int64 old_largest_change_id = |
472 fake_service_.about_resource().largest_change_id(); | 472 fake_service_.about_resource().largest_change_id(); |
473 | 473 |
474 GDataErrorCode error = GDATA_OTHER_ERROR; | 474 GDataErrorCode error = GDATA_OTHER_ERROR; |
475 fake_service_.TrashResource("file:2_file_resource_id", | 475 fake_service_.TrashResource("2_file_resource_id", |
476 test_util::CreateCopyResultCallback(&error)); | 476 test_util::CreateCopyResultCallback(&error)); |
477 base::RunLoop().RunUntilIdle(); | 477 base::RunLoop().RunUntilIdle(); |
478 ASSERT_EQ(HTTP_SUCCESS, error); | 478 ASSERT_EQ(HTTP_SUCCESS, error); |
479 ASSERT_FALSE(Exists("file:2_file_resource_id")); | 479 ASSERT_FALSE(Exists("2_file_resource_id")); |
480 | 480 |
481 // Get the resource list newer than old_largest_change_id. | 481 // Get the resource list newer than old_largest_change_id. |
482 error = GDATA_OTHER_ERROR; | 482 error = GDATA_OTHER_ERROR; |
483 scoped_ptr<ChangeList> change_list; | 483 scoped_ptr<ChangeList> change_list; |
484 fake_service_.GetChangeList( | 484 fake_service_.GetChangeList( |
485 old_largest_change_id + 1, | 485 old_largest_change_id + 1, |
486 test_util::CreateCopyResultCallback(&error, &change_list)); | 486 test_util::CreateCopyResultCallback(&error, &change_list)); |
487 base::RunLoop().RunUntilIdle(); | 487 base::RunLoop().RunUntilIdle(); |
488 | 488 |
489 EXPECT_EQ(HTTP_SUCCESS, error); | 489 EXPECT_EQ(HTTP_SUCCESS, error); |
490 ASSERT_TRUE(change_list); | 490 ASSERT_TRUE(change_list); |
491 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), | 491 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), |
492 change_list->largest_change_id()); | 492 change_list->largest_change_id()); |
493 // The result should only contain the trashed file. | 493 // The result should only contain the trashed file. |
494 ASSERT_EQ(1U, change_list->items().size()); | 494 ASSERT_EQ(1U, change_list->items().size()); |
495 const ChangeResource& item = *change_list->items()[0]; | 495 const ChangeResource& item = *change_list->items()[0]; |
496 EXPECT_EQ("file:2_file_resource_id", item.file_id()); | 496 EXPECT_EQ("2_file_resource_id", item.file_id()); |
497 ASSERT_TRUE(item.file()); | 497 ASSERT_TRUE(item.file()); |
498 EXPECT_TRUE(item.file()->labels().is_trashed()); | 498 EXPECT_TRUE(item.file()->labels().is_trashed()); |
499 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 499 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
500 } | 500 } |
501 | 501 |
502 TEST_F(FakeDriveServiceTest, GetRemainingFileList_GetAllFileList) { | 502 TEST_F(FakeDriveServiceTest, GetRemainingFileList_GetAllFileList) { |
503 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 503 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
504 fake_service_.set_default_max_results(6); | 504 fake_service_.set_default_max_results(6); |
505 | 505 |
506 GDataErrorCode error = GDATA_OTHER_ERROR; | 506 GDataErrorCode error = GDATA_OTHER_ERROR; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 test_util::CreateCopyResultCallback(&error, &app_list)); | 757 test_util::CreateCopyResultCallback(&error, &app_list)); |
758 base::RunLoop().RunUntilIdle(); | 758 base::RunLoop().RunUntilIdle(); |
759 | 759 |
760 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 760 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
761 EXPECT_FALSE(app_list); | 761 EXPECT_FALSE(app_list); |
762 } | 762 } |
763 | 763 |
764 TEST_F(FakeDriveServiceTest, GetFileResource_ExistingFile) { | 764 TEST_F(FakeDriveServiceTest, GetFileResource_ExistingFile) { |
765 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 765 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
766 | 766 |
767 const std::string kResourceId = "file:2_file_resource_id"; | 767 const std::string kResourceId = "2_file_resource_id"; |
768 GDataErrorCode error = GDATA_OTHER_ERROR; | 768 GDataErrorCode error = GDATA_OTHER_ERROR; |
769 scoped_ptr<FileResource> entry; | 769 scoped_ptr<FileResource> entry; |
770 fake_service_.GetFileResource( | 770 fake_service_.GetFileResource( |
771 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); | 771 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); |
772 base::RunLoop().RunUntilIdle(); | 772 base::RunLoop().RunUntilIdle(); |
773 | 773 |
774 EXPECT_EQ(HTTP_SUCCESS, error); | 774 EXPECT_EQ(HTTP_SUCCESS, error); |
775 ASSERT_TRUE(entry); | 775 ASSERT_TRUE(entry); |
776 // Do some sanity check. | 776 // Do some sanity check. |
777 EXPECT_EQ(kResourceId, entry->file_id()); | 777 EXPECT_EQ(kResourceId, entry->file_id()); |
778 } | 778 } |
779 | 779 |
780 TEST_F(FakeDriveServiceTest, GetFileResource_NonexistingFile) { | 780 TEST_F(FakeDriveServiceTest, GetFileResource_NonexistingFile) { |
781 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 781 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
782 | 782 |
783 const std::string kResourceId = "file:nonexisting_resource_id"; | 783 const std::string kResourceId = "nonexisting_resource_id"; |
784 GDataErrorCode error = GDATA_OTHER_ERROR; | 784 GDataErrorCode error = GDATA_OTHER_ERROR; |
785 scoped_ptr<FileResource> entry; | 785 scoped_ptr<FileResource> entry; |
786 fake_service_.GetFileResource( | 786 fake_service_.GetFileResource( |
787 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); | 787 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); |
788 base::RunLoop().RunUntilIdle(); | 788 base::RunLoop().RunUntilIdle(); |
789 | 789 |
790 EXPECT_EQ(HTTP_NOT_FOUND, error); | 790 EXPECT_EQ(HTTP_NOT_FOUND, error); |
791 ASSERT_FALSE(entry); | 791 ASSERT_FALSE(entry); |
792 } | 792 } |
793 | 793 |
794 TEST_F(FakeDriveServiceTest, GetFileResource_Offline) { | 794 TEST_F(FakeDriveServiceTest, GetFileResource_Offline) { |
795 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 795 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
796 fake_service_.set_offline(true); | 796 fake_service_.set_offline(true); |
797 | 797 |
798 const std::string kResourceId = "file:2_file_resource_id"; | 798 const std::string kResourceId = "2_file_resource_id"; |
799 GDataErrorCode error = GDATA_OTHER_ERROR; | 799 GDataErrorCode error = GDATA_OTHER_ERROR; |
800 scoped_ptr<FileResource> entry; | 800 scoped_ptr<FileResource> entry; |
801 fake_service_.GetFileResource( | 801 fake_service_.GetFileResource( |
802 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); | 802 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); |
803 base::RunLoop().RunUntilIdle(); | 803 base::RunLoop().RunUntilIdle(); |
804 | 804 |
805 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 805 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
806 EXPECT_FALSE(entry); | 806 EXPECT_FALSE(entry); |
807 } | 807 } |
808 | 808 |
809 TEST_F(FakeDriveServiceTest, GetShareUrl) { | 809 TEST_F(FakeDriveServiceTest, GetShareUrl) { |
810 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 810 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
811 | 811 |
812 const std::string kResourceId = "file:2_file_resource_id"; | 812 const std::string kResourceId = "2_file_resource_id"; |
813 GDataErrorCode error = GDATA_OTHER_ERROR; | 813 GDataErrorCode error = GDATA_OTHER_ERROR; |
814 GURL share_url; | 814 GURL share_url; |
815 fake_service_.GetShareUrl( | 815 fake_service_.GetShareUrl( |
816 kResourceId, | 816 kResourceId, |
817 GURL(), // embed origin | 817 GURL(), // embed origin |
818 test_util::CreateCopyResultCallback(&error, &share_url)); | 818 test_util::CreateCopyResultCallback(&error, &share_url)); |
819 base::RunLoop().RunUntilIdle(); | 819 base::RunLoop().RunUntilIdle(); |
820 | 820 |
821 EXPECT_EQ(HTTP_SUCCESS, error); | 821 EXPECT_EQ(HTTP_SUCCESS, error); |
822 EXPECT_FALSE(share_url.is_empty()); | 822 EXPECT_FALSE(share_url.is_empty()); |
823 } | 823 } |
824 | 824 |
825 TEST_F(FakeDriveServiceTest, DeleteResource_ExistingFile) { | 825 TEST_F(FakeDriveServiceTest, DeleteResource_ExistingFile) { |
826 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 826 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
827 | 827 |
828 // Resource "file:2_file_resource_id" should now exist. | 828 // Resource "2_file_resource_id" should now exist. |
829 ASSERT_TRUE(Exists("file:2_file_resource_id")); | 829 ASSERT_TRUE(Exists("2_file_resource_id")); |
830 | 830 |
831 GDataErrorCode error = GDATA_OTHER_ERROR; | 831 GDataErrorCode error = GDATA_OTHER_ERROR; |
832 fake_service_.DeleteResource("file:2_file_resource_id", | 832 fake_service_.DeleteResource("2_file_resource_id", |
833 std::string(), // etag | 833 std::string(), // etag |
834 test_util::CreateCopyResultCallback(&error)); | 834 test_util::CreateCopyResultCallback(&error)); |
835 base::RunLoop().RunUntilIdle(); | 835 base::RunLoop().RunUntilIdle(); |
836 | 836 |
837 EXPECT_EQ(HTTP_NO_CONTENT, error); | 837 EXPECT_EQ(HTTP_NO_CONTENT, error); |
838 // Resource "file:2_file_resource_id" should be gone now. | 838 // Resource "2_file_resource_id" should be gone now. |
839 EXPECT_FALSE(Exists("file:2_file_resource_id")); | 839 EXPECT_FALSE(Exists("2_file_resource_id")); |
840 | 840 |
841 error = GDATA_OTHER_ERROR; | 841 error = GDATA_OTHER_ERROR; |
842 fake_service_.DeleteResource("file:2_file_resource_id", | 842 fake_service_.DeleteResource("2_file_resource_id", |
843 std::string(), // etag | 843 std::string(), // etag |
844 test_util::CreateCopyResultCallback(&error)); | 844 test_util::CreateCopyResultCallback(&error)); |
845 base::RunLoop().RunUntilIdle(); | 845 base::RunLoop().RunUntilIdle(); |
846 EXPECT_EQ(HTTP_NOT_FOUND, error); | 846 EXPECT_EQ(HTTP_NOT_FOUND, error); |
847 EXPECT_FALSE(Exists("file:2_file_resource_id")); | 847 EXPECT_FALSE(Exists("2_file_resource_id")); |
848 } | 848 } |
849 | 849 |
850 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) { | 850 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) { |
851 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 851 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
852 | 852 |
853 GDataErrorCode error = GDATA_OTHER_ERROR; | 853 GDataErrorCode error = GDATA_OTHER_ERROR; |
854 fake_service_.DeleteResource("file:nonexisting_resource_id", | 854 fake_service_.DeleteResource("nonexisting_resource_id", |
855 std::string(), // etag | 855 std::string(), // etag |
856 test_util::CreateCopyResultCallback(&error)); | 856 test_util::CreateCopyResultCallback(&error)); |
857 base::RunLoop().RunUntilIdle(); | 857 base::RunLoop().RunUntilIdle(); |
858 | 858 |
859 EXPECT_EQ(HTTP_NOT_FOUND, error); | 859 EXPECT_EQ(HTTP_NOT_FOUND, error); |
860 } | 860 } |
861 | 861 |
862 TEST_F(FakeDriveServiceTest, DeleteResource_ETagMatch) { | 862 TEST_F(FakeDriveServiceTest, DeleteResource_ETagMatch) { |
863 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 863 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
864 | 864 |
865 // Resource "file:2_file_resource_id" should now exist. | 865 // Resource "2_file_resource_id" should now exist. |
866 scoped_ptr<FileResource> entry = FindEntry("file:2_file_resource_id"); | 866 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
867 ASSERT_TRUE(entry); | 867 ASSERT_TRUE(entry); |
868 ASSERT_FALSE(entry->labels().is_trashed()); | 868 ASSERT_FALSE(entry->labels().is_trashed()); |
869 ASSERT_FALSE(entry->etag().empty()); | 869 ASSERT_FALSE(entry->etag().empty()); |
870 | 870 |
871 GDataErrorCode error = GDATA_OTHER_ERROR; | 871 GDataErrorCode error = GDATA_OTHER_ERROR; |
872 fake_service_.DeleteResource("file:2_file_resource_id", | 872 fake_service_.DeleteResource("2_file_resource_id", |
873 entry->etag() + "_mismatch", | 873 entry->etag() + "_mismatch", |
874 test_util::CreateCopyResultCallback(&error)); | 874 test_util::CreateCopyResultCallback(&error)); |
875 base::RunLoop().RunUntilIdle(); | 875 base::RunLoop().RunUntilIdle(); |
876 | 876 |
877 EXPECT_EQ(HTTP_PRECONDITION, error); | 877 EXPECT_EQ(HTTP_PRECONDITION, error); |
878 // Resource "file:2_file_resource_id" should still exist. | 878 // Resource "2_file_resource_id" should still exist. |
879 EXPECT_TRUE(Exists("file:2_file_resource_id")); | 879 EXPECT_TRUE(Exists("2_file_resource_id")); |
880 | 880 |
881 error = GDATA_OTHER_ERROR; | 881 error = GDATA_OTHER_ERROR; |
882 fake_service_.DeleteResource("file:2_file_resource_id", | 882 fake_service_.DeleteResource("2_file_resource_id", |
883 entry->etag(), | 883 entry->etag(), |
884 test_util::CreateCopyResultCallback(&error)); | 884 test_util::CreateCopyResultCallback(&error)); |
885 base::RunLoop().RunUntilIdle(); | 885 base::RunLoop().RunUntilIdle(); |
886 EXPECT_EQ(HTTP_NO_CONTENT, error); | 886 EXPECT_EQ(HTTP_NO_CONTENT, error); |
887 // Resource "file:2_file_resource_id" should be gone now. | 887 // Resource "2_file_resource_id" should be gone now. |
888 EXPECT_FALSE(Exists("file:2_file_resource_id")); | 888 EXPECT_FALSE(Exists("2_file_resource_id")); |
889 } | 889 } |
890 | 890 |
891 TEST_F(FakeDriveServiceTest, DeleteResource_Offline) { | 891 TEST_F(FakeDriveServiceTest, DeleteResource_Offline) { |
892 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 892 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
893 fake_service_.set_offline(true); | 893 fake_service_.set_offline(true); |
894 | 894 |
895 GDataErrorCode error = GDATA_OTHER_ERROR; | 895 GDataErrorCode error = GDATA_OTHER_ERROR; |
896 fake_service_.DeleteResource("file:2_file_resource_id", | 896 fake_service_.DeleteResource("2_file_resource_id", |
897 std::string(), // etag | 897 std::string(), // etag |
898 test_util::CreateCopyResultCallback(&error)); | 898 test_util::CreateCopyResultCallback(&error)); |
899 base::RunLoop().RunUntilIdle(); | 899 base::RunLoop().RunUntilIdle(); |
900 | 900 |
901 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 901 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
902 } | 902 } |
903 | 903 |
904 TEST_F(FakeDriveServiceTest, TrashResource_ExistingFile) { | 904 TEST_F(FakeDriveServiceTest, TrashResource_ExistingFile) { |
905 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 905 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
906 | 906 |
907 // Resource "file:2_file_resource_id" should now exist. | 907 // Resource "2_file_resource_id" should now exist. |
908 ASSERT_TRUE(Exists("file:2_file_resource_id")); | 908 ASSERT_TRUE(Exists("2_file_resource_id")); |
909 | 909 |
910 GDataErrorCode error = GDATA_OTHER_ERROR; | 910 GDataErrorCode error = GDATA_OTHER_ERROR; |
911 fake_service_.TrashResource("file:2_file_resource_id", | 911 fake_service_.TrashResource("2_file_resource_id", |
912 test_util::CreateCopyResultCallback(&error)); | 912 test_util::CreateCopyResultCallback(&error)); |
913 base::RunLoop().RunUntilIdle(); | 913 base::RunLoop().RunUntilIdle(); |
914 | 914 |
915 EXPECT_EQ(HTTP_SUCCESS, error); | 915 EXPECT_EQ(HTTP_SUCCESS, error); |
916 // Resource "file:2_file_resource_id" should be gone now. | 916 // Resource "2_file_resource_id" should be gone now. |
917 EXPECT_FALSE(Exists("file:2_file_resource_id")); | 917 EXPECT_FALSE(Exists("2_file_resource_id")); |
918 | 918 |
919 error = GDATA_OTHER_ERROR; | 919 error = GDATA_OTHER_ERROR; |
920 fake_service_.TrashResource("file:2_file_resource_id", | 920 fake_service_.TrashResource("2_file_resource_id", |
921 test_util::CreateCopyResultCallback(&error)); | 921 test_util::CreateCopyResultCallback(&error)); |
922 base::RunLoop().RunUntilIdle(); | 922 base::RunLoop().RunUntilIdle(); |
923 EXPECT_EQ(HTTP_NOT_FOUND, error); | 923 EXPECT_EQ(HTTP_NOT_FOUND, error); |
924 EXPECT_FALSE(Exists("file:2_file_resource_id")); | 924 EXPECT_FALSE(Exists("2_file_resource_id")); |
925 } | 925 } |
926 | 926 |
927 TEST_F(FakeDriveServiceTest, TrashResource_NonexistingFile) { | 927 TEST_F(FakeDriveServiceTest, TrashResource_NonexistingFile) { |
928 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 928 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
929 | 929 |
930 GDataErrorCode error = GDATA_OTHER_ERROR; | 930 GDataErrorCode error = GDATA_OTHER_ERROR; |
931 fake_service_.TrashResource("file:nonexisting_resource_id", | 931 fake_service_.TrashResource("nonexisting_resource_id", |
932 test_util::CreateCopyResultCallback(&error)); | 932 test_util::CreateCopyResultCallback(&error)); |
933 base::RunLoop().RunUntilIdle(); | 933 base::RunLoop().RunUntilIdle(); |
934 | 934 |
935 EXPECT_EQ(HTTP_NOT_FOUND, error); | 935 EXPECT_EQ(HTTP_NOT_FOUND, error); |
936 } | 936 } |
937 | 937 |
938 TEST_F(FakeDriveServiceTest, TrashResource_Offline) { | 938 TEST_F(FakeDriveServiceTest, TrashResource_Offline) { |
939 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 939 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
940 fake_service_.set_offline(true); | 940 fake_service_.set_offline(true); |
941 | 941 |
942 GDataErrorCode error = GDATA_OTHER_ERROR; | 942 GDataErrorCode error = GDATA_OTHER_ERROR; |
943 fake_service_.TrashResource("file:2_file_resource_id", | 943 fake_service_.TrashResource("2_file_resource_id", |
944 test_util::CreateCopyResultCallback(&error)); | 944 test_util::CreateCopyResultCallback(&error)); |
945 base::RunLoop().RunUntilIdle(); | 945 base::RunLoop().RunUntilIdle(); |
946 | 946 |
947 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 947 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
948 } | 948 } |
949 | 949 |
950 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { | 950 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { |
951 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 951 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
952 | 952 |
953 base::ScopedTempDir temp_dir; | 953 base::ScopedTempDir temp_dir; |
954 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 954 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
955 | 955 |
956 std::vector<test_util::ProgressInfo> download_progress_values; | 956 std::vector<test_util::ProgressInfo> download_progress_values; |
957 | 957 |
958 const base::FilePath kOutputFilePath = | 958 const base::FilePath kOutputFilePath = |
959 temp_dir.path().AppendASCII("whatever.txt"); | 959 temp_dir.path().AppendASCII("whatever.txt"); |
960 GDataErrorCode error = GDATA_OTHER_ERROR; | 960 GDataErrorCode error = GDATA_OTHER_ERROR; |
961 base::FilePath output_file_path; | 961 base::FilePath output_file_path; |
962 test_util::TestGetContentCallback get_content_callback; | 962 test_util::TestGetContentCallback get_content_callback; |
963 fake_service_.DownloadFile( | 963 fake_service_.DownloadFile( |
964 kOutputFilePath, | 964 kOutputFilePath, |
965 "file:2_file_resource_id", | 965 "2_file_resource_id", |
966 test_util::CreateCopyResultCallback(&error, &output_file_path), | 966 test_util::CreateCopyResultCallback(&error, &output_file_path), |
967 get_content_callback.callback(), | 967 get_content_callback.callback(), |
968 base::Bind(&test_util::AppendProgressCallbackResult, | 968 base::Bind(&test_util::AppendProgressCallbackResult, |
969 &download_progress_values)); | 969 &download_progress_values)); |
970 base::RunLoop().RunUntilIdle(); | 970 base::RunLoop().RunUntilIdle(); |
971 | 971 |
972 EXPECT_EQ(HTTP_SUCCESS, error); | 972 EXPECT_EQ(HTTP_SUCCESS, error); |
973 EXPECT_EQ(output_file_path, kOutputFilePath); | 973 EXPECT_EQ(output_file_path, kOutputFilePath); |
974 std::string content; | 974 std::string content; |
975 ASSERT_TRUE(base::ReadFileToString(output_file_path, &content)); | 975 ASSERT_TRUE(base::ReadFileToString(output_file_path, &content)); |
(...skipping 10 matching lines...) Expand all Loading... |
986 | 986 |
987 base::ScopedTempDir temp_dir; | 987 base::ScopedTempDir temp_dir; |
988 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 988 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
989 | 989 |
990 const base::FilePath kOutputFilePath = | 990 const base::FilePath kOutputFilePath = |
991 temp_dir.path().AppendASCII("whatever.txt"); | 991 temp_dir.path().AppendASCII("whatever.txt"); |
992 GDataErrorCode error = GDATA_OTHER_ERROR; | 992 GDataErrorCode error = GDATA_OTHER_ERROR; |
993 base::FilePath output_file_path; | 993 base::FilePath output_file_path; |
994 fake_service_.DownloadFile( | 994 fake_service_.DownloadFile( |
995 kOutputFilePath, | 995 kOutputFilePath, |
996 "file:non_existent_file_resource_id", | 996 "non_existent_file_resource_id", |
997 test_util::CreateCopyResultCallback(&error, &output_file_path), | 997 test_util::CreateCopyResultCallback(&error, &output_file_path), |
998 GetContentCallback(), | 998 GetContentCallback(), |
999 ProgressCallback()); | 999 ProgressCallback()); |
1000 base::RunLoop().RunUntilIdle(); | 1000 base::RunLoop().RunUntilIdle(); |
1001 | 1001 |
1002 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1002 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1003 } | 1003 } |
1004 | 1004 |
1005 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) { | 1005 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) { |
1006 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1006 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1007 fake_service_.set_offline(true); | 1007 fake_service_.set_offline(true); |
1008 | 1008 |
1009 base::ScopedTempDir temp_dir; | 1009 base::ScopedTempDir temp_dir; |
1010 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1010 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1011 | 1011 |
1012 const base::FilePath kOutputFilePath = | 1012 const base::FilePath kOutputFilePath = |
1013 temp_dir.path().AppendASCII("whatever.txt"); | 1013 temp_dir.path().AppendASCII("whatever.txt"); |
1014 GDataErrorCode error = GDATA_OTHER_ERROR; | 1014 GDataErrorCode error = GDATA_OTHER_ERROR; |
1015 base::FilePath output_file_path; | 1015 base::FilePath output_file_path; |
1016 fake_service_.DownloadFile( | 1016 fake_service_.DownloadFile( |
1017 kOutputFilePath, | 1017 kOutputFilePath, |
1018 "file:2_file_resource_id", | 1018 "2_file_resource_id", |
1019 test_util::CreateCopyResultCallback(&error, &output_file_path), | 1019 test_util::CreateCopyResultCallback(&error, &output_file_path), |
1020 GetContentCallback(), | 1020 GetContentCallback(), |
1021 ProgressCallback()); | 1021 ProgressCallback()); |
1022 base::RunLoop().RunUntilIdle(); | 1022 base::RunLoop().RunUntilIdle(); |
1023 | 1023 |
1024 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1024 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1025 } | 1025 } |
1026 | 1026 |
1027 TEST_F(FakeDriveServiceTest, CopyResource) { | 1027 TEST_F(FakeDriveServiceTest, CopyResource) { |
1028 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 1028 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
1029 | 1029 |
1030 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1030 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1031 | 1031 |
1032 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1032 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1033 | 1033 |
1034 const std::string kResourceId = "file:2_file_resource_id"; | 1034 const std::string kResourceId = "2_file_resource_id"; |
1035 const std::string kParentResourceId = "folder:2_folder_resource_id"; | 1035 const std::string kParentResourceId = "2_folder_resource_id"; |
1036 GDataErrorCode error = GDATA_OTHER_ERROR; | 1036 GDataErrorCode error = GDATA_OTHER_ERROR; |
1037 scoped_ptr<FileResource> entry; | 1037 scoped_ptr<FileResource> entry; |
1038 fake_service_.CopyResource( | 1038 fake_service_.CopyResource( |
1039 kResourceId, | 1039 kResourceId, |
1040 kParentResourceId, | 1040 kParentResourceId, |
1041 "new title", | 1041 "new title", |
1042 base::Time::FromUTCExploded(kModifiedDate), | 1042 base::Time::FromUTCExploded(kModifiedDate), |
1043 test_util::CreateCopyResultCallback(&error, &entry)); | 1043 test_util::CreateCopyResultCallback(&error, &entry)); |
1044 base::RunLoop().RunUntilIdle(); | 1044 base::RunLoop().RunUntilIdle(); |
1045 | 1045 |
1046 EXPECT_EQ(HTTP_SUCCESS, error); | 1046 EXPECT_EQ(HTTP_SUCCESS, error); |
1047 ASSERT_TRUE(entry); | 1047 ASSERT_TRUE(entry); |
1048 // The copied entry should have the new resource ID and the title. | 1048 // The copied entry should have the new resource ID and the title. |
1049 EXPECT_NE(kResourceId, entry->file_id()); | 1049 EXPECT_NE(kResourceId, entry->file_id()); |
1050 EXPECT_EQ("new title", entry->title()); | 1050 EXPECT_EQ("new title", entry->title()); |
1051 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate), entry->modified_date()); | 1051 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate), entry->modified_date()); |
1052 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); | 1052 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); |
1053 // Should be incremented as a new hosted document was created. | 1053 // Should be incremented as a new hosted document was created. |
1054 EXPECT_EQ(old_largest_change_id + 1, | 1054 EXPECT_EQ(old_largest_change_id + 1, |
1055 fake_service_.about_resource().largest_change_id()); | 1055 fake_service_.about_resource().largest_change_id()); |
1056 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1056 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1057 } | 1057 } |
1058 | 1058 |
1059 TEST_F(FakeDriveServiceTest, CopyResource_NonExisting) { | 1059 TEST_F(FakeDriveServiceTest, CopyResource_NonExisting) { |
1060 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1060 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1061 | 1061 |
1062 const std::string kResourceId = "document:nonexisting_resource_id"; | 1062 const std::string kResourceId = "nonexisting_resource_id"; |
1063 GDataErrorCode error = GDATA_OTHER_ERROR; | 1063 GDataErrorCode error = GDATA_OTHER_ERROR; |
1064 scoped_ptr<FileResource> entry; | 1064 scoped_ptr<FileResource> entry; |
1065 fake_service_.CopyResource( | 1065 fake_service_.CopyResource( |
1066 kResourceId, | 1066 kResourceId, |
1067 "folder:1_folder_resource_id", | 1067 "1_folder_resource_id", |
1068 "new title", | 1068 "new title", |
1069 base::Time(), | 1069 base::Time(), |
1070 test_util::CreateCopyResultCallback(&error, &entry)); | 1070 test_util::CreateCopyResultCallback(&error, &entry)); |
1071 base::RunLoop().RunUntilIdle(); | 1071 base::RunLoop().RunUntilIdle(); |
1072 | 1072 |
1073 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1073 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1074 } | 1074 } |
1075 | 1075 |
1076 TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) { | 1076 TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) { |
1077 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1077 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1078 | 1078 |
1079 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1079 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1080 | 1080 |
1081 const std::string kResourceId = "file:2_file_resource_id"; | 1081 const std::string kResourceId = "2_file_resource_id"; |
1082 GDataErrorCode error = GDATA_OTHER_ERROR; | 1082 GDataErrorCode error = GDATA_OTHER_ERROR; |
1083 scoped_ptr<FileResource> entry; | 1083 scoped_ptr<FileResource> entry; |
1084 fake_service_.CopyResource( | 1084 fake_service_.CopyResource( |
1085 kResourceId, | 1085 kResourceId, |
1086 std::string(), | 1086 std::string(), |
1087 "new title", | 1087 "new title", |
1088 base::Time(), | 1088 base::Time(), |
1089 test_util::CreateCopyResultCallback(&error, &entry)); | 1089 test_util::CreateCopyResultCallback(&error, &entry)); |
1090 base::RunLoop().RunUntilIdle(); | 1090 base::RunLoop().RunUntilIdle(); |
1091 | 1091 |
1092 EXPECT_EQ(HTTP_SUCCESS, error); | 1092 EXPECT_EQ(HTTP_SUCCESS, error); |
1093 ASSERT_TRUE(entry); | 1093 ASSERT_TRUE(entry); |
1094 // The copied entry should have the new resource ID and the title. | 1094 // The copied entry should have the new resource ID and the title. |
1095 EXPECT_NE(kResourceId, entry->file_id()); | 1095 EXPECT_NE(kResourceId, entry->file_id()); |
1096 EXPECT_EQ("new title", entry->title()); | 1096 EXPECT_EQ("new title", entry->title()); |
1097 EXPECT_TRUE(HasParent(kResourceId, fake_service_.GetRootResourceId())); | 1097 EXPECT_TRUE(HasParent(kResourceId, fake_service_.GetRootResourceId())); |
1098 // Should be incremented as a new hosted document was created. | 1098 // Should be incremented as a new hosted document was created. |
1099 EXPECT_EQ(old_largest_change_id + 1, | 1099 EXPECT_EQ(old_largest_change_id + 1, |
1100 fake_service_.about_resource().largest_change_id()); | 1100 fake_service_.about_resource().largest_change_id()); |
1101 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1101 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1102 } | 1102 } |
1103 | 1103 |
1104 TEST_F(FakeDriveServiceTest, CopyResource_Offline) { | 1104 TEST_F(FakeDriveServiceTest, CopyResource_Offline) { |
1105 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1105 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1106 fake_service_.set_offline(true); | 1106 fake_service_.set_offline(true); |
1107 | 1107 |
1108 const std::string kResourceId = "file:2_file_resource_id"; | 1108 const std::string kResourceId = "2_file_resource_id"; |
1109 GDataErrorCode error = GDATA_OTHER_ERROR; | 1109 GDataErrorCode error = GDATA_OTHER_ERROR; |
1110 scoped_ptr<FileResource> entry; | 1110 scoped_ptr<FileResource> entry; |
1111 fake_service_.CopyResource( | 1111 fake_service_.CopyResource( |
1112 kResourceId, | 1112 kResourceId, |
1113 "folder:1_folder_resource_id", | 1113 "1_folder_resource_id", |
1114 "new title", | 1114 "new title", |
1115 base::Time(), | 1115 base::Time(), |
1116 test_util::CreateCopyResultCallback(&error, &entry)); | 1116 test_util::CreateCopyResultCallback(&error, &entry)); |
1117 base::RunLoop().RunUntilIdle(); | 1117 base::RunLoop().RunUntilIdle(); |
1118 | 1118 |
1119 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1119 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1120 EXPECT_FALSE(entry); | 1120 EXPECT_FALSE(entry); |
1121 } | 1121 } |
1122 | 1122 |
1123 TEST_F(FakeDriveServiceTest, UpdateResource) { | 1123 TEST_F(FakeDriveServiceTest, UpdateResource) { |
1124 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 1124 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
1125 const base::Time::Exploded kViewedDate = {2013, 8, 1, 20, 16, 00, 14, 234}; | 1125 const base::Time::Exploded kViewedDate = {2013, 8, 1, 20, 16, 00, 14, 234}; |
1126 | 1126 |
1127 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1127 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1128 | 1128 |
1129 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1129 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1130 | 1130 |
1131 const std::string kResourceId = "file:2_file_resource_id"; | 1131 const std::string kResourceId = "2_file_resource_id"; |
1132 const std::string kParentResourceId = "folder:2_folder_resource_id"; | 1132 const std::string kParentResourceId = "2_folder_resource_id"; |
1133 GDataErrorCode error = GDATA_OTHER_ERROR; | 1133 GDataErrorCode error = GDATA_OTHER_ERROR; |
1134 scoped_ptr<FileResource> entry; | 1134 scoped_ptr<FileResource> entry; |
1135 fake_service_.UpdateResource( | 1135 fake_service_.UpdateResource( |
1136 kResourceId, | 1136 kResourceId, |
1137 kParentResourceId, | 1137 kParentResourceId, |
1138 "new title", | 1138 "new title", |
1139 base::Time::FromUTCExploded(kModifiedDate), | 1139 base::Time::FromUTCExploded(kModifiedDate), |
1140 base::Time::FromUTCExploded(kViewedDate), | 1140 base::Time::FromUTCExploded(kViewedDate), |
1141 test_util::CreateCopyResultCallback(&error, &entry)); | 1141 test_util::CreateCopyResultCallback(&error, &entry)); |
1142 base::RunLoop().RunUntilIdle(); | 1142 base::RunLoop().RunUntilIdle(); |
(...skipping 10 matching lines...) Expand all Loading... |
1153 EXPECT_TRUE(HasParent(kResourceId, kParentResourceId)); | 1153 EXPECT_TRUE(HasParent(kResourceId, kParentResourceId)); |
1154 // Should be incremented as a new hosted document was created. | 1154 // Should be incremented as a new hosted document was created. |
1155 EXPECT_EQ(old_largest_change_id + 1, | 1155 EXPECT_EQ(old_largest_change_id + 1, |
1156 fake_service_.about_resource().largest_change_id()); | 1156 fake_service_.about_resource().largest_change_id()); |
1157 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1157 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1158 } | 1158 } |
1159 | 1159 |
1160 TEST_F(FakeDriveServiceTest, UpdateResource_NonExisting) { | 1160 TEST_F(FakeDriveServiceTest, UpdateResource_NonExisting) { |
1161 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1161 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1162 | 1162 |
1163 const std::string kResourceId = "document:nonexisting_resource_id"; | 1163 const std::string kResourceId = "nonexisting_resource_id"; |
1164 GDataErrorCode error = GDATA_OTHER_ERROR; | 1164 GDataErrorCode error = GDATA_OTHER_ERROR; |
1165 scoped_ptr<FileResource> entry; | 1165 scoped_ptr<FileResource> entry; |
1166 fake_service_.UpdateResource( | 1166 fake_service_.UpdateResource( |
1167 kResourceId, | 1167 kResourceId, |
1168 "folder:1_folder_resource_id", | 1168 "1_folder_resource_id", |
1169 "new title", | 1169 "new title", |
1170 base::Time(), | 1170 base::Time(), |
1171 base::Time(), | 1171 base::Time(), |
1172 test_util::CreateCopyResultCallback(&error, &entry)); | 1172 test_util::CreateCopyResultCallback(&error, &entry)); |
1173 base::RunLoop().RunUntilIdle(); | 1173 base::RunLoop().RunUntilIdle(); |
1174 | 1174 |
1175 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1175 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1176 } | 1176 } |
1177 | 1177 |
1178 TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) { | 1178 TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) { |
1179 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1179 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1180 | 1180 |
1181 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1181 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1182 | 1182 |
1183 const std::string kResourceId = "file:2_file_resource_id"; | 1183 const std::string kResourceId = "2_file_resource_id"; |
1184 | 1184 |
1185 // Just make sure that the resource is under root. | 1185 // Just make sure that the resource is under root. |
1186 ASSERT_TRUE(HasParent(kResourceId, "fake_root")); | 1186 ASSERT_TRUE(HasParent(kResourceId, "fake_root")); |
1187 | 1187 |
1188 GDataErrorCode error = GDATA_OTHER_ERROR; | 1188 GDataErrorCode error = GDATA_OTHER_ERROR; |
1189 scoped_ptr<FileResource> entry; | 1189 scoped_ptr<FileResource> entry; |
1190 fake_service_.UpdateResource( | 1190 fake_service_.UpdateResource( |
1191 kResourceId, | 1191 kResourceId, |
1192 std::string(), | 1192 std::string(), |
1193 "new title", | 1193 "new title", |
(...skipping 11 matching lines...) Expand all Loading... |
1205 // Should be incremented as a new hosted document was created. | 1205 // Should be incremented as a new hosted document was created. |
1206 EXPECT_EQ(old_largest_change_id + 1, | 1206 EXPECT_EQ(old_largest_change_id + 1, |
1207 fake_service_.about_resource().largest_change_id()); | 1207 fake_service_.about_resource().largest_change_id()); |
1208 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1208 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1209 } | 1209 } |
1210 | 1210 |
1211 TEST_F(FakeDriveServiceTest, UpdateResource_Offline) { | 1211 TEST_F(FakeDriveServiceTest, UpdateResource_Offline) { |
1212 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1212 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1213 fake_service_.set_offline(true); | 1213 fake_service_.set_offline(true); |
1214 | 1214 |
1215 const std::string kResourceId = "file:2_file_resource_id"; | 1215 const std::string kResourceId = "2_file_resource_id"; |
1216 GDataErrorCode error = GDATA_OTHER_ERROR; | 1216 GDataErrorCode error = GDATA_OTHER_ERROR; |
1217 scoped_ptr<FileResource> entry; | 1217 scoped_ptr<FileResource> entry; |
1218 fake_service_.UpdateResource( | 1218 fake_service_.UpdateResource( |
1219 kResourceId, | 1219 kResourceId, |
1220 std::string(), | 1220 std::string(), |
1221 "new title", | 1221 "new title", |
1222 base::Time(), | 1222 base::Time(), |
1223 base::Time(), | 1223 base::Time(), |
1224 test_util::CreateCopyResultCallback(&error, &entry)); | 1224 test_util::CreateCopyResultCallback(&error, &entry)); |
1225 base::RunLoop().RunUntilIdle(); | 1225 base::RunLoop().RunUntilIdle(); |
1226 | 1226 |
1227 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1227 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1228 EXPECT_FALSE(entry); | 1228 EXPECT_FALSE(entry); |
1229 } | 1229 } |
1230 | 1230 |
1231 TEST_F(FakeDriveServiceTest, RenameResource_ExistingFile) { | 1231 TEST_F(FakeDriveServiceTest, RenameResource_ExistingFile) { |
1232 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1232 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1233 | 1233 |
1234 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1234 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1235 | 1235 |
1236 const std::string kResourceId = "file:2_file_resource_id"; | 1236 const std::string kResourceId = "2_file_resource_id"; |
1237 | 1237 |
1238 GDataErrorCode error = GDATA_OTHER_ERROR; | 1238 GDataErrorCode error = GDATA_OTHER_ERROR; |
1239 fake_service_.RenameResource(kResourceId, | 1239 fake_service_.RenameResource(kResourceId, |
1240 "new title", | 1240 "new title", |
1241 test_util::CreateCopyResultCallback(&error)); | 1241 test_util::CreateCopyResultCallback(&error)); |
1242 base::RunLoop().RunUntilIdle(); | 1242 base::RunLoop().RunUntilIdle(); |
1243 | 1243 |
1244 EXPECT_EQ(HTTP_SUCCESS, error); | 1244 EXPECT_EQ(HTTP_SUCCESS, error); |
1245 | 1245 |
1246 scoped_ptr<FileResource> entry = FindEntry(kResourceId); | 1246 scoped_ptr<FileResource> entry = FindEntry(kResourceId); |
1247 ASSERT_TRUE(entry); | 1247 ASSERT_TRUE(entry); |
1248 EXPECT_EQ("new title", entry->title()); | 1248 EXPECT_EQ("new title", entry->title()); |
1249 // Should be incremented as a file was renamed. | 1249 // Should be incremented as a file was renamed. |
1250 EXPECT_EQ(old_largest_change_id + 1, | 1250 EXPECT_EQ(old_largest_change_id + 1, |
1251 fake_service_.about_resource().largest_change_id()); | 1251 fake_service_.about_resource().largest_change_id()); |
1252 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1252 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1253 } | 1253 } |
1254 | 1254 |
1255 TEST_F(FakeDriveServiceTest, RenameResource_NonexistingFile) { | 1255 TEST_F(FakeDriveServiceTest, RenameResource_NonexistingFile) { |
1256 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1256 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1257 | 1257 |
1258 const std::string kResourceId = "file:nonexisting_file"; | 1258 const std::string kResourceId = "nonexisting_file"; |
1259 | 1259 |
1260 GDataErrorCode error = GDATA_OTHER_ERROR; | 1260 GDataErrorCode error = GDATA_OTHER_ERROR; |
1261 fake_service_.RenameResource(kResourceId, | 1261 fake_service_.RenameResource(kResourceId, |
1262 "new title", | 1262 "new title", |
1263 test_util::CreateCopyResultCallback(&error)); | 1263 test_util::CreateCopyResultCallback(&error)); |
1264 base::RunLoop().RunUntilIdle(); | 1264 base::RunLoop().RunUntilIdle(); |
1265 | 1265 |
1266 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1266 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1267 } | 1267 } |
1268 | 1268 |
1269 TEST_F(FakeDriveServiceTest, RenameResource_Offline) { | 1269 TEST_F(FakeDriveServiceTest, RenameResource_Offline) { |
1270 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1270 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1271 fake_service_.set_offline(true); | 1271 fake_service_.set_offline(true); |
1272 | 1272 |
1273 const std::string kResourceId = "file:2_file_resource_id"; | 1273 const std::string kResourceId = "2_file_resource_id"; |
1274 | 1274 |
1275 GDataErrorCode error = GDATA_OTHER_ERROR; | 1275 GDataErrorCode error = GDATA_OTHER_ERROR; |
1276 fake_service_.RenameResource(kResourceId, | 1276 fake_service_.RenameResource(kResourceId, |
1277 "new title", | 1277 "new title", |
1278 test_util::CreateCopyResultCallback(&error)); | 1278 test_util::CreateCopyResultCallback(&error)); |
1279 base::RunLoop().RunUntilIdle(); | 1279 base::RunLoop().RunUntilIdle(); |
1280 | 1280 |
1281 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1281 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1282 } | 1282 } |
1283 | 1283 |
1284 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { | 1284 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { |
1285 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1285 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1286 | 1286 |
1287 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1287 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1288 | 1288 |
1289 const std::string kResourceId = "file:2_file_resource_id"; | 1289 const std::string kResourceId = "2_file_resource_id"; |
1290 const std::string kOldParentResourceId = fake_service_.GetRootResourceId(); | 1290 const std::string kOldParentResourceId = fake_service_.GetRootResourceId(); |
1291 const std::string kNewParentResourceId = "folder:1_folder_resource_id"; | 1291 const std::string kNewParentResourceId = "1_folder_resource_id"; |
1292 | 1292 |
1293 // Here's the original parent link. | 1293 // Here's the original parent link. |
1294 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1294 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
1295 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); | 1295 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); |
1296 | 1296 |
1297 GDataErrorCode error = GDATA_OTHER_ERROR; | 1297 GDataErrorCode error = GDATA_OTHER_ERROR; |
1298 fake_service_.AddResourceToDirectory( | 1298 fake_service_.AddResourceToDirectory( |
1299 kNewParentResourceId, | 1299 kNewParentResourceId, |
1300 kResourceId, | 1300 kResourceId, |
1301 test_util::CreateCopyResultCallback(&error)); | 1301 test_util::CreateCopyResultCallback(&error)); |
1302 base::RunLoop().RunUntilIdle(); | 1302 base::RunLoop().RunUntilIdle(); |
1303 | 1303 |
1304 EXPECT_EQ(HTTP_SUCCESS, error); | 1304 EXPECT_EQ(HTTP_SUCCESS, error); |
1305 | 1305 |
1306 // The parent link should now be changed. | 1306 // The parent link should now be changed. |
1307 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1307 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
1308 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); | 1308 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); |
1309 // Should be incremented as a file was moved. | 1309 // Should be incremented as a file was moved. |
1310 EXPECT_EQ(old_largest_change_id + 1, | 1310 EXPECT_EQ(old_largest_change_id + 1, |
1311 fake_service_.about_resource().largest_change_id()); | 1311 fake_service_.about_resource().largest_change_id()); |
1312 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1312 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1313 } | 1313 } |
1314 | 1314 |
1315 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) { | 1315 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) { |
1316 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1316 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1317 | 1317 |
1318 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1318 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1319 | 1319 |
1320 const std::string kResourceId = "file:subdirectory_file_1_id"; | 1320 const std::string kResourceId = "subdirectory_file_1_id"; |
1321 const std::string kOldParentResourceId = "folder:1_folder_resource_id"; | 1321 const std::string kOldParentResourceId = "1_folder_resource_id"; |
1322 const std::string kNewParentResourceId = "folder:2_folder_resource_id"; | 1322 const std::string kNewParentResourceId = "2_folder_resource_id"; |
1323 | 1323 |
1324 // Here's the original parent link. | 1324 // Here's the original parent link. |
1325 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1325 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
1326 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); | 1326 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); |
1327 | 1327 |
1328 GDataErrorCode error = GDATA_OTHER_ERROR; | 1328 GDataErrorCode error = GDATA_OTHER_ERROR; |
1329 fake_service_.AddResourceToDirectory( | 1329 fake_service_.AddResourceToDirectory( |
1330 kNewParentResourceId, | 1330 kNewParentResourceId, |
1331 kResourceId, | 1331 kResourceId, |
1332 test_util::CreateCopyResultCallback(&error)); | 1332 test_util::CreateCopyResultCallback(&error)); |
1333 base::RunLoop().RunUntilIdle(); | 1333 base::RunLoop().RunUntilIdle(); |
1334 | 1334 |
1335 EXPECT_EQ(HTTP_SUCCESS, error); | 1335 EXPECT_EQ(HTTP_SUCCESS, error); |
1336 | 1336 |
1337 // The parent link should now be changed. | 1337 // The parent link should now be changed. |
1338 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1338 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
1339 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); | 1339 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); |
1340 // Should be incremented as a file was moved. | 1340 // Should be incremented as a file was moved. |
1341 EXPECT_EQ(old_largest_change_id + 1, | 1341 EXPECT_EQ(old_largest_change_id + 1, |
1342 fake_service_.about_resource().largest_change_id()); | 1342 fake_service_.about_resource().largest_change_id()); |
1343 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1343 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1344 } | 1344 } |
1345 | 1345 |
1346 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_NonexistingFile) { | 1346 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_NonexistingFile) { |
1347 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1347 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1348 | 1348 |
1349 const std::string kResourceId = "file:nonexisting_file"; | 1349 const std::string kResourceId = "nonexisting_file"; |
1350 const std::string kNewParentResourceId = "folder:1_folder_resource_id"; | 1350 const std::string kNewParentResourceId = "1_folder_resource_id"; |
1351 | 1351 |
1352 GDataErrorCode error = GDATA_OTHER_ERROR; | 1352 GDataErrorCode error = GDATA_OTHER_ERROR; |
1353 fake_service_.AddResourceToDirectory( | 1353 fake_service_.AddResourceToDirectory( |
1354 kNewParentResourceId, | 1354 kNewParentResourceId, |
1355 kResourceId, | 1355 kResourceId, |
1356 test_util::CreateCopyResultCallback(&error)); | 1356 test_util::CreateCopyResultCallback(&error)); |
1357 base::RunLoop().RunUntilIdle(); | 1357 base::RunLoop().RunUntilIdle(); |
1358 | 1358 |
1359 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1359 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1360 } | 1360 } |
1361 | 1361 |
1362 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_OrphanFile) { | 1362 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_OrphanFile) { |
1363 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1363 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1364 | 1364 |
1365 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1365 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1366 | 1366 |
1367 const std::string kResourceId = "file:1_orphanfile_resource_id"; | 1367 const std::string kResourceId = "1_orphanfile_resource_id"; |
1368 const std::string kNewParentResourceId = "folder:1_folder_resource_id"; | 1368 const std::string kNewParentResourceId = "1_folder_resource_id"; |
1369 | 1369 |
1370 // The file does not belong to any directory, even to the root. | 1370 // The file does not belong to any directory, even to the root. |
1371 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); | 1371 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); |
1372 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); | 1372 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); |
1373 | 1373 |
1374 GDataErrorCode error = GDATA_OTHER_ERROR; | 1374 GDataErrorCode error = GDATA_OTHER_ERROR; |
1375 fake_service_.AddResourceToDirectory( | 1375 fake_service_.AddResourceToDirectory( |
1376 kNewParentResourceId, | 1376 kNewParentResourceId, |
1377 kResourceId, | 1377 kResourceId, |
1378 test_util::CreateCopyResultCallback(&error)); | 1378 test_util::CreateCopyResultCallback(&error)); |
1379 base::RunLoop().RunUntilIdle(); | 1379 base::RunLoop().RunUntilIdle(); |
1380 | 1380 |
1381 EXPECT_EQ(HTTP_SUCCESS, error); | 1381 EXPECT_EQ(HTTP_SUCCESS, error); |
1382 | 1382 |
1383 // The parent link should now be changed. | 1383 // The parent link should now be changed. |
1384 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); | 1384 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); |
1385 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); | 1385 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); |
1386 // Should be incremented as a file was moved. | 1386 // Should be incremented as a file was moved. |
1387 EXPECT_EQ(old_largest_change_id + 1, | 1387 EXPECT_EQ(old_largest_change_id + 1, |
1388 fake_service_.about_resource().largest_change_id()); | 1388 fake_service_.about_resource().largest_change_id()); |
1389 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1389 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1390 } | 1390 } |
1391 | 1391 |
1392 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_Offline) { | 1392 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_Offline) { |
1393 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1393 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1394 fake_service_.set_offline(true); | 1394 fake_service_.set_offline(true); |
1395 | 1395 |
1396 const std::string kResourceId = "file:2_file_resource_id"; | 1396 const std::string kResourceId = "2_file_resource_id"; |
1397 const std::string kNewParentResourceId = "folder:1_folder_resource_id"; | 1397 const std::string kNewParentResourceId = "1_folder_resource_id"; |
1398 | 1398 |
1399 GDataErrorCode error = GDATA_OTHER_ERROR; | 1399 GDataErrorCode error = GDATA_OTHER_ERROR; |
1400 fake_service_.AddResourceToDirectory( | 1400 fake_service_.AddResourceToDirectory( |
1401 kNewParentResourceId, | 1401 kNewParentResourceId, |
1402 kResourceId, | 1402 kResourceId, |
1403 test_util::CreateCopyResultCallback(&error)); | 1403 test_util::CreateCopyResultCallback(&error)); |
1404 base::RunLoop().RunUntilIdle(); | 1404 base::RunLoop().RunUntilIdle(); |
1405 | 1405 |
1406 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1406 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1407 } | 1407 } |
1408 | 1408 |
1409 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { | 1409 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { |
1410 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1410 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1411 | 1411 |
1412 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1412 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1413 | 1413 |
1414 const std::string kResourceId = "file:subdirectory_file_1_id"; | 1414 const std::string kResourceId = "subdirectory_file_1_id"; |
1415 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 1415 const std::string kParentResourceId = "1_folder_resource_id"; |
1416 | 1416 |
1417 scoped_ptr<FileResource> entry = FindEntry(kResourceId); | 1417 scoped_ptr<FileResource> entry = FindEntry(kResourceId); |
1418 ASSERT_TRUE(entry); | 1418 ASSERT_TRUE(entry); |
1419 // The entry should have a parent now. | 1419 // The entry should have a parent now. |
1420 ASSERT_FALSE(entry->parents().empty()); | 1420 ASSERT_FALSE(entry->parents().empty()); |
1421 | 1421 |
1422 GDataErrorCode error = GDATA_OTHER_ERROR; | 1422 GDataErrorCode error = GDATA_OTHER_ERROR; |
1423 fake_service_.RemoveResourceFromDirectory( | 1423 fake_service_.RemoveResourceFromDirectory( |
1424 kParentResourceId, | 1424 kParentResourceId, |
1425 kResourceId, | 1425 kResourceId, |
1426 test_util::CreateCopyResultCallback(&error)); | 1426 test_util::CreateCopyResultCallback(&error)); |
1427 base::RunLoop().RunUntilIdle(); | 1427 base::RunLoop().RunUntilIdle(); |
1428 | 1428 |
1429 EXPECT_EQ(HTTP_NO_CONTENT, error); | 1429 EXPECT_EQ(HTTP_NO_CONTENT, error); |
1430 | 1430 |
1431 entry = FindEntry(kResourceId); | 1431 entry = FindEntry(kResourceId); |
1432 ASSERT_TRUE(entry); | 1432 ASSERT_TRUE(entry); |
1433 // The entry should have no parent now. | 1433 // The entry should have no parent now. |
1434 ASSERT_TRUE(entry->parents().empty()); | 1434 ASSERT_TRUE(entry->parents().empty()); |
1435 // Should be incremented as a file was moved to the root directory. | 1435 // Should be incremented as a file was moved to the root directory. |
1436 EXPECT_EQ(old_largest_change_id + 1, | 1436 EXPECT_EQ(old_largest_change_id + 1, |
1437 fake_service_.about_resource().largest_change_id()); | 1437 fake_service_.about_resource().largest_change_id()); |
1438 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1438 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1439 } | 1439 } |
1440 | 1440 |
1441 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_NonexistingFile) { | 1441 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_NonexistingFile) { |
1442 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1442 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1443 | 1443 |
1444 const std::string kResourceId = "file:nonexisting_file"; | 1444 const std::string kResourceId = "nonexisting_file"; |
1445 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 1445 const std::string kParentResourceId = "1_folder_resource_id"; |
1446 | 1446 |
1447 GDataErrorCode error = GDATA_OTHER_ERROR; | 1447 GDataErrorCode error = GDATA_OTHER_ERROR; |
1448 fake_service_.RemoveResourceFromDirectory( | 1448 fake_service_.RemoveResourceFromDirectory( |
1449 kParentResourceId, | 1449 kParentResourceId, |
1450 kResourceId, | 1450 kResourceId, |
1451 test_util::CreateCopyResultCallback(&error)); | 1451 test_util::CreateCopyResultCallback(&error)); |
1452 base::RunLoop().RunUntilIdle(); | 1452 base::RunLoop().RunUntilIdle(); |
1453 | 1453 |
1454 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1454 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1455 } | 1455 } |
1456 | 1456 |
1457 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_OrphanFile) { | 1457 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_OrphanFile) { |
1458 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1458 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1459 | 1459 |
1460 const std::string kResourceId = "file:1_orphanfile_resource_id"; | 1460 const std::string kResourceId = "1_orphanfile_resource_id"; |
1461 const std::string kParentResourceId = fake_service_.GetRootResourceId(); | 1461 const std::string kParentResourceId = fake_service_.GetRootResourceId(); |
1462 | 1462 |
1463 GDataErrorCode error = GDATA_OTHER_ERROR; | 1463 GDataErrorCode error = GDATA_OTHER_ERROR; |
1464 fake_service_.RemoveResourceFromDirectory( | 1464 fake_service_.RemoveResourceFromDirectory( |
1465 kParentResourceId, | 1465 kParentResourceId, |
1466 kResourceId, | 1466 kResourceId, |
1467 test_util::CreateCopyResultCallback(&error)); | 1467 test_util::CreateCopyResultCallback(&error)); |
1468 base::RunLoop().RunUntilIdle(); | 1468 base::RunLoop().RunUntilIdle(); |
1469 | 1469 |
1470 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1470 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1471 } | 1471 } |
1472 | 1472 |
1473 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_Offline) { | 1473 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_Offline) { |
1474 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1474 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1475 fake_service_.set_offline(true); | 1475 fake_service_.set_offline(true); |
1476 | 1476 |
1477 const std::string kResourceId = "file:subdirectory_file_1_id"; | 1477 const std::string kResourceId = "subdirectory_file_1_id"; |
1478 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 1478 const std::string kParentResourceId = "1_folder_resource_id"; |
1479 | 1479 |
1480 GDataErrorCode error = GDATA_OTHER_ERROR; | 1480 GDataErrorCode error = GDATA_OTHER_ERROR; |
1481 fake_service_.RemoveResourceFromDirectory( | 1481 fake_service_.RemoveResourceFromDirectory( |
1482 kParentResourceId, | 1482 kParentResourceId, |
1483 kResourceId, | 1483 kResourceId, |
1484 test_util::CreateCopyResultCallback(&error)); | 1484 test_util::CreateCopyResultCallback(&error)); |
1485 base::RunLoop().RunUntilIdle(); | 1485 base::RunLoop().RunUntilIdle(); |
1486 | 1486 |
1487 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1487 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1488 } | 1488 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 EXPECT_EQ(old_largest_change_id + 1, | 1561 EXPECT_EQ(old_largest_change_id + 1, |
1562 fake_service_.about_resource().largest_change_id()); | 1562 fake_service_.about_resource().largest_change_id()); |
1563 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1563 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1564 } | 1564 } |
1565 | 1565 |
1566 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { | 1566 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { |
1567 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1567 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1568 | 1568 |
1569 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1569 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1570 | 1570 |
1571 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 1571 const std::string kParentResourceId = "1_folder_resource_id"; |
1572 | 1572 |
1573 GDataErrorCode error = GDATA_OTHER_ERROR; | 1573 GDataErrorCode error = GDATA_OTHER_ERROR; |
1574 scoped_ptr<FileResource> entry; | 1574 scoped_ptr<FileResource> entry; |
1575 fake_service_.AddNewDirectory( | 1575 fake_service_.AddNewDirectory( |
1576 kParentResourceId, | 1576 kParentResourceId, |
1577 "new directory", | 1577 "new directory", |
1578 DriveServiceInterface::AddNewDirectoryOptions(), | 1578 DriveServiceInterface::AddNewDirectoryOptions(), |
1579 test_util::CreateCopyResultCallback(&error, &entry)); | 1579 test_util::CreateCopyResultCallback(&error, &entry)); |
1580 base::RunLoop().RunUntilIdle(); | 1580 base::RunLoop().RunUntilIdle(); |
1581 | 1581 |
1582 EXPECT_EQ(HTTP_CREATED, error); | 1582 EXPECT_EQ(HTTP_CREATED, error); |
1583 ASSERT_TRUE(entry); | 1583 ASSERT_TRUE(entry); |
1584 EXPECT_TRUE(entry->IsDirectory()); | 1584 EXPECT_TRUE(entry->IsDirectory()); |
1585 EXPECT_EQ("resource_id_1", entry->file_id()); | 1585 EXPECT_EQ("resource_id_1", entry->file_id()); |
1586 EXPECT_EQ("new directory", entry->title()); | 1586 EXPECT_EQ("new directory", entry->title()); |
1587 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); | 1587 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); |
1588 // Should be incremented as a new directory was created. | 1588 // Should be incremented as a new directory was created. |
1589 EXPECT_EQ(old_largest_change_id + 1, | 1589 EXPECT_EQ(old_largest_change_id + 1, |
1590 fake_service_.about_resource().largest_change_id()); | 1590 fake_service_.about_resource().largest_change_id()); |
1591 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1591 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1592 } | 1592 } |
1593 | 1593 |
1594 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { | 1594 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { |
1595 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1595 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1596 | 1596 |
1597 const std::string kParentResourceId = "folder:nonexisting_resource_id"; | 1597 const std::string kParentResourceId = "nonexisting_resource_id"; |
1598 | 1598 |
1599 GDataErrorCode error = GDATA_OTHER_ERROR; | 1599 GDataErrorCode error = GDATA_OTHER_ERROR; |
1600 scoped_ptr<FileResource> entry; | 1600 scoped_ptr<FileResource> entry; |
1601 fake_service_.AddNewDirectory( | 1601 fake_service_.AddNewDirectory( |
1602 kParentResourceId, | 1602 kParentResourceId, |
1603 "new directory", | 1603 "new directory", |
1604 DriveServiceInterface::AddNewDirectoryOptions(), | 1604 DriveServiceInterface::AddNewDirectoryOptions(), |
1605 test_util::CreateCopyResultCallback(&error, &entry)); | 1605 test_util::CreateCopyResultCallback(&error, &entry)); |
1606 base::RunLoop().RunUntilIdle(); | 1606 base::RunLoop().RunUntilIdle(); |
1607 | 1607 |
(...skipping 20 matching lines...) Expand all Loading... |
1628 | 1628 |
1629 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { | 1629 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { |
1630 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1630 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1631 fake_service_.set_offline(true); | 1631 fake_service_.set_offline(true); |
1632 | 1632 |
1633 GDataErrorCode error = GDATA_OTHER_ERROR; | 1633 GDataErrorCode error = GDATA_OTHER_ERROR; |
1634 GURL upload_location; | 1634 GURL upload_location; |
1635 fake_service_.InitiateUploadNewFile( | 1635 fake_service_.InitiateUploadNewFile( |
1636 "test/foo", | 1636 "test/foo", |
1637 13, | 1637 13, |
1638 "folder:1_folder_resource_id", | 1638 "1_folder_resource_id", |
1639 "new file.foo", | 1639 "new file.foo", |
1640 FakeDriveService::InitiateUploadNewFileOptions(), | 1640 FakeDriveService::InitiateUploadNewFileOptions(), |
1641 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1641 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1642 base::RunLoop().RunUntilIdle(); | 1642 base::RunLoop().RunUntilIdle(); |
1643 | 1643 |
1644 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1644 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1645 EXPECT_TRUE(upload_location.is_empty()); | 1645 EXPECT_TRUE(upload_location.is_empty()); |
1646 } | 1646 } |
1647 | 1647 |
1648 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_NotFound) { | 1648 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_NotFound) { |
(...skipping 15 matching lines...) Expand all Loading... |
1664 } | 1664 } |
1665 | 1665 |
1666 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile) { | 1666 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile) { |
1667 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1667 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1668 | 1668 |
1669 GDataErrorCode error = GDATA_OTHER_ERROR; | 1669 GDataErrorCode error = GDATA_OTHER_ERROR; |
1670 GURL upload_location; | 1670 GURL upload_location; |
1671 fake_service_.InitiateUploadNewFile( | 1671 fake_service_.InitiateUploadNewFile( |
1672 "test/foo", | 1672 "test/foo", |
1673 13, | 1673 13, |
1674 "folder:1_folder_resource_id", | 1674 "1_folder_resource_id", |
1675 "new file.foo", | 1675 "new file.foo", |
1676 FakeDriveService::InitiateUploadNewFileOptions(), | 1676 FakeDriveService::InitiateUploadNewFileOptions(), |
1677 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1677 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1678 base::RunLoop().RunUntilIdle(); | 1678 base::RunLoop().RunUntilIdle(); |
1679 | 1679 |
1680 EXPECT_EQ(HTTP_SUCCESS, error); | 1680 EXPECT_EQ(HTTP_SUCCESS, error); |
1681 EXPECT_FALSE(upload_location.is_empty()); | 1681 EXPECT_FALSE(upload_location.is_empty()); |
1682 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"), | 1682 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"), |
1683 upload_location); | 1683 upload_location); |
1684 } | 1684 } |
1685 | 1685 |
1686 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Offline) { | 1686 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Offline) { |
1687 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1687 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1688 fake_service_.set_offline(true); | 1688 fake_service_.set_offline(true); |
1689 | 1689 |
1690 GDataErrorCode error = GDATA_OTHER_ERROR; | 1690 GDataErrorCode error = GDATA_OTHER_ERROR; |
1691 GURL upload_location; | 1691 GURL upload_location; |
1692 fake_service_.InitiateUploadExistingFile( | 1692 fake_service_.InitiateUploadExistingFile( |
1693 "test/foo", | 1693 "test/foo", |
1694 13, | 1694 13, |
1695 "file:2_file_resource_id", | 1695 "2_file_resource_id", |
1696 FakeDriveService::InitiateUploadExistingFileOptions(), | 1696 FakeDriveService::InitiateUploadExistingFileOptions(), |
1697 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1697 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1698 base::RunLoop().RunUntilIdle(); | 1698 base::RunLoop().RunUntilIdle(); |
1699 | 1699 |
1700 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1700 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1701 EXPECT_TRUE(upload_location.is_empty()); | 1701 EXPECT_TRUE(upload_location.is_empty()); |
1702 } | 1702 } |
1703 | 1703 |
1704 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) { | 1704 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) { |
1705 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1705 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
(...skipping 16 matching lines...) Expand all Loading... |
1722 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1722 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1723 | 1723 |
1724 FakeDriveService::InitiateUploadExistingFileOptions options; | 1724 FakeDriveService::InitiateUploadExistingFileOptions options; |
1725 options.etag = "invalid_etag"; | 1725 options.etag = "invalid_etag"; |
1726 | 1726 |
1727 GDataErrorCode error = GDATA_OTHER_ERROR; | 1727 GDataErrorCode error = GDATA_OTHER_ERROR; |
1728 GURL upload_location; | 1728 GURL upload_location; |
1729 fake_service_.InitiateUploadExistingFile( | 1729 fake_service_.InitiateUploadExistingFile( |
1730 "text/plain", | 1730 "text/plain", |
1731 13, | 1731 13, |
1732 "file:2_file_resource_id", | 1732 "2_file_resource_id", |
1733 options, | 1733 options, |
1734 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1734 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1735 base::RunLoop().RunUntilIdle(); | 1735 base::RunLoop().RunUntilIdle(); |
1736 | 1736 |
1737 EXPECT_EQ(HTTP_PRECONDITION, error); | 1737 EXPECT_EQ(HTTP_PRECONDITION, error); |
1738 EXPECT_TRUE(upload_location.is_empty()); | 1738 EXPECT_TRUE(upload_location.is_empty()); |
1739 } | 1739 } |
1740 | 1740 |
1741 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) { | 1741 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) { |
1742 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1742 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1743 | 1743 |
1744 scoped_ptr<FileResource> entry = FindEntry("file:2_file_resource_id"); | 1744 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
1745 ASSERT_TRUE(entry); | 1745 ASSERT_TRUE(entry); |
1746 | 1746 |
1747 FakeDriveService::InitiateUploadExistingFileOptions options; | 1747 FakeDriveService::InitiateUploadExistingFileOptions options; |
1748 options.etag = entry->etag(); | 1748 options.etag = entry->etag(); |
1749 | 1749 |
1750 GDataErrorCode error = GDATA_OTHER_ERROR; | 1750 GDataErrorCode error = GDATA_OTHER_ERROR; |
1751 GURL upload_location; | 1751 GURL upload_location; |
1752 fake_service_.InitiateUploadExistingFile( | 1752 fake_service_.InitiateUploadExistingFile( |
1753 "text/plain", | 1753 "text/plain", |
1754 13, | 1754 13, |
1755 "file:2_file_resource_id", | 1755 "2_file_resource_id", |
1756 options, | 1756 options, |
1757 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1757 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1758 base::RunLoop().RunUntilIdle(); | 1758 base::RunLoop().RunUntilIdle(); |
1759 | 1759 |
1760 EXPECT_EQ(HTTP_SUCCESS, error); | 1760 EXPECT_EQ(HTTP_SUCCESS, error); |
1761 EXPECT_TRUE(upload_location.is_valid()); | 1761 EXPECT_TRUE(upload_location.is_valid()); |
1762 } | 1762 } |
1763 | 1763 |
1764 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) { | 1764 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) { |
1765 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1765 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1766 | 1766 |
1767 GDataErrorCode error = GDATA_OTHER_ERROR; | 1767 GDataErrorCode error = GDATA_OTHER_ERROR; |
1768 GURL upload_location; | 1768 GURL upload_location; |
1769 fake_service_.InitiateUploadNewFile( | 1769 fake_service_.InitiateUploadNewFile( |
1770 "test/foo", | 1770 "test/foo", |
1771 15, | 1771 15, |
1772 "folder:1_folder_resource_id", | 1772 "1_folder_resource_id", |
1773 "new file.foo", | 1773 "new file.foo", |
1774 FakeDriveService::InitiateUploadNewFileOptions(), | 1774 FakeDriveService::InitiateUploadNewFileOptions(), |
1775 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1775 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1776 base::RunLoop().RunUntilIdle(); | 1776 base::RunLoop().RunUntilIdle(); |
1777 | 1777 |
1778 EXPECT_EQ(HTTP_SUCCESS, error); | 1778 EXPECT_EQ(HTTP_SUCCESS, error); |
1779 EXPECT_FALSE(upload_location.is_empty()); | 1779 EXPECT_FALSE(upload_location.is_empty()); |
1780 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), | 1780 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), |
1781 upload_location); | 1781 upload_location); |
1782 | 1782 |
(...skipping 14 matching lines...) Expand all Loading... |
1797 } | 1797 } |
1798 | 1798 |
1799 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) { | 1799 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) { |
1800 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1800 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1801 | 1801 |
1802 GDataErrorCode error = GDATA_OTHER_ERROR; | 1802 GDataErrorCode error = GDATA_OTHER_ERROR; |
1803 GURL upload_location; | 1803 GURL upload_location; |
1804 fake_service_.InitiateUploadNewFile( | 1804 fake_service_.InitiateUploadNewFile( |
1805 "test/foo", | 1805 "test/foo", |
1806 15, | 1806 15, |
1807 "folder:1_folder_resource_id", | 1807 "1_folder_resource_id", |
1808 "new file.foo", | 1808 "new file.foo", |
1809 FakeDriveService::InitiateUploadNewFileOptions(), | 1809 FakeDriveService::InitiateUploadNewFileOptions(), |
1810 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1810 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1811 base::RunLoop().RunUntilIdle(); | 1811 base::RunLoop().RunUntilIdle(); |
1812 | 1812 |
1813 ASSERT_EQ(HTTP_SUCCESS, error); | 1813 ASSERT_EQ(HTTP_SUCCESS, error); |
1814 | 1814 |
1815 UploadRangeResponse response; | 1815 UploadRangeResponse response; |
1816 scoped_ptr<FileResource> entry; | 1816 scoped_ptr<FileResource> entry; |
1817 fake_service_.ResumeUpload( | 1817 fake_service_.ResumeUpload( |
(...skipping 11 matching lines...) Expand all Loading... |
1829 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) { | 1829 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) { |
1830 base::ScopedTempDir temp_dir; | 1830 base::ScopedTempDir temp_dir; |
1831 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1831 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1832 base::FilePath local_file_path = | 1832 base::FilePath local_file_path = |
1833 temp_dir.path().Append(FILE_PATH_LITERAL("File 1.txt")); | 1833 temp_dir.path().Append(FILE_PATH_LITERAL("File 1.txt")); |
1834 std::string contents("hogefugapiyo"); | 1834 std::string contents("hogefugapiyo"); |
1835 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1835 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
1836 | 1836 |
1837 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1837 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1838 | 1838 |
1839 scoped_ptr<FileResource> entry = FindEntry("file:2_file_resource_id"); | 1839 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
1840 ASSERT_TRUE(entry); | 1840 ASSERT_TRUE(entry); |
1841 | 1841 |
1842 FakeDriveService::InitiateUploadExistingFileOptions options; | 1842 FakeDriveService::InitiateUploadExistingFileOptions options; |
1843 options.etag = entry->etag(); | 1843 options.etag = entry->etag(); |
1844 | 1844 |
1845 GDataErrorCode error = GDATA_OTHER_ERROR; | 1845 GDataErrorCode error = GDATA_OTHER_ERROR; |
1846 GURL upload_location; | 1846 GURL upload_location; |
1847 fake_service_.InitiateUploadExistingFile( | 1847 fake_service_.InitiateUploadExistingFile( |
1848 "text/plain", | 1848 "text/plain", |
1849 contents.size(), | 1849 contents.size(), |
1850 "file:2_file_resource_id", | 1850 "2_file_resource_id", |
1851 options, | 1851 options, |
1852 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1852 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1853 base::RunLoop().RunUntilIdle(); | 1853 base::RunLoop().RunUntilIdle(); |
1854 | 1854 |
1855 ASSERT_EQ(HTTP_SUCCESS, error); | 1855 ASSERT_EQ(HTTP_SUCCESS, error); |
1856 | 1856 |
1857 UploadRangeResponse response; | 1857 UploadRangeResponse response; |
1858 entry.reset(); | 1858 entry.reset(); |
1859 std::vector<test_util::ProgressInfo> upload_progress_values; | 1859 std::vector<test_util::ProgressInfo> upload_progress_values; |
1860 fake_service_.ResumeUpload( | 1860 fake_service_.ResumeUpload( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 std::string contents("hogefugapiyo"); | 1904 std::string contents("hogefugapiyo"); |
1905 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1905 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
1906 | 1906 |
1907 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1907 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
1908 | 1908 |
1909 GDataErrorCode error = GDATA_OTHER_ERROR; | 1909 GDataErrorCode error = GDATA_OTHER_ERROR; |
1910 GURL upload_location; | 1910 GURL upload_location; |
1911 fake_service_.InitiateUploadNewFile( | 1911 fake_service_.InitiateUploadNewFile( |
1912 "test/foo", | 1912 "test/foo", |
1913 contents.size(), | 1913 contents.size(), |
1914 "folder:1_folder_resource_id", | 1914 "1_folder_resource_id", |
1915 "new file.foo", | 1915 "new file.foo", |
1916 FakeDriveService::InitiateUploadNewFileOptions(), | 1916 FakeDriveService::InitiateUploadNewFileOptions(), |
1917 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1917 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1918 base::RunLoop().RunUntilIdle(); | 1918 base::RunLoop().RunUntilIdle(); |
1919 | 1919 |
1920 EXPECT_EQ(HTTP_SUCCESS, error); | 1920 EXPECT_EQ(HTTP_SUCCESS, error); |
1921 EXPECT_FALSE(upload_location.is_empty()); | 1921 EXPECT_FALSE(upload_location.is_empty()); |
1922 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), | 1922 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), |
1923 upload_location); | 1923 upload_location); |
1924 | 1924 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 } | 2031 } |
2032 | 2032 |
2033 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) { | 2033 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) { |
2034 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2034 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
2035 | 2035 |
2036 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 2036 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
2037 | 2037 |
2038 const std::string kContentType = "text/plain"; | 2038 const std::string kContentType = "text/plain"; |
2039 const std::string kContentData = "This is some test content."; | 2039 const std::string kContentData = "This is some test content."; |
2040 const std::string kTitle = "new file"; | 2040 const std::string kTitle = "new file"; |
2041 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 2041 const std::string kParentResourceId = "1_folder_resource_id"; |
2042 | 2042 |
2043 GDataErrorCode error = GDATA_OTHER_ERROR; | 2043 GDataErrorCode error = GDATA_OTHER_ERROR; |
2044 scoped_ptr<FileResource> entry; | 2044 scoped_ptr<FileResource> entry; |
2045 fake_service_.AddNewFile( | 2045 fake_service_.AddNewFile( |
2046 kContentType, | 2046 kContentType, |
2047 kContentData, | 2047 kContentData, |
2048 kParentResourceId, | 2048 kParentResourceId, |
2049 kTitle, | 2049 kTitle, |
2050 false, // shared_with_me | 2050 false, // shared_with_me |
2051 test_util::CreateCopyResultCallback(&error, &entry)); | 2051 test_util::CreateCopyResultCallback(&error, &entry)); |
(...skipping 12 matching lines...) Expand all Loading... |
2064 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 2064 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
2065 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); | 2065 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); |
2066 } | 2066 } |
2067 | 2067 |
2068 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonexistingDirectory) { | 2068 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonexistingDirectory) { |
2069 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2069 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
2070 | 2070 |
2071 const std::string kContentType = "text/plain"; | 2071 const std::string kContentType = "text/plain"; |
2072 const std::string kContentData = "This is some test content."; | 2072 const std::string kContentData = "This is some test content."; |
2073 const std::string kTitle = "new file"; | 2073 const std::string kTitle = "new file"; |
2074 const std::string kParentResourceId = "folder:nonexisting_resource_id"; | 2074 const std::string kParentResourceId = "nonexisting_resource_id"; |
2075 | 2075 |
2076 GDataErrorCode error = GDATA_OTHER_ERROR; | 2076 GDataErrorCode error = GDATA_OTHER_ERROR; |
2077 scoped_ptr<FileResource> entry; | 2077 scoped_ptr<FileResource> entry; |
2078 fake_service_.AddNewFile( | 2078 fake_service_.AddNewFile( |
2079 kContentType, | 2079 kContentType, |
2080 kContentData, | 2080 kContentData, |
2081 kParentResourceId, | 2081 kParentResourceId, |
2082 kTitle, | 2082 kTitle, |
2083 false, // shared_with_me | 2083 false, // shared_with_me |
2084 test_util::CreateCopyResultCallback(&error, &entry)); | 2084 test_util::CreateCopyResultCallback(&error, &entry)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2142 // Should be incremented as a new directory was created. | 2142 // Should be incremented as a new directory was created. |
2143 EXPECT_EQ(old_largest_change_id + 1, | 2143 EXPECT_EQ(old_largest_change_id + 1, |
2144 fake_service_.about_resource().largest_change_id()); | 2144 fake_service_.about_resource().largest_change_id()); |
2145 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 2145 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
2146 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); | 2146 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); |
2147 } | 2147 } |
2148 | 2148 |
2149 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) { | 2149 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) { |
2150 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2150 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
2151 | 2151 |
2152 const std::string kResourceId = "file:2_file_resource_id"; | 2152 const std::string kResourceId = "2_file_resource_id"; |
2153 base::Time time; | 2153 base::Time time; |
2154 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | 2154 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); |
2155 | 2155 |
2156 GDataErrorCode error = GDATA_OTHER_ERROR; | 2156 GDataErrorCode error = GDATA_OTHER_ERROR; |
2157 scoped_ptr<FileResource> entry; | 2157 scoped_ptr<FileResource> entry; |
2158 fake_service_.SetLastModifiedTime( | 2158 fake_service_.SetLastModifiedTime( |
2159 kResourceId, | 2159 kResourceId, |
2160 time, | 2160 time, |
2161 test_util::CreateCopyResultCallback(&error, &entry)); | 2161 test_util::CreateCopyResultCallback(&error, &entry)); |
2162 base::RunLoop().RunUntilIdle(); | 2162 base::RunLoop().RunUntilIdle(); |
2163 | 2163 |
2164 EXPECT_EQ(HTTP_SUCCESS, error); | 2164 EXPECT_EQ(HTTP_SUCCESS, error); |
2165 ASSERT_TRUE(entry); | 2165 ASSERT_TRUE(entry); |
2166 EXPECT_EQ(time, entry->modified_date()); | 2166 EXPECT_EQ(time, entry->modified_date()); |
2167 } | 2167 } |
2168 | 2168 |
2169 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_NonexistingFile) { | 2169 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_NonexistingFile) { |
2170 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2170 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
2171 | 2171 |
2172 const std::string kResourceId = "file:nonexisting_resource_id"; | 2172 const std::string kResourceId = "nonexisting_resource_id"; |
2173 base::Time time; | 2173 base::Time time; |
2174 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | 2174 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); |
2175 | 2175 |
2176 GDataErrorCode error = GDATA_OTHER_ERROR; | 2176 GDataErrorCode error = GDATA_OTHER_ERROR; |
2177 scoped_ptr<FileResource> entry; | 2177 scoped_ptr<FileResource> entry; |
2178 fake_service_.SetLastModifiedTime( | 2178 fake_service_.SetLastModifiedTime( |
2179 kResourceId, | 2179 kResourceId, |
2180 time, | 2180 time, |
2181 test_util::CreateCopyResultCallback(&error, &entry)); | 2181 test_util::CreateCopyResultCallback(&error, &entry)); |
2182 base::RunLoop().RunUntilIdle(); | 2182 base::RunLoop().RunUntilIdle(); |
2183 | 2183 |
2184 EXPECT_EQ(HTTP_NOT_FOUND, error); | 2184 EXPECT_EQ(HTTP_NOT_FOUND, error); |
2185 EXPECT_FALSE(entry); | 2185 EXPECT_FALSE(entry); |
2186 } | 2186 } |
2187 | 2187 |
2188 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_Offline) { | 2188 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_Offline) { |
2189 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2189 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
2190 fake_service_.set_offline(true); | 2190 fake_service_.set_offline(true); |
2191 | 2191 |
2192 const std::string kResourceId = "file:2_file_resource_id"; | 2192 const std::string kResourceId = "2_file_resource_id"; |
2193 base::Time time; | 2193 base::Time time; |
2194 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | 2194 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); |
2195 | 2195 |
2196 GDataErrorCode error = GDATA_OTHER_ERROR; | 2196 GDataErrorCode error = GDATA_OTHER_ERROR; |
2197 scoped_ptr<FileResource> entry; | 2197 scoped_ptr<FileResource> entry; |
2198 fake_service_.SetLastModifiedTime( | 2198 fake_service_.SetLastModifiedTime( |
2199 kResourceId, | 2199 kResourceId, |
2200 time, | 2200 time, |
2201 test_util::CreateCopyResultCallback(&error, &entry)); | 2201 test_util::CreateCopyResultCallback(&error, &entry)); |
2202 base::RunLoop().RunUntilIdle(); | 2202 base::RunLoop().RunUntilIdle(); |
2203 | 2203 |
2204 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 2204 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
2205 EXPECT_FALSE(entry); | 2205 EXPECT_FALSE(entry); |
2206 } | 2206 } |
2207 | 2207 |
2208 } // namespace | 2208 } // namespace |
2209 | 2209 |
2210 } // namespace drive | 2210 } // namespace drive |
OLD | NEW |