Chromium Code Reviews| 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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 FileSystemURL copy_dest_; | 176 FileSystemURL copy_dest_; |
| 177 FileSystemURL move_src_; | 177 FileSystemURL move_src_; |
| 178 FileSystemURL move_dest_; | 178 FileSystemURL move_dest_; |
| 179 | 179 |
| 180 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); | 180 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 class TestCopyOrMoveFileValidatorFactory | 183 class TestCopyOrMoveFileValidatorFactory |
| 184 : public CopyOrMoveFileValidatorFactory { | 184 : public CopyOrMoveFileValidatorFactory { |
| 185 public: | 185 public: |
| 186 enum Validity { | |
| 187 ALL_VALID, | |
|
vandebo (ex-Chrome)
2013/07/31 18:45:06
How about VALID, PRE_WRITE_INVALID, and POST_WRITE
Greg Billock
2013/07/31 19:01:54
Went with just "INVALID" for the second.
| |
| 188 ALL_INVALID, | |
| 189 WRITE_VALID_POST_WRITE_INVALID | |
| 190 }; | |
| 191 | |
| 186 // A factory that creates validators that accept everything or nothing. | 192 // A factory that creates validators that accept everything or nothing. |
| 187 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid, | 193 // TODO(gbillock): switch args to enum or something |
| 188 bool all_valid_write) | 194 explicit TestCopyOrMoveFileValidatorFactory(Validity validity) |
| 189 : all_valid_(all_valid), | 195 : all_valid_(validity == ALL_VALID || |
| 190 all_valid_write_(all_valid_write) {} | 196 validity == WRITE_VALID_POST_WRITE_INVALID), |
| 197 all_valid_write_(validity == ALL_VALID) {} | |
| 191 virtual ~TestCopyOrMoveFileValidatorFactory() {} | 198 virtual ~TestCopyOrMoveFileValidatorFactory() {} |
| 192 | 199 |
| 193 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( | 200 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( |
| 194 const FileSystemURL& /*src_url*/, | 201 const FileSystemURL& /*src_url*/, |
| 195 const base::FilePath& /*platform_path*/) OVERRIDE { | 202 const base::FilePath& /*platform_path*/) OVERRIDE { |
| 196 return new TestCopyOrMoveFileValidator(all_valid_, all_valid_write_); | 203 return new TestCopyOrMoveFileValidator(all_valid_, all_valid_write_); |
| 197 } | 204 } |
| 198 | 205 |
| 199 private: | 206 private: |
| 200 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { | 207 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { |
| 201 public: | 208 public: |
| 202 explicit TestCopyOrMoveFileValidator(bool pre_copy_valid, | 209 explicit TestCopyOrMoveFileValidator(bool pre_copy_valid, |
|
vandebo (ex-Chrome)
2013/07/31 18:45:06
propagate enum down.
Greg Billock
2013/07/31 19:01:54
Done.
| |
| 203 bool post_copy_valid) | 210 bool post_copy_valid) |
| 204 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK | 211 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK |
| 205 : base::PLATFORM_FILE_ERROR_SECURITY), | 212 : base::PLATFORM_FILE_ERROR_SECURITY), |
| 206 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK | 213 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK |
| 207 : base::PLATFORM_FILE_ERROR_SECURITY) { | 214 : base::PLATFORM_FILE_ERROR_SECURITY) { |
| 208 } | 215 } |
| 209 virtual ~TestCopyOrMoveFileValidator() {} | 216 virtual ~TestCopyOrMoveFileValidator() {} |
| 210 | 217 |
| 211 virtual void StartPreWriteValidation( | 218 virtual void StartPreWriteValidation( |
| 212 const ResultCallback& result_callback) OVERRIDE { | 219 const ResultCallback& result_callback) OVERRIDE { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 266 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 260 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 267 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 261 } | 268 } |
| 262 | 269 |
| 263 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { | 270 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { |
| 264 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 271 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 265 kNoValidatorType, | 272 kNoValidatorType, |
| 266 kWithValidatorType); | 273 kWithValidatorType); |
| 267 helper.SetUp(); | 274 helper.SetUp(); |
| 268 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 275 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
| 269 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); | 276 new TestCopyOrMoveFileValidatorFactory( |
| 277 TestCopyOrMoveFileValidatorFactory::ALL_VALID)); | |
| 270 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 278 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
| 271 | 279 |
| 272 helper.CopyTest(base::PLATFORM_FILE_OK); | 280 helper.CopyTest(base::PLATFORM_FILE_OK); |
| 273 helper.MoveTest(base::PLATFORM_FILE_OK); | 281 helper.MoveTest(base::PLATFORM_FILE_OK); |
| 274 } | 282 } |
| 275 | 283 |
| 276 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { | 284 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { |
| 277 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 285 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 278 kNoValidatorType, | 286 kNoValidatorType, |
| 279 kWithValidatorType); | 287 kWithValidatorType); |
| 280 helper.SetUp(); | 288 helper.SetUp(); |
| 281 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 289 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
| 282 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); | 290 new TestCopyOrMoveFileValidatorFactory( |
| 291 TestCopyOrMoveFileValidatorFactory::ALL_INVALID)); | |
| 283 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 292 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
| 284 | 293 |
| 285 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 294 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 286 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 295 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 287 } | 296 } |
| 288 | 297 |
| 289 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { | 298 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { |
| 290 // Once set, you can not override the validator. | 299 // Once set, you can not override the validator. |
| 291 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 300 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 292 kNoValidatorType, | 301 kNoValidatorType, |
| 293 kWithValidatorType); | 302 kWithValidatorType); |
| 294 helper.SetUp(); | 303 helper.SetUp(); |
| 295 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( | 304 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( |
| 296 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); | 305 new TestCopyOrMoveFileValidatorFactory( |
| 306 TestCopyOrMoveFileValidatorFactory::ALL_INVALID)); | |
| 297 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); | 307 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); |
| 298 | 308 |
| 299 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( | 309 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( |
| 300 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); | 310 new TestCopyOrMoveFileValidatorFactory( |
| 311 TestCopyOrMoveFileValidatorFactory::ALL_VALID)); | |
| 301 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); | 312 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); |
| 302 | 313 |
| 303 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 314 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 304 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 315 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 305 } | 316 } |
| 306 | 317 |
| 307 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { | 318 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { |
| 308 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 319 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
| 309 kNoValidatorType, | 320 kNoValidatorType, |
| 310 kWithValidatorType); | 321 kWithValidatorType); |
| 311 helper.SetUp(); | 322 helper.SetUp(); |
| 312 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 323 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
| 313 // accept pre-copy, reject post-copy | 324 new TestCopyOrMoveFileValidatorFactory( |
| 314 new TestCopyOrMoveFileValidatorFactory(true, false)); | 325 TestCopyOrMoveFileValidatorFactory::WRITE_VALID_POST_WRITE_INVALID)); |
| 315 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 326 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
| 316 | 327 |
| 317 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 328 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 318 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 329 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
| 319 } | 330 } |
| 320 | 331 |
| 321 } // namespace fileapi | 332 } // namespace fileapi |
| OLD | NEW |