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

Unified Diff: ppapi/tests/test_url_loader.cc

Issue 7618039: PPB_URLRequestInfo::AppendFileToBody using sync ipc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/test_url_loader.h ('k') | webkit/plugins/ppapi/mock_plugin_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_url_loader.cc
diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc
index fd0cfd51175880d037c835768a9bf655e3d23b95..bcbef506082366cc41e5a052639c6e65992c3799 100644
--- a/ppapi/tests/test_url_loader.cc
+++ b/ppapi/tests/test_url_loader.cc
@@ -28,6 +28,34 @@
REGISTER_TEST_CASE(URLLoader);
+namespace {
+
+int32_t WriteEntireBuffer(PP_Instance instance,
+ pp::FileIO* file_io,
+ int32_t offset,
+ const std::string& data) {
+ TestCompletionCallback callback(instance);
+ int32_t write_offset = offset;
+ const char* buf = data.c_str();
+ int32_t size = data.size();
+
+ while (write_offset < offset + size) {
+ int32_t rv = file_io->Write(write_offset, &buf[write_offset - offset],
+ size - write_offset + offset, callback);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ if (rv < 0)
+ return rv;
+ if (rv == 0)
+ return PP_ERROR_FAILED;
+ write_offset += rv;
+ }
+
+ return PP_OK;
+}
+
+} // namespace
+
TestURLLoader::TestURLLoader(TestingInstance* instance)
: TestCase(instance),
file_io_trusted_interface_(NULL) {
@@ -45,6 +73,8 @@ bool TestURLLoader::Init() {
void TestURLLoader::RunTest() {
RUN_TEST_FORCEASYNC_AND_NOT(BasicGET);
RUN_TEST_FORCEASYNC_AND_NOT(BasicPOST);
+ RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST);
+ RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST);
RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST);
RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST);
RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST);
@@ -137,6 +167,54 @@ std::string TestURLLoader::LoadAndCompareBody(
PASS();
}
+int32_t TestURLLoader::OpenFileSystem(pp::FileSystem* file_system,
+ std::string* message) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ int32_t rv = file_system->Open(1024, callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING) {
+ message->assign("FileSystem::Open force_async");
+ return rv;
+ }
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK) {
+ message->assign("FileSystem::Open");
+ return rv;
+ }
+ return rv;
+}
+
+int32_t TestURLLoader::PrepareFileForPost(
+ const pp::FileRef& file_ref,
+ const std::string& data,
+ std::string* message) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ pp::FileIO file_io(instance_);
+ int32_t rv = file_io.Open(file_ref,
+ PP_FILEOPENFLAG_CREATE |
+ PP_FILEOPENFLAG_TRUNCATE |
+ PP_FILEOPENFLAG_WRITE,
+ callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING) {
+ message->assign("FileIO::Open force_async");
+ return rv;
+ }
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK) {
+ message->assign("FileIO::Open");
+ return rv;
+ }
+
+ rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, data);
+ if (rv != PP_OK) {
+ message->assign("FileIO::Write");
+ return rv;
+ }
+
+ return rv;
+}
+
std::string TestURLLoader::TestBasicGET() {
pp::URLRequestInfo request(instance_);
request.SetURL("test_url_loader_data/hello.txt");
@@ -152,6 +230,48 @@ std::string TestURLLoader::TestBasicPOST() {
return LoadAndCompareBody(request, postdata);
}
+std::string TestURLLoader::TestBasicFilePOST() {
+ std::string message;
+
+ pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
+ int32_t rv = OpenFileSystem(&file_system, &message);
+ if (rv != PP_OK)
+ return ReportError(message.c_str(), rv);
+
+ pp::FileRef file_ref(file_system, "/file_post_test");
+ std::string postdata("postdata");
+ rv = PrepareFileForPost(file_ref, postdata, &message);
+ if (rv != PP_OK)
+ return ReportError(message.c_str(), rv);
+
+ pp::URLRequestInfo request(instance_);
+ request.SetURL("/echo");
+ request.SetMethod("POST");
+ request.AppendFileToBody(file_ref, 0);
+ return LoadAndCompareBody(request, postdata);
+}
+
+std::string TestURLLoader::TestBasicFileRangePOST() {
+ std::string message;
+
+ pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
+ int32_t rv = OpenFileSystem(&file_system, &message);
+ if (rv != PP_OK)
+ return ReportError(message.c_str(), rv);
+
+ pp::FileRef file_ref(file_system, "/file_range_post_test");
+ std::string postdata("postdatapostdata");
+ rv = PrepareFileForPost(file_ref, postdata, &message);
+ if (rv != PP_OK)
+ return ReportError(message.c_str(), rv);
+
+ pp::URLRequestInfo request(instance_);
+ request.SetURL("/echo");
+ request.SetMethod("POST");
+ request.AppendFileRangeToBody(file_ref, 4, 12, 0);
+ return LoadAndCompareBody(request, postdata.substr(4, 12));
+}
+
std::string TestURLLoader::TestCompoundBodyPOST() {
pp::URLRequestInfo request(instance_);
request.SetURL("/echo");
« no previous file with comments | « ppapi/tests/test_url_loader.h ('k') | webkit/plugins/ppapi/mock_plugin_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698