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

Side by Side Diff: ppapi/tests/test_file_ref.cc

Issue 113363004: PPAPI: Add new PPB_FileRef.MakeDirectory to support exclusive operation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 6 years, 11 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/tests/test_file_ref.h" 5 #include "ppapi/tests/test_file_ref.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <sstream> 9 #include <sstream>
10 #include <vector> 10 #include <vector>
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 291
292 std::string TestFileRef::TestMakeDirectory() { 292 std::string TestFileRef::TestMakeDirectory() {
293 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); 293 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
294 294
295 // Open. 295 // Open.
296 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 296 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
297 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); 297 callback.WaitForResult(file_system.Open(1024, callback.GetCallback()));
298 CHECK_CALLBACK_BEHAVIOR(callback); 298 CHECK_CALLBACK_BEHAVIOR(callback);
299 ASSERT_EQ(PP_OK, callback.result()); 299 ASSERT_EQ(PP_OK, callback.result());
300 300
301 // MakeDirectory. 301 // Make a directory.
302 pp::FileRef dir_ref(file_system, "/test_dir_make_directory"); 302 pp::FileRef dir_ref(file_system, "/dir_make_dir");
303 callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback())); 303 callback.WaitForResult(
304 dir_ref.MakeDirectory(false, false, callback.GetCallback()));
304 CHECK_CALLBACK_BEHAVIOR(callback); 305 CHECK_CALLBACK_BEHAVIOR(callback);
305 ASSERT_EQ(PP_OK, callback.result()); 306 ASSERT_EQ(PP_OK, callback.result());
306 307
307 // MakeDirectory aborted. 308 // Make a directory on the existing path without exclusive flag.
309 callback.WaitForResult(
310 dir_ref.MakeDirectory(false, false, callback.GetCallback()));
311 CHECK_CALLBACK_BEHAVIOR(callback);
312 ASSERT_EQ(PP_OK, callback.result());
313
314 // Making a directory should be aborted.
308 int32_t rv = PP_ERROR_FAILED; 315 int32_t rv = PP_ERROR_FAILED;
309 { 316 {
310 rv = pp::FileRef(file_system, "/test_dir_make_abort") 317 rv = pp::FileRef(file_system, "/dir_make_dir_abort")
311 .MakeDirectory(callback.GetCallback()); 318 .MakeDirectory(false, false, callback.GetCallback());
312 } 319 }
313 callback.WaitForAbortResult(rv); 320 callback.WaitForAbortResult(rv);
314 CHECK_CALLBACK_BEHAVIOR(callback); 321 CHECK_CALLBACK_BEHAVIOR(callback);
315 322
316 // MakeDirectoryIncludingAncestors. 323 // Make nested directories.
317 dir_ref = pp::FileRef(file_system, "/dir_make_dir_1/dir_make_dir_2"); 324 dir_ref = pp::FileRef(file_system, "/dir_make_nested_dir_1/dir");
318 callback.WaitForResult( 325 callback.WaitForResult(
319 dir_ref.MakeDirectoryIncludingAncestors(callback.GetCallback())); 326 dir_ref.MakeDirectory(false, true, callback.GetCallback()));
320 CHECK_CALLBACK_BEHAVIOR(callback); 327 CHECK_CALLBACK_BEHAVIOR(callback);
321 ASSERT_EQ(PP_OK, callback.result()); 328 ASSERT_EQ(PP_OK, callback.result());
322 329
323 // MakeDirectoryIncludingAncestors aborted. 330 dir_ref = pp::FileRef(file_system, "/dir_make_nested_dir_2/dir");
324 { 331 callback.WaitForResult(
325 rv = pp::FileRef(file_system, "/dir_make_abort_1/dir_make_abort_2") 332 dir_ref.MakeDirectory(false, false, callback.GetCallback()));
326 .MakeDirectoryIncludingAncestors(callback.GetCallback());
327 }
328 callback.WaitForAbortResult(rv);
329 CHECK_CALLBACK_BEHAVIOR(callback); 333 CHECK_CALLBACK_BEHAVIOR(callback);
334 ASSERT_EQ(PP_ERROR_FILENOTFOUND, callback.result());
330 335
331 // MakeDirectory with nested path should fail. 336 // Ensure there is no directory on the path to test exclusive cases.
332 dir_ref = pp::FileRef(file_system, "/dir_make_dir_3/dir_make_dir_4"); 337 dir_ref = pp::FileRef(file_system, "/dir_make_dir_exclusive");
333 callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback())); 338 rv = DeleteDirectoryRecursively(&dir_ref);
339 ASSERT_TRUE(rv == PP_OK || rv == PP_ERROR_FILENOTFOUND);
340
341 // Make a directory exclusively.
342 callback.WaitForResult(
343 dir_ref.MakeDirectory(true, false, callback.GetCallback()));
334 CHECK_CALLBACK_BEHAVIOR(callback); 344 CHECK_CALLBACK_BEHAVIOR(callback);
335 ASSERT_NE(PP_OK, callback.result()); 345 ASSERT_EQ(PP_OK, callback.result());
346
347 callback.WaitForResult(
348 dir_ref.MakeDirectory(true, false, callback.GetCallback()));
349 CHECK_CALLBACK_BEHAVIOR(callback);
350 ASSERT_EQ(PP_ERROR_FILEEXISTS, callback.result());
336 351
337 PASS(); 352 PASS();
338 } 353 }
339 354
340 std::string TestFileRef::TestQueryAndTouchFile() { 355 std::string TestFileRef::TestQueryAndTouchFile() {
341 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); 356 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
342 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 357 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
343 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); 358 callback.WaitForResult(file_system.Open(1024, callback.GetCallback()));
344 CHECK_CALLBACK_BEHAVIOR(callback); 359 CHECK_CALLBACK_BEHAVIOR(callback);
345 ASSERT_EQ(PP_OK, callback.result()); 360 ASSERT_EQ(PP_OK, callback.result());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 callback.WaitForResult( 440 callback.WaitForResult(
426 file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback.GetCallback())); 441 file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback.GetCallback()));
427 CHECK_CALLBACK_BEHAVIOR(callback); 442 CHECK_CALLBACK_BEHAVIOR(callback);
428 ASSERT_EQ(PP_OK, callback.result()); 443 ASSERT_EQ(PP_OK, callback.result());
429 444
430 callback.WaitForResult(file_ref.Delete(callback.GetCallback())); 445 callback.WaitForResult(file_ref.Delete(callback.GetCallback()));
431 CHECK_CALLBACK_BEHAVIOR(callback); 446 CHECK_CALLBACK_BEHAVIOR(callback);
432 ASSERT_EQ(PP_OK, callback.result()); 447 ASSERT_EQ(PP_OK, callback.result());
433 448
434 pp::FileRef dir_ref(file_system, "/dir_delete"); 449 pp::FileRef dir_ref(file_system, "/dir_delete");
435 callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback())); 450 callback.WaitForResult(dir_ref.MakeDirectory(
451 false, false, callback.GetCallback()));
436 CHECK_CALLBACK_BEHAVIOR(callback); 452 CHECK_CALLBACK_BEHAVIOR(callback);
437 ASSERT_EQ(PP_OK, callback.result()); 453 ASSERT_EQ(PP_OK, callback.result());
438 454
439 callback.WaitForResult(dir_ref.Delete(callback.GetCallback())); 455 callback.WaitForResult(dir_ref.Delete(callback.GetCallback()));
440 CHECK_CALLBACK_BEHAVIOR(callback); 456 CHECK_CALLBACK_BEHAVIOR(callback);
441 ASSERT_EQ(PP_OK, callback.result()); 457 ASSERT_EQ(PP_OK, callback.result());
442 458
443 pp::FileRef nested_dir_ref(file_system, "/dir_delete_1/dir_delete_2"); 459 pp::FileRef nested_dir_ref(file_system, "/dir_delete_1/dir_delete_2");
444 callback.WaitForResult( 460 callback.WaitForResult(
445 nested_dir_ref.MakeDirectoryIncludingAncestors(callback.GetCallback())); 461 nested_dir_ref.MakeDirectory(false, true, callback.GetCallback()));
446 CHECK_CALLBACK_BEHAVIOR(callback); 462 CHECK_CALLBACK_BEHAVIOR(callback);
447 ASSERT_EQ(PP_OK, callback.result()); 463 ASSERT_EQ(PP_OK, callback.result());
448 464
449 // Attempt to delete the parent directory (should fail; it's non-empty). 465 // Attempt to delete the parent directory (should fail; it's non-empty).
450 pp::FileRef parent_dir_ref = nested_dir_ref.GetParent(); 466 pp::FileRef parent_dir_ref = nested_dir_ref.GetParent();
451 callback.WaitForResult(parent_dir_ref.Delete(callback.GetCallback())); 467 callback.WaitForResult(parent_dir_ref.Delete(callback.GetCallback()));
452 CHECK_CALLBACK_BEHAVIOR(callback); 468 CHECK_CALLBACK_BEHAVIOR(callback);
453 ASSERT_EQ(PP_ERROR_FAILED, callback.result()); 469 ASSERT_EQ(PP_ERROR_FAILED, callback.result());
454 470
455 pp::FileRef nonexistent_file_ref(file_system, "/nonexistent_file_delete"); 471 pp::FileRef nonexistent_file_ref(file_system, "/nonexistent_file_delete");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 CHECK_CALLBACK_BEHAVIOR(callback); 505 CHECK_CALLBACK_BEHAVIOR(callback);
490 ASSERT_EQ(PP_OK, callback.result()); 506 ASSERT_EQ(PP_OK, callback.result());
491 507
492 pp::FileRef target_file_ref(file_system, "/target_file_rename"); 508 pp::FileRef target_file_ref(file_system, "/target_file_rename");
493 callback.WaitForResult( 509 callback.WaitForResult(
494 file_ref.Rename(target_file_ref, callback.GetCallback())); 510 file_ref.Rename(target_file_ref, callback.GetCallback()));
495 CHECK_CALLBACK_BEHAVIOR(callback); 511 CHECK_CALLBACK_BEHAVIOR(callback);
496 ASSERT_EQ(PP_OK, callback.result()); 512 ASSERT_EQ(PP_OK, callback.result());
497 513
498 pp::FileRef dir_ref(file_system, "/dir_rename"); 514 pp::FileRef dir_ref(file_system, "/dir_rename");
499 callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback())); 515 callback.WaitForResult(dir_ref.MakeDirectory(
516 false, false, callback.GetCallback()));
500 CHECK_CALLBACK_BEHAVIOR(callback); 517 CHECK_CALLBACK_BEHAVIOR(callback);
501 ASSERT_EQ(PP_OK, callback.result()); 518 ASSERT_EQ(PP_OK, callback.result());
502 519
503 pp::FileRef target_dir_ref(file_system, "/target_dir_rename"); 520 pp::FileRef target_dir_ref(file_system, "/target_dir_rename");
504 callback.WaitForResult( 521 callback.WaitForResult(
505 dir_ref.Rename(target_dir_ref, callback.GetCallback())); 522 dir_ref.Rename(target_dir_ref, callback.GetCallback()));
506 CHECK_CALLBACK_BEHAVIOR(callback); 523 CHECK_CALLBACK_BEHAVIOR(callback);
507 ASSERT_EQ(PP_OK, callback.result()); 524 ASSERT_EQ(PP_OK, callback.result());
508 525
509 pp::FileRef nested_dir_ref(file_system, "/dir_rename_1/dir_rename_2"); 526 pp::FileRef nested_dir_ref(file_system, "/dir_rename_1/dir_rename_2");
510 callback.WaitForResult( 527 callback.WaitForResult(
511 nested_dir_ref.MakeDirectoryIncludingAncestors(callback.GetCallback())); 528 nested_dir_ref.MakeDirectory(false, true, callback.GetCallback()));
512 CHECK_CALLBACK_BEHAVIOR(callback); 529 CHECK_CALLBACK_BEHAVIOR(callback);
513 ASSERT_EQ(PP_OK, callback.result()); 530 ASSERT_EQ(PP_OK, callback.result());
514 531
515 // Try to rename nested directory to the parent name. Should fail. 532 // Try to rename nested directory to the parent name. Should fail.
516 pp::FileRef target_nested_dir_ref(file_system, "/dir_rename_1"); 533 pp::FileRef target_nested_dir_ref(file_system, "/dir_rename_1");
517 callback.WaitForResult( 534 callback.WaitForResult(
518 nested_dir_ref.Rename(target_nested_dir_ref, callback.GetCallback())); 535 nested_dir_ref.Rename(target_nested_dir_ref, callback.GetCallback()));
519 CHECK_CALLBACK_BEHAVIOR(callback); 536 CHECK_CALLBACK_BEHAVIOR(callback);
520 ASSERT_EQ(PP_ERROR_FAILED, callback.result()); 537 ASSERT_EQ(PP_ERROR_FAILED, callback.result());
521 538
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 std::string TestFileRef::TestFileNameEscaping() { 625 std::string TestFileRef::TestFileNameEscaping() {
609 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); 626 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
610 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 627 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
611 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); 628 callback.WaitForResult(file_system.Open(1024, callback.GetCallback()));
612 CHECK_CALLBACK_BEHAVIOR(callback); 629 CHECK_CALLBACK_BEHAVIOR(callback);
613 ASSERT_EQ(PP_OK, callback.result()); 630 ASSERT_EQ(PP_OK, callback.result());
614 631
615 std::string test_dir_path = "/dir_for_escaping_test"; 632 std::string test_dir_path = "/dir_for_escaping_test";
616 // Create a directory in which to test. 633 // Create a directory in which to test.
617 pp::FileRef test_dir_ref(file_system, test_dir_path.c_str()); 634 pp::FileRef test_dir_ref(file_system, test_dir_path.c_str());
618 callback.WaitForResult(test_dir_ref.MakeDirectory(callback.GetCallback())); 635 callback.WaitForResult(test_dir_ref.MakeDirectory(
636 false, false, callback.GetCallback()));
619 CHECK_CALLBACK_BEHAVIOR(callback); 637 CHECK_CALLBACK_BEHAVIOR(callback);
620 ASSERT_EQ(PP_OK, callback.result()); 638 ASSERT_EQ(PP_OK, callback.result());
621 639
622 // Create the file with the terrible name. 640 // Create the file with the terrible name.
623 std::string full_file_path = test_dir_path + "/" + kTerribleName; 641 std::string full_file_path = test_dir_path + "/" + kTerribleName;
624 pp::FileRef file_ref(file_system, full_file_path.c_str()); 642 pp::FileRef file_ref(file_system, full_file_path.c_str());
625 pp::FileIO file_io(instance_); 643 pp::FileIO file_io(instance_);
626 callback.WaitForResult( 644 callback.WaitForResult(
627 file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback.GetCallback())); 645 file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback.GetCallback()));
628 CHECK_CALLBACK_BEHAVIOR(callback); 646 CHECK_CALLBACK_BEHAVIOR(callback);
(...skipping 27 matching lines...) Expand all
656 674
657 // Setup testing directories and files. 675 // Setup testing directories and files.
658 const char* test_dir_name = "/test_get_next_file"; 676 const char* test_dir_name = "/test_get_next_file";
659 const char* file_prefix = "file_"; 677 const char* file_prefix = "file_";
660 const char* dir_prefix = "dir_"; 678 const char* dir_prefix = "dir_";
661 679
662 pp::FileRef test_dir(file_system, test_dir_name); 680 pp::FileRef test_dir(file_system, test_dir_name);
663 int32_t rv = DeleteDirectoryRecursively(&test_dir); 681 int32_t rv = DeleteDirectoryRecursively(&test_dir);
664 ASSERT_TRUE(rv == PP_OK || rv == PP_ERROR_FILENOTFOUND); 682 ASSERT_TRUE(rv == PP_OK || rv == PP_ERROR_FILENOTFOUND);
665 683
666 callback.WaitForResult(test_dir.MakeDirectory(callback.GetCallback())); 684 callback.WaitForResult(test_dir.MakeDirectory(
685 false, false, callback.GetCallback()));
667 CHECK_CALLBACK_BEHAVIOR(callback); 686 CHECK_CALLBACK_BEHAVIOR(callback);
668 ASSERT_EQ(PP_OK, callback.result()); 687 ASSERT_EQ(PP_OK, callback.result());
669 688
670 static const int kNumFiles = 3; 689 static const int kNumFiles = 3;
671 std::set<std::string> expected_file_names; 690 std::set<std::string> expected_file_names;
672 for (int i = 1; i <= kNumFiles; ++i) { 691 for (int i = 1; i <= kNumFiles; ++i) {
673 std::ostringstream buffer; 692 std::ostringstream buffer;
674 buffer << test_dir_name << '/' << file_prefix << i; 693 buffer << test_dir_name << '/' << file_prefix << i;
675 pp::FileRef file_ref(file_system, buffer.str().c_str()); 694 pp::FileRef file_ref(file_system, buffer.str().c_str());
676 695
677 pp::FileIO file_io(instance_); 696 pp::FileIO file_io(instance_);
678 callback.WaitForResult( 697 callback.WaitForResult(
679 file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback.GetCallback())); 698 file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback.GetCallback()));
680 CHECK_CALLBACK_BEHAVIOR(callback); 699 CHECK_CALLBACK_BEHAVIOR(callback);
681 ASSERT_EQ(PP_OK, callback.result()); 700 ASSERT_EQ(PP_OK, callback.result());
682 701
683 expected_file_names.insert(buffer.str()); 702 expected_file_names.insert(buffer.str());
684 } 703 }
685 704
686 static const int kNumDirectories = 3; 705 static const int kNumDirectories = 3;
687 std::set<std::string> expected_dir_names; 706 std::set<std::string> expected_dir_names;
688 for (int i = 1; i <= kNumDirectories; ++i) { 707 for (int i = 1; i <= kNumDirectories; ++i) {
689 std::ostringstream buffer; 708 std::ostringstream buffer;
690 buffer << test_dir_name << '/' << dir_prefix << i; 709 buffer << test_dir_name << '/' << dir_prefix << i;
691 pp::FileRef file_ref(file_system, buffer.str().c_str()); 710 pp::FileRef file_ref(file_system, buffer.str().c_str());
692 711
693 callback.WaitForResult(file_ref.MakeDirectory(callback.GetCallback())); 712 callback.WaitForResult(file_ref.MakeDirectory(
713 false, false, callback.GetCallback()));
694 CHECK_CALLBACK_BEHAVIOR(callback); 714 CHECK_CALLBACK_BEHAVIOR(callback);
695 ASSERT_EQ(PP_OK, callback.result()); 715 ASSERT_EQ(PP_OK, callback.result());
696 716
697 expected_dir_names.insert(buffer.str()); 717 expected_dir_names.insert(buffer.str());
698 } 718 }
699 719
700 // Test that |ReadDirectoryEntries()| is able to fetch all 720 // Test that |ReadDirectoryEntries()| is able to fetch all
701 // directories and files that we created. 721 // directories and files that we created.
702 { 722 {
703 TestCompletionCallbackWithOutput<DirEntries> output_callback( 723 TestCompletionCallbackWithOutput<DirEntries> output_callback(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 { 761 {
742 rv = pp::FileRef(file_system, test_dir_name) 762 rv = pp::FileRef(file_system, test_dir_name)
743 .ReadDirectoryEntries(output_callback.GetCallback()); 763 .ReadDirectoryEntries(output_callback.GetCallback());
744 } 764 }
745 output_callback.WaitForAbortResult(rv); 765 output_callback.WaitForAbortResult(rv);
746 CHECK_CALLBACK_BEHAVIOR(output_callback); 766 CHECK_CALLBACK_BEHAVIOR(output_callback);
747 767
748 768
749 PASS(); 769 PASS();
750 } 770 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698