Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: ppapi/tests/test_url_loader.cc

Issue 8764003: Implement a proxy for Pepper FileIO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Homestarmy Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_file_io.cc ('k') | ppapi/thunk/interfaces_ppb_private.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (testing_interface_->IsOutOfProcess() && file_io_interface) { 74 if (!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) {
78 instance_->AppendError("FileIO interface not available"); 75 instance_->AppendError("FileIO interface not available");
79 }
80 76
81 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( 77 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>(
82 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); 78 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE));
83 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( 79 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>(
84 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); 80 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE));
85 if (testing_interface_->IsOutOfProcess() && file_io_trusted_interface_) { 81 if (!testing_interface_->IsOutOfProcess()) {
86 instance_->AppendError(
87 "FileIOTrusted interface is now supported by ppapi proxy: "
88 "update this test!");
89 } else if (!testing_interface_->IsOutOfProcess()) {
90 // Trusted interfaces are not supported under NaCl. 82 // Trusted interfaces are not supported under NaCl.
91 #if !(defined __native_client__) 83 #if !(defined __native_client__)
92 if (!file_io_trusted_interface_) 84 if (!file_io_trusted_interface_)
93 instance_->AppendError("FileIOTrusted interface not available"); 85 instance_->AppendError("FileIOTrusted interface not available");
94 if (!url_loader_trusted_interface_) 86 if (!url_loader_trusted_interface_)
95 instance_->AppendError("URLLoaderTrusted interface not available"); 87 instance_->AppendError("URLLoaderTrusted interface not available");
96 #else 88 #else
97 if (file_io_trusted_interface_) 89 if (file_io_trusted_interface_)
98 instance_->AppendError("FileIOTrusted interface is supported by NaCl"); 90 instance_->AppendError("FileIOTrusted interface is supported by NaCl");
99 if (url_loader_trusted_interface_) 91 if (url_loader_trusted_interface_)
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 455
464 rv = loader.FinishStreamingToFile(callback); 456 rv = loader.FinishStreamingToFile(callback);
465 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 457 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
466 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); 458 return ReportError("URLLoader::FinishStreamingToFile force_async", rv);
467 if (rv == PP_OK_COMPLETIONPENDING) 459 if (rv == PP_OK_COMPLETIONPENDING)
468 rv = callback.WaitForResult(); 460 rv = callback.WaitForResult();
469 if (rv != PP_OK) 461 if (rv != PP_OK)
470 return ReportError("URLLoader::FinishStreamingToFile", rv); 462 return ReportError("URLLoader::FinishStreamingToFile", rv);
471 463
472 // FileIO is not yet supported by ppapi/proxy. 464 // FileIO is not yet supported by ppapi/proxy.
465 pp::FileIO reader(instance_);
466 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback);
467 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
468 return ReportError("FileIO::Open force_async", rv);
469 if (rv == PP_OK_COMPLETIONPENDING)
470 rv = callback.WaitForResult();
471 if (rv != PP_OK)
472 return ReportError("FileIO::Open", rv);
473
474 std::string data;
475 std::string error = ReadEntireFile(&reader, &data);
476 if (!error.empty())
477 return error;
478
479 std::string expected_body = "hello\n";
480 if (data.size() != expected_body.size())
481 return "ReadEntireFile returned unexpected content length";
482 if (data != expected_body)
483 return "ReadEntireFile returned unexpected content";
484
485 // FileIOTrusted is not supported by NaCl or ppapi/proxy.
473 if (!testing_interface_->IsOutOfProcess()) { 486 if (!testing_interface_->IsOutOfProcess()) {
474 pp::FileIO reader(instance_);
475 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback);
476 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
477 return ReportError("FileIO::Open force_async", rv);
478 if (rv == PP_OK_COMPLETIONPENDING)
479 rv = callback.WaitForResult();
480 if (rv != PP_OK)
481 return ReportError("FileIO::Open", rv);
482
483 std::string data;
484 std::string error = ReadEntireFile(&reader, &data);
485 if (!error.empty())
486 return error;
487
488 std::string expected_body = "hello\n";
489 if (data.size() != expected_body.size())
490 return "ReadEntireFile returned unexpected content length";
491 if (data != expected_body)
492 return "ReadEntireFile returned unexpected content";
493
494 // FileIOTrusted is not supported by NaCl or ppapi/proxy.
495 if (!testing_interface_->IsOutOfProcess()) {
496 #if !(defined __native_client__) 487 #if !(defined __native_client__)
497 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( 488 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor(
498 reader.pp_resource()); 489 reader.pp_resource());
499 if (file_descriptor < 0) 490 if (file_descriptor < 0)
500 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; 491 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor.";
501 #endif 492 #endif
502 }
503 } 493 }
504 PASS(); 494 PASS();
505 } 495 }
506 496
507 // Untrusted, unintended cross-origin requests should fail. 497 // Untrusted, unintended cross-origin requests should fail.
508 std::string TestURLLoader::TestUntrustedSameOriginRestriction() { 498 std::string TestURLLoader::TestUntrustedSameOriginRestriction() {
509 pp::URLRequestInfo request(instance_); 499 pp::URLRequestInfo request(instance_);
510 std::string cross_origin_url = GetReachableCrossOriginURL(); 500 std::string cross_origin_url = GetReachableCrossOriginURL();
511 request.SetURL(cross_origin_url); 501 request.SetURL(cross_origin_url);
512 502
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 if (!error.empty()) 828 if (!error.empty())
839 return error; 829 return error;
840 if (body != "hello\n") 830 if (body != "hello\n")
841 return ReportError("Couldn't read data", rv); 831 return ReportError("Couldn't read data", rv);
842 832
843 PASS(); 833 PASS();
844 } 834 }
845 835
846 // TODO(viettrungluu): Add tests for FollowRedirect, 836 // TODO(viettrungluu): Add tests for FollowRedirect,
847 // Get{Upload,Download}Progress, Close (including abort tests if applicable). 837 // Get{Upload,Download}Progress, Close (including abort tests if applicable).
OLDNEW
« no previous file with comments | « ppapi/tests/test_file_io.cc ('k') | ppapi/thunk/interfaces_ppb_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698