Index: webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc |
diff --git a/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc b/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc |
index b971fd57c1a9f0f72b517fc1a3e186d78b76e71c..3f6862c67f2e56c2f49feaa7fd8abf9ed2e11cba 100644 |
--- a/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc |
+++ b/webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc |
@@ -18,6 +18,7 @@ |
#include "webkit/browser/fileapi/mock_file_system_context.h" |
#include "webkit/browser/fileapi/test_mount_point_provider.h" |
#include "webkit/browser/quota/mock_special_storage_policy.h" |
+#include "webkit/common/blob/shareable_file_reference.h" |
#include "webkit/common/fileapi/file_system_util.h" |
namespace fileapi { |
@@ -181,22 +182,26 @@ class TestCopyOrMoveFileValidatorFactory |
: public CopyOrMoveFileValidatorFactory { |
public: |
// A factory that creates validators that accept everything or nothing. |
- explicit TestCopyOrMoveFileValidatorFactory(bool all_valid) |
- : all_valid_(all_valid) {} |
+ explicit TestCopyOrMoveFileValidatorFactory(bool all_valid, |
+ bool all_valid_write) |
+ : all_valid_(all_valid), |
+ all_valid_write_(all_valid_write) {} |
virtual ~TestCopyOrMoveFileValidatorFactory() {} |
virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( |
const FileSystemURL& /*src_url*/, |
const base::FilePath& /*platform_path*/) OVERRIDE { |
- return new TestCopyOrMoveFileValidator(all_valid_); |
+ return new TestCopyOrMoveFileValidator(all_valid_, all_valid_write_); |
} |
private: |
class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { |
public: |
- explicit TestCopyOrMoveFileValidator(bool all_valid) |
+ 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.
|
: result_(all_valid ? base::PLATFORM_FILE_OK |
- : base::PLATFORM_FILE_ERROR_SECURITY) { |
+ : base::PLATFORM_FILE_ERROR_SECURITY), |
+ write_result_(all_valid_write ? base::PLATFORM_FILE_OK |
+ : base::PLATFORM_FILE_ERROR_SECURITY) { |
} |
virtual ~TestCopyOrMoveFileValidator() {} |
@@ -207,20 +212,31 @@ class TestCopyOrMoveFileValidatorFactory |
FROM_HERE, base::Bind(result_callback, result_)); |
} |
+ virtual void StartPostWriteValidation( |
+ const base::FilePath& dest_platform_path, |
+ scoped_refptr<webkit_blob::ShareableFileReference> file_ref, |
+ const ResultCallback& result_callback) OVERRIDE { |
+ // Post the result since a real validator must do work asynchronously. |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, base::Bind(result_callback, write_result_)); |
+ } |
+ |
private: |
base::PlatformFileError result_; |
+ base::PlatformFileError write_result_; |
DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); |
}; |
bool all_valid_; |
+ bool all_valid_write_; |
DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory); |
}; |
} // namespace |
-TEST(CopyOrMoveFileValidatorTest, NoValidatorWithin6ameFSType) { |
+TEST(CopyOrMoveFileValidatorTest, NoValidatorWithinSameFSType) { |
// Within a file system type, validation is not expected, so it should |
// work for kWithValidatorType without a validator set. |
CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
@@ -233,7 +249,7 @@ TEST(CopyOrMoveFileValidatorTest, NoValidatorWithin6ameFSType) { |
TEST(CopyOrMoveFileValidatorTest, MissingValidator) { |
// Copying or moving into a kWithValidatorType requires a file |
- // validator. An error is expect if copy is attempted without a validator. |
+ // validator. An error is expected if copy is attempted without a validator. |
CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
kNoValidatorType, |
kWithValidatorType); |
@@ -248,7 +264,7 @@ TEST(CopyOrMoveFileValidatorTest, AcceptAll) { |
kWithValidatorType); |
helper.SetUp(); |
scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
- new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); |
+ new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); |
helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
helper.CopyTest(base::PLATFORM_FILE_OK); |
@@ -261,7 +277,7 @@ TEST(CopyOrMoveFileValidatorTest, AcceptNone) { |
kWithValidatorType); |
helper.SetUp(); |
scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
- new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); |
+ new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); |
helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
@@ -275,15 +291,28 @@ TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { |
kWithValidatorType); |
helper.SetUp(); |
scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( |
- new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); |
+ new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); |
helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); |
scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( |
- new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); |
+ new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); |
helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); |
helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
} |
+TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { |
+ CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
+ kNoValidatorType, |
+ kWithValidatorType); |
+ helper.SetUp(); |
+ scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
+ 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.
|
+ helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
+ |
+ helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
+ helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
+} |
+ |
} // namespace fileapi |