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 50 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 request; | 71 pp::URLRequestInfo request(instance_); |
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 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 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(); |
(...skipping 22 matching lines...) Expand all Loading... |
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 request; | 120 pp::URLRequestInfo request(instance_); |
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 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 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(); |
(...skipping 17 matching lines...) Expand all Loading... |
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 request; | 164 pp::URLRequestInfo request(instance_); |
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 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 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(); |
(...skipping 28 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 request; | 219 pp::URLRequestInfo request(instance_); |
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 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 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(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
338 | 338 |
339 pp::FileRef_Dev file_ref(file_system, "/file_touch"); | 339 pp::FileRef_Dev file_ref(file_system, "/file_touch"); |
340 pp::FileIO_Dev file_io; | 340 pp::FileIO_Dev file_io(instance_); |
341 rv = file_io.Open(file_ref, | 341 rv = file_io.Open(file_ref, |
342 PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_WRITE, | 342 PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_WRITE, |
343 callback); | 343 callback); |
344 if (rv == PP_ERROR_WOULDBLOCK) | 344 if (rv == PP_ERROR_WOULDBLOCK) |
345 rv = callback.WaitForResult(); | 345 rv = callback.WaitForResult(); |
346 if (rv != PP_OK) | 346 if (rv != PP_OK) |
347 return ReportError("FileIO::Open", rv); | 347 return ReportError("FileIO::Open", rv); |
348 | 348 |
349 // Write some data to have a non-zero file size. | 349 // Write some data to have a non-zero file size. |
350 rv = file_io.Write(0, "test", 4, callback); | 350 rv = file_io.Write(0, "test", 4, callback); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
422 | 422 |
423 pp::FileRef_Dev file_ref(file_system, "/file_delete"); | 423 pp::FileRef_Dev file_ref(file_system, "/file_delete"); |
424 pp::FileIO_Dev file_io; | 424 pp::FileIO_Dev file_io(instance_); |
425 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); | 425 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); |
426 if (rv == PP_ERROR_WOULDBLOCK) | 426 if (rv == PP_ERROR_WOULDBLOCK) |
427 rv = callback.WaitForResult(); | 427 rv = callback.WaitForResult(); |
428 if (rv != PP_OK) | 428 if (rv != PP_OK) |
429 return ReportError("FileIO::Open", rv); | 429 return ReportError("FileIO::Open", rv); |
430 | 430 |
431 rv = file_ref.Delete(callback); | 431 rv = file_ref.Delete(callback); |
432 if (rv == PP_ERROR_WOULDBLOCK) | 432 if (rv == PP_ERROR_WOULDBLOCK) |
433 rv = callback.WaitForResult(); | 433 rv = callback.WaitForResult(); |
434 if (rv != PP_OK) | 434 if (rv != PP_OK) |
(...skipping 30 matching lines...) Expand all Loading... |
465 pp::FileRef_Dev nonexistent_file_ref(file_system, "/nonexistent_file_delete"); | 465 pp::FileRef_Dev nonexistent_file_ref(file_system, "/nonexistent_file_delete"); |
466 rv = nonexistent_file_ref.Delete(callback); | 466 rv = nonexistent_file_ref.Delete(callback); |
467 if (rv == PP_ERROR_WOULDBLOCK) | 467 if (rv == PP_ERROR_WOULDBLOCK) |
468 rv = callback.WaitForResult(); | 468 rv = callback.WaitForResult(); |
469 if (rv != PP_ERROR_FILENOTFOUND) | 469 if (rv != PP_ERROR_FILENOTFOUND) |
470 return ReportError("FileSystem::Delete", rv); | 470 return ReportError("FileSystem::Delete", rv); |
471 | 471 |
472 // Delete aborted. | 472 // Delete aborted. |
473 { | 473 { |
474 pp::FileRef_Dev file_ref_abort(file_system, "/file_delete_abort"); | 474 pp::FileRef_Dev file_ref_abort(file_system, "/file_delete_abort"); |
475 pp::FileIO_Dev file_io_abort; | 475 pp::FileIO_Dev file_io_abort(instance_); |
476 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); | 476 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); |
477 if (rv == PP_ERROR_WOULDBLOCK) | 477 if (rv == PP_ERROR_WOULDBLOCK) |
478 rv = callback.WaitForResult(); | 478 rv = callback.WaitForResult(); |
479 if (rv != PP_OK) | 479 if (rv != PP_OK) |
480 return ReportError("FileIO::Open", rv); | 480 return ReportError("FileIO::Open", rv); |
481 | 481 |
482 callback.reset_run_count(); | 482 callback.reset_run_count(); |
483 rv = file_ref_abort.Delete(callback); | 483 rv = file_ref_abort.Delete(callback); |
484 } | 484 } |
485 if (callback.run_count() > 0) | 485 if (callback.run_count() > 0) |
(...skipping 12 matching lines...) Expand all Loading... |
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); |
506 | 506 |
507 pp::FileRef_Dev file_ref(file_system, "/file_rename"); | 507 pp::FileRef_Dev file_ref(file_system, "/file_rename"); |
508 pp::FileIO_Dev file_io; | 508 pp::FileIO_Dev file_io(instance_); |
509 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); | 509 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); |
510 if (rv == PP_ERROR_WOULDBLOCK) | 510 if (rv == PP_ERROR_WOULDBLOCK) |
511 rv = callback.WaitForResult(); | 511 rv = callback.WaitForResult(); |
512 if (rv != PP_OK) | 512 if (rv != PP_OK) |
513 return ReportError("FileIO::Open", rv); | 513 return ReportError("FileIO::Open", rv); |
514 | 514 |
515 pp::FileRef_Dev target_file_ref(file_system, "/target_file_rename"); | 515 pp::FileRef_Dev target_file_ref(file_system, "/target_file_rename"); |
516 rv = file_ref.Rename(target_file_ref, callback); | 516 rv = file_ref.Rename(target_file_ref, callback); |
517 if (rv == PP_ERROR_WOULDBLOCK) | 517 if (rv == PP_ERROR_WOULDBLOCK) |
518 rv = callback.WaitForResult(); | 518 rv = callback.WaitForResult(); |
(...skipping 28 matching lines...) Expand all Loading... |
547 if (rv != PP_ERROR_FAILED) | 547 if (rv != PP_ERROR_FAILED) |
548 return ReportError("FileSystem::Rename", rv); | 548 return ReportError("FileSystem::Rename", rv); |
549 | 549 |
550 // Rename aborted. | 550 // Rename aborted. |
551 // TODO(viettrungluu): Figure out what we want to do if the target file | 551 // TODO(viettrungluu): Figure out what we want to do if the target file |
552 // resource is destroyed before completion. | 552 // resource is destroyed before completion. |
553 pp::FileRef_Dev target_file_ref_abort(file_system, | 553 pp::FileRef_Dev target_file_ref_abort(file_system, |
554 "/target_file_rename_abort"); | 554 "/target_file_rename_abort"); |
555 { | 555 { |
556 pp::FileRef_Dev file_ref_abort(file_system, "/file_rename_abort"); | 556 pp::FileRef_Dev file_ref_abort(file_system, "/file_rename_abort"); |
557 pp::FileIO_Dev file_io_abort; | 557 pp::FileIO_Dev file_io_abort(instance_); |
558 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); | 558 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); |
559 if (rv == PP_ERROR_WOULDBLOCK) | 559 if (rv == PP_ERROR_WOULDBLOCK) |
560 rv = callback.WaitForResult(); | 560 rv = callback.WaitForResult(); |
561 if (rv != PP_OK) | 561 if (rv != PP_OK) |
562 return ReportError("FileIO::Open", rv); | 562 return ReportError("FileIO::Open", rv); |
563 | 563 |
564 callback.reset_run_count(); | 564 callback.reset_run_count(); |
565 rv = file_ref_abort.Rename(target_file_ref_abort, callback); | 565 rv = file_ref_abort.Rename(target_file_ref_abort, callback); |
566 } | 566 } |
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 PASS(); | 577 PASS(); |
578 } | 578 } |
OLD | NEW |