| 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 25 matching lines...) Expand all Loading... |
| 36 bool TestURLLoader::Init() { | 36 bool TestURLLoader::Init() { |
| 37 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted_Dev*>( | 37 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted_Dev*>( |
| 38 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_DEV_INTERFACE)); | 38 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_DEV_INTERFACE)); |
| 39 if (!file_io_trusted_interface_) { | 39 if (!file_io_trusted_interface_) { |
| 40 instance_->AppendError("FileIOTrusted interface not available"); | 40 instance_->AppendError("FileIOTrusted interface not available"); |
| 41 } | 41 } |
| 42 return InitTestingInterface() && EnsureRunningOverHTTP(); | 42 return InitTestingInterface() && EnsureRunningOverHTTP(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void TestURLLoader::RunTest() { | 45 void TestURLLoader::RunTest() { |
| 46 RUN_TEST(BasicGET); | 46 RUN_ASYNC_TEST(BasicGET); |
| 47 RUN_TEST(BasicPOST); | 47 RUN_ASYNC_TEST(BasicPOST); |
| 48 RUN_TEST(CompoundBodyPOST); | 48 RUN_ASYNC_TEST(CompoundBodyPOST); |
| 49 RUN_TEST(EmptyDataPOST); | 49 RUN_ASYNC_TEST(EmptyDataPOST); |
| 50 RUN_TEST(BinaryDataPOST); | 50 RUN_ASYNC_TEST(BinaryDataPOST); |
| 51 RUN_TEST(CustomRequestHeader); | 51 RUN_ASYNC_TEST(CustomRequestHeader); |
| 52 RUN_TEST(IgnoresBogusContentLength); | 52 RUN_ASYNC_TEST(IgnoresBogusContentLength); |
| 53 RUN_TEST(SameOriginRestriction); | 53 RUN_ASYNC_TEST(SameOriginRestriction); |
| 54 RUN_TEST(CrossOriginRequest); | 54 RUN_ASYNC_TEST(CrossOriginRequest); |
| 55 RUN_TEST(StreamToFile); | 55 RUN_ASYNC_TEST(StreamToFile); |
| 56 RUN_TEST(AuditURLRedirect); | 56 RUN_ASYNC_TEST(AuditURLRedirect); |
| 57 RUN_TEST(AbortCalls); | 57 RUN_ASYNC_TEST(AbortCalls); |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::string TestURLLoader::ReadEntireFile(pp::FileIO_Dev* file_io, | 60 std::string TestURLLoader::ReadEntireFile(pp::FileIO_Dev* file_io, |
| 61 std::string* data) { | 61 std::string* data) { |
| 62 TestCompletionCallback callback(instance_->pp_instance()); | 62 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 63 char buf[256]; | 63 char buf[256]; |
| 64 int64_t offset = 0; | 64 int64_t offset = 0; |
| 65 | 65 |
| 66 for (;;) { | 66 for (;;) { |
| 67 int32_t rv = file_io->Read(offset, buf, sizeof(buf), callback); | 67 int32_t rv = file_io->Read(offset, buf, sizeof(buf), callback); |
| 68 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 69 return ReportError("FileIO::Read force_async", rv); |
| 68 if (rv == PP_OK_COMPLETIONPENDING) | 70 if (rv == PP_OK_COMPLETIONPENDING) |
| 69 rv = callback.WaitForResult(); | 71 rv = callback.WaitForResult(); |
| 70 if (rv < 0) | 72 if (rv < 0) |
| 71 return ReportError("FileIO::Read", rv); | 73 return ReportError("FileIO::Read", rv); |
| 72 if (rv == 0) | 74 if (rv == 0) |
| 73 break; | 75 break; |
| 74 offset += rv; | 76 offset += rv; |
| 75 data->append(buf, rv); | 77 data->append(buf, rv); |
| 76 } | 78 } |
| 77 | 79 |
| 78 PASS(); | 80 PASS(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 std::string TestURLLoader::ReadEntireResponseBody(pp::URLLoader* loader, | 83 std::string TestURLLoader::ReadEntireResponseBody(pp::URLLoader* loader, |
| 82 std::string* body) { | 84 std::string* body) { |
| 83 TestCompletionCallback callback(instance_->pp_instance()); | 85 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 84 char buf[2]; // Small so that multiple reads are needed. | 86 char buf[2]; // Small so that multiple reads are needed. |
| 85 | 87 |
| 86 for (;;) { | 88 for (;;) { |
| 87 int32_t rv = loader->ReadResponseBody(buf, sizeof(buf), callback); | 89 int32_t rv = loader->ReadResponseBody(buf, sizeof(buf), callback); |
| 90 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 91 return ReportError("URLLoader::ReadResponseBody force_async", rv); |
| 88 if (rv == PP_OK_COMPLETIONPENDING) | 92 if (rv == PP_OK_COMPLETIONPENDING) |
| 89 rv = callback.WaitForResult(); | 93 rv = callback.WaitForResult(); |
| 90 if (rv < 0) | 94 if (rv < 0) |
| 91 return ReportError("URLLoader::ReadResponseBody", rv); | 95 return ReportError("URLLoader::ReadResponseBody", rv); |
| 92 if (rv == 0) | 96 if (rv == 0) |
| 93 break; | 97 break; |
| 94 body->append(buf, rv); | 98 body->append(buf, rv); |
| 95 } | 99 } |
| 96 | 100 |
| 97 PASS(); | 101 PASS(); |
| 98 } | 102 } |
| 99 | 103 |
| 100 std::string TestURLLoader::LoadAndCompareBody( | 104 std::string TestURLLoader::LoadAndCompareBody( |
| 101 const pp::URLRequestInfo& request, | 105 const pp::URLRequestInfo& request, |
| 102 const std::string& expected_body) { | 106 const std::string& expected_body) { |
| 103 TestCompletionCallback callback(instance_->pp_instance()); | 107 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 104 | 108 |
| 105 pp::URLLoader loader(*instance_); | 109 pp::URLLoader loader(*instance_); |
| 106 int32_t rv = loader.Open(request, callback); | 110 int32_t rv = loader.Open(request, callback); |
| 111 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 112 return ReportError("URLLoader::Open force_async", rv); |
| 107 if (rv == PP_OK_COMPLETIONPENDING) | 113 if (rv == PP_OK_COMPLETIONPENDING) |
| 108 rv = callback.WaitForResult(); | 114 rv = callback.WaitForResult(); |
| 109 if (rv != PP_OK) | 115 if (rv != PP_OK) |
| 110 return ReportError("URLLoader::Open", rv); | 116 return ReportError("URLLoader::Open", rv); |
| 111 | 117 |
| 112 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | 118 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 113 if (response_info.is_null()) | 119 if (response_info.is_null()) |
| 114 return "URLLoader::GetResponseInfo returned null"; | 120 return "URLLoader::GetResponseInfo returned null"; |
| 115 int32_t status_code = response_info.GetStatusCode(); | 121 int32_t status_code = response_info.GetStatusCode(); |
| 116 if (status_code != 200) | 122 if (status_code != 200) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 std::string postdata("postdata"); | 196 std::string postdata("postdata"); |
| 191 request.AppendDataToBody(postdata.data(), postdata.length()); | 197 request.AppendDataToBody(postdata.data(), postdata.length()); |
| 192 return LoadAndCompareBody(request, postdata); | 198 return LoadAndCompareBody(request, postdata); |
| 193 } | 199 } |
| 194 | 200 |
| 195 std::string TestURLLoader::TestStreamToFile() { | 201 std::string TestURLLoader::TestStreamToFile() { |
| 196 pp::URLRequestInfo request(instance_); | 202 pp::URLRequestInfo request(instance_); |
| 197 request.SetURL("test_url_loader_data/hello.txt"); | 203 request.SetURL("test_url_loader_data/hello.txt"); |
| 198 request.SetStreamToFile(true); | 204 request.SetStreamToFile(true); |
| 199 | 205 |
| 200 TestCompletionCallback callback(instance_->pp_instance()); | 206 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 201 | 207 |
| 202 pp::URLLoader loader(*instance_); | 208 pp::URLLoader loader(*instance_); |
| 203 int32_t rv = loader.Open(request, callback); | 209 int32_t rv = loader.Open(request, callback); |
| 210 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 211 return ReportError("URLLoader::Open force_async", rv); |
| 204 if (rv == PP_OK_COMPLETIONPENDING) | 212 if (rv == PP_OK_COMPLETIONPENDING) |
| 205 rv = callback.WaitForResult(); | 213 rv = callback.WaitForResult(); |
| 206 if (rv != PP_OK) | 214 if (rv != PP_OK) |
| 207 return ReportError("URLLoader::Open", rv); | 215 return ReportError("URLLoader::Open", rv); |
| 208 | 216 |
| 209 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | 217 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 210 if (response_info.is_null()) | 218 if (response_info.is_null()) |
| 211 return "URLLoader::GetResponseInfo returned null"; | 219 return "URLLoader::GetResponseInfo returned null"; |
| 212 int32_t status_code = response_info.GetStatusCode(); | 220 int32_t status_code = response_info.GetStatusCode(); |
| 213 if (status_code != 200) | 221 if (status_code != 200) |
| 214 return "Unexpected HTTP status code"; | 222 return "Unexpected HTTP status code"; |
| 215 | 223 |
| 216 pp::FileRef_Dev body(response_info.GetBodyAsFileRef()); | 224 pp::FileRef_Dev body(response_info.GetBodyAsFileRef()); |
| 217 if (body.is_null()) | 225 if (body.is_null()) |
| 218 return "URLResponseInfo::GetBody returned null"; | 226 return "URLResponseInfo::GetBody returned null"; |
| 219 | 227 |
| 220 rv = loader.FinishStreamingToFile(callback); | 228 rv = loader.FinishStreamingToFile(callback); |
| 229 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 230 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); |
| 221 if (rv == PP_OK_COMPLETIONPENDING) | 231 if (rv == PP_OK_COMPLETIONPENDING) |
| 222 rv = callback.WaitForResult(); | 232 rv = callback.WaitForResult(); |
| 223 if (rv != PP_OK) | 233 if (rv != PP_OK) |
| 224 return ReportError("URLLoader::FinishStreamingToFile", rv); | 234 return ReportError("URLLoader::FinishStreamingToFile", rv); |
| 225 | 235 |
| 226 pp::FileIO_Dev reader(instance_); | 236 pp::FileIO_Dev reader(instance_); |
| 227 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); | 237 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); |
| 238 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 239 return ReportError("FileIO::Open force_async", rv); |
| 228 if (rv == PP_OK_COMPLETIONPENDING) | 240 if (rv == PP_OK_COMPLETIONPENDING) |
| 229 rv = callback.WaitForResult(); | 241 rv = callback.WaitForResult(); |
| 230 if (rv != PP_OK) | 242 if (rv != PP_OK) |
| 231 return ReportError("FileIO::Open", rv); | 243 return ReportError("FileIO::Open", rv); |
| 232 | 244 |
| 233 std::string data; | 245 std::string data; |
| 234 std::string error = ReadEntireFile(&reader, &data); | 246 std::string error = ReadEntireFile(&reader, &data); |
| 235 if (!error.empty()) | 247 if (!error.empty()) |
| 236 return error; | 248 return error; |
| 237 | 249 |
| 238 std::string expected_body = "hello\n"; | 250 std::string expected_body = "hello\n"; |
| 239 if (data.size() != expected_body.size()) | 251 if (data.size() != expected_body.size()) |
| 240 return "ReadEntireFile returned unexpected content length"; | 252 return "ReadEntireFile returned unexpected content length"; |
| 241 if (data != expected_body) | 253 if (data != expected_body) |
| 242 return "ReadEntireFile returned unexpected content"; | 254 return "ReadEntireFile returned unexpected content"; |
| 243 | 255 |
| 244 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( | 256 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( |
| 245 reader.pp_resource()); | 257 reader.pp_resource()); |
| 246 if (file_descriptor < 0) | 258 if (file_descriptor < 0) |
| 247 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; | 259 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; |
| 248 | 260 |
| 249 PASS(); | 261 PASS(); |
| 250 } | 262 } |
| 251 | 263 |
| 252 std::string TestURLLoader::TestSameOriginRestriction() { | 264 std::string TestURLLoader::TestSameOriginRestriction() { |
| 253 pp::URLRequestInfo request(instance_); | 265 pp::URLRequestInfo request(instance_); |
| 254 request.SetURL("http://www.google.com/"); | 266 request.SetURL("http://www.google.com/"); |
| 255 | 267 |
| 256 TestCompletionCallback callback(instance_->pp_instance()); | 268 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 257 | 269 |
| 258 pp::URLLoader loader(*instance_); | 270 pp::URLLoader loader(*instance_); |
| 259 int32_t rv = loader.Open(request, callback); | 271 int32_t rv = loader.Open(request, callback); |
| 272 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 273 return ReportError("URLLoader::Open force_async", rv); |
| 260 if (rv == PP_OK_COMPLETIONPENDING) | 274 if (rv == PP_OK_COMPLETIONPENDING) |
| 261 rv = callback.WaitForResult(); | 275 rv = callback.WaitForResult(); |
| 262 | 276 |
| 263 // We expect a failure. | 277 // We expect a failure. |
| 264 if (rv != PP_ERROR_NOACCESS) { | 278 if (rv != PP_ERROR_NOACCESS) { |
| 265 if (rv == PP_OK) { | 279 if (rv == PP_OK) { |
| 266 return "URLLoader::Open() failed to block a cross-origin request."; | 280 return "URLLoader::Open() failed to block a cross-origin request."; |
| 267 } else { | 281 } else { |
| 268 return ReportError("URLLoader::Open()", rv); | 282 return ReportError("URLLoader::Open()", rv); |
| 269 } | 283 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 283 // Replace "127.0.0.1" with "localhost". | 297 // Replace "127.0.0.1" with "localhost". |
| 284 if (document_url.find("127.0.0.1") == std::string::npos) | 298 if (document_url.find("127.0.0.1") == std::string::npos) |
| 285 return "Can't construct a cross-origin URL"; | 299 return "Can't construct a cross-origin URL"; |
| 286 std::string cross_origin_url = document_url.replace( | 300 std::string cross_origin_url = document_url.replace( |
| 287 components.host.begin, components.host.len, "localhost"); | 301 components.host.begin, components.host.len, "localhost"); |
| 288 | 302 |
| 289 pp::URLRequestInfo request(instance_); | 303 pp::URLRequestInfo request(instance_); |
| 290 request.SetURL(cross_origin_url); | 304 request.SetURL(cross_origin_url); |
| 291 request.SetAllowCrossOriginRequests(true); | 305 request.SetAllowCrossOriginRequests(true); |
| 292 | 306 |
| 293 TestCompletionCallback callback(instance_->pp_instance()); | 307 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 294 | 308 |
| 295 pp::URLLoader loader(*instance_); | 309 pp::URLLoader loader(*instance_); |
| 296 int32_t rv = loader.Open(request, callback); | 310 int32_t rv = loader.Open(request, callback); |
| 297 if (rv == PP_ERROR_WOULDBLOCK) | 311 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 312 return ReportError("URLLoader::Open force_async", rv); |
| 313 if (rv == PP_OK_COMPLETIONPENDING) |
| 298 rv = callback.WaitForResult(); | 314 rv = callback.WaitForResult(); |
| 299 | 315 |
| 300 // We expect success since we allowed a cross-origin request. | 316 // We expect success since we allowed a cross-origin request. |
| 301 if (rv != PP_OK) | 317 if (rv != PP_OK) |
| 302 return ReportError("URLLoader::Open()", rv); | 318 return ReportError("URLLoader::Open()", rv); |
| 303 | 319 |
| 304 PASS(); | 320 PASS(); |
| 305 } | 321 } |
| 306 | 322 |
| 307 // This test should cause a redirect and ensure that the loader runs | 323 // This test should cause a redirect and ensure that the loader runs |
| 308 // the callback, rather than following the redirect. | 324 // the callback, rather than following the redirect. |
| 309 std::string TestURLLoader::TestAuditURLRedirect() { | 325 std::string TestURLLoader::TestAuditURLRedirect() { |
| 310 pp::URLRequestInfo request(instance_); | 326 pp::URLRequestInfo request(instance_); |
| 311 // This path will cause the server to return a 301 redirect. | 327 // This path will cause the server to return a 301 redirect. |
| 312 request.SetURL("/server-redirect?www.google.com"); | 328 request.SetURL("/server-redirect?www.google.com"); |
| 313 request.SetFollowRedirects(false); | 329 request.SetFollowRedirects(false); |
| 314 | 330 |
| 315 TestCompletionCallback callback(instance_->pp_instance()); | 331 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 316 | 332 |
| 317 pp::URLLoader loader(*instance_); | 333 pp::URLLoader loader(*instance_); |
| 318 int32_t rv = loader.Open(request, callback); | 334 int32_t rv = loader.Open(request, callback); |
| 335 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 336 return ReportError("URLLoader::Open force_async", rv); |
| 319 if (rv == PP_OK_COMPLETIONPENDING) | 337 if (rv == PP_OK_COMPLETIONPENDING) |
| 320 rv = callback.WaitForResult(); | 338 rv = callback.WaitForResult(); |
| 321 if (rv != PP_OK) | 339 if (rv != PP_OK) |
| 322 return ReportError("URLLoader::Open", rv); | 340 return ReportError("URLLoader::Open", rv); |
| 323 | 341 |
| 324 // Checks that the response indicates a redirect, and that the URL | 342 // Checks that the response indicates a redirect, and that the URL |
| 325 // is correct. | 343 // is correct. |
| 326 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | 344 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 327 if (response_info.is_null()) | 345 if (response_info.is_null()) |
| 328 return "URLLoader::GetResponseInfo returned null"; | 346 return "URLLoader::GetResponseInfo returned null"; |
| 329 int32_t status_code = response_info.GetStatusCode(); | 347 int32_t status_code = response_info.GetStatusCode(); |
| 330 if (status_code != 301) | 348 if (status_code != 301) |
| 331 return "Response status should be 301"; | 349 return "Response status should be 301"; |
| 332 if (response_info.GetRedirectURL().AsString() != "www.google.com") | 350 if (response_info.GetRedirectURL().AsString() != "www.google.com") |
| 333 return "Redirect URL should be www.google.com"; | 351 return "Redirect URL should be www.google.com"; |
| 334 | 352 |
| 335 PASS(); | 353 PASS(); |
| 336 } | 354 } |
| 337 | 355 |
| 338 std::string TestURLLoader::TestAbortCalls() { | 356 std::string TestURLLoader::TestAbortCalls() { |
| 339 pp::URLRequestInfo request(instance_); | 357 pp::URLRequestInfo request(instance_); |
| 340 request.SetURL("test_url_loader_data/hello.txt"); | 358 request.SetURL("test_url_loader_data/hello.txt"); |
| 341 | 359 |
| 342 TestCompletionCallback callback(instance_->pp_instance()); | 360 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 343 int32_t rv; | 361 int32_t rv; |
| 344 | 362 |
| 345 // Abort |Open()|. | 363 // Abort |Open()|. |
| 346 { | 364 { |
| 347 callback.reset_run_count(); | 365 callback.reset_run_count(); |
| 348 rv = pp::URLLoader(*instance_).Open(request, callback); | 366 rv = pp::URLLoader(*instance_).Open(request, callback); |
| 367 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 368 return ReportError("URLLoader::Open force_async", rv); |
| 349 if (callback.run_count() > 0) | 369 if (callback.run_count() > 0) |
| 350 return "URLLoader::Open ran callback synchronously."; | 370 return "URLLoader::Open ran callback synchronously."; |
| 351 if (rv == PP_OK_COMPLETIONPENDING) { | 371 if (rv == PP_OK_COMPLETIONPENDING) { |
| 352 rv = callback.WaitForResult(); | 372 rv = callback.WaitForResult(); |
| 353 if (rv != PP_ERROR_ABORTED) | 373 if (rv != PP_ERROR_ABORTED) |
| 354 return "URLLoader::Open not aborted."; | 374 return "URLLoader::Open not aborted."; |
| 355 } else if (rv != PP_OK) { | 375 } else if (rv != PP_OK) { |
| 356 return ReportError("URLLoader::Open", rv); | 376 return ReportError("URLLoader::Open", rv); |
| 357 } | 377 } |
| 358 } | 378 } |
| 359 | 379 |
| 360 // Abort |ReadResponseBody()|. | 380 // Abort |ReadResponseBody()|. |
| 361 { | 381 { |
| 362 char buf[2] = { 0 }; | 382 char buf[2] = { 0 }; |
| 363 { | 383 { |
| 364 pp::URLLoader loader(*instance_); | 384 pp::URLLoader loader(*instance_); |
| 365 rv = loader.Open(request, callback); | 385 rv = loader.Open(request, callback); |
| 386 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 387 return ReportError("URLLoader::Open force_async", rv); |
| 366 if (rv == PP_OK_COMPLETIONPENDING) | 388 if (rv == PP_OK_COMPLETIONPENDING) |
| 367 rv = callback.WaitForResult(); | 389 rv = callback.WaitForResult(); |
| 368 if (rv != PP_OK) | 390 if (rv != PP_OK) |
| 369 return ReportError("URLLoader::Open", rv); | 391 return ReportError("URLLoader::Open", rv); |
| 370 | 392 |
| 371 callback.reset_run_count(); | 393 callback.reset_run_count(); |
| 372 rv = loader.ReadResponseBody(buf, sizeof(buf), callback); | 394 rv = loader.ReadResponseBody(buf, sizeof(buf), callback); |
| 395 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 396 return ReportError("URLLoader::ReadResponseBody force_async", rv); |
| 373 } // Destroy |loader|. | 397 } // Destroy |loader|. |
| 374 if (rv == PP_OK_COMPLETIONPENDING) { | 398 if (rv == PP_OK_COMPLETIONPENDING) { |
| 375 // Save a copy and make sure |buf| doesn't get written to. | 399 // Save a copy and make sure |buf| doesn't get written to. |
| 376 char buf_copy[2]; | 400 char buf_copy[2]; |
| 377 memcpy(&buf_copy, &buf, sizeof(buf)); | 401 memcpy(&buf_copy, &buf, sizeof(buf)); |
| 378 rv = callback.WaitForResult(); | 402 rv = callback.WaitForResult(); |
| 379 if (rv != PP_ERROR_ABORTED) | 403 if (rv != PP_ERROR_ABORTED) |
| 380 return "URLLoader::ReadResponseBody not aborted."; | 404 return "URLLoader::ReadResponseBody not aborted."; |
| 381 if (memcmp(&buf_copy, &buf, sizeof(buf)) != 0) | 405 if (memcmp(&buf_copy, &buf, sizeof(buf)) != 0) |
| 382 return "URLLoader::ReadResponseBody wrote data after resource " | 406 return "URLLoader::ReadResponseBody wrote data after resource " |
| 383 "destruction."; | 407 "destruction."; |
| 384 } else if (rv != PP_OK) { | 408 } else if (rv != PP_OK) { |
| 385 return ReportError("URLLoader::ReadResponseBody", rv); | 409 return ReportError("URLLoader::ReadResponseBody", rv); |
| 386 } | 410 } |
| 387 } | 411 } |
| 388 | 412 |
| 389 // TODO(viettrungluu): More abort tests (but add basic tests first). | 413 // TODO(viettrungluu): More abort tests (but add basic tests first). |
| 390 // Also test that Close() aborts properly. crbug.com/69457 | 414 // Also test that Close() aborts properly. crbug.com/69457 |
| 391 | 415 |
| 392 PASS(); | 416 PASS(); |
| 393 } | 417 } |
| 394 | 418 |
| 395 // TODO(viettrungluu): Add tests for FollowRedirect, | 419 // TODO(viettrungluu): Add tests for FollowRedirect, |
| 396 // Get{Upload,Download}Progress, Close (including abort tests if applicable). | 420 // Get{Upload,Download}Progress, Close (including abort tests if applicable). |
| 397 // TODO(darin): Add a test for GrantUniversalAccess. | 421 // TODO(darin): Add a test for GrantUniversalAccess. |
| OLD | NEW |