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_url_loader.h" | 5 #include "ppapi/tests/test_url_loader.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 bool TestURLLoader::Init() { | 66 bool TestURLLoader::Init() { |
67 if (!InitTestingInterface()) { | 67 if (!InitTestingInterface()) { |
68 instance_->AppendError("Testing interface not available"); | 68 instance_->AppendError("Testing interface not available"); |
69 return false; | 69 return false; |
70 } | 70 } |
71 | 71 |
72 const PPB_FileIO* file_io_interface = static_cast<const PPB_FileIO*>( | 72 const PPB_FileIO* file_io_interface = static_cast<const PPB_FileIO*>( |
73 pp::Module::Get()->GetBrowserInterface(PPB_FILEIO_INTERFACE)); | 73 pp::Module::Get()->GetBrowserInterface(PPB_FILEIO_INTERFACE)); |
74 if (!file_io_interface) | 74 if (testing_interface_->IsOutOfProcess() && file_io_interface) { |
| 75 instance_->AppendError( |
| 76 "FileIO interface is now supported by ppapi proxy: update this test!"); |
| 77 } else if (!testing_interface_->IsOutOfProcess() && !file_io_interface) { |
75 instance_->AppendError("FileIO interface not available"); | 78 instance_->AppendError("FileIO interface not available"); |
| 79 } |
76 | 80 |
77 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( | 81 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( |
78 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); | 82 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); |
79 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( | 83 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( |
80 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); | 84 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); |
81 if (!testing_interface_->IsOutOfProcess()) { | 85 if (testing_interface_->IsOutOfProcess() && file_io_trusted_interface_) { |
| 86 instance_->AppendError( |
| 87 "FileIOTrusted interface is now supported by ppapi proxy: " |
| 88 "update this test!"); |
| 89 } else if (!testing_interface_->IsOutOfProcess()) { |
82 // Trusted interfaces are not supported under NaCl. | 90 // Trusted interfaces are not supported under NaCl. |
83 #if !(defined __native_client__) | 91 #if !(defined __native_client__) |
84 if (!file_io_trusted_interface_) | 92 if (!file_io_trusted_interface_) |
85 instance_->AppendError("FileIOTrusted interface not available"); | 93 instance_->AppendError("FileIOTrusted interface not available"); |
86 if (!url_loader_trusted_interface_) | 94 if (!url_loader_trusted_interface_) |
87 instance_->AppendError("URLLoaderTrusted interface not available"); | 95 instance_->AppendError("URLLoaderTrusted interface not available"); |
88 #else | 96 #else |
89 if (file_io_trusted_interface_) | 97 if (file_io_trusted_interface_) |
90 instance_->AppendError("FileIOTrusted interface is supported by NaCl"); | 98 instance_->AppendError("FileIOTrusted interface is supported by NaCl"); |
91 if (url_loader_trusted_interface_) | 99 if (url_loader_trusted_interface_) |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 463 |
456 rv = loader.FinishStreamingToFile(callback); | 464 rv = loader.FinishStreamingToFile(callback); |
457 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 465 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
458 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); | 466 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); |
459 if (rv == PP_OK_COMPLETIONPENDING) | 467 if (rv == PP_OK_COMPLETIONPENDING) |
460 rv = callback.WaitForResult(); | 468 rv = callback.WaitForResult(); |
461 if (rv != PP_OK) | 469 if (rv != PP_OK) |
462 return ReportError("URLLoader::FinishStreamingToFile", rv); | 470 return ReportError("URLLoader::FinishStreamingToFile", rv); |
463 | 471 |
464 // FileIO is not yet supported by ppapi/proxy. | 472 // FileIO is not yet supported by ppapi/proxy. |
465 pp::FileIO reader(instance_); | 473 if (!testing_interface_->IsOutOfProcess()) { |
466 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); | 474 pp::FileIO reader(instance_); |
467 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 475 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); |
468 return ReportError("FileIO::Open force_async", rv); | 476 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
469 if (rv == PP_OK_COMPLETIONPENDING) | 477 return ReportError("FileIO::Open force_async", rv); |
470 rv = callback.WaitForResult(); | 478 if (rv == PP_OK_COMPLETIONPENDING) |
471 if (rv != PP_OK) | 479 rv = callback.WaitForResult(); |
472 return ReportError("FileIO::Open", rv); | 480 if (rv != PP_OK) |
| 481 return ReportError("FileIO::Open", rv); |
473 | 482 |
474 std::string data; | 483 std::string data; |
475 std::string error = ReadEntireFile(&reader, &data); | 484 std::string error = ReadEntireFile(&reader, &data); |
476 if (!error.empty()) | 485 if (!error.empty()) |
477 return error; | 486 return error; |
478 | 487 |
479 std::string expected_body = "hello\n"; | 488 std::string expected_body = "hello\n"; |
480 if (data.size() != expected_body.size()) | 489 if (data.size() != expected_body.size()) |
481 return "ReadEntireFile returned unexpected content length"; | 490 return "ReadEntireFile returned unexpected content length"; |
482 if (data != expected_body) | 491 if (data != expected_body) |
483 return "ReadEntireFile returned unexpected content"; | 492 return "ReadEntireFile returned unexpected content"; |
484 | 493 |
485 // FileIOTrusted is not supported by NaCl or ppapi/proxy. | 494 // FileIOTrusted is not supported by NaCl or ppapi/proxy. |
486 if (!testing_interface_->IsOutOfProcess()) { | 495 if (!testing_interface_->IsOutOfProcess()) { |
487 #if !(defined __native_client__) | 496 #if !(defined __native_client__) |
488 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( | 497 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( |
489 reader.pp_resource()); | 498 reader.pp_resource()); |
490 if (file_descriptor < 0) | 499 if (file_descriptor < 0) |
491 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; | 500 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; |
492 #endif | 501 #endif |
| 502 } |
493 } | 503 } |
494 PASS(); | 504 PASS(); |
495 } | 505 } |
496 | 506 |
497 // Untrusted, unintended cross-origin requests should fail. | 507 // Untrusted, unintended cross-origin requests should fail. |
498 std::string TestURLLoader::TestUntrustedSameOriginRestriction() { | 508 std::string TestURLLoader::TestUntrustedSameOriginRestriction() { |
499 pp::URLRequestInfo request(instance_); | 509 pp::URLRequestInfo request(instance_); |
500 std::string cross_origin_url = GetReachableCrossOriginURL(); | 510 std::string cross_origin_url = GetReachableCrossOriginURL(); |
501 request.SetURL(cross_origin_url); | 511 request.SetURL(cross_origin_url); |
502 | 512 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 if (!error.empty()) | 838 if (!error.empty()) |
829 return error; | 839 return error; |
830 if (body != "hello\n") | 840 if (body != "hello\n") |
831 return ReportError("Couldn't read data", rv); | 841 return ReportError("Couldn't read data", rv); |
832 | 842 |
833 PASS(); | 843 PASS(); |
834 } | 844 } |
835 | 845 |
836 // TODO(viettrungluu): Add tests for FollowRedirect, | 846 // TODO(viettrungluu): Add tests for FollowRedirect, |
837 // Get{Upload,Download}Progress, Close (including abort tests if applicable). | 847 // Get{Upload,Download}Progress, Close (including abort tests if applicable). |
OLD | NEW |