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" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 291 } |
292 | 292 |
293 TEST_F(DownloadOperationTest, | 293 TEST_F(DownloadOperationTest, |
294 EnsureFileDownloadedByPath_WithGetContentCallback) { | 294 EnsureFileDownloadedByPath_WithGetContentCallback) { |
295 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 295 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
296 | 296 |
297 { | 297 { |
298 FileError initialized_error = FILE_ERROR_FAILED; | 298 FileError initialized_error = FILE_ERROR_FAILED; |
299 scoped_ptr<ResourceEntry> entry, entry_dontcare; | 299 scoped_ptr<ResourceEntry> entry, entry_dontcare; |
300 base::FilePath local_path, local_path_dontcare; | 300 base::FilePath local_path, local_path_dontcare; |
301 base::Closure cancel_download; | |
302 google_apis::test_util::TestGetContentCallback get_content_callback; | 301 google_apis::test_util::TestGetContentCallback get_content_callback; |
303 | |
304 FileError completion_error = FILE_ERROR_FAILED; | 302 FileError completion_error = FILE_ERROR_FAILED; |
305 | 303 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( |
306 operation_->EnsureFileDownloadedByPath( | |
307 file_in_root, | 304 file_in_root, |
308 ClientContext(USER_INITIATED), | 305 ClientContext(USER_INITIATED), |
309 google_apis::test_util::CreateCopyResultCallback( | 306 google_apis::test_util::CreateCopyResultCallback( |
310 &initialized_error, &entry, &local_path, &cancel_download), | 307 &initialized_error, &local_path, &entry), |
311 get_content_callback.callback(), | 308 get_content_callback.callback(), |
312 google_apis::test_util::CreateCopyResultCallback( | 309 google_apis::test_util::CreateCopyResultCallback( |
313 &completion_error, &local_path_dontcare, &entry_dontcare)); | 310 &completion_error, &local_path_dontcare, &entry_dontcare)); |
314 test_util::RunBlockingPoolTask(); | 311 test_util::RunBlockingPoolTask(); |
315 | 312 |
316 // For the first time, file is downloaded from the remote server. | 313 // For the first time, file is downloaded from the remote server. |
317 // In this case, |local_path| is empty while |cancel_download| is not. | 314 // In this case, |local_path| is empty. |
318 EXPECT_EQ(FILE_ERROR_OK, initialized_error); | 315 EXPECT_EQ(FILE_ERROR_OK, initialized_error); |
319 ASSERT_TRUE(entry); | 316 ASSERT_TRUE(entry); |
320 ASSERT_TRUE(local_path.empty()); | 317 ASSERT_TRUE(local_path.empty()); |
321 EXPECT_TRUE(!cancel_download.is_null()); | 318 EXPECT_FALSE(cancel_download.is_null()); |
322 // Content is available through the second callback argument. | 319 // Content is available through the second callback argument. |
323 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), | 320 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), |
324 get_content_callback.GetConcatenatedData().size()); | 321 get_content_callback.GetConcatenatedData().size()); |
325 EXPECT_EQ(FILE_ERROR_OK, completion_error); | 322 EXPECT_EQ(FILE_ERROR_OK, completion_error); |
326 | 323 |
327 // The transfered file is cached and the change of "offline available" | 324 // The transfered file is cached and the change of "offline available" |
328 // attribute is notified. | 325 // attribute is notified. |
329 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 326 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
330 EXPECT_EQ(1U, | 327 EXPECT_EQ(1U, |
331 observer()->get_changed_paths().count(file_in_root.DirName())); | 328 observer()->get_changed_paths().count(file_in_root.DirName())); |
332 } | 329 } |
333 | 330 |
334 { | 331 { |
335 FileError initialized_error = FILE_ERROR_FAILED; | 332 FileError initialized_error = FILE_ERROR_FAILED; |
336 scoped_ptr<ResourceEntry> entry, entry_dontcare; | 333 scoped_ptr<ResourceEntry> entry, entry_dontcare; |
337 base::FilePath local_path, local_path_dontcare; | 334 base::FilePath local_path, local_path_dontcare; |
338 base::Closure cancel_download; | |
339 google_apis::test_util::TestGetContentCallback get_content_callback; | 335 google_apis::test_util::TestGetContentCallback get_content_callback; |
340 | |
341 FileError completion_error = FILE_ERROR_FAILED; | 336 FileError completion_error = FILE_ERROR_FAILED; |
342 | 337 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( |
343 operation_->EnsureFileDownloadedByPath( | |
344 file_in_root, | 338 file_in_root, |
345 ClientContext(USER_INITIATED), | 339 ClientContext(USER_INITIATED), |
346 google_apis::test_util::CreateCopyResultCallback( | 340 google_apis::test_util::CreateCopyResultCallback( |
347 &initialized_error, &entry, &local_path, &cancel_download), | 341 &initialized_error, &local_path, &entry), |
348 get_content_callback.callback(), | 342 get_content_callback.callback(), |
349 google_apis::test_util::CreateCopyResultCallback( | 343 google_apis::test_util::CreateCopyResultCallback( |
350 &completion_error, &local_path_dontcare, &entry_dontcare)); | 344 &completion_error, &local_path_dontcare, &entry_dontcare)); |
351 test_util::RunBlockingPoolTask(); | 345 test_util::RunBlockingPoolTask(); |
352 | 346 |
353 // Try second download. In this case, the file should be cached, so | 347 // Try second download. In this case, the file should be cached, so |
354 // |local_path| should not be empty while |cancel_download| is empty. | 348 // |local_path| should not be empty. |
355 EXPECT_EQ(FILE_ERROR_OK, initialized_error); | 349 EXPECT_EQ(FILE_ERROR_OK, initialized_error); |
356 ASSERT_TRUE(entry); | 350 ASSERT_TRUE(entry); |
357 ASSERT_TRUE(!local_path.empty()); | 351 ASSERT_TRUE(!local_path.empty()); |
358 EXPECT_TRUE(cancel_download.is_null()); | 352 EXPECT_FALSE(cancel_download.is_null()); |
359 // The content is available from the cache file. | 353 // The content is available from the cache file. |
360 EXPECT_TRUE(get_content_callback.data().empty()); | 354 EXPECT_TRUE(get_content_callback.data().empty()); |
361 int64 local_file_size = 0; | 355 int64 local_file_size = 0; |
362 base::GetFileSize(local_path, &local_file_size); | 356 base::GetFileSize(local_path, &local_file_size); |
363 EXPECT_EQ(entry->file_info().size(), local_file_size); | 357 EXPECT_EQ(entry->file_info().size(), local_file_size); |
364 EXPECT_EQ(FILE_ERROR_OK, completion_error); | 358 EXPECT_EQ(FILE_ERROR_OK, completion_error); |
365 } | 359 } |
366 } | 360 } |
367 | 361 |
368 TEST_F(DownloadOperationTest, EnsureFileDownloadedByLocalId_FromCache) { | 362 TEST_F(DownloadOperationTest, EnsureFileDownloadedByLocalId_FromCache) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 dirty_file, | 426 dirty_file, |
433 internal::FileCache::FILE_OPERATION_COPY), | 427 internal::FileCache::FILE_OPERATION_COPY), |
434 google_apis::test_util::CreateCopyResultCallback(&error)); | 428 google_apis::test_util::CreateCopyResultCallback(&error)); |
435 test_util::RunBlockingPoolTask(); | 429 test_util::RunBlockingPoolTask(); |
436 EXPECT_EQ(FILE_ERROR_OK, error); | 430 EXPECT_EQ(FILE_ERROR_OK, error); |
437 | 431 |
438 // Record values passed to GetFileContentInitializedCallback(). | 432 // Record values passed to GetFileContentInitializedCallback(). |
439 FileError init_error; | 433 FileError init_error; |
440 base::FilePath init_path; | 434 base::FilePath init_path; |
441 scoped_ptr<ResourceEntry> init_entry; | 435 scoped_ptr<ResourceEntry> init_entry; |
442 base::Closure cancel_callback; | |
443 | |
444 base::FilePath file_path; | 436 base::FilePath file_path; |
445 scoped_ptr<ResourceEntry> entry; | 437 scoped_ptr<ResourceEntry> entry; |
446 operation_->EnsureFileDownloadedByPath( | 438 base::Closure cancel_callback = operation_->EnsureFileDownloadedByPath( |
447 file_in_root, | 439 file_in_root, |
448 ClientContext(USER_INITIATED), | 440 ClientContext(USER_INITIATED), |
449 google_apis::test_util::CreateCopyResultCallback( | 441 google_apis::test_util::CreateCopyResultCallback( |
450 &init_error, &init_entry, &init_path, &cancel_callback), | 442 &init_error, &init_path, &init_entry), |
451 google_apis::GetContentCallback(), | 443 google_apis::GetContentCallback(), |
452 google_apis::test_util::CreateCopyResultCallback( | 444 google_apis::test_util::CreateCopyResultCallback( |
453 &error, &file_path, &entry)); | 445 &error, &file_path, &entry)); |
454 test_util::RunBlockingPoolTask(); | 446 test_util::RunBlockingPoolTask(); |
455 | 447 |
456 EXPECT_EQ(FILE_ERROR_OK, error); | 448 EXPECT_EQ(FILE_ERROR_OK, error); |
457 // Check that the result of local modification is propagated. | 449 // Check that the result of local modification is propagated. |
458 EXPECT_EQ(static_cast<int64>(dirty_size), init_entry->file_info().size()); | 450 EXPECT_EQ(static_cast<int64>(dirty_size), init_entry->file_info().size()); |
459 EXPECT_EQ(static_cast<int64>(dirty_size), entry->file_info().size()); | 451 EXPECT_EQ(static_cast<int64>(dirty_size), entry->file_info().size()); |
460 } | 452 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 489 |
498 int64 cache_file_size = 0; | 490 int64 cache_file_size = 0; |
499 EXPECT_TRUE(base::GetFileSize(cache_file_path, &cache_file_size)); | 491 EXPECT_TRUE(base::GetFileSize(cache_file_path, &cache_file_size)); |
500 EXPECT_EQ(static_cast<int64>(0), cache_file_size); | 492 EXPECT_EQ(static_cast<int64>(0), cache_file_size); |
501 ASSERT_TRUE(entry); | 493 ASSERT_TRUE(entry); |
502 EXPECT_EQ(cache_file_size, entry->file_info().size()); | 494 EXPECT_EQ(cache_file_size, entry->file_info().size()); |
503 } | 495 } |
504 | 496 |
505 } // namespace file_system | 497 } // namespace file_system |
506 } // namespace drive | 498 } // namespace drive |
OLD | NEW |