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/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 using content::AsyncFileTestHelper; | 22 using content::AsyncFileTestHelper; |
23 using storage::FileSystemContext; | 23 using storage::FileSystemContext; |
24 using storage::FileSystemURL; | 24 using storage::FileSystemURL; |
25 using storage::IsolatedContext; | 25 using storage::IsolatedContext; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const GURL kOrigin("http://www.example.com"); | 31 const GURL kOrigin1("http://www.example.com"); |
| 32 const GURL kOrigin2("https://www.example.com"); |
32 const std::string kPlugin1("plugin1"); | 33 const std::string kPlugin1("plugin1"); |
33 const std::string kPlugin2("plugin2"); | 34 const std::string kPlugin2("plugin2"); |
34 const storage::FileSystemType kType = storage::kFileSystemTypePluginPrivate; | 35 const storage::FileSystemType kType = storage::kFileSystemTypePluginPrivate; |
35 const std::string kRootName = "pluginprivate"; | 36 const std::string kRootName = "pluginprivate"; |
36 | 37 |
37 void DidOpenFileSystem(base::File::Error* error_out, | 38 void DidOpenFileSystem(base::File::Error* error_out, |
38 base::File::Error error) { | 39 base::File::Error error) { |
39 *error_out = error; | 40 *error_out = error; |
40 } | 41 } |
41 | 42 |
(...skipping 23 matching lines...) Expand all Loading... |
65 | 66 |
66 storage::PluginPrivateFileSystemBackend* backend() const { | 67 storage::PluginPrivateFileSystemBackend* backend() const { |
67 return context_->plugin_private_backend(); | 68 return context_->plugin_private_backend(); |
68 } | 69 } |
69 | 70 |
70 const base::FilePath& base_path() const { return backend()->base_path(); } | 71 const base::FilePath& base_path() const { return backend()->base_path(); } |
71 | 72 |
72 base::ScopedTempDir data_dir_; | 73 base::ScopedTempDir data_dir_; |
73 base::MessageLoop message_loop_; | 74 base::MessageLoop message_loop_; |
74 scoped_refptr<FileSystemContext> context_; | 75 scoped_refptr<FileSystemContext> context_; |
75 std::string filesystem_id_; | |
76 }; | 76 }; |
77 | 77 |
| 78 // TODO(kinuko,nhiroki): There are a lot of duplicate code in these tests. Write |
| 79 // helper functions to simplify the tests. |
| 80 |
78 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { | 81 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { |
79 const std::string filesystem_id1 = RegisterFileSystem(); | 82 const std::string filesystem_id1 = RegisterFileSystem(); |
80 base::File::Error error = base::File::FILE_ERROR_FAILED; | 83 base::File::Error error = base::File::FILE_ERROR_FAILED; |
81 backend()->OpenPrivateFileSystem( | 84 backend()->OpenPrivateFileSystem( |
82 kOrigin, | 85 kOrigin1, |
83 kType, | 86 kType, |
84 filesystem_id1, | 87 filesystem_id1, |
85 kPlugin1, | 88 kPlugin1, |
86 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 89 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
87 base::Bind(&DidOpenFileSystem, &error)); | 90 base::Bind(&DidOpenFileSystem, &error)); |
88 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
89 ASSERT_EQ(base::File::FILE_OK, error); | 92 ASSERT_EQ(base::File::FILE_OK, error); |
90 | 93 |
91 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. | 94 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. |
92 const std::string filesystem_id2 = RegisterFileSystem(); | 95 const std::string filesystem_id2 = RegisterFileSystem(); |
93 error = base::File::FILE_ERROR_FAILED; | 96 error = base::File::FILE_ERROR_FAILED; |
94 backend()->OpenPrivateFileSystem( | 97 backend()->OpenPrivateFileSystem( |
95 kOrigin, | 98 kOrigin1, |
96 kType, | 99 kType, |
97 filesystem_id2, | 100 filesystem_id2, |
98 kPlugin1, | 101 kPlugin1, |
99 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 102 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
100 base::Bind(&DidOpenFileSystem, &error)); | 103 base::Bind(&DidOpenFileSystem, &error)); |
101 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
102 ASSERT_EQ(base::File::FILE_OK, error); | 105 ASSERT_EQ(base::File::FILE_OK, error); |
103 | 106 |
104 const GURL root_url(storage::GetIsolatedFileSystemRootURIString( | 107 const GURL root_url(storage::GetIsolatedFileSystemRootURIString( |
105 kOrigin, filesystem_id1, kRootName)); | 108 kOrigin1, filesystem_id1, kRootName)); |
106 FileSystemURL file = CreateURL(root_url, "foo"); | 109 FileSystemURL file = CreateURL(root_url, "foo"); |
107 base::FilePath platform_path; | 110 base::FilePath platform_path; |
108 EXPECT_EQ(base::File::FILE_OK, | 111 EXPECT_EQ(base::File::FILE_OK, |
109 AsyncFileTestHelper::CreateFile(context_.get(), file)); | 112 AsyncFileTestHelper::CreateFile(context_.get(), file)); |
110 EXPECT_EQ(base::File::FILE_OK, | 113 EXPECT_EQ(base::File::FILE_OK, |
111 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, | 114 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, |
112 &platform_path)); | 115 &platform_path)); |
113 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( | 116 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( |
114 platform_path)); | 117 platform_path)); |
115 } | 118 } |
116 | 119 |
117 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { | 120 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { |
118 // Open filesystem for kPlugin1 and kPlugin2. | 121 // Open filesystem for kPlugin1 and kPlugin2. |
119 const std::string filesystem_id1 = RegisterFileSystem(); | 122 const std::string filesystem_id1 = RegisterFileSystem(); |
120 base::File::Error error = base::File::FILE_ERROR_FAILED; | 123 base::File::Error error = base::File::FILE_ERROR_FAILED; |
121 backend()->OpenPrivateFileSystem( | 124 backend()->OpenPrivateFileSystem( |
122 kOrigin, | 125 kOrigin1, |
123 kType, | 126 kType, |
124 filesystem_id1, | 127 filesystem_id1, |
125 kPlugin1, | 128 kPlugin1, |
126 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 129 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
127 base::Bind(&DidOpenFileSystem, &error)); | 130 base::Bind(&DidOpenFileSystem, &error)); |
128 base::RunLoop().RunUntilIdle(); | 131 base::RunLoop().RunUntilIdle(); |
129 ASSERT_EQ(base::File::FILE_OK, error); | 132 ASSERT_EQ(base::File::FILE_OK, error); |
130 | 133 |
131 const std::string filesystem_id2 = RegisterFileSystem(); | 134 const std::string filesystem_id2 = RegisterFileSystem(); |
132 error = base::File::FILE_ERROR_FAILED; | 135 error = base::File::FILE_ERROR_FAILED; |
133 backend()->OpenPrivateFileSystem( | 136 backend()->OpenPrivateFileSystem( |
134 kOrigin, | 137 kOrigin1, |
135 kType, | 138 kType, |
136 filesystem_id2, | 139 filesystem_id2, |
137 kPlugin2, | 140 kPlugin2, |
138 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 141 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
139 base::Bind(&DidOpenFileSystem, &error)); | 142 base::Bind(&DidOpenFileSystem, &error)); |
140 base::RunLoop().RunUntilIdle(); | 143 base::RunLoop().RunUntilIdle(); |
141 ASSERT_EQ(base::File::FILE_OK, error); | 144 ASSERT_EQ(base::File::FILE_OK, error); |
142 | 145 |
143 // Create 'foo' in kPlugin1. | 146 // Create 'foo' in kPlugin1. |
144 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( | 147 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( |
145 kOrigin, filesystem_id1, kRootName)); | 148 kOrigin1, filesystem_id1, kRootName)); |
146 FileSystemURL file1 = CreateURL(root_url1, "foo"); | 149 FileSystemURL file1 = CreateURL(root_url1, "foo"); |
147 base::FilePath platform_path; | |
148 EXPECT_EQ(base::File::FILE_OK, | 150 EXPECT_EQ(base::File::FILE_OK, |
149 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | 151 AsyncFileTestHelper::CreateFile(context_.get(), file1)); |
150 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | 152 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
151 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | 153 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
152 | 154 |
153 // See the same path is not available in kPlugin2. | 155 // See the same path is not available in kPlugin2. |
154 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( | 156 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( |
155 kOrigin, filesystem_id2, kRootName)); | 157 kOrigin1, filesystem_id2, kRootName)); |
156 FileSystemURL file2 = CreateURL(root_url2, "foo"); | 158 FileSystemURL file2 = CreateURL(root_url2, "foo"); |
157 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | 159 EXPECT_FALSE(AsyncFileTestHelper::FileExists( |
158 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | 160 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
159 } | 161 } |
160 | 162 |
161 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread | 163 TEST_F(PluginPrivateFileSystemBackendTest, OriginIsolation) { |
162 // works fine when there's multiple plugin partitions. | 164 // Open filesystem for kOrigin1 and kOrigin2. |
| 165 const std::string filesystem_id1 = RegisterFileSystem(); |
| 166 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 167 backend()->OpenPrivateFileSystem( |
| 168 kOrigin1, |
| 169 kType, |
| 170 filesystem_id1, |
| 171 kPlugin1, |
| 172 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 173 base::Bind(&DidOpenFileSystem, &error)); |
| 174 base::RunLoop().RunUntilIdle(); |
| 175 ASSERT_EQ(base::File::FILE_OK, error); |
| 176 |
| 177 const std::string filesystem_id2 = RegisterFileSystem(); |
| 178 error = base::File::FILE_ERROR_FAILED; |
| 179 backend()->OpenPrivateFileSystem( |
| 180 kOrigin2, |
| 181 kType, |
| 182 filesystem_id2, |
| 183 kPlugin1, |
| 184 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 185 base::Bind(&DidOpenFileSystem, &error)); |
| 186 base::RunLoop().RunUntilIdle(); |
| 187 ASSERT_EQ(base::File::FILE_OK, error); |
| 188 |
| 189 // Create 'foo' in kOrigin1. |
| 190 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( |
| 191 kOrigin1, filesystem_id1, kRootName)); |
| 192 FileSystemURL file1 = CreateURL(root_url1, "foo"); |
| 193 EXPECT_EQ(base::File::FILE_OK, |
| 194 AsyncFileTestHelper::CreateFile(context_.get(), file1)); |
| 195 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 196 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
| 197 |
| 198 // See the same path is not available in kOrigin2. |
| 199 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( |
| 200 kOrigin2, filesystem_id2, kRootName)); |
| 201 FileSystemURL file2 = CreateURL(root_url2, "foo"); |
| 202 EXPECT_FALSE(AsyncFileTestHelper::FileExists( |
| 203 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
| 204 } |
| 205 |
| 206 TEST_F(PluginPrivateFileSystemBackendTest, DeleteOriginDirectory) { |
| 207 // Open filesystem for kOrigin1 and kOrigin2. |
| 208 const std::string filesystem_id1 = RegisterFileSystem(); |
| 209 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 210 backend()->OpenPrivateFileSystem( |
| 211 kOrigin1, |
| 212 kType, |
| 213 filesystem_id1, |
| 214 kPlugin1, |
| 215 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 216 base::Bind(&DidOpenFileSystem, &error)); |
| 217 base::RunLoop().RunUntilIdle(); |
| 218 ASSERT_EQ(base::File::FILE_OK, error); |
| 219 |
| 220 const std::string filesystem_id2 = RegisterFileSystem(); |
| 221 error = base::File::FILE_ERROR_FAILED; |
| 222 backend()->OpenPrivateFileSystem( |
| 223 kOrigin2, |
| 224 kType, |
| 225 filesystem_id2, |
| 226 kPlugin1, |
| 227 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 228 base::Bind(&DidOpenFileSystem, &error)); |
| 229 base::RunLoop().RunUntilIdle(); |
| 230 ASSERT_EQ(base::File::FILE_OK, error); |
| 231 |
| 232 // Create 'foo' in kOrigin1. |
| 233 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( |
| 234 kOrigin1, filesystem_id1, kRootName)); |
| 235 FileSystemURL file1 = CreateURL(root_url1, "foo"); |
| 236 EXPECT_EQ(base::File::FILE_OK, |
| 237 AsyncFileTestHelper::CreateFile(context_.get(), file1)); |
| 238 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 239 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
| 240 |
| 241 // Create 'foo' in kOrigin2. |
| 242 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( |
| 243 kOrigin2, filesystem_id2, kRootName)); |
| 244 FileSystemURL file2 = CreateURL(root_url2, "foo"); |
| 245 EXPECT_EQ(base::File::FILE_OK, |
| 246 AsyncFileTestHelper::CreateFile(context_.get(), file2)); |
| 247 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 248 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
| 249 |
| 250 // Delete data for kOrigin1. |
| 251 error = backend()->DeleteOriginDataOnFileTaskRunner( |
| 252 context_.get(), NULL, kOrigin1, kType); |
| 253 EXPECT_EQ(base::File::FILE_OK, error); |
| 254 |
| 255 // Confirm 'foo' in kOrigin1 is deleted. |
| 256 EXPECT_FALSE(AsyncFileTestHelper::FileExists( |
| 257 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
| 258 |
| 259 // Confirm 'foo' in kOrigin2 is NOT deleted. |
| 260 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 261 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
| 262 |
| 263 // Re-open filesystem for kOrigin1. |
| 264 const std::string filesystem_id3 = RegisterFileSystem(); |
| 265 error = base::File::FILE_ERROR_FAILED; |
| 266 backend()->OpenPrivateFileSystem( |
| 267 kOrigin1, |
| 268 kType, |
| 269 filesystem_id3, |
| 270 kPlugin1, |
| 271 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 272 base::Bind(&DidOpenFileSystem, &error)); |
| 273 base::RunLoop().RunUntilIdle(); |
| 274 ASSERT_EQ(base::File::FILE_OK, error); |
| 275 |
| 276 // Re-create 'foo' in kOrigin1. |
| 277 const GURL root_url3(storage::GetIsolatedFileSystemRootURIString( |
| 278 kOrigin1, filesystem_id3, kRootName)); |
| 279 FileSystemURL file3 = CreateURL(root_url3, "foo"); |
| 280 EXPECT_EQ(base::File::FILE_OK, |
| 281 AsyncFileTestHelper::CreateFile(context_.get(), file3)); |
| 282 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 283 context_.get(), file3, AsyncFileTestHelper::kDontCheckSize)); |
| 284 |
| 285 // Confirm 'foo' in kOrigin1 is re-created. |
| 286 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 287 context_.get(), file3, AsyncFileTestHelper::kDontCheckSize)); |
| 288 } |
163 | 289 |
164 } // namespace content | 290 } // namespace content |
OLD | NEW |