| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <utility> |
| 7 | 8 |
| 8 #include "base/bind.h" | 9 #include "base/bind.h" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "content/public/test/async_file_test_helper.h" | 17 #include "content/public/test/async_file_test_helper.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 ASSERT_TRUE(FileExists(copy_src_, 10)); | 96 ASSERT_TRUE(FileExists(copy_src_, 10)); |
| 96 ASSERT_TRUE(FileExists(move_src_, 10)); | 97 ASSERT_TRUE(FileExists(move_src_, 10)); |
| 97 ASSERT_FALSE(FileExists(copy_dest_, 10)); | 98 ASSERT_FALSE(FileExists(copy_dest_, 10)); |
| 98 ASSERT_FALSE(FileExists(move_dest_, 10)); | 99 ASSERT_FALSE(FileExists(move_dest_, 10)); |
| 99 } | 100 } |
| 100 | 101 |
| 101 void SetMediaCopyOrMoveFileValidatorFactory( | 102 void SetMediaCopyOrMoveFileValidatorFactory( |
| 102 scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory) { | 103 scoped_ptr<storage::CopyOrMoveFileValidatorFactory> factory) { |
| 103 TestFileSystemBackend* backend = static_cast<TestFileSystemBackend*>( | 104 TestFileSystemBackend* backend = static_cast<TestFileSystemBackend*>( |
| 104 file_system_context_->GetFileSystemBackend(kWithValidatorType)); | 105 file_system_context_->GetFileSystemBackend(kWithValidatorType)); |
| 105 backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass()); | 106 backend->InitializeCopyOrMoveFileValidatorFactory(std::move(factory)); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void CopyTest(base::File::Error expected) { | 109 void CopyTest(base::File::Error expected) { |
| 109 ASSERT_TRUE(FileExists(copy_src_, 10)); | 110 ASSERT_TRUE(FileExists(copy_src_, 10)); |
| 110 ASSERT_FALSE(FileExists(copy_dest_, 10)); | 111 ASSERT_FALSE(FileExists(copy_dest_, 10)); |
| 111 | 112 |
| 112 EXPECT_EQ(expected, | 113 EXPECT_EQ(expected, |
| 113 AsyncFileTestHelper::Copy( | 114 AsyncFileTestHelper::Copy( |
| 114 file_system_context_.get(), copy_src_, copy_dest_)); | 115 file_system_context_.get(), copy_src_, copy_dest_)); |
| 115 | 116 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 helper.MoveTest(base::File::FILE_ERROR_SECURITY); | 276 helper.MoveTest(base::File::FILE_ERROR_SECURITY); |
| 276 } | 277 } |
| 277 | 278 |
| 278 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { | 279 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { |
| 279 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 280 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 280 kNoValidatorType, | 281 kNoValidatorType, |
| 281 kWithValidatorType); | 282 kWithValidatorType); |
| 282 helper.SetUp(); | 283 helper.SetUp(); |
| 283 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 284 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
| 284 new TestCopyOrMoveFileValidatorFactory(VALID)); | 285 new TestCopyOrMoveFileValidatorFactory(VALID)); |
| 285 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 286 helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(factory)); |
| 286 | 287 |
| 287 helper.CopyTest(base::File::FILE_OK); | 288 helper.CopyTest(base::File::FILE_OK); |
| 288 helper.MoveTest(base::File::FILE_OK); | 289 helper.MoveTest(base::File::FILE_OK); |
| 289 } | 290 } |
| 290 | 291 |
| 291 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { | 292 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { |
| 292 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 293 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 293 kNoValidatorType, | 294 kNoValidatorType, |
| 294 kWithValidatorType); | 295 kWithValidatorType); |
| 295 helper.SetUp(); | 296 helper.SetUp(); |
| 296 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 297 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
| 297 new TestCopyOrMoveFileValidatorFactory(PRE_WRITE_INVALID)); | 298 new TestCopyOrMoveFileValidatorFactory(PRE_WRITE_INVALID)); |
| 298 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 299 helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(factory)); |
| 299 | 300 |
| 300 helper.CopyTest(base::File::FILE_ERROR_SECURITY); | 301 helper.CopyTest(base::File::FILE_ERROR_SECURITY); |
| 301 helper.MoveTest(base::File::FILE_ERROR_SECURITY); | 302 helper.MoveTest(base::File::FILE_ERROR_SECURITY); |
| 302 } | 303 } |
| 303 | 304 |
| 304 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { | 305 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { |
| 305 // Once set, you can not override the validator. | 306 // Once set, you can not override the validator. |
| 306 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 307 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 307 kNoValidatorType, | 308 kNoValidatorType, |
| 308 kWithValidatorType); | 309 kWithValidatorType); |
| 309 helper.SetUp(); | 310 helper.SetUp(); |
| 310 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( | 311 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( |
| 311 new TestCopyOrMoveFileValidatorFactory(PRE_WRITE_INVALID)); | 312 new TestCopyOrMoveFileValidatorFactory(PRE_WRITE_INVALID)); |
| 312 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); | 313 helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(reject_factory)); |
| 313 | 314 |
| 314 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( | 315 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( |
| 315 new TestCopyOrMoveFileValidatorFactory(VALID)); | 316 new TestCopyOrMoveFileValidatorFactory(VALID)); |
| 316 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); | 317 helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(accept_factory)); |
| 317 | 318 |
| 318 helper.CopyTest(base::File::FILE_ERROR_SECURITY); | 319 helper.CopyTest(base::File::FILE_ERROR_SECURITY); |
| 319 helper.MoveTest(base::File::FILE_ERROR_SECURITY); | 320 helper.MoveTest(base::File::FILE_ERROR_SECURITY); |
| 320 } | 321 } |
| 321 | 322 |
| 322 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { | 323 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { |
| 323 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 324 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 324 kNoValidatorType, | 325 kNoValidatorType, |
| 325 kWithValidatorType); | 326 kWithValidatorType); |
| 326 helper.SetUp(); | 327 helper.SetUp(); |
| 327 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 328 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
| 328 new TestCopyOrMoveFileValidatorFactory(POST_WRITE_INVALID)); | 329 new TestCopyOrMoveFileValidatorFactory(POST_WRITE_INVALID)); |
| 329 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 330 helper.SetMediaCopyOrMoveFileValidatorFactory(std::move(factory)); |
| 330 | 331 |
| 331 helper.CopyTest(base::File::FILE_ERROR_SECURITY); | 332 helper.CopyTest(base::File::FILE_ERROR_SECURITY); |
| 332 helper.MoveTest(base::File::FILE_ERROR_SECURITY); | 333 helper.MoveTest(base::File::FILE_ERROR_SECURITY); |
| 333 } | 334 } |
| 334 | 335 |
| 335 } // namespace content | 336 } // namespace content |
| OLD | NEW |