| OLD | NEW |
| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 void TestFileRef::RunTests(const std::string& filter) { | 52 void TestFileRef::RunTests(const std::string& filter) { |
| 53 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter); | 53 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter); |
| 54 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter); | 54 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter); |
| 55 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter); | 55 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter); |
| 56 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter); | 56 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter); |
| 57 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter); | 57 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter); |
| 58 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter); | 58 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter); |
| 59 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter); | 59 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter); |
| 60 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter); | 60 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter); |
| 61 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter); | 61 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter); |
| 62 RUN_TEST_FORCEASYNC_AND_NOT(Query, filter); |
| 62 #ifndef PPAPI_OS_NACL // NaCl can't run this test yet. | 63 #ifndef PPAPI_OS_NACL // NaCl can't run this test yet. |
| 63 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter); | 64 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter); |
| 64 #endif | 65 #endif |
| 65 } | 66 } |
| 66 | 67 |
| 67 std::string TestFileRef::TestCreate() { | 68 std::string TestFileRef::TestCreate() { |
| 68 std::vector<std::string> invalid_paths; | 69 std::vector<std::string> invalid_paths; |
| 69 invalid_paths.push_back("invalid_path"); // no '/' at the first character | 70 invalid_paths.push_back("invalid_path"); // no '/' at the first character |
| 70 invalid_paths.push_back(""); // empty path | 71 invalid_paths.push_back(""); // empty path |
| 71 // The following are directory traversal checks | 72 // The following are directory traversal checks |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 rv = callback.WaitForResult(); | 676 rv = callback.WaitForResult(); |
| 676 if (rv != PP_ERROR_ABORTED) | 677 if (rv != PP_ERROR_ABORTED) |
| 677 return "FileSystem::Rename not aborted."; | 678 return "FileSystem::Rename not aborted."; |
| 678 } else if (rv != PP_OK) { | 679 } else if (rv != PP_OK) { |
| 679 return ReportError("FileSystem::Rename", rv); | 680 return ReportError("FileSystem::Rename", rv); |
| 680 } | 681 } |
| 681 | 682 |
| 682 PASS(); | 683 PASS(); |
| 683 } | 684 } |
| 684 | 685 |
| 686 std::string TestFileRef::TestQuery() { |
| 687 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
| 688 |
| 689 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 690 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); |
| 691 CHECK_CALLBACK_BEHAVIOR(callback); |
| 692 ASSERT_EQ(PP_OK, callback.result()); |
| 693 |
| 694 pp::FileRef file_ref(file_system, "/file"); |
| 695 pp::FileIO file_io(instance_); |
| 696 callback.WaitForResult(file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, |
| 697 callback.GetCallback())); |
| 698 CHECK_CALLBACK_BEHAVIOR(callback); |
| 699 ASSERT_EQ(PP_OK, callback.result()); |
| 700 |
| 701 // We touch the file so we can easily check access and modified time. |
| 702 callback.WaitForResult(file_io.Touch(0, 0, callback.GetCallback())); |
| 703 CHECK_CALLBACK_BEHAVIOR(callback); |
| 704 ASSERT_EQ(PP_OK, callback.result()); |
| 705 |
| 706 TestCompletionCallbackWithOutput<PP_FileInfo> out_callback( |
| 707 instance_->pp_instance(), callback_type()); |
| 708 out_callback.WaitForResult(file_ref.Query( |
| 709 out_callback.GetCallbackWithOutput())); |
| 710 CHECK_CALLBACK_BEHAVIOR(out_callback); |
| 711 ASSERT_EQ(PP_OK, out_callback.result()); |
| 712 |
| 713 PP_FileInfo info = out_callback.output(); |
| 714 ASSERT_EQ(0, info.size); |
| 715 ASSERT_EQ(PP_FILETYPE_REGULAR, info.type); |
| 716 ASSERT_EQ(PP_FILESYSTEMTYPE_LOCALTEMPORARY, info.system_type); |
| 717 ASSERT_DOUBLE_EQ(0.0, info.last_access_time); |
| 718 ASSERT_DOUBLE_EQ(0.0, info.last_modified_time); |
| 719 |
| 720 pp::FileRef missing_file_ref(file_system, "/missing_file"); |
| 721 out_callback.WaitForResult(missing_file_ref.Query( |
| 722 out_callback.GetCallbackWithOutput())); |
| 723 CHECK_CALLBACK_BEHAVIOR(out_callback); |
| 724 ASSERT_EQ(PP_ERROR_FILENOTFOUND, out_callback.result()); |
| 725 |
| 726 PASS(); |
| 727 } |
| 728 |
| 685 #ifndef PPAPI_OS_NACL | 729 #ifndef PPAPI_OS_NACL |
| 686 std::string TestFileRef::TestFileNameEscaping() { | 730 std::string TestFileRef::TestFileNameEscaping() { |
| 687 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 731 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 688 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 732 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 689 int32_t rv = file_system.Open(1024, callback.GetCallback()); | 733 int32_t rv = file_system.Open(1024, callback.GetCallback()); |
| 690 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 734 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 691 return ReportError("FileSystem::Open force_async", rv); | 735 return ReportError("FileSystem::Open force_async", rv); |
| 692 if (rv == PP_OK_COMPLETIONPENDING) | 736 if (rv == PP_OK_COMPLETIONPENDING) |
| 693 rv = callback.WaitForResult(); | 737 rv = callback.WaitForResult(); |
| 694 if (rv != PP_OK) | 738 if (rv != PP_OK) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 return "Entry was not found."; | 778 return "Entry was not found."; |
| 735 if (entries.size() != 1) | 779 if (entries.size() != 1) |
| 736 return "Directory had too many entries."; | 780 return "Directory had too many entries."; |
| 737 if (entries.front().file_ref().GetName().AsString() != kTerribleName) | 781 if (entries.front().file_ref().GetName().AsString() != kTerribleName) |
| 738 return "Entry name did not match."; | 782 return "Entry name did not match."; |
| 739 } | 783 } |
| 740 | 784 |
| 741 PASS(); | 785 PASS(); |
| 742 } | 786 } |
| 743 #endif | 787 #endif |
| OLD | NEW |