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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 bool TestURLLoader::Init() { | 65 bool TestURLLoader::Init() { |
66 if (!InitTestingInterface()) { | 66 if (!InitTestingInterface()) { |
67 instance_->AppendError("Testing interface not available"); | 67 instance_->AppendError("Testing interface not available"); |
68 return false; | 68 return false; |
69 } | 69 } |
70 | 70 |
71 const PPB_FileIO* file_io_interface = static_cast<const PPB_FileIO*>( | 71 const PPB_FileIO* file_io_interface = static_cast<const PPB_FileIO*>( |
72 pp::Module::Get()->GetBrowserInterface(PPB_FILEIO_INTERFACE)); | 72 pp::Module::Get()->GetBrowserInterface(PPB_FILEIO_INTERFACE)); |
73 if (!file_io_interface) | 73 if (testing_interface_->IsOutOfProcess() && file_io_interface) { |
| 74 instance_->AppendError( |
| 75 "FileIO interface is now supported by ppapi proxy: update this test!"); |
| 76 } else if (!testing_interface_->IsOutOfProcess() && !file_io_interface) { |
74 instance_->AppendError("FileIO interface not available"); | 77 instance_->AppendError("FileIO interface not available"); |
| 78 } |
75 | 79 |
76 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( | 80 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( |
77 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); | 81 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); |
78 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( | 82 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( |
79 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); | 83 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); |
80 if (!testing_interface_->IsOutOfProcess()) { | 84 if (testing_interface_->IsOutOfProcess() && file_io_trusted_interface_) { |
| 85 instance_->AppendError( |
| 86 "FileIOTrusted interface is now supported by ppapi proxy: " |
| 87 "update this test!"); |
| 88 } else if (!testing_interface_->IsOutOfProcess()) { |
81 // Trusted interfaces are not supported under NaCl. | 89 // Trusted interfaces are not supported under NaCl. |
82 #if !(defined __native_client__) | 90 #if !(defined __native_client__) |
83 if (!file_io_trusted_interface_) | 91 if (!file_io_trusted_interface_) |
84 instance_->AppendError("FileIOTrusted interface not available"); | 92 instance_->AppendError("FileIOTrusted interface not available"); |
85 if (!url_loader_trusted_interface_) | 93 if (!url_loader_trusted_interface_) |
86 instance_->AppendError("URLLoaderTrusted interface not available"); | 94 instance_->AppendError("URLLoaderTrusted interface not available"); |
87 #else | 95 #else |
88 if (file_io_trusted_interface_) | 96 if (file_io_trusted_interface_) |
89 instance_->AppendError("FileIOTrusted interface is supported by NaCl"); | 97 instance_->AppendError("FileIOTrusted interface is supported by NaCl"); |
90 if (url_loader_trusted_interface_) | 98 if (url_loader_trusted_interface_) |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 473 |
466 rv = loader.FinishStreamingToFile(callback); | 474 rv = loader.FinishStreamingToFile(callback); |
467 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 475 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
468 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); | 476 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); |
469 if (rv == PP_OK_COMPLETIONPENDING) | 477 if (rv == PP_OK_COMPLETIONPENDING) |
470 rv = callback.WaitForResult(); | 478 rv = callback.WaitForResult(); |
471 if (rv != PP_OK) | 479 if (rv != PP_OK) |
472 return ReportError("URLLoader::FinishStreamingToFile", rv); | 480 return ReportError("URLLoader::FinishStreamingToFile", rv); |
473 | 481 |
474 // FileIO is not yet supported by ppapi/proxy. | 482 // FileIO is not yet supported by ppapi/proxy. |
475 pp::FileIO reader(instance_); | 483 if (!testing_interface_->IsOutOfProcess()) { |
476 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); | 484 pp::FileIO reader(instance_); |
477 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 485 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); |
478 return ReportError("FileIO::Open force_async", rv); | 486 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
479 if (rv == PP_OK_COMPLETIONPENDING) | 487 return ReportError("FileIO::Open force_async", rv); |
480 rv = callback.WaitForResult(); | 488 if (rv == PP_OK_COMPLETIONPENDING) |
481 if (rv != PP_OK) | 489 rv = callback.WaitForResult(); |
482 return ReportError("FileIO::Open", rv); | 490 if (rv != PP_OK) |
| 491 return ReportError("FileIO::Open", rv); |
483 | 492 |
484 std::string data; | 493 std::string data; |
485 std::string error = ReadEntireFile(&reader, &data); | 494 std::string error = ReadEntireFile(&reader, &data); |
486 if (!error.empty()) | 495 if (!error.empty()) |
487 return error; | 496 return error; |
488 | 497 |
489 std::string expected_body = "hello\n"; | 498 std::string expected_body = "hello\n"; |
490 if (data.size() != expected_body.size()) | 499 if (data.size() != expected_body.size()) |
491 return "ReadEntireFile returned unexpected content length"; | 500 return "ReadEntireFile returned unexpected content length"; |
492 if (data != expected_body) | 501 if (data != expected_body) |
493 return "ReadEntireFile returned unexpected content"; | 502 return "ReadEntireFile returned unexpected content"; |
494 | 503 |
495 // FileIOTrusted is not supported by NaCl or ppapi/proxy. | 504 // FileIOTrusted is not supported by NaCl or ppapi/proxy. |
496 if (!testing_interface_->IsOutOfProcess()) { | 505 if (!testing_interface_->IsOutOfProcess()) { |
497 #if !(defined __native_client__) | 506 #if !(defined __native_client__) |
498 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( | 507 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( |
499 reader.pp_resource()); | 508 reader.pp_resource()); |
500 if (file_descriptor < 0) | 509 if (file_descriptor < 0) |
501 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; | 510 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; |
502 #endif | 511 #endif |
| 512 } |
503 } | 513 } |
504 PASS(); | 514 PASS(); |
505 } | 515 } |
506 | 516 |
507 // Untrusted, unintended cross-origin requests should fail. | 517 // Untrusted, unintended cross-origin requests should fail. |
508 std::string TestURLLoader::TestUntrustedSameOriginRestriction() { | 518 std::string TestURLLoader::TestUntrustedSameOriginRestriction() { |
509 pp::URLRequestInfo request(instance_); | 519 pp::URLRequestInfo request(instance_); |
510 std::string cross_origin_url = GetReachableCrossOriginURL("test_case.html"); | 520 std::string cross_origin_url = GetReachableCrossOriginURL("test_case.html"); |
511 request.SetURL(cross_origin_url); | 521 request.SetURL(cross_origin_url); |
512 | 522 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 return error; | 882 return error; |
873 if (body != "hello\n") | 883 if (body != "hello\n") |
874 return ReportError("Couldn't read data", rv); | 884 return ReportError("Couldn't read data", rv); |
875 | 885 |
876 PASS(); | 886 PASS(); |
877 } | 887 } |
878 | 888 |
879 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close | 889 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close |
880 // (including abort tests if applicable). | 890 // (including abort tests if applicable). |
881 | 891 |
OLD | NEW |