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 #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 19 matching lines...) Expand all Loading... |
30 namespace { | 30 namespace { |
31 | 31 |
32 int32_t WriteEntireBuffer(PP_Instance instance, | 32 int32_t WriteEntireBuffer(PP_Instance instance, |
33 pp::FileIO* file_io, | 33 pp::FileIO* file_io, |
34 int32_t offset, | 34 int32_t offset, |
35 const std::string& data, | 35 const std::string& data, |
36 CallbackType callback_type) { | 36 CallbackType callback_type) { |
37 TestCompletionCallback callback(instance, callback_type); | 37 TestCompletionCallback callback(instance, callback_type); |
38 int32_t write_offset = offset; | 38 int32_t write_offset = offset; |
39 const char* buf = data.c_str(); | 39 const char* buf = data.c_str(); |
40 int32_t size = data.size(); | 40 int32_t size = static_cast<int32_t>(data.size()); |
41 | 41 |
42 while (write_offset < offset + size) { | 42 while (write_offset < offset + size) { |
43 callback.WaitForResult(file_io->Write(write_offset, | 43 callback.WaitForResult(file_io->Write(write_offset, |
44 &buf[write_offset - offset], | 44 &buf[write_offset - offset], |
45 size - write_offset + offset, | 45 size - write_offset + offset, |
46 callback.GetCallback())); | 46 callback.GetCallback())); |
47 if (callback.result() < 0) | 47 if (callback.result() < 0) |
48 return callback.result(); | 48 return callback.result(); |
49 if (callback.result() == 0) | 49 if (callback.result() == 0) |
50 return PP_ERROR_FAILED; | 50 return PP_ERROR_FAILED; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 pp::URLRequestInfo request(instance_); | 336 pp::URLRequestInfo request(instance_); |
337 request.SetURL("test_url_loader_data/hello.txt"); | 337 request.SetURL("test_url_loader_data/hello.txt"); |
338 return LoadAndCompareBody(request, "hello\n"); | 338 return LoadAndCompareBody(request, "hello\n"); |
339 } | 339 } |
340 | 340 |
341 std::string TestURLLoader::TestBasicPOST() { | 341 std::string TestURLLoader::TestBasicPOST() { |
342 pp::URLRequestInfo request(instance_); | 342 pp::URLRequestInfo request(instance_); |
343 request.SetURL("/echo"); | 343 request.SetURL("/echo"); |
344 request.SetMethod("POST"); | 344 request.SetMethod("POST"); |
345 std::string postdata("postdata"); | 345 std::string postdata("postdata"); |
346 request.AppendDataToBody(postdata.data(), postdata.length()); | 346 request.AppendDataToBody(postdata.data(), |
| 347 static_cast<uint32_t>(postdata.length())); |
347 return LoadAndCompareBody(request, postdata); | 348 return LoadAndCompareBody(request, postdata); |
348 } | 349 } |
349 | 350 |
350 std::string TestURLLoader::TestBasicFilePOST() { | 351 std::string TestURLLoader::TestBasicFilePOST() { |
351 std::string message; | 352 std::string message; |
352 | 353 |
353 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 354 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
354 int32_t rv = OpenFileSystem(&file_system, &message); | 355 int32_t rv = OpenFileSystem(&file_system, &message); |
355 if (rv != PP_OK) | 356 if (rv != PP_OK) |
356 return ReportError(message.c_str(), rv); | 357 return ReportError(message.c_str(), rv); |
(...skipping 30 matching lines...) Expand all Loading... |
387 request.SetMethod("POST"); | 388 request.SetMethod("POST"); |
388 request.AppendFileRangeToBody(file_ref, 4, 12, 0); | 389 request.AppendFileRangeToBody(file_ref, 4, 12, 0); |
389 return LoadAndCompareBody(request, postdata.substr(4, 12)); | 390 return LoadAndCompareBody(request, postdata.substr(4, 12)); |
390 } | 391 } |
391 | 392 |
392 std::string TestURLLoader::TestCompoundBodyPOST() { | 393 std::string TestURLLoader::TestCompoundBodyPOST() { |
393 pp::URLRequestInfo request(instance_); | 394 pp::URLRequestInfo request(instance_); |
394 request.SetURL("/echo"); | 395 request.SetURL("/echo"); |
395 request.SetMethod("POST"); | 396 request.SetMethod("POST"); |
396 std::string postdata1("post"); | 397 std::string postdata1("post"); |
397 request.AppendDataToBody(postdata1.data(), postdata1.length()); | 398 request.AppendDataToBody(postdata1.data(), |
| 399 static_cast<uint32_t>(postdata1.length())); |
398 std::string postdata2("data"); | 400 std::string postdata2("data"); |
399 request.AppendDataToBody(postdata2.data(), postdata2.length()); | 401 request.AppendDataToBody(postdata2.data(), |
| 402 static_cast<uint32_t>(postdata2.length())); |
400 return LoadAndCompareBody(request, postdata1 + postdata2); | 403 return LoadAndCompareBody(request, postdata1 + postdata2); |
401 } | 404 } |
402 | 405 |
403 std::string TestURLLoader::TestEmptyDataPOST() { | 406 std::string TestURLLoader::TestEmptyDataPOST() { |
404 pp::URLRequestInfo request(instance_); | 407 pp::URLRequestInfo request(instance_); |
405 request.SetURL("/echo"); | 408 request.SetURL("/echo"); |
406 request.SetMethod("POST"); | 409 request.SetMethod("POST"); |
407 request.AppendDataToBody("", 0); | 410 request.AppendDataToBody("", 0); |
408 return LoadAndCompareBody(request, std::string()); | 411 return LoadAndCompareBody(request, std::string()); |
409 } | 412 } |
410 | 413 |
411 std::string TestURLLoader::TestBinaryDataPOST() { | 414 std::string TestURLLoader::TestBinaryDataPOST() { |
412 pp::URLRequestInfo request(instance_); | 415 pp::URLRequestInfo request(instance_); |
413 request.SetURL("/echo"); | 416 request.SetURL("/echo"); |
414 request.SetMethod("POST"); | 417 request.SetMethod("POST"); |
415 const char postdata_chars[] = | 418 const char postdata_chars[] = |
416 "\x00\x01\x02\x03\x04\x05postdata\xfa\xfb\xfc\xfd\xfe\xff"; | 419 "\x00\x01\x02\x03\x04\x05postdata\xfa\xfb\xfc\xfd\xfe\xff"; |
417 std::string postdata(postdata_chars, | 420 std::string postdata(postdata_chars, |
418 sizeof(postdata_chars) / sizeof(postdata_chars[0])); | 421 sizeof(postdata_chars) / sizeof(postdata_chars[0])); |
419 request.AppendDataToBody(postdata.data(), postdata.length()); | 422 request.AppendDataToBody(postdata.data(), |
| 423 static_cast<uint32_t>(postdata.length())); |
420 return LoadAndCompareBody(request, postdata); | 424 return LoadAndCompareBody(request, postdata); |
421 } | 425 } |
422 | 426 |
423 std::string TestURLLoader::TestCustomRequestHeader() { | 427 std::string TestURLLoader::TestCustomRequestHeader() { |
424 pp::URLRequestInfo request(instance_); | 428 pp::URLRequestInfo request(instance_); |
425 request.SetURL("/echoheader?Foo"); | 429 request.SetURL("/echoheader?Foo"); |
426 request.SetHeaders("Foo: 1"); | 430 request.SetHeaders("Foo: 1"); |
427 return LoadAndCompareBody(request, "1"); | 431 return LoadAndCompareBody(request, "1"); |
428 } | 432 } |
429 | 433 |
430 std::string TestURLLoader::TestFailsBogusContentLength() { | 434 std::string TestURLLoader::TestFailsBogusContentLength() { |
431 pp::URLRequestInfo request(instance_); | 435 pp::URLRequestInfo request(instance_); |
432 request.SetURL("/echo"); | 436 request.SetURL("/echo"); |
433 request.SetMethod("POST"); | 437 request.SetMethod("POST"); |
434 request.SetHeaders("Content-Length: 400"); | 438 request.SetHeaders("Content-Length: 400"); |
435 std::string postdata("postdata"); | 439 std::string postdata("postdata"); |
436 request.AppendDataToBody(postdata.data(), postdata.length()); | 440 request.AppendDataToBody(postdata.data(), |
| 441 static_cast<uint32_t>(postdata.length())); |
437 | 442 |
438 int32_t rv; | 443 int32_t rv; |
439 rv = OpenUntrusted(request); | 444 rv = OpenUntrusted(request); |
440 if (rv != PP_ERROR_NOACCESS) | 445 if (rv != PP_ERROR_NOACCESS) |
441 return ReportError( | 446 return ReportError( |
442 "Untrusted request with bogus Content-Length restriction", rv); | 447 "Untrusted request with bogus Content-Length restriction", rv); |
443 | 448 |
444 PASS(); | 449 PASS(); |
445 } | 450 } |
446 | 451 |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 std::string TestURLLoader::TestXRequestedWithHeader() { | 873 std::string TestURLLoader::TestXRequestedWithHeader() { |
869 pp::URLRequestInfo request(instance_); | 874 pp::URLRequestInfo request(instance_); |
870 request.SetURL("/echoheader?X-Requested-With"); | 875 request.SetURL("/echoheader?X-Requested-With"); |
871 // The name and version of the plugin is set from the command-line (see | 876 // The name and version of the plugin is set from the command-line (see |
872 // chrome/test/ppapi/ppapi_test.cc. | 877 // chrome/test/ppapi/ppapi_test.cc. |
873 return LoadAndCompareBody(request, "PPAPITests/1.2.3"); | 878 return LoadAndCompareBody(request, "PPAPITests/1.2.3"); |
874 } | 879 } |
875 | 880 |
876 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close | 881 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close |
877 // (including abort tests if applicable). | 882 // (including abort tests if applicable). |
OLD | NEW |