Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 return method_name + " returned '" + returned_result + "'; '" + | 42 return method_name + " returned '" + returned_result + "'; '" + |
| 43 expected_result + "' expected."; | 43 expected_result + "' expected."; |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 bool TestFileRef::Init() { | 48 bool TestFileRef::Init() { |
| 49 return CheckTestingInterface() && EnsureRunningOverHTTP(); | 49 return CheckTestingInterface() && EnsureRunningOverHTTP(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 std::string TestFileRef::MakeExternalFileRef(pp::FileRef* file_ref_ext) { | |
| 53 pp::URLRequestInfo request(instance_); | |
| 54 request.SetURL("test_url_loader_data/hello.txt"); | |
| 55 request.SetStreamToFile(true); | |
| 56 | |
| 57 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | |
| 58 | |
| 59 pp::URLLoader loader(instance_); | |
| 60 callback.WaitForResult(loader.Open(request, callback.GetCallback())); | |
| 61 CHECK_CALLBACK_BEHAVIOR(callback); | |
| 62 ASSERT_EQ(PP_OK, callback.result()); | |
| 63 | |
| 64 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | |
| 65 ASSERT_FALSE(response_info.is_null()) | |
| 66 ASSERT_EQ(200, response_info.GetStatusCode()); | |
| 67 | |
| 68 *file_ref_ext = pp::FileRef(response_info.GetBodyAsFileRef()); | |
| 69 ASSERT_EQ(PP_FILESYSTEMTYPE_EXTERNAL, file_ref_ext->GetFileSystemType()) | |
| 70 PASS(); | |
| 71 } | |
| 72 | |
| 52 void TestFileRef::RunTests(const std::string& filter) { | 73 void TestFileRef::RunTests(const std::string& filter) { |
| 53 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter); | 74 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter); |
| 54 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter); | 75 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter); |
| 55 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter); | 76 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter); |
| 56 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter); | 77 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter); |
| 57 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter); | 78 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter); |
| 58 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter); | 79 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter); |
| 59 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter); | 80 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter); |
| 60 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter); | 81 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter); |
| 61 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter); | 82 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter); |
| 83 // RUN_TEST_FORCEASYNC_AND_NOT(Query, filter); | |
|
dmichael (off chromium)
2013/03/27 22:13:55
nit: Please remove ^^^
| |
| 84 RUN_CALLBACK_TEST(TestFileRef, Query, filter); | |
| 62 #ifndef PPAPI_OS_NACL // NaCl can't run this test yet. | 85 #ifndef PPAPI_OS_NACL // NaCl can't run this test yet. |
| 63 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter); | 86 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter); |
| 64 #endif | 87 #endif |
| 65 } | 88 } |
| 66 | 89 |
| 67 std::string TestFileRef::TestCreate() { | 90 std::string TestFileRef::TestCreate() { |
| 68 std::vector<std::string> invalid_paths; | 91 std::vector<std::string> invalid_paths; |
| 69 invalid_paths.push_back("invalid_path"); // no '/' at the first character | 92 invalid_paths.push_back("invalid_path"); // no '/' at the first character |
| 70 invalid_paths.push_back(""); // empty path | 93 invalid_paths.push_back(""); // empty path |
| 71 // The following are directory traversal checks | 94 // The following are directory traversal checks |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 101 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 124 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 102 | 125 |
| 103 pp::FileRef file_ref_pers(file_system_pers, kPersFilePath); | 126 pp::FileRef file_ref_pers(file_system_pers, kPersFilePath); |
| 104 if (file_ref_pers.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) | 127 if (file_ref_pers.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) |
| 105 return "file_ref_pers expected to be persistent."; | 128 return "file_ref_pers expected to be persistent."; |
| 106 | 129 |
| 107 pp::FileRef file_ref_temp(file_system_temp, kTempFilePath); | 130 pp::FileRef file_ref_temp(file_system_temp, kTempFilePath); |
| 108 if (file_ref_temp.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) | 131 if (file_ref_temp.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) |
| 109 return "file_ref_temp expected to be temporary."; | 132 return "file_ref_temp expected to be temporary."; |
| 110 | 133 |
| 111 pp::URLRequestInfo request(instance_); | 134 pp::FileRef file_ref_ext; |
| 112 request.SetURL("test_url_loader_data/hello.txt"); | 135 std::string result = MakeExternalFileRef(&file_ref_ext); |
| 113 request.SetStreamToFile(true); | 136 if (!result.empty()) |
| 114 | 137 return result; |
| 115 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | |
| 116 | |
| 117 pp::URLLoader loader(instance_); | |
| 118 int32_t rv = loader.Open(request, callback.GetCallback()); | |
| 119 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | |
| 120 return ReportError("URLLoader::Open force_async", rv); | |
| 121 if (rv == PP_OK_COMPLETIONPENDING) | |
| 122 rv = callback.WaitForResult(); | |
| 123 if (rv != PP_OK) | |
| 124 return "URLLoader::Open() failed."; | |
| 125 | |
| 126 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | |
| 127 if (response_info.is_null()) | |
| 128 return "URLLoader::GetResponseInfo returned null"; | |
| 129 int32_t status_code = response_info.GetStatusCode(); | |
| 130 if (status_code != 200) | |
| 131 return "Unexpected HTTP status code"; | |
| 132 | |
| 133 pp::FileRef file_ref_ext(response_info.GetBodyAsFileRef()); | |
| 134 if (file_ref_ext.GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) | |
| 135 return "file_ref_ext expected to be external."; | |
| 136 | |
| 137 PASS(); | 138 PASS(); |
| 138 } | 139 } |
| 139 | 140 |
| 140 std::string TestFileRef::TestGetName() { | 141 std::string TestFileRef::TestGetName() { |
| 141 pp::FileSystem file_system_pers( | 142 pp::FileSystem file_system_pers( |
| 142 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); | 143 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); |
| 143 pp::FileSystem file_system_temp( | 144 pp::FileSystem file_system_temp( |
| 144 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 145 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 145 | 146 |
| 146 pp::FileRef file_ref_pers(file_system_pers, kPersFilePath); | 147 pp::FileRef file_ref_pers(file_system_pers, kPersFilePath); |
| (...skipping 528 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 // Query a file ref on an external filesystem. | |
| 721 pp::FileRef file_ref_ext; | |
| 722 std::string result = MakeExternalFileRef(&file_ref_ext); | |
| 723 if (!result.empty()) | |
| 724 return result; | |
| 725 out_callback.WaitForResult(file_ref_ext.Query( | |
| 726 out_callback.GetCallbackWithOutput())); | |
| 727 CHECK_CALLBACK_BEHAVIOR(out_callback); | |
| 728 if (out_callback.result() != PP_OK) | |
| 729 return ReportError("Query() result", out_callback.result()); | |
| 730 ASSERT_EQ(PP_OK, out_callback.result()); | |
| 731 | |
| 732 info = out_callback.output(); | |
| 733 ASSERT_EQ(PP_FILETYPE_REGULAR, info.type); | |
| 734 ASSERT_EQ(PP_FILESYSTEMTYPE_EXTERNAL, info.system_type); | |
| 735 | |
| 736 // We can't touch the file, so just sanity check the times. | |
| 737 ASSERT_TRUE(info.creation_time >= 0.0); | |
| 738 ASSERT_TRUE(info.last_modified_time >= 0.0); | |
| 739 ASSERT_TRUE(info.last_access_time >= 0.0); | |
| 740 | |
| 741 // Query a file ref for a file that doesn't exist. | |
| 742 pp::FileRef missing_file_ref(file_system, "/missing_file"); | |
| 743 out_callback.WaitForResult(missing_file_ref.Query( | |
| 744 out_callback.GetCallbackWithOutput())); | |
| 745 CHECK_CALLBACK_BEHAVIOR(out_callback); | |
| 746 ASSERT_EQ(PP_ERROR_FILENOTFOUND, out_callback.result()); | |
| 747 | |
| 748 PASS(); | |
| 749 } | |
| 750 | |
| 685 #ifndef PPAPI_OS_NACL | 751 #ifndef PPAPI_OS_NACL |
| 686 std::string TestFileRef::TestFileNameEscaping() { | 752 std::string TestFileRef::TestFileNameEscaping() { |
| 687 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 753 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 688 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 754 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 689 int32_t rv = file_system.Open(1024, callback.GetCallback()); | 755 int32_t rv = file_system.Open(1024, callback.GetCallback()); |
| 690 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 756 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 691 return ReportError("FileSystem::Open force_async", rv); | 757 return ReportError("FileSystem::Open force_async", rv); |
| 692 if (rv == PP_OK_COMPLETIONPENDING) | 758 if (rv == PP_OK_COMPLETIONPENDING) |
| 693 rv = callback.WaitForResult(); | 759 rv = callback.WaitForResult(); |
| 694 if (rv != PP_OK) | 760 if (rv != PP_OK) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 return "Entry was not found."; | 800 return "Entry was not found."; |
| 735 if (entries.size() != 1) | 801 if (entries.size() != 1) |
| 736 return "Directory had too many entries."; | 802 return "Directory had too many entries."; |
| 737 if (entries.front().file_ref().GetName().AsString() != kTerribleName) | 803 if (entries.front().file_ref().GetName().AsString() != kTerribleName) |
| 738 return "Entry name did not match."; | 804 return "Entry name did not match."; |
| 739 } | 805 } |
| 740 | 806 |
| 741 PASS(); | 807 PASS(); |
| 742 } | 808 } |
| 743 #endif | 809 #endif |
| OLD | NEW |