| 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/write_on_cache_file.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" | |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "content/public/test/test_utils.h" |
| 11 #include "google_apis/drive/test_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace drive { | 14 namespace drive { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const base::FilePath::CharType kDrivePath[] = | 18 const base::FilePath::CharType kDrivePath[] = |
| 18 FILE_PATH_LITERAL("drive/root/file.txt"); | 19 FILE_PATH_LITERAL("drive/root/file.txt"); |
| 19 const base::FilePath::CharType kInvalidPath[] = | 20 const base::FilePath::CharType kInvalidPath[] = |
| 20 FILE_PATH_LITERAL("drive/invalid/path"); | 21 FILE_PATH_LITERAL("drive/invalid/path"); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 TestFileSystem test_file_system; | 64 TestFileSystem test_file_system; |
| 64 | 65 |
| 65 FileError error = FILE_ERROR_FAILED; | 66 FileError error = FILE_ERROR_FAILED; |
| 66 base::FilePath path; | 67 base::FilePath path; |
| 67 // The file should successfully be opened. | 68 // The file should successfully be opened. |
| 68 WriteOnCacheFile( | 69 WriteOnCacheFile( |
| 69 &test_file_system, | 70 &test_file_system, |
| 70 base::FilePath(kDrivePath), | 71 base::FilePath(kDrivePath), |
| 71 std::string(), // mime_type | 72 std::string(), // mime_type |
| 72 google_apis::test_util::CreateCopyResultCallback(&error, &path)); | 73 google_apis::test_util::CreateCopyResultCallback(&error, &path)); |
| 73 test_util::RunBlockingPoolTask(); | 74 content::RunAllBlockingPoolTasksUntilIdle(); |
| 74 | 75 |
| 75 EXPECT_EQ(FILE_ERROR_OK, error); | 76 EXPECT_EQ(FILE_ERROR_OK, error); |
| 76 EXPECT_EQ(kLocalPath, path.value()); | 77 EXPECT_EQ(kLocalPath, path.value()); |
| 77 | 78 |
| 78 // Make sure that the file is actually closed. | 79 // Make sure that the file is actually closed. |
| 79 EXPECT_EQ(1, test_file_system.num_closed()); | 80 EXPECT_EQ(1, test_file_system.num_closed()); |
| 80 } | 81 } |
| 81 | 82 |
| 82 TEST(WriteOnCacheFileTest, PrepareFileForWritingCreateFail) { | 83 TEST(WriteOnCacheFileTest, PrepareFileForWritingCreateFail) { |
| 83 content::TestBrowserThreadBundle thread_bundle; | 84 content::TestBrowserThreadBundle thread_bundle; |
| 84 TestFileSystem test_file_system; | 85 TestFileSystem test_file_system; |
| 85 | 86 |
| 86 FileError error = FILE_ERROR_FAILED; | 87 FileError error = FILE_ERROR_FAILED; |
| 87 base::FilePath path; | 88 base::FilePath path; |
| 88 // Access to kInvalidPath should fail, and FileWriteHelper should not try to | 89 // Access to kInvalidPath should fail, and FileWriteHelper should not try to |
| 89 // open or close the file. | 90 // open or close the file. |
| 90 WriteOnCacheFile( | 91 WriteOnCacheFile( |
| 91 &test_file_system, | 92 &test_file_system, |
| 92 base::FilePath(kInvalidPath), | 93 base::FilePath(kInvalidPath), |
| 93 std::string(), // mime_type | 94 std::string(), // mime_type |
| 94 google_apis::test_util::CreateCopyResultCallback(&error, &path)); | 95 google_apis::test_util::CreateCopyResultCallback(&error, &path)); |
| 95 test_util::RunBlockingPoolTask(); | 96 content::RunAllBlockingPoolTasksUntilIdle(); |
| 96 | 97 |
| 97 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error); | 98 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error); |
| 98 EXPECT_TRUE(path.empty()); | 99 EXPECT_TRUE(path.empty()); |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace drive | 102 } // namespace drive |
| OLD | NEW |