| 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/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "content/public/test/test_file_system_context.h" | 12 #include "content/public/test/test_file_system_context.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webkit/browser/fileapi/file_system_context.h" | 14 #include "webkit/browser/fileapi/file_system_context.h" |
| 15 #include "webkit/browser/fileapi/file_system_operation_context.h" | 15 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 16 #include "webkit/browser/fileapi/isolated_context.h" | 16 #include "webkit/browser/fileapi/isolated_context.h" |
| 17 #include "webkit/browser/fileapi/transient_file_util.h" | 17 #include "webkit/browser/fileapi/transient_file_util.h" |
| 18 #include "webkit/common/blob/scoped_file.h" | 18 #include "webkit/common/blob/scoped_file.h" |
| 19 | 19 |
| 20 namespace fileapi { | 20 using fileapi::FileSystemURL; |
| 21 |
| 22 namespace content { |
| 21 | 23 |
| 22 class TransientFileUtilTest : public testing::Test { | 24 class TransientFileUtilTest : public testing::Test { |
| 23 public: | 25 public: |
| 24 TransientFileUtilTest() {} | 26 TransientFileUtilTest() {} |
| 25 virtual ~TransientFileUtilTest() {} | 27 virtual ~TransientFileUtilTest() {} |
| 26 | 28 |
| 27 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() OVERRIDE { |
| 28 file_system_context_ = CreateFileSystemContextForTesting( | 30 file_system_context_ = CreateFileSystemContextForTesting( |
| 29 NULL, base::FilePath(FILE_PATH_LITERAL("dummy"))); | 31 NULL, base::FilePath(FILE_PATH_LITERAL("dummy"))); |
| 30 transient_file_util_.reset(new TransientFileUtil); | 32 transient_file_util_.reset(new fileapi::TransientFileUtil); |
| 31 | 33 |
| 32 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 34 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 33 } | 35 } |
| 34 | 36 |
| 35 virtual void TearDown() OVERRIDE { | 37 virtual void TearDown() OVERRIDE { |
| 36 file_system_context_ = NULL; | 38 file_system_context_ = NULL; |
| 37 base::RunLoop().RunUntilIdle(); | 39 base::RunLoop().RunUntilIdle(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void CreateAndRegisterTemporaryFile( | 42 void CreateAndRegisterTemporaryFile( |
| 41 FileSystemURL* file_url, | 43 FileSystemURL* file_url, |
| 42 base::FilePath* file_path) { | 44 base::FilePath* file_path) { |
| 43 EXPECT_TRUE(base::CreateTemporaryFileInDir(data_dir_.path(), file_path)); | 45 EXPECT_TRUE(base::CreateTemporaryFileInDir(data_dir_.path(), file_path)); |
| 44 IsolatedContext* isolated_context = IsolatedContext::GetInstance(); | 46 fileapi::IsolatedContext* isolated_context = |
| 47 fileapi::IsolatedContext::GetInstance(); |
| 45 std::string name = "tmp"; | 48 std::string name = "tmp"; |
| 46 std::string fsid = isolated_context->RegisterFileSystemForPath( | 49 std::string fsid = isolated_context->RegisterFileSystemForPath( |
| 47 kFileSystemTypeForTransientFile, | 50 fileapi::kFileSystemTypeForTransientFile, |
| 48 *file_path, | 51 *file_path, |
| 49 &name); | 52 &name); |
| 50 ASSERT_TRUE(!fsid.empty()); | 53 ASSERT_TRUE(!fsid.empty()); |
| 51 base::FilePath virtual_path = isolated_context->CreateVirtualRootPath( | 54 base::FilePath virtual_path = isolated_context->CreateVirtualRootPath( |
| 52 fsid).AppendASCII(name); | 55 fsid).AppendASCII(name); |
| 53 *file_url = file_system_context_->CreateCrackedFileSystemURL( | 56 *file_url = file_system_context_->CreateCrackedFileSystemURL( |
| 54 GURL("http://foo"), | 57 GURL("http://foo"), |
| 55 kFileSystemTypeIsolated, | 58 fileapi::kFileSystemTypeIsolated, |
| 56 virtual_path); | 59 virtual_path); |
| 57 } | 60 } |
| 58 | 61 |
| 59 scoped_ptr<FileSystemOperationContext> NewOperationContext() { | 62 scoped_ptr<fileapi::FileSystemOperationContext> NewOperationContext() { |
| 60 return make_scoped_ptr( | 63 return make_scoped_ptr( |
| 61 new FileSystemOperationContext(file_system_context_.get())); | 64 new fileapi::FileSystemOperationContext(file_system_context_.get())); |
| 62 } | 65 } |
| 63 | 66 |
| 64 FileSystemFileUtil* file_util() { return transient_file_util_.get(); } | 67 fileapi::FileSystemFileUtil* file_util() { |
| 68 return transient_file_util_.get(); |
| 69 } |
| 65 | 70 |
| 66 private: | 71 private: |
| 67 base::MessageLoop message_loop_; | 72 base::MessageLoop message_loop_; |
| 68 base::ScopedTempDir data_dir_; | 73 base::ScopedTempDir data_dir_; |
| 69 scoped_refptr<FileSystemContext> file_system_context_; | 74 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 70 scoped_ptr<TransientFileUtil> transient_file_util_; | 75 scoped_ptr<fileapi::TransientFileUtil> transient_file_util_; |
| 71 | 76 |
| 72 DISALLOW_COPY_AND_ASSIGN(TransientFileUtilTest); | 77 DISALLOW_COPY_AND_ASSIGN(TransientFileUtilTest); |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 TEST_F(TransientFileUtilTest, TransientFile) { | 80 TEST_F(TransientFileUtilTest, TransientFile) { |
| 76 FileSystemURL temp_url; | 81 FileSystemURL temp_url; |
| 77 base::FilePath temp_path; | 82 base::FilePath temp_path; |
| 78 | 83 |
| 79 CreateAndRegisterTemporaryFile(&temp_url, &temp_path); | 84 CreateAndRegisterTemporaryFile(&temp_url, &temp_path); |
| 80 | 85 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 111 // The file's now scoped out. | 116 // The file's now scoped out. |
| 112 base::RunLoop().RunUntilIdle(); | 117 base::RunLoop().RunUntilIdle(); |
| 113 | 118 |
| 114 // Now the temporary file and the transient filesystem must be gone too. | 119 // Now the temporary file and the transient filesystem must be gone too. |
| 115 ASSERT_FALSE(base::PathExists(temp_path)); | 120 ASSERT_FALSE(base::PathExists(temp_path)); |
| 116 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 121 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 117 file_util()->GetFileInfo(NewOperationContext().get(), | 122 file_util()->GetFileInfo(NewOperationContext().get(), |
| 118 temp_url, &file_info, &path)); | 123 temp_url, &file_info, &path)); |
| 119 } | 124 } |
| 120 | 125 |
| 121 } // namespace fileapi | 126 } // namespace content |
| OLD | NEW |