| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/dev/ppb_file_io_dev.h" | 10 #include "ppapi/c/dev/ppb_file_io_dev.h" |
| 11 #include "ppapi/c/dev/ppb_testing_dev.h" | 11 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 12 #include "ppapi/cpp/dev/file_io_dev.h" | 12 #include "ppapi/cpp/dev/file_io_dev.h" |
| 13 #include "ppapi/cpp/dev/file_ref_dev.h" | 13 #include "ppapi/cpp/dev/file_ref_dev.h" |
| 14 #include "ppapi/cpp/dev/file_system_dev.h" | 14 #include "ppapi/cpp/dev/file_system_dev.h" |
| 15 #include "ppapi/cpp/dev/url_loader_dev.h" | |
| 16 #include "ppapi/cpp/dev/url_request_info_dev.h" | |
| 17 #include "ppapi/cpp/dev/url_response_info_dev.h" | |
| 18 #include "ppapi/cpp/instance.h" | 15 #include "ppapi/cpp/instance.h" |
| 19 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
| 17 #include "ppapi/cpp/url_loader.h" |
| 18 #include "ppapi/cpp/url_request_info.h" |
| 19 #include "ppapi/cpp/url_response_info.h" |
| 20 #include "ppapi/tests/test_utils.h" | 20 #include "ppapi/tests/test_utils.h" |
| 21 #include "ppapi/tests/testing_instance.h" | 21 #include "ppapi/tests/testing_instance.h" |
| 22 | 22 |
| 23 REGISTER_TEST_CASE(FileRef); | 23 REGISTER_TEST_CASE(FileRef); |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const char* kPersFileName = "persistent"; | 27 const char* kPersFileName = "persistent"; |
| 28 const char* kTempFileName = "temporary"; | 28 const char* kTempFileName = "temporary"; |
| 29 const char* kParentPath = "/foo/bar"; | 29 const char* kParentPath = "/foo/bar"; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 61 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 62 | 62 |
| 63 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); | 63 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); |
| 64 if (file_ref_pers.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) | 64 if (file_ref_pers.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) |
| 65 return "file_ref_pers expected to be persistent."; | 65 return "file_ref_pers expected to be persistent."; |
| 66 | 66 |
| 67 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); | 67 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); |
| 68 if (file_ref_temp.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) | 68 if (file_ref_temp.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) |
| 69 return "file_ref_temp expected to be temporary."; | 69 return "file_ref_temp expected to be temporary."; |
| 70 | 70 |
| 71 pp::URLRequestInfo_Dev request; | 71 pp::URLRequestInfo request; |
| 72 request.SetURL("test_url_loader_data/hello.txt"); | 72 request.SetURL("test_url_loader_data/hello.txt"); |
| 73 request.SetStreamToFile(true); | 73 request.SetStreamToFile(true); |
| 74 | 74 |
| 75 TestCompletionCallback callback; | 75 TestCompletionCallback callback; |
| 76 | 76 |
| 77 pp::URLLoader_Dev loader(*instance_); | 77 pp::URLLoader loader(*instance_); |
| 78 int32_t rv = loader.Open(request, callback); | 78 int32_t rv = loader.Open(request, callback); |
| 79 if (rv == PP_ERROR_WOULDBLOCK) | 79 if (rv == PP_ERROR_WOULDBLOCK) |
| 80 rv = callback.WaitForResult(); | 80 rv = callback.WaitForResult(); |
| 81 if (rv != PP_OK) | 81 if (rv != PP_OK) |
| 82 return "URLLoader::Open() failed."; | 82 return "URLLoader::Open() failed."; |
| 83 | 83 |
| 84 pp::URLResponseInfo_Dev response_info(loader.GetResponseInfo()); | 84 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 85 if (response_info.is_null()) | 85 if (response_info.is_null()) |
| 86 return "URLLoader::GetResponseInfo returned null"; | 86 return "URLLoader::GetResponseInfo returned null"; |
| 87 int32_t status_code = response_info.GetStatusCode(); | 87 int32_t status_code = response_info.GetStatusCode(); |
| 88 if (status_code != 200) | 88 if (status_code != 200) |
| 89 return "Unexpected HTTP status code"; | 89 return "Unexpected HTTP status code"; |
| 90 | 90 |
| 91 pp::FileRef_Dev file_ref_ext(response_info.GetBody()); | 91 pp::FileRef_Dev file_ref_ext(response_info.GetBodyAsFileRef()); |
| 92 if (file_ref_ext.GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) | 92 if (file_ref_ext.GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) |
| 93 return "file_ref_ext expected to be external."; | 93 return "file_ref_ext expected to be external."; |
| 94 | 94 |
| 95 return ""; | 95 return ""; |
| 96 } | 96 } |
| 97 | 97 |
| 98 std::string TestFileRef::TestGetName() { | 98 std::string TestFileRef::TestGetName() { |
| 99 pp::FileSystem_Dev file_system_pers( | 99 pp::FileSystem_Dev file_system_pers( |
| 100 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); | 100 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); |
| 101 pp::FileSystem_Dev file_system_temp( | 101 pp::FileSystem_Dev file_system_temp( |
| 102 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 102 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 103 | 103 |
| 104 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); | 104 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); |
| 105 std::string name = file_ref_pers.GetName().AsString(); | 105 std::string name = file_ref_pers.GetName().AsString(); |
| 106 if (name != kPersFileName) | 106 if (name != kPersFileName) |
| 107 return ReportMismatch("FileRef::GetName", name, kPersFileName); | 107 return ReportMismatch("FileRef::GetName", name, kPersFileName); |
| 108 | 108 |
| 109 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); | 109 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); |
| 110 name = file_ref_temp.GetName().AsString(); | 110 name = file_ref_temp.GetName().AsString(); |
| 111 if (name != kTempFileName) | 111 if (name != kTempFileName) |
| 112 return ReportMismatch("FileRef::GetName", name, kTempFileName); | 112 return ReportMismatch("FileRef::GetName", name, kTempFileName); |
| 113 | 113 |
| 114 // Test the "/" case. | 114 // Test the "/" case. |
| 115 pp::FileRef_Dev file_ref_slash(file_system_temp, "/"); | 115 pp::FileRef_Dev file_ref_slash(file_system_temp, "/"); |
| 116 name = file_ref_slash.GetName().AsString(); | 116 name = file_ref_slash.GetName().AsString(); |
| 117 if (name != "/") | 117 if (name != "/") |
| 118 return ReportMismatch("FileRef::GetName", name, "/"); | 118 return ReportMismatch("FileRef::GetName", name, "/"); |
| 119 | 119 |
| 120 pp::URLRequestInfo_Dev request; | 120 pp::URLRequestInfo request; |
| 121 request.SetURL("test_url_loader_data/hello.txt"); | 121 request.SetURL("test_url_loader_data/hello.txt"); |
| 122 request.SetStreamToFile(true); | 122 request.SetStreamToFile(true); |
| 123 | 123 |
| 124 TestCompletionCallback callback; | 124 TestCompletionCallback callback; |
| 125 | 125 |
| 126 pp::URLLoader_Dev loader(*instance_); | 126 pp::URLLoader loader(*instance_); |
| 127 int32_t rv = loader.Open(request, callback); | 127 int32_t rv = loader.Open(request, callback); |
| 128 if (rv == PP_ERROR_WOULDBLOCK) | 128 if (rv == PP_ERROR_WOULDBLOCK) |
| 129 rv = callback.WaitForResult(); | 129 rv = callback.WaitForResult(); |
| 130 if (rv != PP_OK) | 130 if (rv != PP_OK) |
| 131 return "URLLoader::Open() failed."; | 131 return "URLLoader::Open() failed."; |
| 132 | 132 |
| 133 pp::URLResponseInfo_Dev response_info(loader.GetResponseInfo()); | 133 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 134 if (response_info.is_null()) | 134 if (response_info.is_null()) |
| 135 return "URLLoader::GetResponseInfo returned null"; | 135 return "URLLoader::GetResponseInfo returned null"; |
| 136 int32_t status_code = response_info.GetStatusCode(); | 136 int32_t status_code = response_info.GetStatusCode(); |
| 137 if (status_code != 200) | 137 if (status_code != 200) |
| 138 return "Unexpected HTTP status code"; | 138 return "Unexpected HTTP status code"; |
| 139 | 139 |
| 140 pp::FileRef_Dev file_ref_ext(response_info.GetBody()); | 140 pp::FileRef_Dev file_ref_ext(response_info.GetBodyAsFileRef()); |
| 141 name = file_ref_ext.GetName().AsString(); | 141 name = file_ref_ext.GetName().AsString(); |
| 142 if (name != "") | 142 if (name != "") |
| 143 return ReportMismatch("FileRef::GetName", name, "<empty string>"); | 143 return ReportMismatch("FileRef::GetName", name, "<empty string>"); |
| 144 | 144 |
| 145 return ""; | 145 return ""; |
| 146 } | 146 } |
| 147 | 147 |
| 148 std::string TestFileRef::TestGetPath() { | 148 std::string TestFileRef::TestGetPath() { |
| 149 pp::FileSystem_Dev file_system_pers( | 149 pp::FileSystem_Dev file_system_pers( |
| 150 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); | 150 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); |
| 151 pp::FileSystem_Dev file_system_temp( | 151 pp::FileSystem_Dev file_system_temp( |
| 152 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 152 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 153 | 153 |
| 154 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); | 154 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); |
| 155 std::string path = file_ref_pers.GetPath().AsString(); | 155 std::string path = file_ref_pers.GetPath().AsString(); |
| 156 if (path != kPersFilePath) | 156 if (path != kPersFilePath) |
| 157 return ReportMismatch("FileRef::GetPath", path, kPersFilePath); | 157 return ReportMismatch("FileRef::GetPath", path, kPersFilePath); |
| 158 | 158 |
| 159 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); | 159 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); |
| 160 path = file_ref_temp.GetPath().AsString(); | 160 path = file_ref_temp.GetPath().AsString(); |
| 161 if (path != kTempFilePath) | 161 if (path != kTempFilePath) |
| 162 return ReportMismatch("FileRef::GetPath", path, kTempFilePath); | 162 return ReportMismatch("FileRef::GetPath", path, kTempFilePath); |
| 163 | 163 |
| 164 pp::URLRequestInfo_Dev request; | 164 pp::URLRequestInfo request; |
| 165 request.SetURL("test_url_loader_data/hello.txt"); | 165 request.SetURL("test_url_loader_data/hello.txt"); |
| 166 request.SetStreamToFile(true); | 166 request.SetStreamToFile(true); |
| 167 | 167 |
| 168 TestCompletionCallback callback; | 168 TestCompletionCallback callback; |
| 169 | 169 |
| 170 pp::URLLoader_Dev loader(*instance_); | 170 pp::URLLoader loader(*instance_); |
| 171 int32_t rv = loader.Open(request, callback); | 171 int32_t rv = loader.Open(request, callback); |
| 172 if (rv == PP_ERROR_WOULDBLOCK) | 172 if (rv == PP_ERROR_WOULDBLOCK) |
| 173 rv = callback.WaitForResult(); | 173 rv = callback.WaitForResult(); |
| 174 if (rv != PP_OK) | 174 if (rv != PP_OK) |
| 175 return "URLLoader::Open() failed."; | 175 return "URLLoader::Open() failed."; |
| 176 | 176 |
| 177 pp::URLResponseInfo_Dev response_info(loader.GetResponseInfo()); | 177 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 178 if (response_info.is_null()) | 178 if (response_info.is_null()) |
| 179 return "URLLoader::GetResponseInfo returned null"; | 179 return "URLLoader::GetResponseInfo returned null"; |
| 180 int32_t status_code = response_info.GetStatusCode(); | 180 int32_t status_code = response_info.GetStatusCode(); |
| 181 if (status_code != 200) | 181 if (status_code != 200) |
| 182 return "Unexpected HTTP status code"; | 182 return "Unexpected HTTP status code"; |
| 183 | 183 |
| 184 pp::FileRef_Dev file_ref_ext(response_info.GetBody()); | 184 pp::FileRef_Dev file_ref_ext(response_info.GetBodyAsFileRef()); |
| 185 if (!file_ref_ext.GetPath().is_undefined()) | 185 if (!file_ref_ext.GetPath().is_undefined()) |
| 186 return "The path of an external FileRef should be void."; | 186 return "The path of an external FileRef should be void."; |
| 187 | 187 |
| 188 return ""; | 188 return ""; |
| 189 } | 189 } |
| 190 | 190 |
| 191 std::string TestFileRef::TestGetParent() { | 191 std::string TestFileRef::TestGetParent() { |
| 192 pp::FileSystem_Dev file_system_pers( | 192 pp::FileSystem_Dev file_system_pers( |
| 193 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); | 193 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); |
| 194 pp::FileSystem_Dev file_system_temp( | 194 pp::FileSystem_Dev file_system_temp( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 209 parent_path = file_ref_slash.GetParent().GetPath().AsString(); | 209 parent_path = file_ref_slash.GetParent().GetPath().AsString(); |
| 210 if (parent_path != "/") | 210 if (parent_path != "/") |
| 211 return ReportMismatch("FileRef::GetParent", parent_path, "/"); | 211 return ReportMismatch("FileRef::GetParent", parent_path, "/"); |
| 212 | 212 |
| 213 // Test the "/foo" case (the parent is "/"). | 213 // Test the "/foo" case (the parent is "/"). |
| 214 pp::FileRef_Dev file_ref_with_root_parent(file_system_temp, "/foo"); | 214 pp::FileRef_Dev file_ref_with_root_parent(file_system_temp, "/foo"); |
| 215 parent_path = file_ref_with_root_parent.GetParent().GetPath().AsString(); | 215 parent_path = file_ref_with_root_parent.GetParent().GetPath().AsString(); |
| 216 if (parent_path != "/") | 216 if (parent_path != "/") |
| 217 return ReportMismatch("FileRef::GetParent", parent_path, "/"); | 217 return ReportMismatch("FileRef::GetParent", parent_path, "/"); |
| 218 | 218 |
| 219 pp::URLRequestInfo_Dev request; | 219 pp::URLRequestInfo request; |
| 220 request.SetURL("test_url_loader_data/hello.txt"); | 220 request.SetURL("test_url_loader_data/hello.txt"); |
| 221 request.SetStreamToFile(true); | 221 request.SetStreamToFile(true); |
| 222 | 222 |
| 223 TestCompletionCallback callback; | 223 TestCompletionCallback callback; |
| 224 | 224 |
| 225 pp::URLLoader_Dev loader(*instance_); | 225 pp::URLLoader loader(*instance_); |
| 226 int32_t rv = loader.Open(request, callback); | 226 int32_t rv = loader.Open(request, callback); |
| 227 if (rv == PP_ERROR_WOULDBLOCK) | 227 if (rv == PP_ERROR_WOULDBLOCK) |
| 228 rv = callback.WaitForResult(); | 228 rv = callback.WaitForResult(); |
| 229 if (rv != PP_OK) | 229 if (rv != PP_OK) |
| 230 return "URLLoader::Open() failed."; | 230 return "URLLoader::Open() failed."; |
| 231 | 231 |
| 232 pp::URLResponseInfo_Dev response_info(loader.GetResponseInfo()); | 232 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 233 if (response_info.is_null()) | 233 if (response_info.is_null()) |
| 234 return "URLLoader::GetResponseInfo returned null"; | 234 return "URLLoader::GetResponseInfo returned null"; |
| 235 int32_t status_code = response_info.GetStatusCode(); | 235 int32_t status_code = response_info.GetStatusCode(); |
| 236 if (status_code != 200) | 236 if (status_code != 200) |
| 237 return "Unexpected HTTP status code"; | 237 return "Unexpected HTTP status code"; |
| 238 | 238 |
| 239 pp::FileRef_Dev file_ref_ext(response_info.GetBody()); | 239 pp::FileRef_Dev file_ref_ext(response_info.GetBodyAsFileRef()); |
| 240 if (!file_ref_ext.GetParent().is_null()) | 240 if (!file_ref_ext.GetParent().is_null()) |
| 241 return "The parent of an external FileRef should be null."; | 241 return "The parent of an external FileRef should be null."; |
| 242 | 242 |
| 243 return ""; | 243 return ""; |
| 244 } | 244 } |
| 245 | 245 |
| 246 std::string TestFileRef::TestMakeDirectory() { | 246 std::string TestFileRef::TestMakeDirectory() { |
| 247 TestCompletionCallback callback; | 247 TestCompletionCallback callback; |
| 248 | 248 |
| 249 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 249 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 437 |
| 438 pp::FileRef_Dev target_nested_dir_ref(file_system, "/dir_rename_1"); | 438 pp::FileRef_Dev target_nested_dir_ref(file_system, "/dir_rename_1"); |
| 439 rv = nested_dir_ref.Rename(target_nested_dir_ref, callback); | 439 rv = nested_dir_ref.Rename(target_nested_dir_ref, callback); |
| 440 if (rv == PP_ERROR_WOULDBLOCK) | 440 if (rv == PP_ERROR_WOULDBLOCK) |
| 441 rv = callback.WaitForResult(); | 441 rv = callback.WaitForResult(); |
| 442 if (rv != PP_ERROR_FAILED) | 442 if (rv != PP_ERROR_FAILED) |
| 443 return ReportError("FileSystem::Rename", rv); | 443 return ReportError("FileSystem::Rename", rv); |
| 444 | 444 |
| 445 return ""; | 445 return ""; |
| 446 } | 446 } |
| OLD | NEW |