| 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 "components/drive/file_system.h" | 5 #include "components/drive/file_system.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <string> | 10 #include <string> |
| 8 #include <vector> | 11 #include <vector> |
| 9 | 12 |
| 10 #include "base/bind.h" | 13 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/prefs/testing_pref_service.h" | 19 #include "base/prefs/testing_pref_service.h" |
| 16 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 18 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 19 #include "components/drive/change_list_loader.h" | 23 #include "components/drive/change_list_loader.h" |
| 20 #include "components/drive/drive.pb.h" | 24 #include "components/drive/drive.pb.h" |
| 21 #include "components/drive/drive_api_util.h" | 25 #include "components/drive/drive_api_util.h" |
| 22 #include "components/drive/drive_test_util.h" | 26 #include "components/drive/drive_test_util.h" |
| 23 #include "components/drive/event_logger.h" | 27 #include "components/drive/event_logger.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 base::ThreadTaskRunnerHandle::Get().get(), | 238 base::ThreadTaskRunnerHandle::Get().get(), |
| 235 fake_free_disk_space_getter_.get())); | 239 fake_free_disk_space_getter_.get())); |
| 236 | 240 |
| 237 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> | 241 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> |
| 238 resource_metadata(new internal::ResourceMetadata( | 242 resource_metadata(new internal::ResourceMetadata( |
| 239 metadata_storage_.get(), cache.get(), | 243 metadata_storage_.get(), cache.get(), |
| 240 base::ThreadTaskRunnerHandle::Get())); | 244 base::ThreadTaskRunnerHandle::Get())); |
| 241 | 245 |
| 242 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->Initialize()); | 246 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->Initialize()); |
| 243 | 247 |
| 244 const int64 changestamp = param == USE_SERVER_TIMESTAMP ? | 248 const int64_t changestamp = |
| 245 fake_drive_service_->about_resource().largest_change_id() : 1; | 249 param == USE_SERVER_TIMESTAMP |
| 250 ? fake_drive_service_->about_resource().largest_change_id() |
| 251 : 1; |
| 246 ASSERT_EQ(FILE_ERROR_OK, | 252 ASSERT_EQ(FILE_ERROR_OK, |
| 247 resource_metadata->SetLargestChangestamp(changestamp)); | 253 resource_metadata->SetLargestChangestamp(changestamp)); |
| 248 | 254 |
| 249 // drive/root | 255 // drive/root |
| 250 ResourceEntry root; | 256 ResourceEntry root; |
| 251 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->GetResourceEntryByPath( | 257 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->GetResourceEntryByPath( |
| 252 util::GetDriveMyDriveRootPath(), &root)); | 258 util::GetDriveMyDriveRootPath(), &root)); |
| 253 root.set_resource_id(fake_drive_service_->GetRootResourceId()); | 259 root.set_resource_id(fake_drive_service_->GetRootResourceId()); |
| 254 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->RefreshEntry(root)); | 260 ASSERT_EQ(FILE_ERROR_OK, resource_metadata->RefreshEntry(root)); |
| 255 | 261 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 ASSERT_TRUE(server_entry); | 561 ASSERT_TRUE(server_entry); |
| 556 EXPECT_EQ(last_accessed, server_entry->last_viewed_by_me_date()); | 562 EXPECT_EQ(last_accessed, server_entry->last_viewed_by_me_date()); |
| 557 EXPECT_EQ(last_modified, server_entry->modified_date()); | 563 EXPECT_EQ(last_modified, server_entry->modified_date()); |
| 558 } | 564 } |
| 559 | 565 |
| 560 TEST_F(FileSystemTest, TruncateFile) { | 566 TEST_F(FileSystemTest, TruncateFile) { |
| 561 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 567 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 562 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); | 568 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); |
| 563 ASSERT_TRUE(entry); | 569 ASSERT_TRUE(entry); |
| 564 | 570 |
| 565 const int64 kLength = entry->file_info().size() + 100; | 571 const int64_t kLength = entry->file_info().size() + 100; |
| 566 | 572 |
| 567 FileError error = FILE_ERROR_FAILED; | 573 FileError error = FILE_ERROR_FAILED; |
| 568 file_system_->TruncateFile( | 574 file_system_->TruncateFile( |
| 569 file_path, | 575 file_path, |
| 570 kLength, | 576 kLength, |
| 571 google_apis::test_util::CreateCopyResultCallback(&error)); | 577 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 572 content::RunAllBlockingPoolTasksUntilIdle(); | 578 content::RunAllBlockingPoolTasksUntilIdle(); |
| 573 EXPECT_EQ(FILE_ERROR_OK, error); | 579 EXPECT_EQ(FILE_ERROR_OK, error); |
| 574 | 580 |
| 575 // File is touched on the server. | 581 // File is touched on the server. |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 EXPECT_EQ(FILE_ERROR_OK, error_unpin); | 961 EXPECT_EQ(FILE_ERROR_OK, error_unpin); |
| 956 | 962 |
| 957 // No cache file available because the sync was cancelled by Unpin(). | 963 // No cache file available because the sync was cancelled by Unpin(). |
| 958 entry = GetResourceEntrySync(file_path); | 964 entry = GetResourceEntrySync(file_path); |
| 959 ASSERT_TRUE(entry); | 965 ASSERT_TRUE(entry); |
| 960 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); | 966 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); |
| 961 } | 967 } |
| 962 | 968 |
| 963 TEST_F(FileSystemTest, GetAvailableSpace) { | 969 TEST_F(FileSystemTest, GetAvailableSpace) { |
| 964 FileError error = FILE_ERROR_OK; | 970 FileError error = FILE_ERROR_OK; |
| 965 int64 bytes_total; | 971 int64_t bytes_total; |
| 966 int64 bytes_used; | 972 int64_t bytes_used; |
| 967 file_system_->GetAvailableSpace( | 973 file_system_->GetAvailableSpace( |
| 968 google_apis::test_util::CreateCopyResultCallback( | 974 google_apis::test_util::CreateCopyResultCallback( |
| 969 &error, &bytes_total, &bytes_used)); | 975 &error, &bytes_total, &bytes_used)); |
| 970 content::RunAllBlockingPoolTasksUntilIdle(); | 976 content::RunAllBlockingPoolTasksUntilIdle(); |
| 971 EXPECT_EQ(6789012345LL, bytes_used); | 977 EXPECT_EQ(6789012345LL, bytes_used); |
| 972 EXPECT_EQ(9876543210LL, bytes_total); | 978 EXPECT_EQ(9876543210LL, bytes_total); |
| 973 } | 979 } |
| 974 | 980 |
| 975 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) { | 981 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) { |
| 976 ASSERT_TRUE(LoadFullResourceList()); | 982 ASSERT_TRUE(LoadFullResourceList()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 google_apis::test_util::CreateCopyResultCallback(&available)); | 1061 google_apis::test_util::CreateCopyResultCallback(&available)); |
| 1056 content::RunAllBlockingPoolTasksUntilIdle(); | 1062 content::RunAllBlockingPoolTasksUntilIdle(); |
| 1057 ASSERT_FALSE(available); | 1063 ASSERT_FALSE(available); |
| 1058 | 1064 |
| 1059 entry = GetResourceEntrySync(file_in_root); | 1065 entry = GetResourceEntrySync(file_in_root); |
| 1060 ASSERT_TRUE(entry); | 1066 ASSERT_TRUE(entry); |
| 1061 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); | 1067 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); |
| 1062 } | 1068 } |
| 1063 | 1069 |
| 1064 } // namespace drive | 1070 } // namespace drive |
| OLD | NEW |