OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/drive/file_system/download_operation.h" | 5 #include "components/drive/file_system/download_operation.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
8 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
9 #include "components/drive/fake_free_disk_space_getter.h" | 12 #include "components/drive/fake_free_disk_space_getter.h" |
10 #include "components/drive/file_cache.h" | 13 #include "components/drive/file_cache.h" |
11 #include "components/drive/file_change.h" | 14 #include "components/drive/file_change.h" |
12 #include "components/drive/file_system/operation_test_base.h" | 15 #include "components/drive/file_system/operation_test_base.h" |
13 #include "components/drive/file_system_core_util.h" | 16 #include "components/drive/file_system_core_util.h" |
14 #include "components/drive/job_scheduler.h" | 17 #include "components/drive/job_scheduler.h" |
15 #include "components/drive/service/fake_drive_service.h" | 18 #include "components/drive/service/fake_drive_service.h" |
16 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
(...skipping 14 matching lines...) Expand all Loading... |
31 } | 34 } |
32 | 35 |
33 scoped_ptr<DownloadOperation> operation_; | 36 scoped_ptr<DownloadOperation> operation_; |
34 }; | 37 }; |
35 | 38 |
36 TEST_F(DownloadOperationTest, | 39 TEST_F(DownloadOperationTest, |
37 EnsureFileDownloadedByPath_FromServer_EnoughSpace) { | 40 EnsureFileDownloadedByPath_FromServer_EnoughSpace) { |
38 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 41 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
39 ResourceEntry src_entry; | 42 ResourceEntry src_entry; |
40 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 43 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
41 const int64 file_size = src_entry.file_info().size(); | 44 const int64_t file_size = src_entry.file_info().size(); |
42 | 45 |
43 // Pretend we have enough space. | 46 // Pretend we have enough space. |
44 fake_free_disk_space_getter()->set_default_value( | 47 fake_free_disk_space_getter()->set_default_value( |
45 file_size + drive::internal::kMinFreeSpaceInBytes); | 48 file_size + drive::internal::kMinFreeSpaceInBytes); |
46 | 49 |
47 FileError error = FILE_ERROR_FAILED; | 50 FileError error = FILE_ERROR_FAILED; |
48 base::FilePath file_path; | 51 base::FilePath file_path; |
49 scoped_ptr<ResourceEntry> entry; | 52 scoped_ptr<ResourceEntry> entry; |
50 operation_->EnsureFileDownloadedByPath( | 53 operation_->EnsureFileDownloadedByPath( |
51 file_in_root, | 54 file_in_root, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 content::RunAllBlockingPoolTasksUntilIdle(); | 89 content::RunAllBlockingPoolTasksUntilIdle(); |
87 | 90 |
88 EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error); | 91 EXPECT_EQ(FILE_ERROR_NO_LOCAL_SPACE, error); |
89 } | 92 } |
90 | 93 |
91 TEST_F(DownloadOperationTest, | 94 TEST_F(DownloadOperationTest, |
92 EnsureFileDownloadedByPath_FromServer_NoEnoughSpaceButCanFreeUp) { | 95 EnsureFileDownloadedByPath_FromServer_NoEnoughSpaceButCanFreeUp) { |
93 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 96 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
94 ResourceEntry src_entry; | 97 ResourceEntry src_entry; |
95 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 98 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
96 const int64 file_size = src_entry.file_info().size(); | 99 const int64_t file_size = src_entry.file_info().size(); |
97 | 100 |
98 // Make another file cached. | 101 // Make another file cached. |
99 // This file's cache file will be removed to free up the disk space. | 102 // This file's cache file will be removed to free up the disk space. |
100 base::FilePath cached_file( | 103 base::FilePath cached_file( |
101 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); | 104 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); |
102 FileError error = FILE_ERROR_FAILED; | 105 FileError error = FILE_ERROR_FAILED; |
103 base::FilePath file_path; | 106 base::FilePath file_path; |
104 scoped_ptr<ResourceEntry> entry; | 107 scoped_ptr<ResourceEntry> entry; |
105 operation_->EnsureFileDownloadedByPath( | 108 operation_->EnsureFileDownloadedByPath( |
106 cached_file, | 109 cached_file, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 GetLocalResourceEntry(cached_file, &cached_file_entry)); | 150 GetLocalResourceEntry(cached_file, &cached_file_entry)); |
148 EXPECT_FALSE( | 151 EXPECT_FALSE( |
149 cached_file_entry.file_specific_info().cache_state().is_present()); | 152 cached_file_entry.file_specific_info().cache_state().is_present()); |
150 } | 153 } |
151 | 154 |
152 TEST_F(DownloadOperationTest, | 155 TEST_F(DownloadOperationTest, |
153 EnsureFileDownloadedByPath_FromServer_EnoughSpaceButBecomeFull) { | 156 EnsureFileDownloadedByPath_FromServer_EnoughSpaceButBecomeFull) { |
154 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 157 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
155 ResourceEntry src_entry; | 158 ResourceEntry src_entry; |
156 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 159 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
157 const int64 file_size = src_entry.file_info().size(); | 160 const int64_t file_size = src_entry.file_info().size(); |
158 | 161 |
159 // Pretend we have enough space first (checked before downloading a file), | 162 // Pretend we have enough space first (checked before downloading a file), |
160 // but then start reporting we have not enough space. This is to emulate that | 163 // but then start reporting we have not enough space. This is to emulate that |
161 // the disk space becomes full after the file is downloaded for some reason | 164 // the disk space becomes full after the file is downloaded for some reason |
162 // (ex. the actual file was larger than the expected size). | 165 // (ex. the actual file was larger than the expected size). |
163 fake_free_disk_space_getter()->PushFakeValue( | 166 fake_free_disk_space_getter()->PushFakeValue( |
164 file_size + drive::internal::kMinFreeSpaceInBytes); | 167 file_size + drive::internal::kMinFreeSpaceInBytes); |
165 fake_free_disk_space_getter()->set_default_value( | 168 fake_free_disk_space_getter()->set_default_value( |
166 drive::internal::kMinFreeSpaceInBytes - 1); | 169 drive::internal::kMinFreeSpaceInBytes - 1); |
167 | 170 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 content::RunAllBlockingPoolTasksUntilIdle(); | 330 content::RunAllBlockingPoolTasksUntilIdle(); |
328 | 331 |
329 // Try second download. In this case, the file should be cached, so | 332 // Try second download. In this case, the file should be cached, so |
330 // |local_path| should not be empty. | 333 // |local_path| should not be empty. |
331 EXPECT_EQ(FILE_ERROR_OK, initialized_error); | 334 EXPECT_EQ(FILE_ERROR_OK, initialized_error); |
332 ASSERT_TRUE(entry); | 335 ASSERT_TRUE(entry); |
333 ASSERT_TRUE(!local_path.empty()); | 336 ASSERT_TRUE(!local_path.empty()); |
334 EXPECT_FALSE(cancel_download.is_null()); | 337 EXPECT_FALSE(cancel_download.is_null()); |
335 // The content is available from the cache file. | 338 // The content is available from the cache file. |
336 EXPECT_TRUE(get_content_callback.data().empty()); | 339 EXPECT_TRUE(get_content_callback.data().empty()); |
337 int64 local_file_size = 0; | 340 int64_t local_file_size = 0; |
338 base::GetFileSize(local_path, &local_file_size); | 341 base::GetFileSize(local_path, &local_file_size); |
339 EXPECT_EQ(entry->file_info().size(), local_file_size); | 342 EXPECT_EQ(entry->file_info().size(), local_file_size); |
340 EXPECT_EQ(FILE_ERROR_OK, completion_error); | 343 EXPECT_EQ(FILE_ERROR_OK, completion_error); |
341 } | 344 } |
342 } | 345 } |
343 | 346 |
344 TEST_F(DownloadOperationTest, EnsureFileDownloadedByLocalId_FromCache) { | 347 TEST_F(DownloadOperationTest, EnsureFileDownloadedByLocalId_FromCache) { |
345 base::FilePath temp_file; | 348 base::FilePath temp_file; |
346 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir(), &temp_file)); | 349 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir(), &temp_file)); |
347 | 350 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 ClientContext(USER_INITIATED), | 425 ClientContext(USER_INITIATED), |
423 google_apis::test_util::CreateCopyResultCallback( | 426 google_apis::test_util::CreateCopyResultCallback( |
424 &init_error, &init_path, &init_entry), | 427 &init_error, &init_path, &init_entry), |
425 google_apis::GetContentCallback(), | 428 google_apis::GetContentCallback(), |
426 google_apis::test_util::CreateCopyResultCallback( | 429 google_apis::test_util::CreateCopyResultCallback( |
427 &error, &file_path, &entry)); | 430 &error, &file_path, &entry)); |
428 content::RunAllBlockingPoolTasksUntilIdle(); | 431 content::RunAllBlockingPoolTasksUntilIdle(); |
429 | 432 |
430 EXPECT_EQ(FILE_ERROR_OK, error); | 433 EXPECT_EQ(FILE_ERROR_OK, error); |
431 // Check that the result of local modification is propagated. | 434 // Check that the result of local modification is propagated. |
432 EXPECT_EQ(static_cast<int64>(dirty_size), init_entry->file_info().size()); | 435 EXPECT_EQ(static_cast<int64_t>(dirty_size), init_entry->file_info().size()); |
433 EXPECT_EQ(static_cast<int64>(dirty_size), entry->file_info().size()); | 436 EXPECT_EQ(static_cast<int64_t>(dirty_size), entry->file_info().size()); |
434 } | 437 } |
435 | 438 |
436 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_LocallyCreatedFile) { | 439 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_LocallyCreatedFile) { |
437 // Add a new file with an empty resource ID. | 440 // Add a new file with an empty resource ID. |
438 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); | 441 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); |
439 ResourceEntry parent; | 442 ResourceEntry parent; |
440 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_path.DirName(), &parent)); | 443 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_path.DirName(), &parent)); |
441 | 444 |
442 ResourceEntry new_file; | 445 ResourceEntry new_file; |
443 new_file.set_title("New File.txt"); | 446 new_file.set_title("New File.txt"); |
(...skipping 18 matching lines...) Expand all Loading... |
462 operation_->EnsureFileDownloadedByPath( | 465 operation_->EnsureFileDownloadedByPath( |
463 file_path, | 466 file_path, |
464 ClientContext(USER_INITIATED), | 467 ClientContext(USER_INITIATED), |
465 GetFileContentInitializedCallback(), | 468 GetFileContentInitializedCallback(), |
466 google_apis::GetContentCallback(), | 469 google_apis::GetContentCallback(), |
467 google_apis::test_util::CreateCopyResultCallback( | 470 google_apis::test_util::CreateCopyResultCallback( |
468 &error, &cache_file_path, &entry)); | 471 &error, &cache_file_path, &entry)); |
469 content::RunAllBlockingPoolTasksUntilIdle(); | 472 content::RunAllBlockingPoolTasksUntilIdle(); |
470 EXPECT_EQ(FILE_ERROR_OK, error); | 473 EXPECT_EQ(FILE_ERROR_OK, error); |
471 | 474 |
472 int64 cache_file_size = 0; | 475 int64_t cache_file_size = 0; |
473 EXPECT_TRUE(base::GetFileSize(cache_file_path, &cache_file_size)); | 476 EXPECT_TRUE(base::GetFileSize(cache_file_path, &cache_file_size)); |
474 EXPECT_EQ(static_cast<int64>(0), cache_file_size); | 477 EXPECT_EQ(static_cast<int64_t>(0), cache_file_size); |
475 ASSERT_TRUE(entry); | 478 ASSERT_TRUE(entry); |
476 EXPECT_EQ(cache_file_size, entry->file_info().size()); | 479 EXPECT_EQ(cache_file_size, entry->file_info().size()); |
477 } | 480 } |
478 | 481 |
479 TEST_F(DownloadOperationTest, CancelBeforeDownloadStarts) { | 482 TEST_F(DownloadOperationTest, CancelBeforeDownloadStarts) { |
480 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 483 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
481 ResourceEntry src_entry; | 484 ResourceEntry src_entry; |
482 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 485 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
483 | 486 |
484 // Start operation. | 487 // Start operation. |
(...skipping 11 matching lines...) Expand all Loading... |
496 // Cancel immediately. | 499 // Cancel immediately. |
497 ASSERT_FALSE(cancel_closure.is_null()); | 500 ASSERT_FALSE(cancel_closure.is_null()); |
498 cancel_closure.Run(); | 501 cancel_closure.Run(); |
499 content::RunAllBlockingPoolTasksUntilIdle(); | 502 content::RunAllBlockingPoolTasksUntilIdle(); |
500 | 503 |
501 EXPECT_EQ(FILE_ERROR_ABORT, error); | 504 EXPECT_EQ(FILE_ERROR_ABORT, error); |
502 } | 505 } |
503 | 506 |
504 } // namespace file_system | 507 } // namespace file_system |
505 } // namespace drive | 508 } // namespace drive |
OLD | NEW |