OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/drive/file_system/update_operation.h" |
| 6 |
| 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 8 #include "chrome/browser/google_apis/fake_drive_service.h" |
| 9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 10 #include "chrome/browser/google_apis/test_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace drive { |
| 14 namespace file_system { |
| 15 |
| 16 class UpdateOperationTest : public OperationTestBase { |
| 17 protected: |
| 18 virtual void SetUp() OVERRIDE { |
| 19 OperationTestBase::SetUp(); |
| 20 operation_.reset( |
| 21 new UpdateOperation(observer(), scheduler(), metadata(), cache())); |
| 22 } |
| 23 |
| 24 virtual void TearDown() OVERRIDE { |
| 25 operation_.reset(); |
| 26 OperationTestBase::TearDown(); |
| 27 } |
| 28 |
| 29 scoped_ptr<UpdateOperation> operation_; |
| 30 }; |
| 31 |
| 32 TEST_F(UpdateOperationTest, UpdateFileByResourceId_PersistentFile) { |
| 33 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 34 const std::string kResourceId("file:2_file_resource_id"); |
| 35 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); |
| 36 |
| 37 const base::FilePath kTestFile = temp_dir().Append(FILE_PATH_LITERAL("foo")); |
| 38 const std::string kTestFileContent = "I'm being uploaded! Yay!"; |
| 39 google_apis::test_util::WriteStringToFile(kTestFile, kTestFileContent); |
| 40 |
| 41 // Pin the file so it'll be store in "persistent" directory. |
| 42 FileError error = FILE_ERROR_FAILED; |
| 43 cache()->PinOnUIThread( |
| 44 kResourceId, kMd5, |
| 45 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 46 google_apis::test_util::RunBlockingPoolTask(); |
| 47 EXPECT_EQ(FILE_ERROR_OK, error); |
| 48 |
| 49 // First store a file to cache. |
| 50 error = FILE_ERROR_FAILED; |
| 51 cache()->StoreOnUIThread( |
| 52 kResourceId, kMd5, kTestFile, |
| 53 internal::FileCache::FILE_OPERATION_COPY, |
| 54 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 55 google_apis::test_util::RunBlockingPoolTask(); |
| 56 EXPECT_EQ(FILE_ERROR_OK, error); |
| 57 |
| 58 // Add the dirty bit. |
| 59 error = FILE_ERROR_FAILED; |
| 60 cache()->MarkDirtyOnUIThread( |
| 61 kResourceId, kMd5, |
| 62 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 63 google_apis::test_util::RunBlockingPoolTask(); |
| 64 EXPECT_EQ(FILE_ERROR_OK, error); |
| 65 |
| 66 // Commit the dirty bit. |
| 67 error = FILE_ERROR_FAILED; |
| 68 cache()->CommitDirtyOnUIThread( |
| 69 kResourceId, kMd5, |
| 70 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 71 google_apis::test_util::RunBlockingPoolTask(); |
| 72 EXPECT_EQ(FILE_ERROR_OK, error); |
| 73 |
| 74 int64 original_changestamp = fake_service()->largest_changestamp(); |
| 75 |
| 76 // The callback will be called upon completion of |
| 77 // UpdateFileByResourceId(). |
| 78 error = FILE_ERROR_FAILED; |
| 79 operation_->UpdateFileByResourceId( |
| 80 kResourceId, |
| 81 DriveClientContext(USER_INITIATED), |
| 82 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 83 google_apis::test_util::RunBlockingPoolTask(); |
| 84 EXPECT_EQ(FILE_ERROR_OK, error); |
| 85 |
| 86 // Check that the server has received an update. |
| 87 EXPECT_LT(original_changestamp, fake_service()->largest_changestamp()); |
| 88 |
| 89 // Check that the file size is updated to that of the updated content. |
| 90 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; |
| 91 scoped_ptr<google_apis::ResourceEntry> server_entry; |
| 92 fake_service()->GetResourceEntry( |
| 93 kResourceId, |
| 94 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
| 95 &server_entry)); |
| 96 google_apis::test_util::RunBlockingPoolTask(); |
| 97 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error); |
| 98 EXPECT_EQ(static_cast<int64>(kTestFileContent.size()), |
| 99 server_entry->file_size()); |
| 100 } |
| 101 |
| 102 TEST_F(UpdateOperationTest, UpdateFileByResourceId_NonexistentFile) { |
| 103 FileError error = FILE_ERROR_OK; |
| 104 operation_->UpdateFileByResourceId( |
| 105 "file:nonexistent_resource_id", |
| 106 DriveClientContext(USER_INITIATED), |
| 107 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 108 google_apis::test_util::RunBlockingPoolTask(); |
| 109 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| 110 } |
| 111 |
| 112 } // namespace file_system |
| 113 } // namespace drive |
OLD | NEW |