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 "chrome/browser/chromeos/drive/file_system/download_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/task_runner_util.h" | 8 #include "base/task_runner_util.h" |
9 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" | 9 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
10 #include "chrome/browser/chromeos/drive/file_cache.h" | 10 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 11 #include "chrome/browser/chromeos/drive/file_change.h" |
11 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 12 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
12 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
14 #include "chrome/browser/drive/fake_drive_service.h" | 15 #include "chrome/browser/drive/fake_drive_service.h" |
15 #include "google_apis/drive/test_util.h" | 16 #include "google_apis/drive/test_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/cros_system_api/constants/cryptohome.h" | 18 #include "third_party/cros_system_api/constants/cryptohome.h" |
18 | 19 |
19 namespace drive { | 20 namespace drive { |
20 namespace file_system { | 21 namespace file_system { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 google_apis::test_util::CreateCopyResultCallback( | 55 google_apis::test_util::CreateCopyResultCallback( |
55 &error, &file_path, &entry)); | 56 &error, &file_path, &entry)); |
56 test_util::RunBlockingPoolTask(); | 57 test_util::RunBlockingPoolTask(); |
57 | 58 |
58 EXPECT_EQ(FILE_ERROR_OK, error); | 59 EXPECT_EQ(FILE_ERROR_OK, error); |
59 ASSERT_TRUE(entry); | 60 ASSERT_TRUE(entry); |
60 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 61 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
61 | 62 |
62 // The transfered file is cached and the change of "offline available" | 63 // The transfered file is cached and the change of "offline available" |
63 // attribute is notified. | 64 // attribute is notified. |
64 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 65 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
65 EXPECT_EQ(1U, observer()->get_changed_paths().count(file_in_root.DirName())); | 66 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); |
66 } | 67 } |
67 | 68 |
68 TEST_F(DownloadOperationTest, | 69 TEST_F(DownloadOperationTest, |
69 EnsureFileDownloadedByPath_FromServer_NoSpaceAtAll) { | 70 EnsureFileDownloadedByPath_FromServer_NoSpaceAtAll) { |
70 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 71 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
71 | 72 |
72 // Pretend we have no space at all. | 73 // Pretend we have no space at all. |
73 fake_free_disk_space_getter()->set_default_value(0); | 74 fake_free_disk_space_getter()->set_default_value(0); |
74 | 75 |
75 FileError error = FILE_ERROR_OK; | 76 FileError error = FILE_ERROR_OK; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 google_apis::test_util::CreateCopyResultCallback( | 129 google_apis::test_util::CreateCopyResultCallback( |
129 &error, &file_path, &entry)); | 130 &error, &file_path, &entry)); |
130 test_util::RunBlockingPoolTask(); | 131 test_util::RunBlockingPoolTask(); |
131 | 132 |
132 EXPECT_EQ(FILE_ERROR_OK, error); | 133 EXPECT_EQ(FILE_ERROR_OK, error); |
133 ASSERT_TRUE(entry); | 134 ASSERT_TRUE(entry); |
134 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 135 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
135 | 136 |
136 // The transfered file is cached and the change of "offline available" | 137 // The transfered file is cached and the change of "offline available" |
137 // attribute is notified. | 138 // attribute is notified. |
138 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 139 EXPECT_EQ(2U, observer()->get_changed_files().size()); |
139 EXPECT_EQ(1U, observer()->get_changed_paths().count(file_in_root.DirName())); | 140 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); |
| 141 EXPECT_TRUE(observer()->get_changed_files().count(cached_file)); |
140 | 142 |
141 // The cache for the other file should be removed in order to free up space. | 143 // The cache for the other file should be removed in order to free up space. |
142 ResourceEntry cached_file_entry; | 144 ResourceEntry cached_file_entry; |
143 EXPECT_EQ(FILE_ERROR_OK, | 145 EXPECT_EQ(FILE_ERROR_OK, |
144 GetLocalResourceEntry(cached_file, &cached_file_entry)); | 146 GetLocalResourceEntry(cached_file, &cached_file_entry)); |
145 EXPECT_FALSE( | 147 EXPECT_FALSE( |
146 cached_file_entry.file_specific_info().cache_state().is_present()); | 148 cached_file_entry.file_specific_info().cache_state().is_present()); |
147 } | 149 } |
148 | 150 |
149 TEST_F(DownloadOperationTest, | 151 TEST_F(DownloadOperationTest, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 google_apis::test_util::CreateCopyResultCallback( | 261 google_apis::test_util::CreateCopyResultCallback( |
260 &error, &file_path, &entry)); | 262 &error, &file_path, &entry)); |
261 test_util::RunBlockingPoolTask(); | 263 test_util::RunBlockingPoolTask(); |
262 | 264 |
263 EXPECT_EQ(FILE_ERROR_OK, error); | 265 EXPECT_EQ(FILE_ERROR_OK, error); |
264 ASSERT_TRUE(entry); | 266 ASSERT_TRUE(entry); |
265 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 267 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
266 | 268 |
267 // The transfered file is cached and the change of "offline available" | 269 // The transfered file is cached and the change of "offline available" |
268 // attribute is notified. | 270 // attribute is notified. |
269 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 271 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
270 EXPECT_EQ(1U, observer()->get_changed_paths().count(file_in_root.DirName())); | 272 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); |
271 } | 273 } |
272 | 274 |
273 TEST_F(DownloadOperationTest, | 275 TEST_F(DownloadOperationTest, |
274 EnsureFileDownloadedByPath_WithGetContentCallback) { | 276 EnsureFileDownloadedByPath_WithGetContentCallback) { |
275 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 277 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
276 | 278 |
277 { | 279 { |
278 FileError initialized_error = FILE_ERROR_FAILED; | 280 FileError initialized_error = FILE_ERROR_FAILED; |
279 scoped_ptr<ResourceEntry> entry, entry_dontcare; | 281 scoped_ptr<ResourceEntry> entry, entry_dontcare; |
280 base::FilePath local_path, local_path_dontcare; | 282 base::FilePath local_path, local_path_dontcare; |
(...skipping 15 matching lines...) Expand all Loading... |
296 ASSERT_TRUE(entry); | 298 ASSERT_TRUE(entry); |
297 ASSERT_TRUE(local_path.empty()); | 299 ASSERT_TRUE(local_path.empty()); |
298 EXPECT_FALSE(cancel_download.is_null()); | 300 EXPECT_FALSE(cancel_download.is_null()); |
299 // Content is available through the second callback argument. | 301 // Content is available through the second callback argument. |
300 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), | 302 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), |
301 get_content_callback.GetConcatenatedData().size()); | 303 get_content_callback.GetConcatenatedData().size()); |
302 EXPECT_EQ(FILE_ERROR_OK, completion_error); | 304 EXPECT_EQ(FILE_ERROR_OK, completion_error); |
303 | 305 |
304 // The transfered file is cached and the change of "offline available" | 306 // The transfered file is cached and the change of "offline available" |
305 // attribute is notified. | 307 // attribute is notified. |
306 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 308 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
307 EXPECT_EQ(1U, | 309 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); |
308 observer()->get_changed_paths().count(file_in_root.DirName())); | |
309 } | 310 } |
310 | 311 |
311 { | 312 { |
312 FileError initialized_error = FILE_ERROR_FAILED; | 313 FileError initialized_error = FILE_ERROR_FAILED; |
313 scoped_ptr<ResourceEntry> entry, entry_dontcare; | 314 scoped_ptr<ResourceEntry> entry, entry_dontcare; |
314 base::FilePath local_path, local_path_dontcare; | 315 base::FilePath local_path, local_path_dontcare; |
315 google_apis::test_util::TestGetContentCallback get_content_callback; | 316 google_apis::test_util::TestGetContentCallback get_content_callback; |
316 FileError completion_error = FILE_ERROR_FAILED; | 317 FileError completion_error = FILE_ERROR_FAILED; |
317 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( | 318 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( |
318 file_in_root, | 319 file_in_root, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 // Cancel immediately. | 495 // Cancel immediately. |
495 ASSERT_FALSE(cancel_closure.is_null()); | 496 ASSERT_FALSE(cancel_closure.is_null()); |
496 cancel_closure.Run(); | 497 cancel_closure.Run(); |
497 test_util::RunBlockingPoolTask(); | 498 test_util::RunBlockingPoolTask(); |
498 | 499 |
499 EXPECT_EQ(FILE_ERROR_ABORT, error); | 500 EXPECT_EQ(FILE_ERROR_ABORT, error); |
500 } | 501 } |
501 | 502 |
502 } // namespace file_system | 503 } // namespace file_system |
503 } // namespace drive | 504 } // namespace drive |
OLD | NEW |