| 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/sync/entry_update_performer.h" | 5 #include "chrome/browser/chromeos/drive/sync/entry_update_performer.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| 11 #include "chrome/browser/chromeos/drive/file_cache.h" | 11 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 12 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 12 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 13 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 14 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 14 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 15 #include "chrome/browser/drive/drive_api_util.h" | 15 #include "chrome/browser/drive/drive_api_util.h" |
| 16 #include "chrome/browser/drive/fake_drive_service.h" | 16 #include "chrome/browser/drive/fake_drive_service.h" |
| 17 #include "google_apis/drive/drive_api_parser.h" | 17 #include "google_apis/drive/drive_api_parser.h" |
| 18 #include "google_apis/drive/gdata_wapi_parser.h" | 18 #include "google_apis/drive/gdata_wapi_parser.h" |
| 19 #include "google_apis/drive/test_util.h" | 19 #include "google_apis/drive/test_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 namespace drive { | 22 namespace drive { |
| 23 namespace internal { | 23 namespace internal { |
| 24 | 24 |
| 25 class EntryUpdatePerformerTest : public file_system::OperationTestBase { | 25 class EntryUpdatePerformerTest : public file_system::OperationTestBase { |
| 26 protected: | 26 protected: |
| 27 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() OVERRIDE { |
| 28 OperationTestBase::SetUp(); | 28 OperationTestBase::SetUp(); |
| 29 performer_.reset(new EntryUpdatePerformer(blocking_task_runner(), | 29 performer_.reset(new EntryUpdatePerformer(blocking_task_runner(), |
| 30 observer(), | 30 observer(), |
| 31 scheduler(), | 31 scheduler(), |
| 32 metadata(), | 32 metadata(), |
| 33 cache())); | 33 cache(), |
| 34 change_list_loader())); |
| 34 } | 35 } |
| 35 | 36 |
| 36 // Stores |content| to the cache and mark it as dirty. | 37 // Stores |content| to the cache and mark it as dirty. |
| 37 FileError StoreAndMarkDirty(const std::string& local_id, | 38 FileError StoreAndMarkDirty(const std::string& local_id, |
| 38 const std::string& content) { | 39 const std::string& content) { |
| 39 base::FilePath path; | 40 base::FilePath path; |
| 40 if (!base::CreateTemporaryFileInDir(temp_dir(), &path) || | 41 if (!base::CreateTemporaryFileInDir(temp_dir(), &path) || |
| 41 !google_apis::test_util::WriteStringToFile(path, content)) | 42 !google_apis::test_util::WriteStringToFile(path, content)) |
| 42 return FILE_ERROR_FAILED; | 43 return FILE_ERROR_FAILED; |
| 43 | 44 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 base::Bind(&FileCache::GetCacheEntry, | 354 base::Bind(&FileCache::GetCacheEntry, |
| 354 base::Unretained(cache()), | 355 base::Unretained(cache()), |
| 355 local_id, | 356 local_id, |
| 356 &cache_entry), | 357 &cache_entry), |
| 357 google_apis::test_util::CreateCopyResultCallback(&success)); | 358 google_apis::test_util::CreateCopyResultCallback(&success)); |
| 358 test_util::RunBlockingPoolTask(); | 359 test_util::RunBlockingPoolTask(); |
| 359 EXPECT_TRUE(success); | 360 EXPECT_TRUE(success); |
| 360 EXPECT_FALSE(cache_entry.is_dirty()); | 361 EXPECT_FALSE(cache_entry.is_dirty()); |
| 361 } | 362 } |
| 362 | 363 |
| 364 TEST_F(EntryUpdatePerformerTest, UpdateEntry_UploadNewFile) { |
| 365 // Create a new file locally. |
| 366 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt")); |
| 367 |
| 368 ResourceEntry parent; |
| 369 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath.DirName(), &parent)); |
| 370 |
| 371 ResourceEntry entry; |
| 372 entry.set_parent_local_id(parent.local_id()); |
| 373 entry.set_title(kFilePath.BaseName().AsUTF8Unsafe()); |
| 374 entry.mutable_file_specific_info()->set_content_mime_type("text/plain"); |
| 375 entry.set_metadata_edit_state(ResourceEntry::DIRTY); |
| 376 |
| 377 FileError error = FILE_ERROR_FAILED; |
| 378 std::string local_id; |
| 379 base::PostTaskAndReplyWithResult( |
| 380 blocking_task_runner(), |
| 381 FROM_HERE, |
| 382 base::Bind(&internal::ResourceMetadata::AddEntry, |
| 383 base::Unretained(metadata()), |
| 384 entry, |
| 385 &local_id), |
| 386 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 387 test_util::RunBlockingPoolTask(); |
| 388 EXPECT_EQ(FILE_ERROR_OK, error); |
| 389 |
| 390 // Update. This should result in creating a new file on the server. |
| 391 error = FILE_ERROR_FAILED; |
| 392 performer_->UpdateEntry( |
| 393 local_id, |
| 394 ClientContext(USER_INITIATED), |
| 395 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 396 test_util::RunBlockingPoolTask(); |
| 397 EXPECT_EQ(FILE_ERROR_OK, error); |
| 398 |
| 399 // The entry got a resource ID. |
| 400 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); |
| 401 EXPECT_FALSE(entry.resource_id().empty()); |
| 402 EXPECT_EQ(ResourceEntry::CLEAN, entry.metadata_edit_state()); |
| 403 |
| 404 // Make sure that the cache is no longer dirty. |
| 405 bool success = false; |
| 406 FileCacheEntry cache_entry; |
| 407 base::PostTaskAndReplyWithResult( |
| 408 blocking_task_runner(), |
| 409 FROM_HERE, |
| 410 base::Bind(&FileCache::GetCacheEntry, |
| 411 base::Unretained(cache()), |
| 412 local_id, |
| 413 &cache_entry), |
| 414 google_apis::test_util::CreateCopyResultCallback(&success)); |
| 415 test_util::RunBlockingPoolTask(); |
| 416 EXPECT_TRUE(success); |
| 417 EXPECT_FALSE(cache_entry.is_dirty()); |
| 418 } |
| 419 |
| 363 } // namespace internal | 420 } // namespace internal |
| 364 } // namespace drive | 421 } // namespace drive |
| OLD | NEW |