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/chromeos/drive/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 namespace drive { | 24 namespace drive { |
25 namespace { | 25 namespace { |
26 | 26 |
27 // See drive.proto for the difference between the two URLs. | 27 // See drive.proto for the difference between the two URLs. |
28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; | 28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; |
29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; | 29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; |
30 | 30 |
31 const char kTestRootResourceId[] = "test_root"; | 31 const char kTestRootResourceId[] = "test_root"; |
32 | 32 |
33 // The initial changestamp of the resource metadata used in | |
34 // DriveResourceMetadataTest. | |
35 const int64 kInitialChangestamp = 100; | |
hashimoto
2013/03/12 05:07:54
"initial" seems a bit confusing, it sounds like so
satorux1
2013/03/12 05:12:01
Sounds reasonable. Changed it to kTestChangestamp.
| |
36 | |
33 // Copies result from GetChildDirectoriesCallback. | 37 // Copies result from GetChildDirectoriesCallback. |
34 void CopyResultFromGetChildDirectoriesCallback( | 38 void CopyResultFromGetChildDirectoriesCallback( |
35 std::set<base::FilePath>* out_child_directories, | 39 std::set<base::FilePath>* out_child_directories, |
36 const std::set<base::FilePath>& in_child_directories) { | 40 const std::set<base::FilePath>& in_child_directories) { |
37 *out_child_directories = in_child_directories; | 41 *out_child_directories = in_child_directories; |
38 } | 42 } |
39 | 43 |
40 // Copies result from GetChangestampCallback. | 44 // Copies result from GetChangestampCallback. |
41 void CopyResultFromGetChangestampCallback( | 45 void CopyResultFromGetChangestampCallback( |
42 int64* out_changestamp, int64 in_changestamp) { | 46 int64* out_changestamp, int64 in_changestamp) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 resource_metadata, sequence_id++, false, "resource_id:dir2")); | 124 resource_metadata, sequence_id++, false, "resource_id:dir2")); |
121 ASSERT_TRUE(AddDriveEntryProto( | 125 ASSERT_TRUE(AddDriveEntryProto( |
122 resource_metadata, sequence_id++, false, "resource_id:dir2")); | 126 resource_metadata, sequence_id++, false, "resource_id:dir2")); |
123 ASSERT_TRUE(AddDriveEntryProto( | 127 ASSERT_TRUE(AddDriveEntryProto( |
124 resource_metadata, sequence_id++, false, "resource_id:dir2")); | 128 resource_metadata, sequence_id++, false, "resource_id:dir2")); |
125 | 129 |
126 ASSERT_TRUE(AddDriveEntryProto( | 130 ASSERT_TRUE(AddDriveEntryProto( |
127 resource_metadata, sequence_id++, false, "resource_id:dir3")); | 131 resource_metadata, sequence_id++, false, "resource_id:dir3")); |
128 ASSERT_TRUE(AddDriveEntryProto( | 132 ASSERT_TRUE(AddDriveEntryProto( |
129 resource_metadata, sequence_id++, false, "resource_id:dir3")); | 133 resource_metadata, sequence_id++, false, "resource_id:dir3")); |
134 | |
135 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | |
136 resource_metadata->SetLargestChangestamp( | |
137 kInitialChangestamp, | |
138 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, | |
139 &error)); | |
140 google_apis::test_util::RunBlockingPoolTask(); | |
141 EXPECT_EQ(DRIVE_FILE_OK, error); | |
130 } | 142 } |
131 | 143 |
132 // static | 144 // static |
133 DriveEntryProto DriveResourceMetadataTest::CreateDriveEntryProto( | 145 DriveEntryProto DriveResourceMetadataTest::CreateDriveEntryProto( |
134 int sequence_id, | 146 int sequence_id, |
135 bool is_directory, | 147 bool is_directory, |
136 const std::string& parent_resource_id) { | 148 const std::string& parent_resource_id) { |
137 DriveEntryProto entry_proto; | 149 DriveEntryProto entry_proto; |
138 const std::string sequence_id_str = base::IntToString(sequence_id); | 150 const std::string sequence_id_str = base::IntToString(sequence_id); |
139 const std::string title = (is_directory ? "dir" : "file") + sequence_id_str; | 151 const std::string title = (is_directory ? "dir" : "file") + sequence_id_str; |
140 const std::string resource_id = "resource_id:" + title; | 152 const std::string resource_id = "resource_id:" + title; |
141 entry_proto.set_title(title); | 153 entry_proto.set_title(title); |
142 entry_proto.set_resource_id(resource_id); | 154 entry_proto.set_resource_id(resource_id); |
143 entry_proto.set_parent_resource_id(parent_resource_id); | 155 entry_proto.set_parent_resource_id(parent_resource_id); |
144 | 156 |
145 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info(); | 157 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info(); |
146 file_info->set_is_directory(is_directory); | 158 file_info->set_is_directory(is_directory); |
147 | 159 |
148 if (!is_directory) { | 160 if (!is_directory) { |
149 DriveFileSpecificInfo* file_specific_info = | 161 DriveFileSpecificInfo* file_specific_info = |
150 entry_proto.mutable_file_specific_info(); | 162 entry_proto.mutable_file_specific_info(); |
151 file_info->set_size(sequence_id * 1024); | 163 file_info->set_size(sequence_id * 1024); |
152 file_specific_info->set_file_md5(std::string("md5:") + title); | 164 file_specific_info->set_file_md5(std::string("md5:") + title); |
165 } else { | |
166 DriveDirectorySpecificInfo* directory_specific_info = | |
167 entry_proto.mutable_directory_specific_info(); | |
168 directory_specific_info->set_changestamp(kInitialChangestamp); | |
153 } | 169 } |
154 return entry_proto; | 170 return entry_proto; |
155 } | 171 } |
156 | 172 |
157 bool DriveResourceMetadataTest::AddDriveEntryProto( | 173 bool DriveResourceMetadataTest::AddDriveEntryProto( |
158 DriveResourceMetadataInterface* resource_metadata, | 174 DriveResourceMetadataInterface* resource_metadata, |
159 int sequence_id, | 175 int sequence_id, |
160 bool is_directory, | 176 bool is_directory, |
161 const std::string& parent_resource_id) { | 177 const std::string& parent_resource_id) { |
162 DriveEntryProto entry_proto = CreateDriveEntryProto(sequence_id, | 178 DriveEntryProto entry_proto = CreateDriveEntryProto(sequence_id, |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 790 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
775 &error, &entry_proto)); | 791 &error, &entry_proto)); |
776 google_apis::test_util::RunBlockingPoolTask(); | 792 google_apis::test_util::RunBlockingPoolTask(); |
777 EXPECT_EQ(DRIVE_FILE_OK, error); | 793 EXPECT_EQ(DRIVE_FILE_OK, error); |
778 ASSERT_TRUE(entry_proto.get()); | 794 ASSERT_TRUE(entry_proto.get()); |
779 EXPECT_EQ("file9", entry_proto->base_name()); | 795 EXPECT_EQ("file9", entry_proto->base_name()); |
780 } | 796 } |
781 | 797 |
782 TEST_F(DriveResourceMetadataTest, RefreshDirectory_EmtpyMap) { | 798 TEST_F(DriveResourceMetadataTest, RefreshDirectory_EmtpyMap) { |
783 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/dir1")); | 799 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/dir1")); |
784 const int64 kChangestamp = 123; | 800 const int64 kNewChangestamp = kInitialChangestamp + 1; |
785 | 801 |
786 // Read the directory. | 802 // Read the directory. |
787 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 803 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
788 scoped_ptr<DriveEntryProtoVector> entries; | 804 scoped_ptr<DriveEntryProtoVector> entries; |
789 resource_metadata_->ReadDirectoryByPath( | 805 resource_metadata_->ReadDirectoryByPath( |
790 base::FilePath(kDirectoryPath), | 806 base::FilePath(kDirectoryPath), |
791 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 807 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
792 &error, &entries)); | 808 &error, &entries)); |
793 google_apis::test_util::RunBlockingPoolTask(); | 809 google_apis::test_util::RunBlockingPoolTask(); |
794 EXPECT_EQ(DRIVE_FILE_OK, error); | 810 EXPECT_EQ(DRIVE_FILE_OK, error); |
795 ASSERT_TRUE(entries.get()); | 811 ASSERT_TRUE(entries.get()); |
796 // "file4", "file5", "dir3" should exist in drive/dir1. | 812 // "file4", "file5", "dir3" should exist in drive/dir1. |
797 ASSERT_EQ(3U, entries->size()); | 813 ASSERT_EQ(3U, entries->size()); |
798 std::vector<std::string> base_names = GetSortedBaseNames(*entries); | 814 std::vector<std::string> base_names = GetSortedBaseNames(*entries); |
799 EXPECT_EQ("dir3", base_names[0]); | 815 EXPECT_EQ("dir3", base_names[0]); |
800 EXPECT_EQ("file4", base_names[1]); | 816 EXPECT_EQ("file4", base_names[1]); |
801 EXPECT_EQ("file5", base_names[2]); | 817 EXPECT_EQ("file5", base_names[2]); |
802 | 818 |
803 // Get the directory. | 819 // Get the directory. |
804 scoped_ptr<DriveEntryProto> dir1_proto; | 820 scoped_ptr<DriveEntryProto> dir1_proto; |
805 resource_metadata_->GetEntryInfoByPath( | 821 resource_metadata_->GetEntryInfoByPath( |
806 kDirectoryPath, | 822 kDirectoryPath, |
807 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 823 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
808 &error, &dir1_proto)); | 824 &error, &dir1_proto)); |
809 google_apis::test_util::RunBlockingPoolTask(); | 825 google_apis::test_util::RunBlockingPoolTask(); |
810 EXPECT_EQ(DRIVE_FILE_OK, error); | 826 EXPECT_EQ(DRIVE_FILE_OK, error); |
811 ASSERT_TRUE(dir1_proto.get()); | 827 ASSERT_TRUE(dir1_proto.get()); |
812 // The changestamp should be initially zero. | 828 // The changestamp should be initially kInitialChangestamp. |
813 EXPECT_EQ(0, dir1_proto->directory_specific_info().changestamp()); | 829 EXPECT_EQ(kInitialChangestamp, |
830 dir1_proto->directory_specific_info().changestamp()); | |
814 | 831 |
815 // Update the directory with an empty map. | 832 // Update the directory with an empty map. |
816 base::FilePath file_path; | 833 base::FilePath file_path; |
817 DriveEntryProtoMap entry_map; | 834 DriveEntryProtoMap entry_map; |
818 resource_metadata_->RefreshDirectory( | 835 resource_metadata_->RefreshDirectory( |
819 DirectoryFetchInfo(dir1_proto->resource_id(), kChangestamp), | 836 DirectoryFetchInfo(dir1_proto->resource_id(), kNewChangestamp), |
820 entry_map, | 837 entry_map, |
821 base::Bind(&test_util::CopyResultsFromFileMoveCallback, | 838 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
822 &error, | 839 &error, |
823 &file_path)); | 840 &file_path)); |
824 google_apis::test_util::RunBlockingPoolTask(); | 841 google_apis::test_util::RunBlockingPoolTask(); |
825 EXPECT_EQ(DRIVE_FILE_OK, error); | 842 EXPECT_EQ(DRIVE_FILE_OK, error); |
826 EXPECT_EQ(kDirectoryPath, file_path); | 843 EXPECT_EQ(kDirectoryPath, file_path); |
827 | 844 |
828 // Get the directory again. | 845 // Get the directory again. |
829 resource_metadata_->GetEntryInfoByPath( | 846 resource_metadata_->GetEntryInfoByPath( |
830 kDirectoryPath, | 847 kDirectoryPath, |
831 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 848 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
832 &error, &dir1_proto)); | 849 &error, &dir1_proto)); |
833 google_apis::test_util::RunBlockingPoolTask(); | 850 google_apis::test_util::RunBlockingPoolTask(); |
834 EXPECT_EQ(DRIVE_FILE_OK, error); | 851 EXPECT_EQ(DRIVE_FILE_OK, error); |
835 ASSERT_TRUE(dir1_proto.get()); | 852 ASSERT_TRUE(dir1_proto.get()); |
836 // The new changestamp should be set. | 853 // The new changestamp should be set. |
837 EXPECT_EQ(kChangestamp, dir1_proto->directory_specific_info().changestamp()); | 854 EXPECT_EQ(kNewChangestamp, |
855 dir1_proto->directory_specific_info().changestamp()); | |
838 | 856 |
839 // Read the directory again. | 857 // Read the directory again. |
840 resource_metadata_->ReadDirectoryByPath( | 858 resource_metadata_->ReadDirectoryByPath( |
841 base::FilePath(kDirectoryPath), | 859 base::FilePath(kDirectoryPath), |
842 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 860 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
843 &error, &entries)); | 861 &error, &entries)); |
844 google_apis::test_util::RunBlockingPoolTask(); | 862 google_apis::test_util::RunBlockingPoolTask(); |
845 EXPECT_EQ(DRIVE_FILE_OK, error); | 863 EXPECT_EQ(DRIVE_FILE_OK, error); |
846 ASSERT_TRUE(entries.get()); | 864 ASSERT_TRUE(entries.get()); |
847 // "file4", "file5" should be gone now, as RefreshDirectory() was called | 865 // "file4", "file5" should be gone now, as RefreshDirectory() was called |
848 // with an empty map. "dir3" should still remain, as RefreshDirectory() | 866 // with an empty map. "dir3" should still remain, as RefreshDirectory() |
849 // does not touch directories at this moment. TODO(satorux): | 867 // does not touch directories at this moment. TODO(satorux): |
850 // RefreshDirectory() should update directories too. crbug.com/178348 | 868 // RefreshDirectory() should update directories too. crbug.com/178348 |
851 ASSERT_EQ(1U, entries->size()); | 869 ASSERT_EQ(1U, entries->size()); |
852 base_names = GetSortedBaseNames(*entries); | 870 base_names = GetSortedBaseNames(*entries); |
853 EXPECT_EQ("dir3", base_names[0]); | 871 EXPECT_EQ("dir3", base_names[0]); |
854 } | 872 } |
855 | 873 |
856 TEST_F(DriveResourceMetadataTest, RefreshDirectory_NonEmptyMap) { | 874 TEST_F(DriveResourceMetadataTest, RefreshDirectory_NonEmptyMap) { |
857 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/dir1")); | 875 base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/dir1")); |
858 const int64 kChangestamp = 123; | 876 const int64 kNewChangestamp = kInitialChangestamp + 1; |
859 | 877 |
860 // Read the directory. | 878 // Read the directory. |
861 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 879 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
862 scoped_ptr<DriveEntryProtoVector> entries; | 880 scoped_ptr<DriveEntryProtoVector> entries; |
863 resource_metadata_->ReadDirectoryByPath( | 881 resource_metadata_->ReadDirectoryByPath( |
864 base::FilePath(kDirectoryPath), | 882 base::FilePath(kDirectoryPath), |
865 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 883 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
866 &error, &entries)); | 884 &error, &entries)); |
867 google_apis::test_util::RunBlockingPoolTask(); | 885 google_apis::test_util::RunBlockingPoolTask(); |
868 EXPECT_EQ(DRIVE_FILE_OK, error); | 886 EXPECT_EQ(DRIVE_FILE_OK, error); |
869 ASSERT_TRUE(entries.get()); | 887 ASSERT_TRUE(entries.get()); |
870 // "file4", "file5", "dir3" should exist in drive/dir1. | 888 // "file4", "file5", "dir3" should exist in drive/dir1. |
871 ASSERT_EQ(3U, entries->size()); | 889 ASSERT_EQ(3U, entries->size()); |
872 std::vector<std::string> base_names = GetSortedBaseNames(*entries); | 890 std::vector<std::string> base_names = GetSortedBaseNames(*entries); |
873 EXPECT_EQ("dir3", base_names[0]); | 891 EXPECT_EQ("dir3", base_names[0]); |
874 EXPECT_EQ("file4", base_names[1]); | 892 EXPECT_EQ("file4", base_names[1]); |
875 EXPECT_EQ("file5", base_names[2]); | 893 EXPECT_EQ("file5", base_names[2]); |
876 | 894 |
877 // Get the directory. | 895 // Get the directory. |
878 scoped_ptr<DriveEntryProto> dir1_proto; | 896 scoped_ptr<DriveEntryProto> dir1_proto; |
879 resource_metadata_->GetEntryInfoByPath( | 897 resource_metadata_->GetEntryInfoByPath( |
880 kDirectoryPath, | 898 kDirectoryPath, |
881 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 899 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
882 &error, &dir1_proto)); | 900 &error, &dir1_proto)); |
883 google_apis::test_util::RunBlockingPoolTask(); | 901 google_apis::test_util::RunBlockingPoolTask(); |
884 EXPECT_EQ(DRIVE_FILE_OK, error); | 902 EXPECT_EQ(DRIVE_FILE_OK, error); |
885 ASSERT_TRUE(dir1_proto.get()); | 903 ASSERT_TRUE(dir1_proto.get()); |
886 // The changestamp should be initially zero. | 904 // The changestamp should be initially kInitialChangestamp. |
887 EXPECT_EQ(0, dir1_proto->directory_specific_info().changestamp()); | 905 EXPECT_EQ(kInitialChangestamp, |
906 dir1_proto->directory_specific_info().changestamp()); | |
888 | 907 |
889 // Create a map with a new file. | 908 // Create a map with a new file. |
890 DriveEntryProto new_file; | 909 DriveEntryProto new_file; |
891 new_file.set_title("new_file"); | 910 new_file.set_title("new_file"); |
892 new_file.set_resource_id("new_resource_id"); | 911 new_file.set_resource_id("new_resource_id"); |
893 new_file.set_parent_resource_id(dir1_proto->resource_id()); | 912 new_file.set_parent_resource_id(dir1_proto->resource_id()); |
894 DriveEntryProtoMap entry_map; | 913 DriveEntryProtoMap entry_map; |
895 entry_map["new_resource_id"] = new_file; | 914 entry_map["new_resource_id"] = new_file; |
896 | 915 |
897 // Update the directory with the map. | 916 // Update the directory with the map. |
898 base::FilePath file_path; | 917 base::FilePath file_path; |
899 resource_metadata_->RefreshDirectory( | 918 resource_metadata_->RefreshDirectory( |
900 DirectoryFetchInfo(dir1_proto->resource_id(), kChangestamp), | 919 DirectoryFetchInfo(dir1_proto->resource_id(), kNewChangestamp), |
901 entry_map, | 920 entry_map, |
902 base::Bind(&test_util::CopyResultsFromFileMoveCallback, | 921 base::Bind(&test_util::CopyResultsFromFileMoveCallback, |
903 &error, | 922 &error, |
904 &file_path)); | 923 &file_path)); |
905 google_apis::test_util::RunBlockingPoolTask(); | 924 google_apis::test_util::RunBlockingPoolTask(); |
906 EXPECT_EQ(DRIVE_FILE_OK, error); | 925 EXPECT_EQ(DRIVE_FILE_OK, error); |
907 EXPECT_EQ(kDirectoryPath, file_path); | 926 EXPECT_EQ(kDirectoryPath, file_path); |
908 | 927 |
909 // Get the directory again. | 928 // Get the directory again. |
910 resource_metadata_->GetEntryInfoByPath( | 929 resource_metadata_->GetEntryInfoByPath( |
911 kDirectoryPath, | 930 kDirectoryPath, |
912 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 931 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
913 &error, &dir1_proto)); | 932 &error, &dir1_proto)); |
914 google_apis::test_util::RunBlockingPoolTask(); | 933 google_apis::test_util::RunBlockingPoolTask(); |
915 EXPECT_EQ(DRIVE_FILE_OK, error); | 934 EXPECT_EQ(DRIVE_FILE_OK, error); |
916 ASSERT_TRUE(dir1_proto.get()); | 935 ASSERT_TRUE(dir1_proto.get()); |
917 // The new changestamp should be set. | 936 // The new changestamp should be set. |
918 EXPECT_EQ(kChangestamp, dir1_proto->directory_specific_info().changestamp()); | 937 EXPECT_EQ(kNewChangestamp, |
938 dir1_proto->directory_specific_info().changestamp()); | |
919 | 939 |
920 // Read the directory again. | 940 // Read the directory again. |
921 resource_metadata_->ReadDirectoryByPath( | 941 resource_metadata_->ReadDirectoryByPath( |
922 base::FilePath(kDirectoryPath), | 942 base::FilePath(kDirectoryPath), |
923 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 943 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
924 &error, &entries)); | 944 &error, &entries)); |
925 google_apis::test_util::RunBlockingPoolTask(); | 945 google_apis::test_util::RunBlockingPoolTask(); |
926 EXPECT_EQ(DRIVE_FILE_OK, error); | 946 EXPECT_EQ(DRIVE_FILE_OK, error); |
927 ASSERT_TRUE(entries.get()); | 947 ASSERT_TRUE(entries.get()); |
928 // "file4", "file5" should be gone now, and "new_file" should now be added. | 948 // "file4", "file5" should be gone now, and "new_file" should now be added. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 base::FilePath::FromUTF8Unsafe("drive"), | 1111 base::FilePath::FromUTF8Unsafe("drive"), |
1092 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 1112 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
1093 &error, &entries)); | 1113 &error, &entries)); |
1094 google_apis::test_util::RunBlockingPoolTask(); | 1114 google_apis::test_util::RunBlockingPoolTask(); |
1095 EXPECT_EQ(DRIVE_FILE_OK, error); | 1115 EXPECT_EQ(DRIVE_FILE_OK, error); |
1096 ASSERT_TRUE(entries.get()); | 1116 ASSERT_TRUE(entries.get()); |
1097 EXPECT_TRUE(entries->empty()); | 1117 EXPECT_TRUE(entries->empty()); |
1098 } | 1118 } |
1099 | 1119 |
1100 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) { | 1120 TEST_F(DriveResourceMetadataTest, PerDirectoryChangestamp) { |
1101 const int kChangestamp = 123; | 1121 const int kNewChangestamp = kInitialChangestamp + 1; |
1102 const char kSubDirectoryResourceId[] = "sub-directory-id"; | 1122 const char kSubDirectoryResourceId[] = "sub-directory-id"; |
1103 | 1123 |
1104 DriveRootDirectoryProto proto; | 1124 DriveRootDirectoryProto proto; |
1105 proto.set_version(kProtoVersion); | 1125 proto.set_version(kProtoVersion); |
1106 proto.set_largest_changestamp(kChangestamp); | 1126 proto.set_largest_changestamp(kNewChangestamp); |
1107 | 1127 |
1108 // Set up the root directory. | 1128 // Set up the root directory. |
1109 DriveDirectoryProto* root = proto.mutable_drive_directory(); | 1129 DriveDirectoryProto* root = proto.mutable_drive_directory(); |
1110 DriveEntryProto* root_entry = root->mutable_drive_entry(); | 1130 DriveEntryProto* root_entry = root->mutable_drive_entry(); |
1111 root_entry->mutable_file_info()->set_is_directory(true); | 1131 root_entry->mutable_file_info()->set_is_directory(true); |
1112 root_entry->set_resource_id(kTestRootResourceId); | 1132 root_entry->set_resource_id(kTestRootResourceId); |
1113 root_entry->set_title("drive"); | 1133 root_entry->set_title("drive"); |
1114 // Add a sub directory. | 1134 // Add a sub directory. |
1115 DriveDirectoryProto* directory = root->add_child_directories(); | 1135 DriveDirectoryProto* directory = root->add_child_directories(); |
1116 DriveEntryProto* directory_entry = directory->mutable_drive_entry(); | 1136 DriveEntryProto* directory_entry = directory->mutable_drive_entry(); |
(...skipping 13 matching lines...) Expand all Loading... | |
1130 | 1150 |
1131 // Confirm that the root directory contains the changestamp. | 1151 // Confirm that the root directory contains the changestamp. |
1132 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 1152 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
1133 scoped_ptr<DriveEntryProto> entry_proto; | 1153 scoped_ptr<DriveEntryProto> entry_proto; |
1134 resource_metadata.GetEntryInfoByPath( | 1154 resource_metadata.GetEntryInfoByPath( |
1135 base::FilePath::FromUTF8Unsafe("drive"), | 1155 base::FilePath::FromUTF8Unsafe("drive"), |
1136 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 1156 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
1137 &error, &entry_proto)); | 1157 &error, &entry_proto)); |
1138 google_apis::test_util::RunBlockingPoolTask(); | 1158 google_apis::test_util::RunBlockingPoolTask(); |
1139 ASSERT_EQ(DRIVE_FILE_OK, error); | 1159 ASSERT_EQ(DRIVE_FILE_OK, error); |
1140 EXPECT_EQ(kChangestamp, entry_proto->directory_specific_info().changestamp()); | 1160 EXPECT_EQ(kNewChangestamp, |
1161 entry_proto->directory_specific_info().changestamp()); | |
1141 | 1162 |
1142 // Confirm that the sub directory contains the changestamp. | 1163 // Confirm that the sub directory contains the changestamp. |
1143 resource_metadata.GetEntryInfoByPath( | 1164 resource_metadata.GetEntryInfoByPath( |
1144 base::FilePath::FromUTF8Unsafe("drive/directory"), | 1165 base::FilePath::FromUTF8Unsafe("drive/directory"), |
1145 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, | 1166 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, |
1146 &error, &entry_proto)); | 1167 &error, &entry_proto)); |
1147 google_apis::test_util::RunBlockingPoolTask(); | 1168 google_apis::test_util::RunBlockingPoolTask(); |
1148 ASSERT_EQ(DRIVE_FILE_OK, error); | 1169 ASSERT_EQ(DRIVE_FILE_OK, error); |
1149 EXPECT_EQ(kChangestamp, entry_proto->directory_specific_info().changestamp()); | 1170 EXPECT_EQ(kNewChangestamp, |
1171 entry_proto->directory_specific_info().changestamp()); | |
1150 | 1172 |
1151 // Save the current metadata to a string as serialized proto. | 1173 // Save the current metadata to a string as serialized proto. |
1152 std::string new_serialized_proto; | 1174 std::string new_serialized_proto; |
1153 resource_metadata.SerializeToString(&new_serialized_proto); | 1175 resource_metadata.SerializeToString(&new_serialized_proto); |
1154 // Read the proto to see if per-directory changestamps were properly saved. | 1176 // Read the proto to see if per-directory changestamps were properly saved. |
1155 DriveRootDirectoryProto new_proto; | 1177 DriveRootDirectoryProto new_proto; |
1156 ASSERT_TRUE(new_proto.ParseFromString(new_serialized_proto)); | 1178 ASSERT_TRUE(new_proto.ParseFromString(new_serialized_proto)); |
1157 | 1179 |
1158 // Confirm that the root directory contains the changestamp. | 1180 // Confirm that the root directory contains the changestamp. |
1159 const DriveDirectoryProto& root_proto = new_proto.drive_directory(); | 1181 const DriveDirectoryProto& root_proto = new_proto.drive_directory(); |
1160 EXPECT_EQ(kChangestamp, | 1182 EXPECT_EQ(kNewChangestamp, |
1161 root_proto.drive_entry().directory_specific_info().changestamp()); | 1183 root_proto.drive_entry().directory_specific_info().changestamp()); |
1162 | 1184 |
1163 // Confirm that the sub directory contains the changestamp. | 1185 // Confirm that the sub directory contains the changestamp. |
1164 ASSERT_EQ(1, new_proto.drive_directory().child_directories_size()); | 1186 ASSERT_EQ(1, new_proto.drive_directory().child_directories_size()); |
1165 const DriveDirectoryProto& dir_proto = root_proto.child_directories(0); | 1187 const DriveDirectoryProto& dir_proto = root_proto.child_directories(0); |
1166 EXPECT_EQ(kChangestamp, | 1188 EXPECT_EQ(kNewChangestamp, |
1167 dir_proto.drive_entry().directory_specific_info().changestamp()); | 1189 dir_proto.drive_entry().directory_specific_info().changestamp()); |
1168 | 1190 |
1169 } | 1191 } |
1170 | 1192 |
1171 } // namespace drive | 1193 } // namespace drive |
OLD | NEW |