| 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 16 matching lines...) Expand all Loading... |
| 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 // Callback for DriveResourceMetadata::InitFromDB. | 31 // Callback for DriveResourceMetadata::InitFromDB. |
| 32 void CopyResultsFromInitFromDBCallback(DriveFileError* expected_error, | 32 void CopyResultsFromInitFromDBCallback(DriveFileError* expected_error, |
| 33 DriveFileError actual_error) { | 33 DriveFileError actual_error) { |
| 34 *expected_error = actual_error; | 34 *expected_error = actual_error; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Copies result from GetChildDirectoriesCallback. |
| 37 void CopyResultFromGetChildDirectoriesCallback( | 38 void CopyResultFromGetChildDirectoriesCallback( |
| 38 std::set<FilePath>* out_child_directories, | 39 std::set<FilePath>* out_child_directories, |
| 39 const std::set<FilePath>& in_child_directories) { | 40 const std::set<FilePath>& in_child_directories) { |
| 40 *out_child_directories = in_child_directories; | 41 *out_child_directories = in_child_directories; |
| 41 } | 42 } |
| 42 | 43 |
| 44 // Copies result from GetChangestampCallback. |
| 45 void CopyResultFromGetChangestampCallback( |
| 46 int64* out_changestamp, int64 in_changestamp) { |
| 47 *out_changestamp = in_changestamp; |
| 48 } |
| 49 |
| 43 } // namespace | 50 } // namespace |
| 44 | 51 |
| 45 class DriveResourceMetadataTest : public testing::Test { | 52 class DriveResourceMetadataTest : public testing::Test { |
| 46 public: | 53 public: |
| 47 DriveResourceMetadataTest(); | 54 DriveResourceMetadataTest(); |
| 48 | 55 |
| 49 protected: | 56 protected: |
| 50 // Creates a DriveEntryProto. | 57 // Creates a DriveEntryProto. |
| 51 DriveEntryProto CreateDriveEntryProto(int sequence_id, | 58 DriveEntryProto CreateDriveEntryProto(int sequence_id, |
| 52 bool is_directory, | 59 bool is_directory, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // This should succeed as the version matches the current number. | 180 // This should succeed as the version matches the current number. |
| 174 ASSERT_TRUE(resource_metadata.ParseFromString(serialized_proto)); | 181 ASSERT_TRUE(resource_metadata.ParseFromString(serialized_proto)); |
| 175 | 182 |
| 176 // Set a newer version, and serialize. | 183 // Set a newer version, and serialize. |
| 177 proto.set_version(kProtoVersion + 1); | 184 proto.set_version(kProtoVersion + 1); |
| 178 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); | 185 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
| 179 // This should fail as the version is newer. | 186 // This should fail as the version is newer. |
| 180 ASSERT_FALSE(resource_metadata.ParseFromString(serialized_proto)); | 187 ASSERT_FALSE(resource_metadata.ParseFromString(serialized_proto)); |
| 181 } | 188 } |
| 182 | 189 |
| 190 TEST_F(DriveResourceMetadataTest, LargestChangestamp) { |
| 191 DriveResourceMetadata resource_metadata; |
| 192 |
| 193 int64 in_changestamp = 123456; |
| 194 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 195 resource_metadata.SetLargestChangestamp( |
| 196 in_changestamp, |
| 197 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, |
| 198 &error)); |
| 199 google_apis::test_util::RunBlockingPoolTask(); |
| 200 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 201 |
| 202 int64 out_changestamp = 0; |
| 203 resource_metadata.GetLargestChangestamp( |
| 204 base::Bind(&CopyResultFromGetChangestampCallback, |
| 205 &out_changestamp)); |
| 206 google_apis::test_util::RunBlockingPoolTask(); |
| 207 DCHECK_EQ(in_changestamp, out_changestamp); |
| 208 } |
| 209 |
| 183 TEST_F(DriveResourceMetadataTest, GetEntryByResourceId_RootDirectory) { | 210 TEST_F(DriveResourceMetadataTest, GetEntryByResourceId_RootDirectory) { |
| 184 DriveResourceMetadata resource_metadata; | 211 DriveResourceMetadata resource_metadata; |
| 185 | 212 |
| 186 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 213 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 187 FilePath drive_file_path; | 214 FilePath drive_file_path; |
| 188 scoped_ptr<DriveEntryProto> entry_proto; | 215 scoped_ptr<DriveEntryProto> entry_proto; |
| 189 | 216 |
| 190 // Look up the root directory by its resource ID. | 217 // Look up the root directory by its resource ID. |
| 191 resource_metadata.GetEntryInfoByResourceId( | 218 resource_metadata.GetEntryInfoByResourceId( |
| 192 kWAPIRootDirectoryResourceId, | 219 kWAPIRootDirectoryResourceId, |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 FilePath::FromUTF8Unsafe("drive"), | 959 FilePath::FromUTF8Unsafe("drive"), |
| 933 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 960 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
| 934 &error, &entries)); | 961 &error, &entries)); |
| 935 google_apis::test_util::RunBlockingPoolTask(); | 962 google_apis::test_util::RunBlockingPoolTask(); |
| 936 EXPECT_EQ(DRIVE_FILE_OK, error); | 963 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 937 ASSERT_TRUE(entries.get()); | 964 ASSERT_TRUE(entries.get()); |
| 938 EXPECT_TRUE(entries->empty()); | 965 EXPECT_TRUE(entries->empty()); |
| 939 } | 966 } |
| 940 | 967 |
| 941 } // namespace drive | 968 } // namespace drive |
| OLD | NEW |