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_backend.h" | 14 #include "webkit/browser/fileapi/file_system_backend.h" |
15 #include "webkit/browser/fileapi/file_system_context.h" | 15 #include "webkit/browser/fileapi/file_system_context.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_file_system_backend.h" | 19 #include "webkit/browser/fileapi/test_file_system_backend.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(const GURL& origin_url, | 31 void ExpectOk(const GURL& origin_url, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 FileSystemURL move_src_; | 177 FileSystemURL move_src_; |
177 FileSystemURL move_dest_; | 178 FileSystemURL move_dest_; |
178 | 179 |
179 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); | 180 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); |
180 }; | 181 }; |
181 | 182 |
182 class TestCopyOrMoveFileValidatorFactory | 183 class TestCopyOrMoveFileValidatorFactory |
183 : public CopyOrMoveFileValidatorFactory { | 184 : public CopyOrMoveFileValidatorFactory { |
184 public: | 185 public: |
185 // A factory that creates validators that accept everything or nothing. | 186 // A factory that creates validators that accept everything or nothing. |
186 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid) | 187 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid, |
vandebo (ex-Chrome)
2013/07/18 17:35:14
nit: these args could use some help. Maybe an enu
Greg Billock
2013/07/30 23:18:31
Done.
| |
187 : all_valid_(all_valid) {} | 188 bool all_valid_write) |
189 : all_valid_(all_valid), | |
190 all_valid_write_(all_valid_write) {} | |
188 virtual ~TestCopyOrMoveFileValidatorFactory() {} | 191 virtual ~TestCopyOrMoveFileValidatorFactory() {} |
189 | 192 |
190 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( | 193 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( |
191 const FileSystemURL& /*src_url*/, | 194 const FileSystemURL& /*src_url*/, |
192 const base::FilePath& /*platform_path*/) OVERRIDE { | 195 const base::FilePath& /*platform_path*/) OVERRIDE { |
193 return new TestCopyOrMoveFileValidator(all_valid_); | 196 return new TestCopyOrMoveFileValidator(all_valid_, all_valid_write_); |
194 } | 197 } |
195 | 198 |
196 private: | 199 private: |
197 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { | 200 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { |
198 public: | 201 public: |
199 explicit TestCopyOrMoveFileValidator(bool all_valid) | 202 explicit TestCopyOrMoveFileValidator(bool pre_copy_valid, |
200 : result_(all_valid ? base::PLATFORM_FILE_OK | 203 bool post_copy_valid) |
201 : base::PLATFORM_FILE_ERROR_SECURITY) { | 204 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK |
205 : base::PLATFORM_FILE_ERROR_SECURITY), | |
206 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK | |
207 : base::PLATFORM_FILE_ERROR_SECURITY) { | |
202 } | 208 } |
203 virtual ~TestCopyOrMoveFileValidator() {} | 209 virtual ~TestCopyOrMoveFileValidator() {} |
204 | 210 |
205 virtual void StartValidation( | 211 virtual void StartPreWriteValidation( |
206 const ResultCallback& result_callback) OVERRIDE { | 212 const ResultCallback& result_callback) OVERRIDE { |
207 // Post the result since a real validator must do work asynchronously. | 213 // Post the result since a real validator must do work asynchronously. |
208 base::MessageLoop::current()->PostTask( | 214 base::MessageLoop::current()->PostTask( |
209 FROM_HERE, base::Bind(result_callback, result_)); | 215 FROM_HERE, base::Bind(result_callback, result_)); |
210 } | 216 } |
211 | 217 |
218 virtual void StartPostWriteValidation( | |
219 const base::FilePath& dest_platform_path, | |
220 const ResultCallback& result_callback) OVERRIDE { | |
221 // Post the result since a real validator must do work asynchronously. | |
222 base::MessageLoop::current()->PostTask( | |
223 FROM_HERE, base::Bind(result_callback, write_result_)); | |
224 } | |
225 | |
212 private: | 226 private: |
213 base::PlatformFileError result_; | 227 base::PlatformFileError result_; |
228 base::PlatformFileError write_result_; | |
214 | 229 |
215 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); | 230 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); |
216 }; | 231 }; |
217 | 232 |
218 bool all_valid_; | 233 bool all_valid_; |
234 bool all_valid_write_; | |
219 | 235 |
220 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory); | 236 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory); |
221 }; | 237 }; |
222 | 238 |
223 } // namespace | 239 } // namespace |
224 | 240 |
225 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithin6ameFSType) { | 241 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithinSameFSType) { |
226 // Within a file system type, validation is not expected, so it should | 242 // Within a file system type, validation is not expected, so it should |
227 // work for kWithValidatorType without a validator set. | 243 // work for kWithValidatorType without a validator set. |
228 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 244 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
229 kWithValidatorType, | 245 kWithValidatorType, |
230 kWithValidatorType); | 246 kWithValidatorType); |
231 helper.SetUp(); | 247 helper.SetUp(); |
232 helper.CopyTest(base::PLATFORM_FILE_OK); | 248 helper.CopyTest(base::PLATFORM_FILE_OK); |
233 helper.MoveTest(base::PLATFORM_FILE_OK); | 249 helper.MoveTest(base::PLATFORM_FILE_OK); |
234 } | 250 } |
235 | 251 |
236 TEST(CopyOrMoveFileValidatorTest, MissingValidator) { | 252 TEST(CopyOrMoveFileValidatorTest, MissingValidator) { |
237 // Copying or moving into a kWithValidatorType requires a file | 253 // Copying or moving into a kWithValidatorType requires a file |
238 // validator. An error is expect if copy is attempted without a validator. | 254 // validator. An error is expected if copy is attempted without a validator. |
239 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 255 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
240 kNoValidatorType, | 256 kNoValidatorType, |
241 kWithValidatorType); | 257 kWithValidatorType); |
242 helper.SetUp(); | 258 helper.SetUp(); |
243 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 259 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
244 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 260 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
245 } | 261 } |
246 | 262 |
247 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { | 263 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { |
248 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 264 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
249 kNoValidatorType, | 265 kNoValidatorType, |
250 kWithValidatorType); | 266 kWithValidatorType); |
251 helper.SetUp(); | 267 helper.SetUp(); |
252 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 268 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
253 new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); | 269 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); |
254 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 270 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
255 | 271 |
256 helper.CopyTest(base::PLATFORM_FILE_OK); | 272 helper.CopyTest(base::PLATFORM_FILE_OK); |
257 helper.MoveTest(base::PLATFORM_FILE_OK); | 273 helper.MoveTest(base::PLATFORM_FILE_OK); |
258 } | 274 } |
259 | 275 |
260 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { | 276 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { |
261 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 277 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
262 kNoValidatorType, | 278 kNoValidatorType, |
263 kWithValidatorType); | 279 kWithValidatorType); |
264 helper.SetUp(); | 280 helper.SetUp(); |
265 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 281 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( |
266 new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); | 282 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); |
267 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | 283 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); |
268 | 284 |
269 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 285 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
270 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 286 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
271 } | 287 } |
272 | 288 |
273 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { | 289 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { |
274 // Once set, you can not override the validator. | 290 // Once set, you can not override the validator. |
275 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | 291 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), |
276 kNoValidatorType, | 292 kNoValidatorType, |
277 kWithValidatorType); | 293 kWithValidatorType); |
278 helper.SetUp(); | 294 helper.SetUp(); |
279 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( | 295 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( |
280 new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); | 296 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); |
281 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); | 297 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); |
282 | 298 |
283 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( | 299 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( |
284 new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); | 300 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); |
285 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); | 301 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); |
286 | 302 |
287 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | 303 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); |
288 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | 304 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); |
289 } | 305 } |
290 | 306 |
307 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { | |
308 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), | |
309 kNoValidatorType, | |
310 kWithValidatorType); | |
311 helper.SetUp(); | |
312 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | |
313 // accept pre-copy, reject post-copy | |
314 new TestCopyOrMoveFileValidatorFactory(true, false)); | |
315 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); | |
316 | |
317 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); | |
318 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); | |
319 } | |
320 | |
291 } // namespace fileapi | 321 } // namespace fileapi |
OLD | NEW |