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