| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() OVERRIDE { |
| 28 file_system_context_ = CreateFileSystemContextForTesting( | 28 file_system_context_ = CreateFileSystemContextForTesting( |
| 29 NULL, base::FilePath(FILE_PATH_LITERAL("dummy"))); | 29 NULL, base::FilePath(FILE_PATH_LITERAL("dummy"))); |
| 30 transient_file_util_.reset(new TransientFileUtil); | 30 transient_file_util_.reset(new TransientFileUtil); |
| 31 | 31 |
| 32 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 32 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual void TearDown() OVERRIDE { | 35 virtual void TearDown() OVERRIDE { |
| 36 file_system_context_ = NULL; | 36 file_system_context_ = NULL; |
| 37 MessageLoop::current()->RunUntilIdle(); | 37 base::MessageLoop::current()->RunUntilIdle(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void CreateAndRegisterTemporaryFile( | 40 void CreateAndRegisterTemporaryFile( |
| 41 FileSystemURL* file_url, | 41 FileSystemURL* file_url, |
| 42 base::FilePath* file_path) { | 42 base::FilePath* file_path) { |
| 43 EXPECT_TRUE( | 43 EXPECT_TRUE( |
| 44 file_util::CreateTemporaryFileInDir(data_dir_.path(), file_path)); | 44 file_util::CreateTemporaryFileInDir(data_dir_.path(), file_path)); |
| 45 IsolatedContext* isolated_context = IsolatedContext::GetInstance(); | 45 IsolatedContext* isolated_context = IsolatedContext::GetInstance(); |
| 46 std::string name = "tmp"; | 46 std::string name = "tmp"; |
| 47 std::string fsid = isolated_context->RegisterFileSystemForPath( | 47 std::string fsid = isolated_context->RegisterFileSystemForPath( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 scoped_ptr<FileSystemOperationContext> NewOperationContext() { | 60 scoped_ptr<FileSystemOperationContext> NewOperationContext() { |
| 61 return make_scoped_ptr( | 61 return make_scoped_ptr( |
| 62 new FileSystemOperationContext(file_system_context_)); | 62 new FileSystemOperationContext(file_system_context_)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 FileSystemFileUtil* file_util() { return transient_file_util_.get(); } | 65 FileSystemFileUtil* file_util() { return transient_file_util_.get(); } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 MessageLoop message_loop_; | 68 base::MessageLoop message_loop_; |
| 69 base::ScopedTempDir data_dir_; | 69 base::ScopedTempDir data_dir_; |
| 70 scoped_refptr<FileSystemContext> file_system_context_; | 70 scoped_refptr<FileSystemContext> file_system_context_; |
| 71 scoped_ptr<TransientFileUtil> transient_file_util_; | 71 scoped_ptr<TransientFileUtil> transient_file_util_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(TransientFileUtilTest); | 73 DISALLOW_COPY_AND_ASSIGN(TransientFileUtilTest); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 TEST_F(TransientFileUtilTest, TransientFile) { | 76 TEST_F(TransientFileUtilTest, TransientFile) { |
| 77 FileSystemURL temp_url; | 77 FileSystemURL temp_url; |
| 78 base::FilePath temp_path; | 78 base::FilePath temp_path; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 103 // The file should be still there. | 103 // The file should be still there. |
| 104 ASSERT_TRUE(file_util::PathExists(temp_path)); | 104 ASSERT_TRUE(file_util::PathExists(temp_path)); |
| 105 ASSERT_EQ(base::PLATFORM_FILE_OK, | 105 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 106 file_util()->GetFileInfo(NewOperationContext().get(), | 106 file_util()->GetFileInfo(NewOperationContext().get(), |
| 107 temp_url, &file_info, &path)); | 107 temp_url, &file_info, &path)); |
| 108 ASSERT_EQ(temp_path, path); | 108 ASSERT_EQ(temp_path, path); |
| 109 ASSERT_FALSE(file_info.is_directory); | 109 ASSERT_FALSE(file_info.is_directory); |
| 110 } | 110 } |
| 111 | 111 |
| 112 // The file's now scoped out. | 112 // The file's now scoped out. |
| 113 MessageLoop::current()->RunUntilIdle(); | 113 base::MessageLoop::current()->RunUntilIdle(); |
| 114 | 114 |
| 115 // Now the temporary file and the transient filesystem must be gone too. | 115 // Now the temporary file and the transient filesystem must be gone too. |
| 116 ASSERT_FALSE(file_util::PathExists(temp_path)); | 116 ASSERT_FALSE(file_util::PathExists(temp_path)); |
| 117 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 117 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 118 file_util()->GetFileInfo(NewOperationContext().get(), | 118 file_util()->GetFileInfo(NewOperationContext().get(), |
| 119 temp_url, &file_info, &path)); | 119 temp_url, &file_info, &path)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace fileapi | 122 } // namespace fileapi |
| OLD | NEW |