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/bind.h" | 6 #include "base/bind.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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "webkit/browser/fileapi/async_file_test_helper.h" | 11 #include "webkit/browser/fileapi/async_file_test_helper.h" |
12 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 12 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
13 #include "webkit/browser/fileapi/external_mount_points.h" | 13 #include "webkit/browser/fileapi/external_mount_points.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_mount_point_provider.h" | 15 #include "webkit/browser/fileapi/file_system_mount_point_provider.h" |
16 #include "webkit/browser/fileapi/file_system_url.h" | 16 #include "webkit/browser/fileapi/file_system_url.h" |
17 #include "webkit/browser/fileapi/isolated_context.h" | 17 #include "webkit/browser/fileapi/isolated_context.h" |
18 #include "webkit/browser/fileapi/mock_file_system_context.h" | 18 #include "webkit/browser/fileapi/mock_file_system_context.h" |
19 #include "webkit/browser/fileapi/test_mount_point_provider.h" | 19 #include "webkit/browser/fileapi/test_mount_point_provider.h" |
20 #include "webkit/browser/quota/mock_special_storage_policy.h" | 20 #include "webkit/browser/quota/mock_special_storage_policy.h" |
21 #include "webkit/common/blob/shareable_file_reference.h" | |
21 #include "webkit/common/fileapi/file_system_util.h" | 22 #include "webkit/common/fileapi/file_system_util.h" |
22 | 23 |
23 namespace fileapi { | 24 namespace fileapi { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 const FileSystemType kNoValidatorType = kFileSystemTypeTemporary; | 28 const FileSystemType kNoValidatorType = kFileSystemTypeTemporary; |
28 const FileSystemType kWithValidatorType = kFileSystemTypeTest; | 29 const FileSystemType kWithValidatorType = kFileSystemTypeTest; |
29 | 30 |
30 void ExpectOk(base::PlatformFileError error) { | 31 void ExpectOk(base::PlatformFileError error) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 FileSystemURL move_src_; | 175 FileSystemURL move_src_; |
175 FileSystemURL move_dest_; | 176 FileSystemURL move_dest_; |
176 | 177 |
177 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); | 178 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); |
178 }; | 179 }; |
179 | 180 |
180 class TestCopyOrMoveFileValidatorFactory | 181 class TestCopyOrMoveFileValidatorFactory |
181 : public CopyOrMoveFileValidatorFactory { | 182 : public CopyOrMoveFileValidatorFactory { |
182 public: | 183 public: |
183 // A factory that creates validators that accept everything or nothing. | 184 // A factory that creates validators that accept everything or nothing. |
184 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid) | 185 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid, |
185 : all_valid_(all_valid) {} | 186 bool all_valid_write) |
187 : all_valid_(all_valid), | |
188 all_valid_write_(all_valid_write) {} | |
186 virtual ~TestCopyOrMoveFileValidatorFactory() {} | 189 virtual ~TestCopyOrMoveFileValidatorFactory() {} |
187 | 190 |
188 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( | 191 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( |
189 const FileSystemURL& /*src_url*/, | 192 const FileSystemURL& /*src_url*/, |
190 const base::FilePath& /*platform_path*/) OVERRIDE { | 193 const base::FilePath& /*platform_path*/) OVERRIDE { |
191 return new TestCopyOrMoveFileValidator(all_valid_); | 194 return new TestCopyOrMoveFileValidator(all_valid_, all_valid_write_); |
192 } | 195 } |
193 | 196 |
194 private: | 197 private: |
195 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { | 198 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { |
196 public: | 199 public: |
197 explicit TestCopyOrMoveFileValidator(bool all_valid) | 200 explicit TestCopyOrMoveFileValidator(bool all_valid, bool all_valid_write) |
vandebo (ex-Chrome)
2013/07/10 15:52:46
all_valid -> pre_copy_valid
all_valid_write -> pos
Greg Billock
2013/07/11 22:54:35
Done.
| |
198 : result_(all_valid ? base::PLATFORM_FILE_OK | 201 : result_(all_valid ? base::PLATFORM_FILE_OK |
199 : base::PLATFORM_FILE_ERROR_SECURITY) { | 202 : base::PLATFORM_FILE_ERROR_SECURITY), |
203 write_result_(all_valid_write ? base::PLATFORM_FILE_OK | |
204 : base::PLATFORM_FILE_ERROR_SECURITY) { | |
200 } | 205 } |
201 virtual ~TestCopyOrMoveFileValidator() {} | 206 virtual ~TestCopyOrMoveFileValidator() {} |
202 | 207 |
203 virtual void StartValidation( | 208 virtual void StartValidation( |
204 const ResultCallback& result_callback) OVERRIDE { | 209 const ResultCallback& result_callback) OVERRIDE { |
205 // Post the result since a real validator must do work asynchronously. | 210 // Post the result since a real validator must do work asynchronously. |
206 base::MessageLoop::current()->PostTask( | 211 base::MessageLoop::current()->PostTask( |
207 FROM_HERE, base::Bind(result_callback, result_)); | 212 FROM_HERE, base::Bind(result_callback, result_)); |
208 } | 213 } |
209 | 214 |
215 virtual void StartPostWriteValidation( | |
216 const base::FilePath& dest_platform_path, | |
217 scoped_refptr<webkit_blob::ShareableFileReference> file_ref, | |
218 const ResultCallback& result_callback) OVERRIDE { | |
219 // Post the result since a real validator must do work asynchronously. | |
220 base::MessageLoop::current()->PostTask( | |
221 FROM_HERE, base::Bind(result_callback, write_result_)); | |
222 } | |
223 | |
210 private: | 224 private: |
211 base::PlatformFileError result_; | 225 base::PlatformFileError result_; |
226 base::PlatformFileError write_result_; | |
212 | 227 |
213 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); | 228 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); |
214 }; | 229 }; |
215 | 230 |
216 bool all_valid_; | 231 bool all_valid_; |
232 bool all_valid_write_; | |
217 | 233 |
218 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory); | 234 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory); |
219 }; | 235 }; |
220 | 236 |
221 } // namespace | 237 } // namespace |
222 | 238 |
223 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithin6ameFSType) { | 239 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithinSameFSType) { |
224 // Within a file system type, validation is not expected, so it should | 240 // Within a file system type, validation is not expected, so it should |
225 // work for kWithValidatorType without a validator set. | 241 // work for kWithValidatorType without a validator set. |
226 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 242 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
227 kWithValidatorType, | 243 kWithValidatorType, |
228 kWithValidatorType); | 244 kWithValidatorType); |
229 helper.SetUp(); | 245 helper.SetUp(); |
230 helper.CopyTest(base::PLATFORM_FILE_OK); | 246 helper.CopyTest(base::PLATFORM_FILE_OK); |
231 helper.MoveTest(base::PLATFORM_FILE_OK); | 247 helper.MoveTest(base::PLATFORM_FILE_OK); |
232 } | 248 } |
233 | 249 |
234 TEST(CopyOrMoveFileValidatorTest, MissingValidator) { | 250 TEST(CopyOrMoveFileValidatorTest, MissingValidator) { |
235 // Copying or moving into a kWithValidatorType requires a file | 251 // Copying or moving into a kWithValidatorType requires a file |
236 // validator. An error is expect if copy is attempted without a validator. | 252 // validator. An error is expected if copy is attempted without a validator. |
237 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 253 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
238 kNoValidatorType, | 254 kNoValidatorType, |
239 kWithValidatorType); | 255 kWithValidatorType); |
240 helper.SetUp(); | 256 helper.SetUp(); |
241 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 257 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
242 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 258 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
243 } | 259 } |
244 | 260 |
245 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { | 261 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { |
246 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 262 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
247 kNoValidatorType, | 263 kNoValidatorType, |
248 kWithValidatorType); | 264 kWithValidatorType); |
249 helper.SetUp(); | 265 helper.SetUp(); |
250 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 266 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
251 new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); | 267 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); |
252 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 268 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
253 | 269 |
254 helper.CopyTest(base::PLATFORM_FILE_OK); | 270 helper.CopyTest(base::PLATFORM_FILE_OK); |
255 helper.MoveTest(base::PLATFORM_FILE_OK); | 271 helper.MoveTest(base::PLATFORM_FILE_OK); |
256 } | 272 } |
257 | 273 |
258 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { | 274 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { |
259 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 275 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
260 kNoValidatorType, | 276 kNoValidatorType, |
261 kWithValidatorType); | 277 kWithValidatorType); |
262 helper.SetUp(); | 278 helper.SetUp(); |
263 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 279 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
264 new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); | 280 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); |
265 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 281 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
266 | 282 |
267 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 283 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
268 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 284 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
269 } | 285 } |
270 | 286 |
271 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { | 287 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { |
272 // Once set, you can not override the validator. | 288 // Once set, you can not override the validator. |
273 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 289 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
274 kNoValidatorType, | 290 kNoValidatorType, |
275 kWithValidatorType); | 291 kWithValidatorType); |
276 helper.SetUp(); | 292 helper.SetUp(); |
277 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( | 293 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( |
278 new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); | 294 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); |
279 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); | 295 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); |
280 | 296 |
281 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( | 297 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( |
282 new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); | 298 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); |
283 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); | 299 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); |
284 | 300 |
285 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 301 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
286 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 302 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
287 } | 303 } |
288 | 304 |
305 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { | |
306 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | |
307 kNoValidatorType, | |
308 kWithValidatorType); | |
309 helper.SetUp(); | |
310 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | |
311 new TestCopyOrMoveFileValidatorFactory(true, false)); | |
kinuko
2013/07/10 04:42:19
nit: add comment for the bool values here too?
Greg Billock
2013/07/11 22:54:35
Done.
| |
312 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | |
313 | |
314 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | |
315 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | |
316 } | |
317 | |
289 } // namespace fileapi | 318 } // namespace fileapi |
OLD | NEW |