| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_write_helper.h" | 5 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/chromeos/drive/dummy_file_system.h" | 8 #include "chrome/browser/chromeos/drive/dummy_file_system.h" |
| 9 #include "chrome/browser/chromeos/drive/test_util.h" | 9 #include "chrome/browser/chromeos/drive/test_util.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace drive { | 13 namespace drive { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 void CloseFile() { | 51 void CloseFile() { |
| 52 ++num_closed_; | 52 ++num_closed_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 int num_closed_; | 55 int num_closed_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 class FileWriteHelperTest : public testing::Test { | 60 TEST(WriteOnCacheFileTest, PrepareFileForWritingSuccess) { |
| 61 public: | 61 content::TestBrowserThreadBundle thread_bundle; |
| 62 FileWriteHelperTest() | 62 TestFileSystem test_file_system; |
| 63 : test_file_system_(new TestFileSystem) { | |
| 64 } | |
| 65 | 63 |
| 66 protected: | |
| 67 content::TestBrowserThreadBundle thread_bundle_; | |
| 68 scoped_ptr<TestFileSystem> test_file_system_; | |
| 69 }; | |
| 70 | |
| 71 TEST_F(FileWriteHelperTest, PrepareFileForWritingSuccess) { | |
| 72 FileWriteHelper file_write_helper(test_file_system_.get()); | |
| 73 FileError error = FILE_ERROR_FAILED; | 64 FileError error = FILE_ERROR_FAILED; |
| 74 base::FilePath path; | 65 base::FilePath path; |
| 75 // The file should successfully be opened. | 66 // The file should successfully be opened. |
| 76 file_write_helper.PrepareWritableFileAndRun( | 67 WriteOnCacheFile( |
| 68 &test_file_system, |
| 77 base::FilePath(kDrivePath), | 69 base::FilePath(kDrivePath), |
| 78 google_apis::test_util::CreateCopyResultCallback(&error, &path)); | 70 google_apis::test_util::CreateCopyResultCallback(&error, &path)); |
| 79 test_util::RunBlockingPoolTask(); | 71 test_util::RunBlockingPoolTask(); |
| 80 | 72 |
| 81 EXPECT_EQ(FILE_ERROR_OK, error); | 73 EXPECT_EQ(FILE_ERROR_OK, error); |
| 82 EXPECT_EQ(kLocalPath, path.value()); | 74 EXPECT_EQ(kLocalPath, path.value()); |
| 83 | 75 |
| 84 // Make sure that the file is actually closed. | 76 // Make sure that the file is actually closed. |
| 85 EXPECT_EQ(1, test_file_system_->num_closed()); | 77 EXPECT_EQ(1, test_file_system.num_closed()); |
| 86 } | 78 } |
| 87 | 79 |
| 88 TEST_F(FileWriteHelperTest, PrepareFileForWritingCreateFail) { | 80 TEST(WriteOnCacheFileTest, PrepareFileForWritingCreateFail) { |
| 89 FileWriteHelper file_write_helper(test_file_system_.get()); | 81 content::TestBrowserThreadBundle thread_bundle; |
| 82 TestFileSystem test_file_system; |
| 83 |
| 90 FileError error = FILE_ERROR_FAILED; | 84 FileError error = FILE_ERROR_FAILED; |
| 91 base::FilePath path; | 85 base::FilePath path; |
| 92 // Access to kInvalidPath should fail, and FileWriteHelper should not try to | 86 // Access to kInvalidPath should fail, and FileWriteHelper should not try to |
| 93 // open or close the file. | 87 // open or close the file. |
| 94 file_write_helper.PrepareWritableFileAndRun( | 88 WriteOnCacheFile( |
| 89 &test_file_system, |
| 95 base::FilePath(kInvalidPath), | 90 base::FilePath(kInvalidPath), |
| 96 google_apis::test_util::CreateCopyResultCallback(&error, &path)); | 91 google_apis::test_util::CreateCopyResultCallback(&error, &path)); |
| 97 test_util::RunBlockingPoolTask(); | 92 test_util::RunBlockingPoolTask(); |
| 98 | 93 |
| 99 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error); | 94 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error); |
| 100 EXPECT_TRUE(path.empty()); | 95 EXPECT_TRUE(path.empty()); |
| 101 } | 96 } |
| 102 | 97 |
| 103 } // namespace drive | 98 } // namespace drive |
| OLD | NEW |