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

Side by Side Diff: content/browser/fileapi/copy_or_move_operation_delegate_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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 <map> 5 #include <map>
6 #include <queue> 6 #include <queue>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 28 matching lines...) Expand all
39 using fileapi::test::TestCaseRecord; 39 using fileapi::test::TestCaseRecord;
40 40
41 namespace content { 41 namespace content {
42 42
43 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; 43 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList;
44 44
45 namespace { 45 namespace {
46 46
47 void ExpectOk(const GURL& origin_url, 47 void ExpectOk(const GURL& origin_url,
48 const std::string& name, 48 const std::string& name,
49 base::PlatformFileError error) { 49 base::File::Error error) {
50 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 50 ASSERT_EQ(base::File::FILE_OK, error);
51 } 51 }
52 52
53 class TestValidatorFactory : public fileapi::CopyOrMoveFileValidatorFactory { 53 class TestValidatorFactory : public fileapi::CopyOrMoveFileValidatorFactory {
54 public: 54 public:
55 // A factory that creates validators that accept everything or nothing. 55 // A factory that creates validators that accept everything or nothing.
56 TestValidatorFactory() {} 56 TestValidatorFactory() {}
57 virtual ~TestValidatorFactory() {} 57 virtual ~TestValidatorFactory() {}
58 58
59 virtual fileapi::CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( 59 virtual fileapi::CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator(
60 const FileSystemURL& /*src_url*/, 60 const FileSystemURL& /*src_url*/,
61 const base::FilePath& /*platform_path*/) OVERRIDE { 61 const base::FilePath& /*platform_path*/) OVERRIDE {
62 // Move arg management to TestValidator? 62 // Move arg management to TestValidator?
63 return new TestValidator(true, true, std::string("2")); 63 return new TestValidator(true, true, std::string("2"));
64 } 64 }
65 65
66 private: 66 private:
67 class TestValidator : public fileapi::CopyOrMoveFileValidator { 67 class TestValidator : public fileapi::CopyOrMoveFileValidator {
68 public: 68 public:
69 explicit TestValidator(bool pre_copy_valid, 69 explicit TestValidator(bool pre_copy_valid,
70 bool post_copy_valid, 70 bool post_copy_valid,
71 const std::string& reject_string) 71 const std::string& reject_string)
72 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK 72 : result_(pre_copy_valid ? base::File::FILE_OK :
73 : base::PLATFORM_FILE_ERROR_SECURITY), 73 base::File::FILE_ERROR_SECURITY),
74 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK 74 write_result_(post_copy_valid ? base::File::FILE_OK :
75 : base::PLATFORM_FILE_ERROR_SECURITY), 75 base::File::FILE_ERROR_SECURITY),
76 reject_string_(reject_string) { 76 reject_string_(reject_string) {
77 } 77 }
78 virtual ~TestValidator() {} 78 virtual ~TestValidator() {}
79 79
80 virtual void StartPreWriteValidation( 80 virtual void StartPreWriteValidation(
81 const ResultCallback& result_callback) OVERRIDE { 81 const ResultCallback& result_callback) OVERRIDE {
82 // Post the result since a real validator must do work asynchronously. 82 // Post the result since a real validator must do work asynchronously.
83 base::MessageLoop::current()->PostTask( 83 base::MessageLoop::current()->PostTask(
84 FROM_HERE, base::Bind(result_callback, result_)); 84 FROM_HERE, base::Bind(result_callback, result_));
85 } 85 }
86 86
87 virtual void StartPostWriteValidation( 87 virtual void StartPostWriteValidation(
88 const base::FilePath& dest_platform_path, 88 const base::FilePath& dest_platform_path,
89 const ResultCallback& result_callback) OVERRIDE { 89 const ResultCallback& result_callback) OVERRIDE {
90 base::PlatformFileError result = write_result_; 90 base::File::Error result = write_result_;
91 std::string unsafe = dest_platform_path.BaseName().AsUTF8Unsafe(); 91 std::string unsafe = dest_platform_path.BaseName().AsUTF8Unsafe();
92 if (unsafe.find(reject_string_) != std::string::npos) { 92 if (unsafe.find(reject_string_) != std::string::npos) {
93 result = base::PLATFORM_FILE_ERROR_SECURITY; 93 result = base::File::FILE_ERROR_SECURITY;
94 } 94 }
95 // Post the result since a real validator must do work asynchronously. 95 // Post the result since a real validator must do work asynchronously.
96 base::MessageLoop::current()->PostTask( 96 base::MessageLoop::current()->PostTask(
97 FROM_HERE, base::Bind(result_callback, result)); 97 FROM_HERE, base::Bind(result_callback, result));
98 } 98 }
99 99
100 private: 100 private:
101 base::PlatformFileError result_; 101 base::File::Error result_;
102 base::PlatformFileError write_result_; 102 base::File::Error write_result_;
103 std::string reject_string_; 103 std::string reject_string_;
104 104
105 DISALLOW_COPY_AND_ASSIGN(TestValidator); 105 DISALLOW_COPY_AND_ASSIGN(TestValidator);
106 }; 106 };
107 }; 107 };
108 108
109 // Records CopyProgressCallback invocations. 109 // Records CopyProgressCallback invocations.
110 struct ProgressRecord { 110 struct ProgressRecord {
111 fileapi::FileSystemOperation::CopyProgressType type; 111 fileapi::FileSystemOperation::CopyProgressType type;
112 FileSystemURL source_url; 112 FileSystemURL source_url;
(...skipping 13 matching lines...) Expand all
126 record.size = size; 126 record.size = size;
127 records->push_back(record); 127 records->push_back(record);
128 } 128 }
129 129
130 void RecordFileProgressCallback(std::vector<int64>* records, 130 void RecordFileProgressCallback(std::vector<int64>* records,
131 int64 progress) { 131 int64 progress) {
132 records->push_back(progress); 132 records->push_back(progress);
133 } 133 }
134 134
135 void AssignAndQuit(base::RunLoop* run_loop, 135 void AssignAndQuit(base::RunLoop* run_loop,
136 base::PlatformFileError* result_out, 136 base::File::Error* result_out,
137 base::PlatformFileError result) { 137 base::File::Error result) {
138 *result_out = result; 138 *result_out = result;
139 run_loop->Quit(); 139 run_loop->Quit();
140 } 140 }
141 141
142 class ScopedThreadStopper { 142 class ScopedThreadStopper {
143 public: 143 public:
144 ScopedThreadStopper(base::Thread* thread) : thread_(thread) { 144 ScopedThreadStopper(base::Thread* thread) : thread_(thread) {
145 } 145 }
146 146
147 ~ScopedThreadStopper() { 147 ~ScopedThreadStopper() {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 FileSystemURL SourceURL(const std::string& path) { 253 FileSystemURL SourceURL(const std::string& path) {
254 return file_system_context_->CreateCrackedFileSystemURL( 254 return file_system_context_->CreateCrackedFileSystemURL(
255 origin_, src_type_, base::FilePath::FromUTF8Unsafe(path)); 255 origin_, src_type_, base::FilePath::FromUTF8Unsafe(path));
256 } 256 }
257 257
258 FileSystemURL DestURL(const std::string& path) { 258 FileSystemURL DestURL(const std::string& path) {
259 return file_system_context_->CreateCrackedFileSystemURL( 259 return file_system_context_->CreateCrackedFileSystemURL(
260 origin_, dest_type_, base::FilePath::FromUTF8Unsafe(path)); 260 origin_, dest_type_, base::FilePath::FromUTF8Unsafe(path));
261 } 261 }
262 262
263 base::PlatformFileError Copy(const FileSystemURL& src, 263 base::File::Error Copy(const FileSystemURL& src,
264 const FileSystemURL& dest) { 264 const FileSystemURL& dest) {
265 return AsyncFileTestHelper::Copy(file_system_context_.get(), src, dest); 265 return AsyncFileTestHelper::Copy(file_system_context_.get(), src, dest);
266 } 266 }
267 267
268 base::PlatformFileError CopyWithProgress( 268 base::File::Error CopyWithProgress(
269 const FileSystemURL& src, 269 const FileSystemURL& src,
270 const FileSystemURL& dest, 270 const FileSystemURL& dest,
271 const AsyncFileTestHelper::CopyProgressCallback& progress_callback) { 271 const AsyncFileTestHelper::CopyProgressCallback& progress_callback) {
272 return AsyncFileTestHelper::CopyWithProgress( 272 return AsyncFileTestHelper::CopyWithProgress(
273 file_system_context_.get(), src, dest, progress_callback); 273 file_system_context_.get(), src, dest, progress_callback);
274 } 274 }
275 275
276 base::PlatformFileError Move(const FileSystemURL& src, 276 base::File::Error Move(const FileSystemURL& src,
277 const FileSystemURL& dest) { 277 const FileSystemURL& dest) {
278 return AsyncFileTestHelper::Move(file_system_context_.get(), src, dest); 278 return AsyncFileTestHelper::Move(file_system_context_.get(), src, dest);
279 } 279 }
280 280
281 base::PlatformFileError SetUpTestCaseFiles( 281 base::File::Error SetUpTestCaseFiles(
282 const FileSystemURL& root, 282 const FileSystemURL& root,
283 const TestCaseRecord* const test_cases, 283 const TestCaseRecord* const test_cases,
284 size_t test_case_size) { 284 size_t test_case_size) {
285 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; 285 base::File::Error result = base::File::FILE_ERROR_FAILED;
286 for (size_t i = 0; i < test_case_size; ++i) { 286 for (size_t i = 0; i < test_case_size; ++i) {
287 const TestCaseRecord& test_case = test_cases[i]; 287 const TestCaseRecord& test_case = test_cases[i];
288 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( 288 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL(
289 root.origin(), 289 root.origin(),
290 root.mount_type(), 290 root.mount_type(),
291 root.virtual_path().Append(test_case.path)); 291 root.virtual_path().Append(test_case.path));
292 if (test_case.is_directory) 292 if (test_case.is_directory)
293 result = CreateDirectory(url); 293 result = CreateDirectory(url);
294 else 294 else
295 result = CreateFile(url, test_case.data_file_size); 295 result = CreateFile(url, test_case.data_file_size);
296 EXPECT_EQ(base::PLATFORM_FILE_OK, result) << url.DebugString(); 296 EXPECT_EQ(base::File::FILE_OK, result) << url.DebugString();
297 if (result != base::PLATFORM_FILE_OK) 297 if (result != base::File::FILE_OK)
298 return result; 298 return result;
299 } 299 }
300 return result; 300 return result;
301 } 301 }
302 302
303 void VerifyTestCaseFiles( 303 void VerifyTestCaseFiles(
304 const FileSystemURL& root, 304 const FileSystemURL& root,
305 const TestCaseRecord* const test_cases, 305 const TestCaseRecord* const test_cases,
306 size_t test_case_size) { 306 size_t test_case_size) {
307 std::map<base::FilePath, const TestCaseRecord*> test_case_map; 307 std::map<base::FilePath, const TestCaseRecord*> test_case_map;
308 for (size_t i = 0; i < test_case_size; ++i) { 308 for (size_t i = 0; i < test_case_size; ++i) {
309 test_case_map[ 309 test_case_map[
310 base::FilePath(test_cases[i].path).NormalizePathSeparators()] = 310 base::FilePath(test_cases[i].path).NormalizePathSeparators()] =
311 &test_cases[i]; 311 &test_cases[i];
312 } 312 }
313 313
314 std::queue<FileSystemURL> directories; 314 std::queue<FileSystemURL> directories;
315 FileEntryList entries; 315 FileEntryList entries;
316 directories.push(root); 316 directories.push(root);
317 while (!directories.empty()) { 317 while (!directories.empty()) {
318 FileSystemURL dir = directories.front(); 318 FileSystemURL dir = directories.front();
319 directories.pop(); 319 directories.pop();
320 ASSERT_EQ(base::PLATFORM_FILE_OK, ReadDirectory(dir, &entries)); 320 ASSERT_EQ(base::File::FILE_OK, ReadDirectory(dir, &entries));
321 for (size_t i = 0; i < entries.size(); ++i) { 321 for (size_t i = 0; i < entries.size(); ++i) {
322 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( 322 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL(
323 dir.origin(), 323 dir.origin(),
324 dir.mount_type(), 324 dir.mount_type(),
325 dir.virtual_path().Append(entries[i].name)); 325 dir.virtual_path().Append(entries[i].name));
326 base::FilePath relative; 326 base::FilePath relative;
327 root.virtual_path().AppendRelativePath(url.virtual_path(), &relative); 327 root.virtual_path().AppendRelativePath(url.virtual_path(), &relative);
328 relative = relative.NormalizePathSeparators(); 328 relative = relative.NormalizePathSeparators();
329 ASSERT_TRUE(ContainsKey(test_case_map, relative)); 329 ASSERT_TRUE(ContainsKey(test_case_map, relative));
330 if (entries[i].is_directory) { 330 if (entries[i].is_directory) {
331 EXPECT_TRUE(test_case_map[relative]->is_directory); 331 EXPECT_TRUE(test_case_map[relative]->is_directory);
332 directories.push(url); 332 directories.push(url);
333 } else { 333 } else {
334 EXPECT_FALSE(test_case_map[relative]->is_directory); 334 EXPECT_FALSE(test_case_map[relative]->is_directory);
335 EXPECT_TRUE(FileExists(url, test_case_map[relative]->data_file_size)); 335 EXPECT_TRUE(FileExists(url, test_case_map[relative]->data_file_size));
336 } 336 }
337 test_case_map.erase(relative); 337 test_case_map.erase(relative);
338 } 338 }
339 } 339 }
340 EXPECT_TRUE(test_case_map.empty()); 340 EXPECT_TRUE(test_case_map.empty());
341 std::map<base::FilePath, const TestCaseRecord*>::const_iterator it; 341 std::map<base::FilePath, const TestCaseRecord*>::const_iterator it;
342 for (it = test_case_map.begin(); it != test_case_map.end(); ++it) { 342 for (it = test_case_map.begin(); it != test_case_map.end(); ++it) {
343 LOG(ERROR) << "Extra entry: " << it->first.LossyDisplayName(); 343 LOG(ERROR) << "Extra entry: " << it->first.LossyDisplayName();
344 } 344 }
345 } 345 }
346 346
347 base::PlatformFileError ReadDirectory(const FileSystemURL& url, 347 base::File::Error ReadDirectory(const FileSystemURL& url,
348 FileEntryList* entries) { 348 FileEntryList* entries) {
349 return AsyncFileTestHelper::ReadDirectory( 349 return AsyncFileTestHelper::ReadDirectory(
350 file_system_context_.get(), url, entries); 350 file_system_context_.get(), url, entries);
351 } 351 }
352 352
353 base::PlatformFileError CreateDirectory(const FileSystemURL& url) { 353 base::File::Error CreateDirectory(const FileSystemURL& url) {
354 return AsyncFileTestHelper::CreateDirectory(file_system_context_.get(), 354 return AsyncFileTestHelper::CreateDirectory(file_system_context_.get(),
355 url); 355 url);
356 } 356 }
357 357
358 base::PlatformFileError CreateFile(const FileSystemURL& url, size_t size) { 358 base::File::Error CreateFile(const FileSystemURL& url, size_t size) {
359 base::PlatformFileError result = 359 base::File::Error result =
360 AsyncFileTestHelper::CreateFile(file_system_context_.get(), url); 360 AsyncFileTestHelper::CreateFile(file_system_context_.get(), url);
361 if (result != base::PLATFORM_FILE_OK) 361 if (result != base::File::FILE_OK)
362 return result; 362 return result;
363 return AsyncFileTestHelper::TruncateFile( 363 return AsyncFileTestHelper::TruncateFile(
364 file_system_context_.get(), url, size); 364 file_system_context_.get(), url, size);
365 } 365 }
366 366
367 bool FileExists(const FileSystemURL& url, int64 expected_size) { 367 bool FileExists(const FileSystemURL& url, int64 expected_size) {
368 return AsyncFileTestHelper::FileExists( 368 return AsyncFileTestHelper::FileExists(
369 file_system_context_.get(), url, expected_size); 369 file_system_context_.get(), url, expected_size);
370 } 370 }
371 371
(...skipping 29 matching lines...) Expand all
401 fileapi::kFileSystemTypeTemporary, 401 fileapi::kFileSystemTypeTemporary,
402 fileapi::kFileSystemTypePersistent); 402 fileapi::kFileSystemTypePersistent);
403 helper.SetUp(); 403 helper.SetUp();
404 404
405 FileSystemURL src = helper.SourceURL("a"); 405 FileSystemURL src = helper.SourceURL("a");
406 FileSystemURL dest = helper.DestURL("b"); 406 FileSystemURL dest = helper.DestURL("b");
407 int64 src_initial_usage = helper.GetSourceUsage(); 407 int64 src_initial_usage = helper.GetSourceUsage();
408 int64 dest_initial_usage = helper.GetDestUsage(); 408 int64 dest_initial_usage = helper.GetDestUsage();
409 409
410 // Set up a source file. 410 // Set up a source file.
411 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); 411 ASSERT_EQ(base::File::FILE_OK, helper.CreateFile(src, 10));
412 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; 412 int64 src_increase = helper.GetSourceUsage() - src_initial_usage;
413 413
414 // Copy it. 414 // Copy it.
415 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Copy(src, dest)); 415 ASSERT_EQ(base::File::FILE_OK, helper.Copy(src, dest));
416 416
417 // Verify. 417 // Verify.
418 ASSERT_TRUE(helper.FileExists(src, 10)); 418 ASSERT_TRUE(helper.FileExists(src, 10));
419 ASSERT_TRUE(helper.FileExists(dest, 10)); 419 ASSERT_TRUE(helper.FileExists(dest, 10));
420 420
421 int64 src_new_usage = helper.GetSourceUsage(); 421 int64 src_new_usage = helper.GetSourceUsage();
422 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); 422 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage);
423 423
424 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; 424 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage;
425 ASSERT_EQ(src_increase, dest_increase); 425 ASSERT_EQ(src_increase, dest_increase);
426 } 426 }
427 427
428 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleFile) { 428 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleFile) {
429 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), 429 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
430 fileapi::kFileSystemTypeTemporary, 430 fileapi::kFileSystemTypeTemporary,
431 fileapi::kFileSystemTypePersistent); 431 fileapi::kFileSystemTypePersistent);
432 helper.SetUp(); 432 helper.SetUp();
433 433
434 FileSystemURL src = helper.SourceURL("a"); 434 FileSystemURL src = helper.SourceURL("a");
435 FileSystemURL dest = helper.DestURL("b"); 435 FileSystemURL dest = helper.DestURL("b");
436 int64 src_initial_usage = helper.GetSourceUsage(); 436 int64 src_initial_usage = helper.GetSourceUsage();
437 int64 dest_initial_usage = helper.GetDestUsage(); 437 int64 dest_initial_usage = helper.GetDestUsage();
438 438
439 // Set up a source file. 439 // Set up a source file.
440 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); 440 ASSERT_EQ(base::File::FILE_OK, helper.CreateFile(src, 10));
441 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; 441 int64 src_increase = helper.GetSourceUsage() - src_initial_usage;
442 442
443 // Move it. 443 // Move it.
444 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); 444 ASSERT_EQ(base::File::FILE_OK, helper.Move(src, dest));
445 445
446 // Verify. 446 // Verify.
447 ASSERT_FALSE(helper.FileExists(src, AsyncFileTestHelper::kDontCheckSize)); 447 ASSERT_FALSE(helper.FileExists(src, AsyncFileTestHelper::kDontCheckSize));
448 ASSERT_TRUE(helper.FileExists(dest, 10)); 448 ASSERT_TRUE(helper.FileExists(dest, 10));
449 449
450 int64 src_new_usage = helper.GetSourceUsage(); 450 int64 src_new_usage = helper.GetSourceUsage();
451 ASSERT_EQ(src_initial_usage, src_new_usage); 451 ASSERT_EQ(src_initial_usage, src_new_usage);
452 452
453 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; 453 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage;
454 ASSERT_EQ(src_increase, dest_increase); 454 ASSERT_EQ(src_increase, dest_increase);
455 } 455 }
456 456
457 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleDirectory) { 457 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleDirectory) {
458 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), 458 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
459 fileapi::kFileSystemTypeTemporary, 459 fileapi::kFileSystemTypeTemporary,
460 fileapi::kFileSystemTypePersistent); 460 fileapi::kFileSystemTypePersistent);
461 helper.SetUp(); 461 helper.SetUp();
462 462
463 FileSystemURL src = helper.SourceURL("a"); 463 FileSystemURL src = helper.SourceURL("a");
464 FileSystemURL dest = helper.DestURL("b"); 464 FileSystemURL dest = helper.DestURL("b");
465 int64 src_initial_usage = helper.GetSourceUsage(); 465 int64 src_initial_usage = helper.GetSourceUsage();
466 int64 dest_initial_usage = helper.GetDestUsage(); 466 int64 dest_initial_usage = helper.GetDestUsage();
467 467
468 // Set up a source directory. 468 // Set up a source directory.
469 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); 469 ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src));
470 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; 470 int64 src_increase = helper.GetSourceUsage() - src_initial_usage;
471 471
472 // Copy it. 472 // Copy it.
473 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Copy(src, dest)); 473 ASSERT_EQ(base::File::FILE_OK, helper.Copy(src, dest));
474 474
475 // Verify. 475 // Verify.
476 ASSERT_TRUE(helper.DirectoryExists(src)); 476 ASSERT_TRUE(helper.DirectoryExists(src));
477 ASSERT_TRUE(helper.DirectoryExists(dest)); 477 ASSERT_TRUE(helper.DirectoryExists(dest));
478 478
479 int64 src_new_usage = helper.GetSourceUsage(); 479 int64 src_new_usage = helper.GetSourceUsage();
480 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); 480 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage);
481 481
482 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; 482 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage;
483 ASSERT_EQ(src_increase, dest_increase); 483 ASSERT_EQ(src_increase, dest_increase);
484 } 484 }
485 485
486 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleDirectory) { 486 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleDirectory) {
487 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), 487 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
488 fileapi::kFileSystemTypeTemporary, 488 fileapi::kFileSystemTypeTemporary,
489 fileapi::kFileSystemTypePersistent); 489 fileapi::kFileSystemTypePersistent);
490 helper.SetUp(); 490 helper.SetUp();
491 491
492 FileSystemURL src = helper.SourceURL("a"); 492 FileSystemURL src = helper.SourceURL("a");
493 FileSystemURL dest = helper.DestURL("b"); 493 FileSystemURL dest = helper.DestURL("b");
494 int64 src_initial_usage = helper.GetSourceUsage(); 494 int64 src_initial_usage = helper.GetSourceUsage();
495 int64 dest_initial_usage = helper.GetDestUsage(); 495 int64 dest_initial_usage = helper.GetDestUsage();
496 496
497 // Set up a source directory. 497 // Set up a source directory.
498 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); 498 ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src));
499 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; 499 int64 src_increase = helper.GetSourceUsage() - src_initial_usage;
500 500
501 // Move it. 501 // Move it.
502 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); 502 ASSERT_EQ(base::File::FILE_OK, helper.Move(src, dest));
503 503
504 // Verify. 504 // Verify.
505 ASSERT_FALSE(helper.DirectoryExists(src)); 505 ASSERT_FALSE(helper.DirectoryExists(src));
506 ASSERT_TRUE(helper.DirectoryExists(dest)); 506 ASSERT_TRUE(helper.DirectoryExists(dest));
507 507
508 int64 src_new_usage = helper.GetSourceUsage(); 508 int64 src_new_usage = helper.GetSourceUsage();
509 ASSERT_EQ(src_initial_usage, src_new_usage); 509 ASSERT_EQ(src_initial_usage, src_new_usage);
510 510
511 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; 511 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage;
512 ASSERT_EQ(src_increase, dest_increase); 512 ASSERT_EQ(src_increase, dest_increase);
513 } 513 }
514 514
515 TEST(LocalFileSystemCopyOrMoveOperationTest, CopyDirectory) { 515 TEST(LocalFileSystemCopyOrMoveOperationTest, CopyDirectory) {
516 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), 516 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
517 fileapi::kFileSystemTypeTemporary, 517 fileapi::kFileSystemTypeTemporary,
518 fileapi::kFileSystemTypePersistent); 518 fileapi::kFileSystemTypePersistent);
519 helper.SetUp(); 519 helper.SetUp();
520 520
521 FileSystemURL src = helper.SourceURL("a"); 521 FileSystemURL src = helper.SourceURL("a");
522 FileSystemURL dest = helper.DestURL("b"); 522 FileSystemURL dest = helper.DestURL("b");
523 int64 src_initial_usage = helper.GetSourceUsage(); 523 int64 src_initial_usage = helper.GetSourceUsage();
524 int64 dest_initial_usage = helper.GetDestUsage(); 524 int64 dest_initial_usage = helper.GetDestUsage();
525 525
526 // Set up a source directory. 526 // Set up a source directory.
527 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); 527 ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src));
528 ASSERT_EQ(base::PLATFORM_FILE_OK, 528 ASSERT_EQ(base::File::FILE_OK,
529 helper.SetUpTestCaseFiles(src, 529 helper.SetUpTestCaseFiles(src,
530 fileapi::test::kRegularTestCases, 530 fileapi::test::kRegularTestCases,
531 fileapi::test::kRegularTestCaseSize)); 531 fileapi::test::kRegularTestCaseSize));
532 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; 532 int64 src_increase = helper.GetSourceUsage() - src_initial_usage;
533 533
534 // Copy it. 534 // Copy it.
535 ASSERT_EQ(base::PLATFORM_FILE_OK, 535 ASSERT_EQ(base::File::FILE_OK,
536 helper.CopyWithProgress( 536 helper.CopyWithProgress(
537 src, dest, 537 src, dest,
538 AsyncFileTestHelper::CopyProgressCallback())); 538 AsyncFileTestHelper::CopyProgressCallback()));
539 539
540 // Verify. 540 // Verify.
541 ASSERT_TRUE(helper.DirectoryExists(src)); 541 ASSERT_TRUE(helper.DirectoryExists(src));
542 ASSERT_TRUE(helper.DirectoryExists(dest)); 542 ASSERT_TRUE(helper.DirectoryExists(dest));
543 543
544 helper.VerifyTestCaseFiles(dest, 544 helper.VerifyTestCaseFiles(dest,
545 fileapi::test::kRegularTestCases, 545 fileapi::test::kRegularTestCases,
(...skipping 11 matching lines...) Expand all
557 fileapi::kFileSystemTypeTemporary, 557 fileapi::kFileSystemTypeTemporary,
558 fileapi::kFileSystemTypePersistent); 558 fileapi::kFileSystemTypePersistent);
559 helper.SetUp(); 559 helper.SetUp();
560 560
561 FileSystemURL src = helper.SourceURL("a"); 561 FileSystemURL src = helper.SourceURL("a");
562 FileSystemURL dest = helper.DestURL("b"); 562 FileSystemURL dest = helper.DestURL("b");
563 int64 src_initial_usage = helper.GetSourceUsage(); 563 int64 src_initial_usage = helper.GetSourceUsage();
564 int64 dest_initial_usage = helper.GetDestUsage(); 564 int64 dest_initial_usage = helper.GetDestUsage();
565 565
566 // Set up a source directory. 566 // Set up a source directory.
567 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); 567 ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src));
568 ASSERT_EQ(base::PLATFORM_FILE_OK, 568 ASSERT_EQ(base::File::FILE_OK,
569 helper.SetUpTestCaseFiles(src, 569 helper.SetUpTestCaseFiles(src,
570 fileapi::test::kRegularTestCases, 570 fileapi::test::kRegularTestCases,
571 fileapi::test::kRegularTestCaseSize)); 571 fileapi::test::kRegularTestCaseSize));
572 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; 572 int64 src_increase = helper.GetSourceUsage() - src_initial_usage;
573 573
574 // Move it. 574 // Move it.
575 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); 575 ASSERT_EQ(base::File::FILE_OK, helper.Move(src, dest));
576 576
577 // Verify. 577 // Verify.
578 ASSERT_FALSE(helper.DirectoryExists(src)); 578 ASSERT_FALSE(helper.DirectoryExists(src));
579 ASSERT_TRUE(helper.DirectoryExists(dest)); 579 ASSERT_TRUE(helper.DirectoryExists(dest));
580 580
581 helper.VerifyTestCaseFiles(dest, 581 helper.VerifyTestCaseFiles(dest,
582 fileapi::test::kRegularTestCases, 582 fileapi::test::kRegularTestCases,
583 fileapi::test::kRegularTestCaseSize); 583 fileapi::test::kRegularTestCaseSize);
584 584
585 int64 src_new_usage = helper.GetSourceUsage(); 585 int64 src_new_usage = helper.GetSourceUsage();
586 ASSERT_EQ(src_initial_usage, src_new_usage); 586 ASSERT_EQ(src_initial_usage, src_new_usage);
587 587
588 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; 588 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage;
589 ASSERT_EQ(src_increase, dest_increase); 589 ASSERT_EQ(src_increase, dest_increase);
590 } 590 }
591 591
592 TEST(LocalFileSystemCopyOrMoveOperationTest, 592 TEST(LocalFileSystemCopyOrMoveOperationTest,
593 MoveDirectoryFailPostWriteValidation) { 593 MoveDirectoryFailPostWriteValidation) {
594 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), 594 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
595 fileapi::kFileSystemTypeTemporary, 595 fileapi::kFileSystemTypeTemporary,
596 fileapi::kFileSystemTypeTest); 596 fileapi::kFileSystemTypeTest);
597 helper.SetUp(); 597 helper.SetUp();
598 598
599 FileSystemURL src = helper.SourceURL("a"); 599 FileSystemURL src = helper.SourceURL("a");
600 FileSystemURL dest = helper.DestURL("b"); 600 FileSystemURL dest = helper.DestURL("b");
601 601
602 // Set up a source directory. 602 // Set up a source directory.
603 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); 603 ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src));
604 ASSERT_EQ(base::PLATFORM_FILE_OK, 604 ASSERT_EQ(base::File::FILE_OK,
605 helper.SetUpTestCaseFiles(src, 605 helper.SetUpTestCaseFiles(src,
606 fileapi::test::kRegularTestCases, 606 fileapi::test::kRegularTestCases,
607 fileapi::test::kRegularTestCaseSize)); 607 fileapi::test::kRegularTestCaseSize));
608 608
609 // Move it. 609 // Move it.
610 helper.Move(src, dest); 610 helper.Move(src, dest);
611 611
612 // Verify. 612 // Verify.
613 ASSERT_TRUE(helper.DirectoryExists(src)); 613 ASSERT_TRUE(helper.DirectoryExists(src));
614 ASSERT_TRUE(helper.DirectoryExists(dest)); 614 ASSERT_TRUE(helper.DirectoryExists(dest));
(...skipping 11 matching lines...) Expand all
626 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFileNoValidator) { 626 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFileNoValidator) {
627 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), 627 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
628 fileapi::kFileSystemTypeTemporary, 628 fileapi::kFileSystemTypeTemporary,
629 fileapi::kFileSystemTypeTest); 629 fileapi::kFileSystemTypeTest);
630 helper.SetUpNoValidator(); 630 helper.SetUpNoValidator();
631 631
632 FileSystemURL src = helper.SourceURL("a"); 632 FileSystemURL src = helper.SourceURL("a");
633 FileSystemURL dest = helper.DestURL("b"); 633 FileSystemURL dest = helper.DestURL("b");
634 634
635 // Set up a source file. 635 // Set up a source file.
636 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); 636 ASSERT_EQ(base::File::FILE_OK, helper.CreateFile(src, 10));
637 637
638 // The copy attempt should fail with a security error -- getting 638 // The copy attempt should fail with a security error -- getting
639 // the factory returns a security error, and the copy operation must 639 // the factory returns a security error, and the copy operation must
640 // respect that. 640 // respect that.
641 ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, helper.Copy(src, dest)); 641 ASSERT_EQ(base::File::FILE_ERROR_SECURITY, helper.Copy(src, dest));
642 } 642 }
643 643
644 TEST(LocalFileSystemCopyOrMoveOperationTest, ProgressCallback) { 644 TEST(LocalFileSystemCopyOrMoveOperationTest, ProgressCallback) {
645 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), 645 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
646 fileapi::kFileSystemTypeTemporary, 646 fileapi::kFileSystemTypeTemporary,
647 fileapi::kFileSystemTypePersistent); 647 fileapi::kFileSystemTypePersistent);
648 helper.SetUp(); 648 helper.SetUp();
649 649
650 FileSystemURL src = helper.SourceURL("a"); 650 FileSystemURL src = helper.SourceURL("a");
651 FileSystemURL dest = helper.DestURL("b"); 651 FileSystemURL dest = helper.DestURL("b");
652 652
653 // Set up a source directory. 653 // Set up a source directory.
654 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); 654 ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src));
655 ASSERT_EQ(base::PLATFORM_FILE_OK, 655 ASSERT_EQ(base::File::FILE_OK,
656 helper.SetUpTestCaseFiles(src, 656 helper.SetUpTestCaseFiles(src,
657 fileapi::test::kRegularTestCases, 657 fileapi::test::kRegularTestCases,
658 fileapi::test::kRegularTestCaseSize)); 658 fileapi::test::kRegularTestCaseSize));
659 659
660 std::vector<ProgressRecord> records; 660 std::vector<ProgressRecord> records;
661 ASSERT_EQ(base::PLATFORM_FILE_OK, 661 ASSERT_EQ(base::File::FILE_OK,
662 helper.CopyWithProgress(src, dest, 662 helper.CopyWithProgress(src, dest,
663 base::Bind(&RecordProgressCallback, 663 base::Bind(&RecordProgressCallback,
664 base::Unretained(&records)))); 664 base::Unretained(&records))));
665 665
666 // Verify progress callback. 666 // Verify progress callback.
667 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { 667 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) {
668 const TestCaseRecord& test_case = fileapi::test::kRegularTestCases[i]; 668 const TestCaseRecord& test_case = fileapi::test::kRegularTestCases[i];
669 669
670 FileSystemURL src_url = helper.SourceURL( 670 FileSystemURL src_url = helper.SourceURL(
671 std::string("a/") + base::FilePath(test_case.path).AsUTF8Unsafe()); 671 std::string("a/") + base::FilePath(test_case.path).AsUTF8Unsafe());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 FileStreamWriter::CreateForLocalFile(task_runner.get(), dest_path, 0)); 741 FileStreamWriter::CreateForLocalFile(task_runner.get(), dest_path, 0));
742 742
743 std::vector<int64> progress; 743 std::vector<int64> progress;
744 CopyOrMoveOperationDelegate::StreamCopyHelper helper( 744 CopyOrMoveOperationDelegate::StreamCopyHelper helper(
745 reader.Pass(), writer.Pass(), 745 reader.Pass(), writer.Pass(),
746 false, // don't need flush 746 false, // don't need flush
747 10, // buffer size 747 10, // buffer size
748 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), 748 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)),
749 base::TimeDelta()); // For testing, we need all the progress. 749 base::TimeDelta()); // For testing, we need all the progress.
750 750
751 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 751 base::File::Error error = base::File::FILE_ERROR_FAILED;
752 base::RunLoop run_loop; 752 base::RunLoop run_loop;
753 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); 753 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error));
754 run_loop.Run(); 754 run_loop.Run();
755 755
756 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 756 EXPECT_EQ(base::File::FILE_OK, error);
757 ASSERT_EQ(5U, progress.size()); 757 ASSERT_EQ(5U, progress.size());
758 EXPECT_EQ(0, progress[0]); 758 EXPECT_EQ(0, progress[0]);
759 EXPECT_EQ(10, progress[1]); 759 EXPECT_EQ(10, progress[1]);
760 EXPECT_EQ(20, progress[2]); 760 EXPECT_EQ(20, progress[2]);
761 EXPECT_EQ(30, progress[3]); 761 EXPECT_EQ(30, progress[3]);
762 EXPECT_EQ(36, progress[4]); 762 EXPECT_EQ(36, progress[4]);
763 763
764 std::string content; 764 std::string content;
765 ASSERT_TRUE(base::ReadFileToString(dest_path, &content)); 765 ASSERT_TRUE(base::ReadFileToString(dest_path, &content));
766 EXPECT_EQ(kTestData, content); 766 EXPECT_EQ(kTestData, content);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 FileStreamWriter::CreateForLocalFile(task_runner.get(), dest_path, 0)); 799 FileStreamWriter::CreateForLocalFile(task_runner.get(), dest_path, 0));
800 800
801 std::vector<int64> progress; 801 std::vector<int64> progress;
802 CopyOrMoveOperationDelegate::StreamCopyHelper helper( 802 CopyOrMoveOperationDelegate::StreamCopyHelper helper(
803 reader.Pass(), writer.Pass(), 803 reader.Pass(), writer.Pass(),
804 true, // need flush 804 true, // need flush
805 10, // buffer size 805 10, // buffer size
806 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), 806 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)),
807 base::TimeDelta()); // For testing, we need all the progress. 807 base::TimeDelta()); // For testing, we need all the progress.
808 808
809 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 809 base::File::Error error = base::File::FILE_ERROR_FAILED;
810 base::RunLoop run_loop; 810 base::RunLoop run_loop;
811 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); 811 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error));
812 run_loop.Run(); 812 run_loop.Run();
813 813
814 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 814 EXPECT_EQ(base::File::FILE_OK, error);
815 ASSERT_EQ(5U, progress.size()); 815 ASSERT_EQ(5U, progress.size());
816 EXPECT_EQ(0, progress[0]); 816 EXPECT_EQ(0, progress[0]);
817 EXPECT_EQ(10, progress[1]); 817 EXPECT_EQ(10, progress[1]);
818 EXPECT_EQ(20, progress[2]); 818 EXPECT_EQ(20, progress[2]);
819 EXPECT_EQ(30, progress[3]); 819 EXPECT_EQ(30, progress[3]);
820 EXPECT_EQ(36, progress[4]); 820 EXPECT_EQ(36, progress[4]);
821 821
822 std::string content; 822 std::string content;
823 ASSERT_TRUE(base::ReadFileToString(dest_path, &content)); 823 ASSERT_TRUE(base::ReadFileToString(dest_path, &content));
824 EXPECT_EQ(kTestData, content); 824 EXPECT_EQ(kTestData, content);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 10, // buffer size 859 10, // buffer size
860 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), 860 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)),
861 base::TimeDelta()); // For testing, we need all the progress. 861 base::TimeDelta()); // For testing, we need all the progress.
862 862
863 // Call Cancel() later. 863 // Call Cancel() later.
864 base::MessageLoopProxy::current()->PostTask( 864 base::MessageLoopProxy::current()->PostTask(
865 FROM_HERE, 865 FROM_HERE,
866 base::Bind(&CopyOrMoveOperationDelegate::StreamCopyHelper::Cancel, 866 base::Bind(&CopyOrMoveOperationDelegate::StreamCopyHelper::Cancel,
867 base::Unretained(&helper))); 867 base::Unretained(&helper)));
868 868
869 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 869 base::File::Error error = base::File::FILE_ERROR_FAILED;
870 base::RunLoop run_loop; 870 base::RunLoop run_loop;
871 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); 871 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error));
872 run_loop.Run(); 872 run_loop.Run();
873 873
874 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, error); 874 EXPECT_EQ(base::File::FILE_ERROR_ABORT, error);
875 } 875 }
876 876
877 } // namespace content 877 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/copy_or_move_file_validator_unittest.cc ('k') | content/browser/fileapi/dragged_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698