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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 REGISTER_TEST_CASE(FileRef); | 26 REGISTER_TEST_CASE(FileRef); |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 const char* kPersFileName = "persistent"; | 30 const char* kPersFileName = "persistent"; |
31 const char* kTempFileName = "temporary"; | 31 const char* kTempFileName = "temporary"; |
32 const char* kParentPath = "/foo/bar"; | 32 const char* kParentPath = "/foo/bar"; |
33 const char* kPersFilePath = "/foo/bar/persistent"; | 33 const char* kPersFilePath = "/foo/bar/persistent"; |
34 const char* kTempFilePath = "/foo/bar/temporary"; | 34 const char* kTempFilePath = "/foo/bar/temporary"; |
35 #ifndef PPAPI_OS_NACL // Only used for a test that NaCl can't run yet. | |
36 const char* kTerribleName = "!@#$%^&*()-_=+{}[] ;:'\"|`~\t\n\r\b?"; | 35 const char* kTerribleName = "!@#$%^&*()-_=+{}[] ;:'\"|`~\t\n\r\b?"; |
37 #endif | |
38 | 36 |
39 std::string ReportMismatch(const std::string& method_name, | 37 std::string ReportMismatch(const std::string& method_name, |
40 const std::string& returned_result, | 38 const std::string& returned_result, |
41 const std::string& expected_result) { | 39 const std::string& expected_result) { |
42 return method_name + " returned '" + returned_result + "'; '" + | 40 return method_name + " returned '" + returned_result + "'; '" + |
43 expected_result + "' expected."; | 41 expected_result + "' expected."; |
44 } | 42 } |
45 | 43 |
46 } // namespace | 44 } // namespace |
47 | 45 |
(...skipping 26 matching lines...) Expand all Loading... |
74 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter); | 72 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter); |
75 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter); | 73 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter); |
76 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter); | 74 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter); |
77 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter); | 75 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter); |
78 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter); | 76 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter); |
79 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter); | 77 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter); |
80 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter); | 78 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter); |
81 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter); | 79 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter); |
82 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter); | 80 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter); |
83 RUN_CALLBACK_TEST(TestFileRef, Query, filter); | 81 RUN_CALLBACK_TEST(TestFileRef, Query, filter); |
84 #ifndef PPAPI_OS_NACL // NaCl can't run this test yet. | |
85 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter); | 82 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter); |
86 #endif | |
87 } | 83 } |
88 | 84 |
89 std::string TestFileRef::TestCreate() { | 85 std::string TestFileRef::TestCreate() { |
90 std::vector<std::string> invalid_paths; | 86 std::vector<std::string> invalid_paths; |
91 invalid_paths.push_back("invalid_path"); // no '/' at the first character | 87 invalid_paths.push_back("invalid_path"); // no '/' at the first character |
92 invalid_paths.push_back(""); // empty path | 88 invalid_paths.push_back(""); // empty path |
93 // The following are directory traversal checks | 89 // The following are directory traversal checks |
94 invalid_paths.push_back(".."); | 90 invalid_paths.push_back(".."); |
95 invalid_paths.push_back("/../invalid_path"); | 91 invalid_paths.push_back("/../invalid_path"); |
96 invalid_paths.push_back("/../../invalid_path"); | 92 invalid_paths.push_back("/../../invalid_path"); |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 // Query a file ref for a file that doesn't exist. | 734 // Query a file ref for a file that doesn't exist. |
739 pp::FileRef missing_file_ref(file_system, "/missing_file"); | 735 pp::FileRef missing_file_ref(file_system, "/missing_file"); |
740 out_callback.WaitForResult(missing_file_ref.Query( | 736 out_callback.WaitForResult(missing_file_ref.Query( |
741 out_callback.GetCallback())); | 737 out_callback.GetCallback())); |
742 CHECK_CALLBACK_BEHAVIOR(out_callback); | 738 CHECK_CALLBACK_BEHAVIOR(out_callback); |
743 ASSERT_EQ(PP_ERROR_FILENOTFOUND, out_callback.result()); | 739 ASSERT_EQ(PP_ERROR_FILENOTFOUND, out_callback.result()); |
744 | 740 |
745 PASS(); | 741 PASS(); |
746 } | 742 } |
747 | 743 |
748 #ifndef PPAPI_OS_NACL | |
749 std::string TestFileRef::TestFileNameEscaping() { | 744 std::string TestFileRef::TestFileNameEscaping() { |
750 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 745 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
751 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 746 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
752 int32_t rv = file_system.Open(1024, callback.GetCallback()); | 747 int32_t rv = file_system.Open(1024, callback.GetCallback()); |
753 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 748 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
754 return ReportError("FileSystem::Open force_async", rv); | 749 return ReportError("FileSystem::Open force_async", rv); |
755 if (rv == PP_OK_COMPLETIONPENDING) | 750 if (rv == PP_OK_COMPLETIONPENDING) |
756 rv = callback.WaitForResult(); | 751 rv = callback.WaitForResult(); |
757 if (rv != PP_OK) | 752 if (rv != PP_OK) |
758 return ReportError("FileSystem::Open", rv); | 753 return ReportError("FileSystem::Open", rv); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 if (entries.empty()) | 791 if (entries.empty()) |
797 return "Entry was not found."; | 792 return "Entry was not found."; |
798 if (entries.size() != 1) | 793 if (entries.size() != 1) |
799 return "Directory had too many entries."; | 794 return "Directory had too many entries."; |
800 if (entries.front().file_ref().GetName().AsString() != kTerribleName) | 795 if (entries.front().file_ref().GetName().AsString() != kTerribleName) |
801 return "Entry name did not match."; | 796 return "Entry name did not match."; |
802 } | 797 } |
803 | 798 |
804 PASS(); | 799 PASS(); |
805 } | 800 } |
806 #endif | |
OLD | NEW |