| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 std::string postdata2("data"); | 368 std::string postdata2("data"); |
| 369 request.AppendDataToBody(postdata2.data(), postdata2.length()); | 369 request.AppendDataToBody(postdata2.data(), postdata2.length()); |
| 370 return LoadAndCompareBody(request, postdata1 + postdata2); | 370 return LoadAndCompareBody(request, postdata1 + postdata2); |
| 371 } | 371 } |
| 372 | 372 |
| 373 std::string TestURLLoader::TestEmptyDataPOST() { | 373 std::string TestURLLoader::TestEmptyDataPOST() { |
| 374 pp::URLRequestInfo request(instance_); | 374 pp::URLRequestInfo request(instance_); |
| 375 request.SetURL("/echo"); | 375 request.SetURL("/echo"); |
| 376 request.SetMethod("POST"); | 376 request.SetMethod("POST"); |
| 377 request.AppendDataToBody("", 0); | 377 request.AppendDataToBody("", 0); |
| 378 return LoadAndCompareBody(request, ""); | 378 return LoadAndCompareBody(request, std::string()); |
| 379 } | 379 } |
| 380 | 380 |
| 381 std::string TestURLLoader::TestBinaryDataPOST() { | 381 std::string TestURLLoader::TestBinaryDataPOST() { |
| 382 pp::URLRequestInfo request(instance_); | 382 pp::URLRequestInfo request(instance_); |
| 383 request.SetURL("/echo"); | 383 request.SetURL("/echo"); |
| 384 request.SetMethod("POST"); | 384 request.SetMethod("POST"); |
| 385 const char postdata_chars[] = | 385 const char postdata_chars[] = |
| 386 "\x00\x01\x02\x03\x04\x05postdata\xfa\xfb\xfc\xfd\xfe\xff"; | 386 "\x00\x01\x02\x03\x04\x05postdata\xfa\xfb\xfc\xfd\xfe\xff"; |
| 387 std::string postdata(postdata_chars, | 387 std::string postdata(postdata_chars, |
| 388 sizeof(postdata_chars) / sizeof(postdata_chars[0])); | 388 sizeof(postdata_chars) / sizeof(postdata_chars[0])); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 551 |
| 552 PASS(); | 552 PASS(); |
| 553 } | 553 } |
| 554 | 554 |
| 555 std::string TestURLLoader::TestUntrustedHttpRequests() { | 555 std::string TestURLLoader::TestUntrustedHttpRequests() { |
| 556 // HTTP methods are restricted only for untrusted loaders. Forbidden | 556 // HTTP methods are restricted only for untrusted loaders. Forbidden |
| 557 // methods are CONNECT, TRACE, and TRACK, and any string that is not a | 557 // methods are CONNECT, TRACE, and TRACK, and any string that is not a |
| 558 // valid token (containing special characters like CR, LF). | 558 // valid token (containing special characters like CR, LF). |
| 559 // http://www.w3.org/TR/XMLHttpRequest/ | 559 // http://www.w3.org/TR/XMLHttpRequest/ |
| 560 { | 560 { |
| 561 ASSERT_EQ(OpenUntrusted("cOnNeCt", ""), PP_ERROR_NOACCESS); | 561 ASSERT_EQ(OpenUntrusted("cOnNeCt", std::string()), PP_ERROR_NOACCESS); |
| 562 ASSERT_EQ(OpenUntrusted("tRaCk", ""), PP_ERROR_NOACCESS); | 562 ASSERT_EQ(OpenUntrusted("tRaCk", std::string()), PP_ERROR_NOACCESS); |
| 563 ASSERT_EQ(OpenUntrusted("tRaCe", ""), PP_ERROR_NOACCESS); | 563 ASSERT_EQ(OpenUntrusted("tRaCe", std::string()), PP_ERROR_NOACCESS); |
| 564 ASSERT_EQ(OpenUntrusted("POST\x0d\x0ax-csrf-token:\x20test1234", ""), | 564 ASSERT_EQ( |
| 565 PP_ERROR_NOACCESS); | 565 OpenUntrusted("POST\x0d\x0ax-csrf-token:\x20test1234", std::string()), |
| 566 PP_ERROR_NOACCESS); |
| 566 } | 567 } |
| 567 // HTTP methods are restricted only for untrusted loaders. Try all headers | 568 // HTTP methods are restricted only for untrusted loaders. Try all headers |
| 568 // that are forbidden by http://www.w3.org/TR/XMLHttpRequest/. | 569 // that are forbidden by http://www.w3.org/TR/XMLHttpRequest/. |
| 569 { | 570 { |
| 570 ASSERT_EQ(OpenUntrusted("GET", "Accept-Charset:\n"), PP_ERROR_NOACCESS); | 571 ASSERT_EQ(OpenUntrusted("GET", "Accept-Charset:\n"), PP_ERROR_NOACCESS); |
| 571 ASSERT_EQ(OpenUntrusted("GET", "Accept-Encoding:\n"), PP_ERROR_NOACCESS); | 572 ASSERT_EQ(OpenUntrusted("GET", "Accept-Encoding:\n"), PP_ERROR_NOACCESS); |
| 572 ASSERT_EQ(OpenUntrusted("GET", "Connection:\n"), PP_ERROR_NOACCESS); | 573 ASSERT_EQ(OpenUntrusted("GET", "Connection:\n"), PP_ERROR_NOACCESS); |
| 573 ASSERT_EQ(OpenUntrusted("GET", "Content-Length:\n"), PP_ERROR_NOACCESS); | 574 ASSERT_EQ(OpenUntrusted("GET", "Content-Length:\n"), PP_ERROR_NOACCESS); |
| 574 ASSERT_EQ(OpenUntrusted("GET", "Cookie:\n"), PP_ERROR_NOACCESS); | 575 ASSERT_EQ(OpenUntrusted("GET", "Cookie:\n"), PP_ERROR_NOACCESS); |
| 575 ASSERT_EQ(OpenUntrusted("GET", "Cookie2:\n"), PP_ERROR_NOACCESS); | 576 ASSERT_EQ(OpenUntrusted("GET", "Cookie2:\n"), PP_ERROR_NOACCESS); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 return ReportError( | 613 return ReportError( |
| 613 "Untrusted request with content-transfer-encoding restriction", rv); | 614 "Untrusted request with content-transfer-encoding restriction", rv); |
| 614 } | 615 } |
| 615 | 616 |
| 616 PASS(); | 617 PASS(); |
| 617 } | 618 } |
| 618 | 619 |
| 619 std::string TestURLLoader::TestTrustedHttpRequests() { | 620 std::string TestURLLoader::TestTrustedHttpRequests() { |
| 620 // Trusted requests can use restricted methods. | 621 // Trusted requests can use restricted methods. |
| 621 { | 622 { |
| 622 ASSERT_EQ(OpenTrusted("cOnNeCt", ""), PP_OK); | 623 ASSERT_EQ(OpenTrusted("cOnNeCt", std::string()), PP_OK); |
| 623 ASSERT_EQ(OpenTrusted("tRaCk", ""), PP_OK); | 624 ASSERT_EQ(OpenTrusted("tRaCk", std::string()), PP_OK); |
| 624 ASSERT_EQ(OpenTrusted("tRaCe", ""), PP_OK); | 625 ASSERT_EQ(OpenTrusted("tRaCe", std::string()), PP_OK); |
| 625 } | 626 } |
| 626 // Trusted requests can use restricted headers. | 627 // Trusted requests can use restricted headers. |
| 627 { | 628 { |
| 628 ASSERT_EQ(OpenTrusted("GET", "Accept-Charset:\n"), PP_OK); | 629 ASSERT_EQ(OpenTrusted("GET", "Accept-Charset:\n"), PP_OK); |
| 629 ASSERT_EQ(OpenTrusted("GET", "Accept-Encoding:\n"), PP_OK); | 630 ASSERT_EQ(OpenTrusted("GET", "Accept-Encoding:\n"), PP_OK); |
| 630 ASSERT_EQ(OpenTrusted("GET", "Connection:\n"), PP_OK); | 631 ASSERT_EQ(OpenTrusted("GET", "Connection:\n"), PP_OK); |
| 631 ASSERT_EQ(OpenTrusted("GET", "Content-Length:\n"), PP_OK); | 632 ASSERT_EQ(OpenTrusted("GET", "Content-Length:\n"), PP_OK); |
| 632 ASSERT_EQ(OpenTrusted("GET", "Cookie:\n"), PP_OK); | 633 ASSERT_EQ(OpenTrusted("GET", "Cookie:\n"), PP_OK); |
| 633 ASSERT_EQ(OpenTrusted("GET", "Cookie2:\n"), PP_OK); | 634 ASSERT_EQ(OpenTrusted("GET", "Cookie2:\n"), PP_OK); |
| 634 ASSERT_EQ(OpenTrusted( | 635 ASSERT_EQ(OpenTrusted( |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 if (rv != PP_ERROR_FAILED) { | 839 if (rv != PP_ERROR_FAILED) { |
| 839 return ReportError("The lower buffer value was higher than the upper but " | 840 return ReportError("The lower buffer value was higher than the upper but " |
| 840 "the URLLoader did not fail.", rv); | 841 "the URLLoader did not fail.", rv); |
| 841 } | 842 } |
| 842 | 843 |
| 843 PASS(); | 844 PASS(); |
| 844 } | 845 } |
| 845 | 846 |
| 846 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close | 847 // TODO(viettrungluu): Add tests for Get{Upload,Download}Progress, Close |
| 847 // (including abort tests if applicable). | 848 // (including abort tests if applicable). |
| OLD | NEW |