Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc

Issue 18565002: [FileSystem] Add another copy-or-move validation hook for post-write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix flakey test Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 FileSystemURL move_src_; 178 FileSystemURL move_src_;
178 FileSystemURL move_dest_; 179 FileSystemURL move_dest_;
179 180
180 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); 181 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper);
181 }; 182 };
182 183
183 class TestCopyOrMoveFileValidatorFactory 184 class TestCopyOrMoveFileValidatorFactory
184 : public CopyOrMoveFileValidatorFactory { 185 : public CopyOrMoveFileValidatorFactory {
185 public: 186 public:
186 // A factory that creates validators that accept everything or nothing. 187 // A factory that creates validators that accept everything or nothing.
187 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid) 188 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid,
188 : all_valid_(all_valid) {} 189 bool all_valid_write)
190 : all_valid_(all_valid),
191 all_valid_write_(all_valid_write) {}
189 virtual ~TestCopyOrMoveFileValidatorFactory() {} 192 virtual ~TestCopyOrMoveFileValidatorFactory() {}
190 193
191 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( 194 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator(
192 const FileSystemURL& /*src_url*/, 195 const FileSystemURL& /*src_url*/,
193 const base::FilePath& /*platform_path*/) OVERRIDE { 196 const base::FilePath& /*platform_path*/) OVERRIDE {
194 return new TestCopyOrMoveFileValidator(all_valid_); 197 return new TestCopyOrMoveFileValidator(all_valid_, all_valid_write_);
195 } 198 }
196 199
197 private: 200 private:
198 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { 201 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator {
199 public: 202 public:
200 explicit TestCopyOrMoveFileValidator(bool all_valid) 203 explicit TestCopyOrMoveFileValidator(bool pre_copy_valid,
201 : result_(all_valid ? base::PLATFORM_FILE_OK 204 bool post_copy_valid)
202 : base::PLATFORM_FILE_ERROR_SECURITY) { 205 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK
206 : base::PLATFORM_FILE_ERROR_SECURITY),
207 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK
208 : base::PLATFORM_FILE_ERROR_SECURITY) {
203 } 209 }
204 virtual ~TestCopyOrMoveFileValidator() {} 210 virtual ~TestCopyOrMoveFileValidator() {}
205 211
206 virtual void StartValidation( 212 virtual void StartPreWriteValidation(
207 const ResultCallback& result_callback) OVERRIDE { 213 const ResultCallback& result_callback) OVERRIDE {
208 // Post the result since a real validator must do work asynchronously. 214 // Post the result since a real validator must do work asynchronously.
209 base::MessageLoop::current()->PostTask( 215 base::MessageLoop::current()->PostTask(
210 FROM_HERE, base::Bind(result_callback, result_)); 216 FROM_HERE, base::Bind(result_callback, result_));
211 } 217 }
212 218
219 virtual void StartPostWriteValidation(
220 const base::FilePath& dest_platform_path,
221 const ResultCallback& result_callback) OVERRIDE {
222 // Post the result since a real validator must do work asynchronously.
223 base::MessageLoop::current()->PostTask(
224 FROM_HERE, base::Bind(result_callback, write_result_));
225 }
226
213 private: 227 private:
214 base::PlatformFileError result_; 228 base::PlatformFileError result_;
229 base::PlatformFileError write_result_;
215 230
216 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); 231 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator);
217 }; 232 };
218 233
219 bool all_valid_; 234 bool all_valid_;
235 bool all_valid_write_;
220 236
221 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory); 237 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory);
222 }; 238 };
223 239
224 } // namespace 240 } // namespace
225 241
226 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithin6ameFSType) { 242 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithinSameFSType) {
227 // Within a file system type, validation is not expected, so it should 243 // Within a file system type, validation is not expected, so it should
228 // work for kWithValidatorType without a validator set. 244 // work for kWithValidatorType without a validator set.
229 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 245 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
230 kWithValidatorType, 246 kWithValidatorType,
231 kWithValidatorType); 247 kWithValidatorType);
232 helper.SetUp(); 248 helper.SetUp();
233 helper.CopyTest(base::PLATFORM_FILE_OK); 249 helper.CopyTest(base::PLATFORM_FILE_OK);
234 helper.MoveTest(base::PLATFORM_FILE_OK); 250 helper.MoveTest(base::PLATFORM_FILE_OK);
235 } 251 }
236 252
237 TEST(CopyOrMoveFileValidatorTest, MissingValidator) { 253 TEST(CopyOrMoveFileValidatorTest, MissingValidator) {
238 // Copying or moving into a kWithValidatorType requires a file 254 // Copying or moving into a kWithValidatorType requires a file
239 // validator. An error is expect if copy is attempted without a validator. 255 // validator. An error is expected if copy is attempted without a validator.
240 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 256 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
241 kNoValidatorType, 257 kNoValidatorType,
242 kWithValidatorType); 258 kWithValidatorType);
243 helper.SetUp(); 259 helper.SetUp();
244 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 260 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
245 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 261 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
246 } 262 }
247 263
248 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { 264 TEST(CopyOrMoveFileValidatorTest, AcceptAll) {
249 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 265 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
250 kNoValidatorType, 266 kNoValidatorType,
251 kWithValidatorType); 267 kWithValidatorType);
252 helper.SetUp(); 268 helper.SetUp();
253 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( 269 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
254 new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); 270 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/));
255 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); 271 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass());
256 272
257 helper.CopyTest(base::PLATFORM_FILE_OK); 273 helper.CopyTest(base::PLATFORM_FILE_OK);
258 helper.MoveTest(base::PLATFORM_FILE_OK); 274 helper.MoveTest(base::PLATFORM_FILE_OK);
259 } 275 }
260 276
261 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { 277 TEST(CopyOrMoveFileValidatorTest, AcceptNone) {
262 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 278 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
263 kNoValidatorType, 279 kNoValidatorType,
264 kWithValidatorType); 280 kWithValidatorType);
265 helper.SetUp(); 281 helper.SetUp();
266 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( 282 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
267 new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); 283 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/));
268 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); 284 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass());
269 285
270 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 286 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
271 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 287 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
272 } 288 }
273 289
274 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { 290 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) {
275 // Once set, you can not override the validator. 291 // Once set, you can not override the validator.
276 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 292 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
277 kNoValidatorType, 293 kNoValidatorType,
278 kWithValidatorType); 294 kWithValidatorType);
279 helper.SetUp(); 295 helper.SetUp();
280 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( 296 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory(
281 new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/)); 297 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/));
282 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); 298 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass());
283 299
284 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( 300 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory(
285 new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/)); 301 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/));
286 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); 302 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass());
287 303
288 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 304 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
289 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 305 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
290 } 306 }
291 307
308 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) {
309 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
310 kNoValidatorType,
311 kWithValidatorType);
312 helper.SetUp();
313 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
314 // accept pre-copy, reject post-copy
315 new TestCopyOrMoveFileValidatorFactory(true, false));
316 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass());
317
318 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
319 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
320 }
321
292 } // namespace fileapi 322 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/copy_or_move_file_validator.h ('k') | webkit/browser/fileapi/copy_or_move_operation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698