| 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/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/public/test/async_file_test_helper.h" | 10 #include "content/public/test/async_file_test_helper.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 : public storage::CopyOrMoveFileValidatorFactory { | 194 : public storage::CopyOrMoveFileValidatorFactory { |
| 195 public: | 195 public: |
| 196 // A factory that creates validators that accept everything or nothing. | 196 // A factory that creates validators that accept everything or nothing. |
| 197 // TODO(gbillock): switch args to enum or something | 197 // TODO(gbillock): switch args to enum or something |
| 198 explicit TestCopyOrMoveFileValidatorFactory(Validity validity) | 198 explicit TestCopyOrMoveFileValidatorFactory(Validity validity) |
| 199 : validity_(validity) {} | 199 : validity_(validity) {} |
| 200 virtual ~TestCopyOrMoveFileValidatorFactory() {} | 200 virtual ~TestCopyOrMoveFileValidatorFactory() {} |
| 201 | 201 |
| 202 virtual storage::CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( | 202 virtual storage::CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( |
| 203 const FileSystemURL& /*src_url*/, | 203 const FileSystemURL& /*src_url*/, |
| 204 const base::FilePath& /*platform_path*/) OVERRIDE { | 204 const base::FilePath& /*platform_path*/) override { |
| 205 return new TestCopyOrMoveFileValidator(validity_); | 205 return new TestCopyOrMoveFileValidator(validity_); |
| 206 } | 206 } |
| 207 | 207 |
| 208 private: | 208 private: |
| 209 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { | 209 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { |
| 210 public: | 210 public: |
| 211 explicit TestCopyOrMoveFileValidator(Validity validity) | 211 explicit TestCopyOrMoveFileValidator(Validity validity) |
| 212 : result_(validity == VALID || validity == POST_WRITE_INVALID ? | 212 : result_(validity == VALID || validity == POST_WRITE_INVALID ? |
| 213 base::File::FILE_OK : | 213 base::File::FILE_OK : |
| 214 base::File::FILE_ERROR_SECURITY), | 214 base::File::FILE_ERROR_SECURITY), |
| 215 write_result_(validity == VALID || validity == PRE_WRITE_INVALID ? | 215 write_result_(validity == VALID || validity == PRE_WRITE_INVALID ? |
| 216 base::File::FILE_OK : | 216 base::File::FILE_OK : |
| 217 base::File::FILE_ERROR_SECURITY) { | 217 base::File::FILE_ERROR_SECURITY) { |
| 218 } | 218 } |
| 219 virtual ~TestCopyOrMoveFileValidator() {} | 219 virtual ~TestCopyOrMoveFileValidator() {} |
| 220 | 220 |
| 221 virtual void StartPreWriteValidation( | 221 virtual void StartPreWriteValidation( |
| 222 const ResultCallback& result_callback) OVERRIDE { | 222 const ResultCallback& result_callback) override { |
| 223 // Post the result since a real validator must do work asynchronously. | 223 // Post the result since a real validator must do work asynchronously. |
| 224 base::MessageLoop::current()->PostTask( | 224 base::MessageLoop::current()->PostTask( |
| 225 FROM_HERE, base::Bind(result_callback, result_)); | 225 FROM_HERE, base::Bind(result_callback, result_)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 virtual void StartPostWriteValidation( | 228 virtual void StartPostWriteValidation( |
| 229 const base::FilePath& dest_platform_path, | 229 const base::FilePath& dest_platform_path, |
| 230 const ResultCallback& result_callback) OVERRIDE { | 230 const ResultCallback& result_callback) override { |
| 231 // Post the result since a real validator must do work asynchronously. | 231 // Post the result since a real validator must do work asynchronously. |
| 232 base::MessageLoop::current()->PostTask( | 232 base::MessageLoop::current()->PostTask( |
| 233 FROM_HERE, base::Bind(result_callback, write_result_)); | 233 FROM_HERE, base::Bind(result_callback, write_result_)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 private: | 236 private: |
| 237 base::File::Error result_; | 237 base::File::Error result_; |
| 238 base::File::Error write_result_; | 238 base::File::Error write_result_; |
| 239 | 239 |
| 240 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); | 240 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 helper.SetUp(); | 320 helper.SetUp(); |
| 321 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 321 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
| 322 new TestCopyOrMoveFileValidatorFactory(POST_WRITE_INVALID)); | 322 new TestCopyOrMoveFileValidatorFactory(POST_WRITE_INVALID)); |
| 323 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 323 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
| 324 | 324 |
| 325 helper.CopyTest(base::File::FILE_ERROR_SECURITY); | 325 helper.CopyTest(base::File::FILE_ERROR_SECURITY); |
| 326 helper.MoveTest(base::File::FILE_ERROR_SECURITY); | 326 helper.MoveTest(base::File::FILE_ERROR_SECURITY); |
| 327 } | 327 } |
| 328 | 328 |
| 329 } // namespace content | 329 } // namespace content |
| OLD | NEW |