OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Tests PPB_URLRequestInfo interface. | 5 // Tests PPB_URLRequestInfo interface. |
6 | 6 |
7 #include "ppapi/tests/test_url_request.h" | 7 #include "ppapi/tests/test_url_request.h" |
8 | 8 |
9 #include <string.h> | 9 #include <string.h> |
10 #include <string> | 10 #include <string> |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 267 } |
268 ppb_var_interface_->Release(test_data[i].var); | 268 ppb_var_interface_->Release(test_data[i].var); |
269 } | 269 } |
270 | 270 |
271 ppb_core_interface_->ReleaseResource(url_request); | 271 ppb_core_interface_->ReleaseResource(url_request); |
272 return error; // == PASS() if empty. | 272 return error; // == PASS() if empty. |
273 } | 273 } |
274 | 274 |
275 std::string TestURLRequest::LoadAndCompareBody( | 275 std::string TestURLRequest::LoadAndCompareBody( |
276 PP_Resource url_request, const std::string& expected_body) { | 276 PP_Resource url_request, const std::string& expected_body) { |
277 TestCompletionCallback test_callback(instance_->pp_instance(), true); | 277 TestCompletionCallback callback(instance_->pp_instance(), PP_REQUIRED); |
278 pp::CompletionCallback callback = | 278 callback.WaitForResult(ppb_url_loader_interface_->Open( |
279 static_cast<pp::CompletionCallback>(test_callback); | 279 url_loader_, url_request, |
280 int32_t result = ppb_url_loader_interface_->Open( | 280 callback.GetCallback().pp_completion_callback())); |
281 url_loader_, url_request, callback.pp_completion_callback()); | 281 CHECK_CALLBACK_BEHAVIOR(callback); |
282 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 282 ASSERT_EQ(PP_OK, callback.result()); |
283 result = test_callback.WaitForResult(); | |
284 ASSERT_EQ(PP_OK, result); | |
285 | 283 |
286 std::string error; | 284 std::string error; |
287 PP_Resource url_response = | 285 PP_Resource url_response = |
288 ppb_url_loader_interface_->GetResponseInfo(url_loader_); | 286 ppb_url_loader_interface_->GetResponseInfo(url_loader_); |
289 if (url_response == kInvalidResource) { | 287 if (url_response == kInvalidResource) { |
290 error = "PPB_URLLoader::GetResponseInfo() returned invalid resource"; | 288 error = "PPB_URLLoader::GetResponseInfo() returned invalid resource"; |
291 } else { | 289 } else { |
292 PP_Var status = ppb_url_response_interface_->GetProperty( | 290 PP_Var status = ppb_url_response_interface_->GetProperty( |
293 url_response, PP_URLRESPONSEPROPERTY_STATUSCODE); | 291 url_response, PP_URLRESPONSEPROPERTY_STATUSCODE); |
294 if (status.type != PP_VARTYPE_INT32 && status.value.as_int != 200) | 292 if (status.type != PP_VARTYPE_INT32 && status.value.as_int != 200) |
295 error = ReportError("PPB_URLLoader::Open() status", status.value.as_int); | 293 error = ReportError("PPB_URLLoader::Open() status", status.value.as_int); |
296 | 294 |
297 std::string actual_body; | 295 std::string actual_body; |
298 for (; error.empty();) { // Read the entire body in this loop. | 296 for (; error.empty();) { // Read the entire body in this loop. |
299 const size_t kBufferSize = 32; | 297 const size_t kBufferSize = 32; |
300 char buf[kBufferSize]; | 298 char buf[kBufferSize]; |
301 result = ppb_url_loader_interface_->ReadResponseBody( | 299 callback.WaitForResult(ppb_url_loader_interface_->ReadResponseBody( |
302 url_loader_, buf, kBufferSize, | 300 url_loader_, buf, kBufferSize, |
303 callback.pp_completion_callback()); | 301 callback.GetCallback().pp_completion_callback())); |
304 if (PP_OK_COMPLETIONPENDING != result) { | 302 if (callback.failed()) |
305 error = ReportError("PPB_URLLoader::ReadResponseBody()", result); | 303 error.assign(callback.errors()); |
| 304 else if (callback.result() < PP_OK) |
| 305 error.assign(ReportError("PPB_URLLoader::ReadResponseBody()", |
| 306 callback.result())); |
| 307 if (callback.result() <= PP_OK || callback.failed()) |
306 break; | 308 break; |
307 } | 309 actual_body.append(buf, callback.result()); |
308 result = test_callback.WaitForResult(); | |
309 if (result < PP_OK) | |
310 error = ReportError("PPB_URLLoader::ReadResponseBody()", result); | |
311 if (result <= PP_OK) | |
312 break; | |
313 actual_body.append(buf, result); | |
314 } | 310 } |
315 if (actual_body != expected_body) | 311 if (actual_body != expected_body) |
316 error = "PPB_URLLoader::ReadResponseBody() read unexpected response"; | 312 error = "PPB_URLLoader::ReadResponseBody() read unexpected response"; |
317 } | 313 } |
318 ppb_core_interface_->ReleaseResource(url_response); | 314 ppb_core_interface_->ReleaseResource(url_response); |
319 return error; | 315 return error; |
320 } | 316 } |
321 | 317 |
322 // Tests | 318 // Tests |
323 // PP_Bool AppendDataToBody( | 319 // PP_Bool AppendDataToBody( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 387 } |
392 } | 388 } |
393 for (int i = 0; i < num_created; i++) { | 389 for (int i = 0; i < num_created; i++) { |
394 ppb_core_interface_->ReleaseResource(url_request_info[i]); | 390 ppb_core_interface_->ReleaseResource(url_request_info[i]); |
395 if (PP_TRUE == | 391 if (PP_TRUE == |
396 ppb_url_request_interface_->IsURLRequestInfo(url_request_info[i])) | 392 ppb_url_request_interface_->IsURLRequestInfo(url_request_info[i])) |
397 error = "IsURLREquestInfo() succeeded after release"; | 393 error = "IsURLREquestInfo() succeeded after release"; |
398 } | 394 } |
399 return error; // == PASS() if empty. | 395 return error; // == PASS() if empty. |
400 } | 396 } |
OLD | NEW |