| 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" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.GetBodyAsFileRef()); | 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 PASS(); |
| 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(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 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.GetBodyAsFileRef()); | 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, "<a temp file>"); | 143 return ReportMismatch("FileRef::GetName", name, "<a temp file>"); |
| 144 | 144 |
| 145 return ""; | 145 PASS(); |
| 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(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 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.GetBodyAsFileRef()); | 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 PASS(); |
| 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( |
| 195 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 195 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 196 | 196 |
| 197 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); | 197 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); |
| 198 std::string parent_path = file_ref_pers.GetParent().GetPath().AsString(); | 198 std::string parent_path = file_ref_pers.GetParent().GetPath().AsString(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.GetBodyAsFileRef()); | 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 PASS(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 std::string TestFileRef::TestMakeDirectory() { | 246 std::string TestFileRef::TestMakeDirectory() { |
| 247 TestCompletionCallback callback; | 247 TestCompletionCallback callback; |
| 248 | 248 |
| 249 // Open. | 249 // Open. |
| 250 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 250 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 251 int32_t rv = file_system.Open(1024, callback); | 251 int32_t rv = file_system.Open(1024, callback); |
| 252 if (rv == PP_ERROR_WOULDBLOCK) | 252 if (rv == PP_ERROR_WOULDBLOCK) |
| 253 rv = callback.WaitForResult(); | 253 rv = callback.WaitForResult(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // MakeDirectory with nested path. | 317 // MakeDirectory with nested path. |
| 318 dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_3/dir_make_dir_4"); | 318 dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_3/dir_make_dir_4"); |
| 319 rv = dir_ref.MakeDirectory(callback); | 319 rv = dir_ref.MakeDirectory(callback); |
| 320 if (rv == PP_ERROR_WOULDBLOCK) | 320 if (rv == PP_ERROR_WOULDBLOCK) |
| 321 rv = callback.WaitForResult(); | 321 rv = callback.WaitForResult(); |
| 322 if (rv == PP_OK) { | 322 if (rv == PP_OK) { |
| 323 return "Calling FileSystem::MakeDirectory() with a nested directory path " | 323 return "Calling FileSystem::MakeDirectory() with a nested directory path " |
| 324 "should have failed."; | 324 "should have failed."; |
| 325 } | 325 } |
| 326 | 326 |
| 327 return ""; | 327 PASS(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 std::string TestFileRef::TestQueryAndTouchFile() { | 330 std::string TestFileRef::TestQueryAndTouchFile() { |
| 331 TestCompletionCallback callback; | 331 TestCompletionCallback callback; |
| 332 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 332 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 333 int32_t rv = file_system.Open(1024, callback); | 333 int32_t rv = file_system.Open(1024, callback); |
| 334 if (rv == PP_ERROR_WOULDBLOCK) | 334 if (rv == PP_ERROR_WOULDBLOCK) |
| 335 rv = callback.WaitForResult(); | 335 rv = callback.WaitForResult(); |
| 336 if (rv != PP_OK) | 336 if (rv != PP_OK) |
| 337 return ReportError("FileSystem::Open", rv); | 337 return ReportError("FileSystem::Open", rv); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 if (callback.run_count() > 0) | 401 if (callback.run_count() > 0) |
| 402 return "FileSystem::Query ran callback synchronously."; | 402 return "FileSystem::Query ran callback synchronously."; |
| 403 if (rv == PP_ERROR_WOULDBLOCK) { | 403 if (rv == PP_ERROR_WOULDBLOCK) { |
| 404 rv = callback.WaitForResult(); | 404 rv = callback.WaitForResult(); |
| 405 if (rv != PP_ERROR_ABORTED) | 405 if (rv != PP_ERROR_ABORTED) |
| 406 return "FileSystem::Query not aborted."; | 406 return "FileSystem::Query not aborted."; |
| 407 } else if (rv != PP_OK) { | 407 } else if (rv != PP_OK) { |
| 408 return ReportError("FileSystem::Query", rv); | 408 return ReportError("FileSystem::Query", rv); |
| 409 } | 409 } |
| 410 | 410 |
| 411 return ""; | 411 PASS(); |
| 412 } | 412 } |
| 413 | 413 |
| 414 std::string TestFileRef::TestDeleteFileAndDirectory() { | 414 std::string TestFileRef::TestDeleteFileAndDirectory() { |
| 415 TestCompletionCallback callback; | 415 TestCompletionCallback callback; |
| 416 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 416 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 417 int32_t rv = file_system.Open(1024, callback); | 417 int32_t rv = file_system.Open(1024, callback); |
| 418 if (rv == PP_ERROR_WOULDBLOCK) | 418 if (rv == PP_ERROR_WOULDBLOCK) |
| 419 rv = callback.WaitForResult(); | 419 rv = callback.WaitForResult(); |
| 420 if (rv != PP_OK) | 420 if (rv != PP_OK) |
| 421 return ReportError("FileSystem::Open", rv); | 421 return ReportError("FileSystem::Open", rv); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 if (callback.run_count() > 0) | 485 if (callback.run_count() > 0) |
| 486 return "FileSystem::Delete ran callback synchronously."; | 486 return "FileSystem::Delete ran callback synchronously."; |
| 487 if (rv == PP_ERROR_WOULDBLOCK) { | 487 if (rv == PP_ERROR_WOULDBLOCK) { |
| 488 rv = callback.WaitForResult(); | 488 rv = callback.WaitForResult(); |
| 489 if (rv != PP_ERROR_ABORTED) | 489 if (rv != PP_ERROR_ABORTED) |
| 490 return "FileSystem::Delete not aborted."; | 490 return "FileSystem::Delete not aborted."; |
| 491 } else if (rv != PP_OK) { | 491 } else if (rv != PP_OK) { |
| 492 return ReportError("FileSystem::Delete", rv); | 492 return ReportError("FileSystem::Delete", rv); |
| 493 } | 493 } |
| 494 | 494 |
| 495 return ""; | 495 PASS(); |
| 496 } | 496 } |
| 497 | 497 |
| 498 std::string TestFileRef::TestRenameFileAndDirectory() { | 498 std::string TestFileRef::TestRenameFileAndDirectory() { |
| 499 TestCompletionCallback callback; | 499 TestCompletionCallback callback; |
| 500 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 500 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 501 int32_t rv = file_system.Open(1024, callback); | 501 int32_t rv = file_system.Open(1024, callback); |
| 502 if (rv == PP_ERROR_WOULDBLOCK) | 502 if (rv == PP_ERROR_WOULDBLOCK) |
| 503 rv = callback.WaitForResult(); | 503 rv = callback.WaitForResult(); |
| 504 if (rv != PP_OK) | 504 if (rv != PP_OK) |
| 505 return ReportError("FileSystem::Open", rv); | 505 return ReportError("FileSystem::Open", rv); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if (callback.run_count() > 0) | 567 if (callback.run_count() > 0) |
| 568 return "FileSystem::Rename ran callback synchronously."; | 568 return "FileSystem::Rename ran callback synchronously."; |
| 569 if (rv == PP_ERROR_WOULDBLOCK) { | 569 if (rv == PP_ERROR_WOULDBLOCK) { |
| 570 rv = callback.WaitForResult(); | 570 rv = callback.WaitForResult(); |
| 571 if (rv != PP_ERROR_ABORTED) | 571 if (rv != PP_ERROR_ABORTED) |
| 572 return "FileSystem::Rename not aborted."; | 572 return "FileSystem::Rename not aborted."; |
| 573 } else if (rv != PP_OK) { | 573 } else if (rv != PP_OK) { |
| 574 return ReportError("FileSystem::Rename", rv); | 574 return ReportError("FileSystem::Rename", rv); |
| 575 } | 575 } |
| 576 | 576 |
| 577 return ""; | 577 PASS(); |
| 578 } | 578 } |
| OLD | NEW |