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 "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" | 8 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
9 #include "chrome/browser/chromeos/drive/file_cache.h" | 9 #include "chrome/browser/chromeos/drive/file_cache.h" |
10 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 10 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 google_apis::GetContentCallback(), | 382 google_apis::GetContentCallback(), |
383 google_apis::test_util::CreateCopyResultCallback( | 383 google_apis::test_util::CreateCopyResultCallback( |
384 &error, &file_path, &entry)); | 384 &error, &file_path, &entry)); |
385 google_apis::test_util::RunBlockingPoolTask(); | 385 google_apis::test_util::RunBlockingPoolTask(); |
386 | 386 |
387 EXPECT_EQ(FILE_ERROR_OK, error); | 387 EXPECT_EQ(FILE_ERROR_OK, error); |
388 ASSERT_TRUE(entry); | 388 ASSERT_TRUE(entry); |
389 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 389 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
390 } | 390 } |
391 | 391 |
| 392 TEST_F(DownloadOperationTest, EnsureFileDownloadedByPath_DirtyCache) { |
| 393 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 394 ResourceEntry src_entry; |
| 395 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
| 396 |
| 397 // Prepare a dirty file to store to cache that has a different size than |
| 398 // stored in resource metadata. |
| 399 base::FilePath dirty_file = temp_dir().AppendASCII("dirty.txt"); |
| 400 size_t dirty_size = src_entry.file_info().size() + 10; |
| 401 google_apis::test_util::WriteStringToFile(dirty_file, |
| 402 std::string(dirty_size, 'x')); |
| 403 |
| 404 // Store the file as a cache, marking it to be dirty. |
| 405 FileError error = FILE_ERROR_FAILED; |
| 406 cache()->StoreLocallyModifiedOnUIThread( |
| 407 src_entry.resource_id(), |
| 408 src_entry.file_specific_info().file_md5(), |
| 409 dirty_file, |
| 410 internal::FileCache::FILE_OPERATION_COPY, |
| 411 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 412 google_apis::test_util::RunBlockingPoolTask(); |
| 413 EXPECT_EQ(FILE_ERROR_OK, error); |
| 414 |
| 415 // Record values passed to GetFileContentInitializedCallback(). |
| 416 FileError init_error; |
| 417 base::FilePath init_path; |
| 418 scoped_ptr<ResourceEntry> init_entry; |
| 419 base::Closure cancel_callback; |
| 420 |
| 421 base::FilePath file_path; |
| 422 scoped_ptr<ResourceEntry> entry; |
| 423 operation_->EnsureFileDownloadedByPath( |
| 424 file_in_root, |
| 425 ClientContext(USER_INITIATED), |
| 426 google_apis::test_util::CreateCopyResultCallback( |
| 427 &init_error, &init_entry, &init_path, &cancel_callback), |
| 428 google_apis::GetContentCallback(), |
| 429 google_apis::test_util::CreateCopyResultCallback( |
| 430 &error, &file_path, &entry)); |
| 431 google_apis::test_util::RunBlockingPoolTask(); |
| 432 |
| 433 EXPECT_EQ(FILE_ERROR_OK, error); |
| 434 // Check that the result of local modification is propagated. |
| 435 EXPECT_EQ(static_cast<int64>(dirty_size), init_entry->file_info().size()); |
| 436 EXPECT_EQ(static_cast<int64>(dirty_size), entry->file_info().size()); |
| 437 } |
| 438 |
392 } // namespace file_system | 439 } // namespace file_system |
393 } // namespace drive | 440 } // namespace drive |
OLD | NEW |