Chromium Code Reviews| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 if (url_loader_trusted_interface_) | 99 if (url_loader_trusted_interface_) |
| 100 instance_->AppendError("URLLoaderTrusted interface is supported by NaCl"); | 100 instance_->AppendError("URLLoaderTrusted interface is supported by NaCl"); |
| 101 #endif | 101 #endif |
| 102 } | 102 } |
| 103 return EnsureRunningOverHTTP(); | 103 return EnsureRunningOverHTTP(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void TestURLLoader::RunTests(const std::string& filter) { | 106 void TestURLLoader::RunTests(const std::string& filter) { |
| 107 RUN_TEST_FORCEASYNC_AND_NOT(BasicGET, filter); | 107 RUN_TEST_FORCEASYNC_AND_NOT(BasicGET, filter); |
| 108 RUN_TEST_FORCEASYNC_AND_NOT(BasicPOST, filter); | 108 RUN_TEST_FORCEASYNC_AND_NOT(BasicPOST, filter); |
| 109 // FileIO interface is not yet supported by ppapi/proxy. | 109 RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter); |
| 110 if (!testing_interface_->IsOutOfProcess()) { | 110 RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter); |
| 111 RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter); | |
| 112 RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter); | |
| 113 } | |
| 114 RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter); | 111 RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter); |
| 115 RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter); | 112 RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter); |
| 116 RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter); | 113 RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter); |
| 117 RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter); | 114 RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter); |
| 118 RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter); | 115 RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter); |
| 119 // TODO(bbudge) Enable these tests for NaCl when we have a way to get | |
| 120 // the document URL. The PPAPI tests use PPB_URLUtil_Dev. | |
| 121 #if !(defined __native_client__) | |
| 122 RUN_TEST_FORCEASYNC_AND_NOT(SameOriginRestriction, filter); | |
| 123 // Cross origin requests require the 'test_case.html.mock-http-headers' | |
| 124 // file to be in the same directory as 'test_case.html', so that the test | |
| 125 // server returns CORS response headers. | |
| 126 RUN_TEST_FORCEASYNC_AND_NOT(CrossOriginRequest, filter); | |
| 127 #endif | |
| 128 RUN_TEST_FORCEASYNC_AND_NOT(JavascriptURLRestriction, filter); | |
| 129 RUN_TEST_FORCEASYNC_AND_NOT(MethodRestriction, filter); | |
| 130 RUN_TEST_FORCEASYNC_AND_NOT(HeaderRestriction, filter); | |
| 131 RUN_TEST_FORCEASYNC_AND_NOT(CustomReferrer, filter); | |
| 132 RUN_TEST_FORCEASYNC_AND_NOT(CustomContentTransferEncoding, filter); | |
| 133 RUN_TEST_FORCEASYNC_AND_NOT(StreamToFile, filter); | 116 RUN_TEST_FORCEASYNC_AND_NOT(StreamToFile, filter); |
| 117 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedSameOriginRestriction, filter); | |
| 118 RUN_TEST_FORCEASYNC_AND_NOT(TrustedSameOriginRestriction, filter); | |
| 119 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedCrossOriginRequest, filter); | |
| 120 RUN_TEST_FORCEASYNC_AND_NOT(TrustedCrossOriginRequest, filter); | |
| 121 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedJavascriptURLRestriction, filter); | |
| 122 RUN_TEST_FORCEASYNC_AND_NOT(TrustedJavascriptURLRestriction, filter); | |
| 123 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedMethodRestriction, filter); | |
| 124 RUN_TEST_FORCEASYNC_AND_NOT(TrustedMethodRestriction, filter); | |
| 125 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedHeaderRestriction, filter); | |
| 126 RUN_TEST_FORCEASYNC_AND_NOT(TrustedHeaderRestriction, filter); | |
| 127 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedCustomReferrer, filter); | |
| 128 RUN_TEST_FORCEASYNC_AND_NOT(TrustedCustomReferrer, filter); | |
| 129 RUN_TEST_FORCEASYNC_AND_NOT(UntrustedCustomContentTransferEncoding, filter); | |
| 130 RUN_TEST_FORCEASYNC_AND_NOT(TrustedCustomContentTransferEncoding, filter); | |
| 134 RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter); | 131 RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter); |
| 135 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter); | 132 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter); |
| 136 RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter); | 133 RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter); |
| 137 } | 134 } |
| 138 | 135 |
| 139 std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io, | 136 std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io, |
| 140 std::string* data) { | 137 std::string* data) { |
| 141 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 138 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 142 char buf[256]; | 139 char buf[256]; |
| 143 int64_t offset = 0; | 140 int64_t offset = 0; |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( | 503 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( |
| 507 reader.pp_resource()); | 504 reader.pp_resource()); |
| 508 if (file_descriptor < 0) | 505 if (file_descriptor < 0) |
| 509 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; | 506 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; |
| 510 #endif | 507 #endif |
| 511 } | 508 } |
| 512 } | 509 } |
| 513 PASS(); | 510 PASS(); |
| 514 } | 511 } |
| 515 | 512 |
| 516 // If a cross-origin request is not specified, the load should fail only for | 513 // Untrusted, unintended cross-origin requests should fail. |
| 517 // untrusted loaders. | 514 std::string TestURLLoader::TestUntrustedSameOriginRestriction() { |
| 518 std::string TestURLLoader::TestSameOriginRestriction() { | |
| 519 pp::URLRequestInfo request(instance_); | 515 pp::URLRequestInfo request(instance_); |
| 520 std::string cross_origin_url = GetReachableCrossOriginURL(); | 516 std::string cross_origin_url = GetReachableCrossOriginURL(); |
| 521 request.SetURL(cross_origin_url); | 517 request.SetURL(cross_origin_url); |
| 522 | 518 |
| 523 int32_t rv; | 519 int32_t rv = OpenUntrusted(request); |
| 524 rv = OpenUntrusted(request); | |
| 525 if (rv != PP_ERROR_NOACCESS) | 520 if (rv != PP_ERROR_NOACCESS) |
| 526 return ReportError( | 521 return ReportError( |
| 527 "Untrusted, unintended cross-origin request restriction", rv); | 522 "Untrusted, unintended cross-origin request restriction", rv); |
| 528 #if !(defined __native_client__) | |
| 529 rv = OpenTrusted(request); | |
| 530 if (rv != PP_OK) | |
| 531 return ReportError("Trusted cross-origin request", rv); | |
| 532 #endif | |
| 533 | 523 |
| 534 PASS(); | 524 PASS(); |
| 535 } | 525 } |
| 536 | 526 |
| 537 // If a cross-origin request is specified, and the URL is reachable, the load | 527 // Trusted, unintended cross-origin requests should succeed. |
| 538 // should succeed. | 528 std::string TestURLLoader::TestTrustedSameOriginRestriction() { |
| 539 std::string TestURLLoader::TestCrossOriginRequest() { | 529 pp::URLRequestInfo request(instance_); |
| 530 std::string cross_origin_url = GetReachableCrossOriginURL(); | |
| 531 request.SetURL(cross_origin_url); | |
| 532 | |
| 533 int32_t rv = OpenTrusted(request); | |
| 534 if (rv != PP_OK) | |
| 535 return ReportError("Trusted cross-origin request failed", rv); | |
| 536 | |
| 537 PASS(); | |
| 538 } | |
| 539 | |
| 540 // Untrusted, intended cross-origin requests should use CORS and succeed. | |
| 541 std::string TestURLLoader::TestUntrustedCrossOriginRequest() { | |
| 540 pp::URLRequestInfo request(instance_); | 542 pp::URLRequestInfo request(instance_); |
| 541 std::string cross_origin_url = GetReachableCrossOriginURL(); | 543 std::string cross_origin_url = GetReachableCrossOriginURL(); |
| 542 request.SetURL(cross_origin_url); | 544 request.SetURL(cross_origin_url); |
| 543 request.SetAllowCrossOriginRequests(true); | 545 request.SetAllowCrossOriginRequests(true); |
| 544 | 546 |
| 545 int32_t rv; | 547 int32_t rv = OpenUntrusted(request); |
| 546 rv = OpenUntrusted(request); | |
| 547 if (rv != PP_OK) | 548 if (rv != PP_OK) |
| 548 return ReportError( | 549 return ReportError( |
| 549 "Untrusted, intended cross-origin request", rv); | 550 "Untrusted, intended cross-origin request failed", rv); |
| 550 #if !(defined __native_client__) | |
| 551 rv = OpenTrusted(request); | |
| 552 if (rv != PP_OK) | |
| 553 return ReportError("Trusted cross-origin request", rv); | |
| 554 #endif | |
| 555 | 551 |
| 556 PASS(); | 552 PASS(); |
| 557 } | 553 } |
| 558 | 554 |
| 559 // Javascript URLs are only reachable by trusted loaders. | 555 // Trusted, intended cross-origin requests should use CORS and succeed. |
| 560 std::string TestURLLoader::TestJavascriptURLRestriction() { | 556 std::string TestURLLoader::TestTrustedCrossOriginRequest() { |
| 557 pp::URLRequestInfo request(instance_); | |
| 558 std::string cross_origin_url = GetReachableCrossOriginURL(); | |
| 559 request.SetURL(cross_origin_url); | |
| 560 request.SetAllowCrossOriginRequests(true); | |
| 561 | |
| 562 int32_t rv = OpenTrusted(request); | |
| 563 if (rv != PP_OK) | |
| 564 return ReportError("Trusted cross-origin request failed", rv); | |
| 565 | |
| 566 PASS(); | |
| 567 } | |
| 568 | |
| 569 // Untrusted Javascript URLs requests should fail. | |
| 570 std::string TestURLLoader::TestUntrustedJavascriptURLRestriction() { | |
| 561 pp::URLRequestInfo request(instance_); | 571 pp::URLRequestInfo request(instance_); |
| 562 request.SetURL("javascript:foo = bar"); | 572 request.SetURL("javascript:foo = bar"); |
| 563 | 573 |
| 564 int32_t rv; | 574 int32_t rv = OpenUntrusted(request); |
| 565 rv = OpenUntrusted(request); | |
| 566 if (rv != PP_ERROR_NOACCESS) | 575 if (rv != PP_ERROR_NOACCESS) |
| 567 return ReportError( | 576 return ReportError( |
| 568 "Untrusted Javascript URL request restriction", rv); | 577 "Untrusted Javascript URL request restriction failed", rv); |
| 569 #if !(defined __native_client__) | 578 |
| 579 PASS(); | |
| 580 } | |
| 581 | |
| 582 // Trusted Javascript URLs requests should succeed. | |
| 583 std::string TestURLLoader::TestTrustedJavascriptURLRestriction() { | |
| 584 pp::URLRequestInfo request(instance_); | |
| 585 request.SetURL("javascript:foo = bar"); | |
| 586 | |
| 570 // TODO(bbudge) Fix Javascript URLs for trusted loaders. | 587 // TODO(bbudge) Fix Javascript URLs for trusted loaders. |
| 571 // http://code.google.com/p/chromium/issues/detail?id=103062 | 588 // http://code.google.com/p/chromium/issues/detail?id=103062 |
| 572 // rv = OpenTrusted(request); | 589 // int32_t rv = OpenTrusted(request); |
|
dmichael (off chromium)
2011/12/02 20:28:33
Would it make sense to uncomment this but just mar
bbudge
2011/12/02 21:32:10
Yes. Done.
On 2011/12/02 20:28:33, dmichael wrote:
| |
| 573 // if (rv == PP_ERROR_NOACCESS) | 590 // if (rv == PP_ERROR_NOACCESS) |
| 574 // return ReportError( | 591 // return ReportError( |
| 575 // "Trusted Javascript URL request", rv); | 592 // "Trusted Javascript URL request", rv); |
| 576 #endif | |
| 577 | 593 |
| 578 PASS(); | 594 PASS(); |
| 579 } | 595 } |
| 580 | 596 |
| 581 // HTTP methods are restricted only for untrusted loaders. Forbidden | 597 // HTTP methods are restricted only for untrusted loaders. Forbidden |
| 582 // methods are CONNECT, TRACE, and TRACK, and any string that is not a valid | 598 // methods are CONNECT, TRACE, and TRACK, and any string that is not a valid |
| 583 // token (containing special characters like CR, LF). | 599 // token (containing special characters like CR, LF). |
| 584 // http://www.w3.org/TR/XMLHttpRequest/ | 600 // http://www.w3.org/TR/XMLHttpRequest/ |
| 585 std::string TestURLLoader::TestMethodRestriction() { | 601 std::string TestURLLoader::TestUntrustedMethodRestriction() { |
| 586 ASSERT_EQ(OpenUntrusted("cOnNeCt", ""), PP_ERROR_NOACCESS); | 602 ASSERT_EQ(OpenUntrusted("cOnNeCt", ""), PP_ERROR_NOACCESS); |
| 587 ASSERT_EQ(OpenUntrusted("tRaCk", ""), PP_ERROR_NOACCESS); | 603 ASSERT_EQ(OpenUntrusted("tRaCk", ""), PP_ERROR_NOACCESS); |
| 588 ASSERT_EQ(OpenUntrusted("tRaCe", ""), PP_ERROR_NOACCESS); | 604 ASSERT_EQ(OpenUntrusted("tRaCe", ""), PP_ERROR_NOACCESS); |
| 589 ASSERT_EQ(OpenUntrusted("POST\x0d\x0ax-csrf-token:\x20test1234", ""), | 605 ASSERT_EQ(OpenUntrusted("POST\x0d\x0ax-csrf-token:\x20test1234", ""), |
| 590 PP_ERROR_NOACCESS); | 606 PP_ERROR_NOACCESS); |
| 591 #if !(defined __native_client__) | 607 PASS(); |
| 608 } | |
| 609 | |
| 610 // Trusted requests can use restricted methods. | |
| 611 std::string TestURLLoader::TestTrustedMethodRestriction() { | |
| 592 ASSERT_EQ(OpenTrusted("cOnNeCt", ""), PP_OK); | 612 ASSERT_EQ(OpenTrusted("cOnNeCt", ""), PP_OK); |
| 593 ASSERT_EQ(OpenTrusted("tRaCk", ""), PP_OK); | 613 ASSERT_EQ(OpenTrusted("tRaCk", ""), PP_OK); |
| 594 ASSERT_EQ(OpenTrusted("tRaCe", ""), PP_OK); | 614 ASSERT_EQ(OpenTrusted("tRaCe", ""), PP_OK); |
| 595 #endif | |
| 596 | 615 |
| 597 PASS(); | 616 PASS(); |
| 598 } | 617 } |
| 599 | 618 |
| 600 // HTTP methods are restricted only for untrusted loaders. Try all headers | 619 // HTTP methods are restricted only for untrusted loaders. Try all headers |
| 601 // that are forbidden by http://www.w3.org/TR/XMLHttpRequest/. | 620 // that are forbidden by http://www.w3.org/TR/XMLHttpRequest/. |
| 602 std::string TestURLLoader::TestHeaderRestriction() { | 621 std::string TestURLLoader::TestUntrustedHeaderRestriction() { |
| 603 ASSERT_EQ(OpenUntrusted("GET", "Accept-Charset:\n"), PP_ERROR_NOACCESS); | 622 ASSERT_EQ(OpenUntrusted("GET", "Accept-Charset:\n"), PP_ERROR_NOACCESS); |
| 604 ASSERT_EQ(OpenUntrusted("GET", "Accept-Encoding:\n"), PP_ERROR_NOACCESS); | 623 ASSERT_EQ(OpenUntrusted("GET", "Accept-Encoding:\n"), PP_ERROR_NOACCESS); |
| 605 ASSERT_EQ(OpenUntrusted("GET", "Connection:\n"), PP_ERROR_NOACCESS); | 624 ASSERT_EQ(OpenUntrusted("GET", "Connection:\n"), PP_ERROR_NOACCESS); |
| 606 ASSERT_EQ(OpenUntrusted("GET", "Content-Length:\n"), PP_ERROR_NOACCESS); | 625 ASSERT_EQ(OpenUntrusted("GET", "Content-Length:\n"), PP_ERROR_NOACCESS); |
| 607 ASSERT_EQ(OpenUntrusted("GET", "Cookie:\n"), PP_ERROR_NOACCESS); | 626 ASSERT_EQ(OpenUntrusted("GET", "Cookie:\n"), PP_ERROR_NOACCESS); |
| 608 ASSERT_EQ(OpenUntrusted("GET", "Cookie2:\n"), PP_ERROR_NOACCESS); | 627 ASSERT_EQ(OpenUntrusted("GET", "Cookie2:\n"), PP_ERROR_NOACCESS); |
| 609 ASSERT_EQ(OpenUntrusted( | 628 ASSERT_EQ(OpenUntrusted( |
| 610 "GET", "Content-Transfer-Encoding:\n"), PP_ERROR_NOACCESS); | 629 "GET", "Content-Transfer-Encoding:\n"), PP_ERROR_NOACCESS); |
| 611 ASSERT_EQ(OpenUntrusted("GET", "Date:\n"), PP_ERROR_NOACCESS); | 630 ASSERT_EQ(OpenUntrusted("GET", "Date:\n"), PP_ERROR_NOACCESS); |
| 612 ASSERT_EQ(OpenUntrusted("GET", "Expect:\n"), PP_ERROR_NOACCESS); | 631 ASSERT_EQ(OpenUntrusted("GET", "Expect:\n"), PP_ERROR_NOACCESS); |
| 613 ASSERT_EQ(OpenUntrusted("GET", "Host:\n"), PP_ERROR_NOACCESS); | 632 ASSERT_EQ(OpenUntrusted("GET", "Host:\n"), PP_ERROR_NOACCESS); |
| 614 ASSERT_EQ(OpenUntrusted("GET", "Keep-Alive:\n"), PP_ERROR_NOACCESS); | 633 ASSERT_EQ(OpenUntrusted("GET", "Keep-Alive:\n"), PP_ERROR_NOACCESS); |
| 615 ASSERT_EQ(OpenUntrusted("GET", "Referer:\n"), PP_ERROR_NOACCESS); | 634 ASSERT_EQ(OpenUntrusted("GET", "Referer:\n"), PP_ERROR_NOACCESS); |
| 616 ASSERT_EQ(OpenUntrusted("GET", "TE:\n"), PP_ERROR_NOACCESS); | 635 ASSERT_EQ(OpenUntrusted("GET", "TE:\n"), PP_ERROR_NOACCESS); |
| 617 ASSERT_EQ(OpenUntrusted("GET", "Trailer:\n"), PP_ERROR_NOACCESS); | 636 ASSERT_EQ(OpenUntrusted("GET", "Trailer:\n"), PP_ERROR_NOACCESS); |
| 618 ASSERT_EQ(OpenUntrusted("GET", "Transfer-Encoding:\n"), PP_ERROR_NOACCESS); | 637 ASSERT_EQ(OpenUntrusted("GET", "Transfer-Encoding:\n"), PP_ERROR_NOACCESS); |
| 619 ASSERT_EQ(OpenUntrusted("GET", "Upgrade:\n"), PP_ERROR_NOACCESS); | 638 ASSERT_EQ(OpenUntrusted("GET", "Upgrade:\n"), PP_ERROR_NOACCESS); |
| 620 ASSERT_EQ(OpenUntrusted("GET", "User-Agent:\n"), PP_ERROR_NOACCESS); | 639 ASSERT_EQ(OpenUntrusted("GET", "User-Agent:\n"), PP_ERROR_NOACCESS); |
| 621 ASSERT_EQ(OpenUntrusted("GET", "Via:\n"), PP_ERROR_NOACCESS); | 640 ASSERT_EQ(OpenUntrusted("GET", "Via:\n"), PP_ERROR_NOACCESS); |
| 622 ASSERT_EQ(OpenUntrusted( | 641 ASSERT_EQ(OpenUntrusted( |
| 623 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), | 642 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), |
| 624 PP_ERROR_NOACCESS); | 643 PP_ERROR_NOACCESS); |
| 625 ASSERT_EQ(OpenUntrusted("GET", "Sec-foo:\n"), PP_ERROR_NOACCESS); | 644 ASSERT_EQ(OpenUntrusted("GET", "Sec-foo:\n"), PP_ERROR_NOACCESS); |
| 626 | 645 |
| 627 #if !(defined __native_client__) | 646 PASS(); |
| 647 } | |
| 648 | |
| 649 // Trusted requests can use restricted headers. | |
| 650 std::string TestURLLoader::TestTrustedHeaderRestriction() { | |
| 628 ASSERT_EQ(OpenTrusted("GET", "Accept-Charset:\n"), PP_OK); | 651 ASSERT_EQ(OpenTrusted("GET", "Accept-Charset:\n"), PP_OK); |
| 629 ASSERT_EQ(OpenTrusted("GET", "Accept-Encoding:\n"), PP_OK); | 652 ASSERT_EQ(OpenTrusted("GET", "Accept-Encoding:\n"), PP_OK); |
| 630 ASSERT_EQ(OpenTrusted("GET", "Connection:\n"), PP_OK); | 653 ASSERT_EQ(OpenTrusted("GET", "Connection:\n"), PP_OK); |
| 631 ASSERT_EQ(OpenTrusted("GET", "Content-Length:\n"), PP_OK); | 654 ASSERT_EQ(OpenTrusted("GET", "Content-Length:\n"), PP_OK); |
| 632 ASSERT_EQ(OpenTrusted("GET", "Cookie:\n"), PP_OK); | 655 ASSERT_EQ(OpenTrusted("GET", "Cookie:\n"), PP_OK); |
| 633 ASSERT_EQ(OpenTrusted("GET", "Cookie2:\n"), PP_OK); | 656 ASSERT_EQ(OpenTrusted("GET", "Cookie2:\n"), PP_OK); |
| 634 ASSERT_EQ(OpenTrusted( | 657 ASSERT_EQ(OpenTrusted( |
| 635 "GET", "Content-Transfer-Encoding:\n"), PP_OK); | 658 "GET", "Content-Transfer-Encoding:\n"), PP_OK); |
| 636 ASSERT_EQ(OpenTrusted("GET", "Date:\n"), PP_OK); | 659 ASSERT_EQ(OpenTrusted("GET", "Date:\n"), PP_OK); |
| 637 ASSERT_EQ(OpenTrusted("GET", "Expect:\n"), PP_OK); | 660 ASSERT_EQ(OpenTrusted("GET", "Expect:\n"), PP_OK); |
| 638 ASSERT_EQ(OpenTrusted("GET", "Host:\n"), PP_OK); | 661 ASSERT_EQ(OpenTrusted("GET", "Host:\n"), PP_OK); |
| 639 ASSERT_EQ(OpenTrusted("GET", "Keep-Alive:\n"), PP_OK); | 662 ASSERT_EQ(OpenTrusted("GET", "Keep-Alive:\n"), PP_OK); |
| 640 ASSERT_EQ(OpenTrusted("GET", "Referer:\n"), PP_OK); | 663 ASSERT_EQ(OpenTrusted("GET", "Referer:\n"), PP_OK); |
| 641 ASSERT_EQ(OpenTrusted("GET", "TE:\n"), PP_OK); | 664 ASSERT_EQ(OpenTrusted("GET", "TE:\n"), PP_OK); |
| 642 ASSERT_EQ(OpenTrusted("GET", "Trailer:\n"), PP_OK); | 665 ASSERT_EQ(OpenTrusted("GET", "Trailer:\n"), PP_OK); |
| 643 ASSERT_EQ(OpenTrusted("GET", "Transfer-Encoding:\n"), PP_OK); | 666 ASSERT_EQ(OpenTrusted("GET", "Transfer-Encoding:\n"), PP_OK); |
| 644 ASSERT_EQ(OpenTrusted("GET", "Upgrade:\n"), PP_OK); | 667 ASSERT_EQ(OpenTrusted("GET", "Upgrade:\n"), PP_OK); |
| 645 ASSERT_EQ(OpenTrusted("GET", "User-Agent:\n"), PP_OK); | 668 ASSERT_EQ(OpenTrusted("GET", "User-Agent:\n"), PP_OK); |
| 646 ASSERT_EQ(OpenTrusted("GET", "Via:\n"), PP_OK); | 669 ASSERT_EQ(OpenTrusted("GET", "Via:\n"), PP_OK); |
| 647 ASSERT_EQ(OpenTrusted( | 670 ASSERT_EQ(OpenTrusted( |
| 648 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), PP_OK); | 671 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), PP_OK); |
| 649 ASSERT_EQ(OpenTrusted("GET", "Sec-foo:\n"), PP_OK); | 672 ASSERT_EQ(OpenTrusted("GET", "Sec-foo:\n"), PP_OK); |
| 650 #endif | |
| 651 | 673 |
| 652 PASS(); | 674 PASS(); |
| 653 } | 675 } |
| 654 | 676 |
| 655 // Custom referrers are only allowed for trusted loaders. | 677 // Untrusted requests with custom referrer should fail. |
| 656 std::string TestURLLoader::TestCustomReferrer() { | 678 std::string TestURLLoader::TestUntrustedCustomReferrer() { |
| 657 pp::URLRequestInfo request(instance_); | 679 pp::URLRequestInfo request(instance_); |
| 658 request.SetCustomReferrerURL("http://www.google.com/"); | 680 request.SetCustomReferrerURL("http://www.google.com/"); |
| 659 | 681 |
| 660 int32_t rv; | 682 int32_t rv = OpenUntrusted(request); |
| 661 rv = OpenUntrusted(request); | |
| 662 if (rv != PP_ERROR_NOACCESS) | 683 if (rv != PP_ERROR_NOACCESS) |
| 663 return ReportError( | 684 return ReportError( |
| 664 "Untrusted request with custom referrer restriction", rv); | 685 "Untrusted request with custom referrer restriction", rv); |
| 665 #if !(defined __native_client__) | 686 |
| 666 rv = OpenTrusted(request); | |
| 667 if (rv != PP_OK) | |
| 668 return ReportError("Trusted request with custom referrer", rv); | |
| 669 #endif | |
| 670 PASS(); | 687 PASS(); |
| 671 } | 688 } |
| 672 | 689 |
| 673 // Custom transfer encodings are only allowed for trusted loaders. | 690 // Trusted requests with custom referrer should succeed. |
| 674 std::string TestURLLoader::TestCustomContentTransferEncoding() { | 691 std::string TestURLLoader::TestTrustedCustomReferrer() { |
| 692 pp::URLRequestInfo request(instance_); | |
| 693 request.SetCustomReferrerURL("http://www.google.com/"); | |
| 694 | |
| 695 int32_t rv = OpenTrusted(request); | |
| 696 if (rv != PP_OK) | |
| 697 return ReportError("Trusted request with custom referrer", rv); | |
| 698 | |
| 699 PASS(); | |
| 700 } | |
| 701 | |
| 702 // Untrusted requests with custom transfer encodings should fail. | |
| 703 std::string TestURLLoader::TestUntrustedCustomContentTransferEncoding() { | |
| 675 pp::URLRequestInfo request(instance_); | 704 pp::URLRequestInfo request(instance_); |
| 676 request.SetCustomContentTransferEncoding("foo"); | 705 request.SetCustomContentTransferEncoding("foo"); |
| 677 | 706 |
| 678 int32_t rv; | 707 int32_t rv = OpenUntrusted(request); |
| 679 rv = OpenUntrusted(request); | |
| 680 if (rv != PP_ERROR_NOACCESS) | 708 if (rv != PP_ERROR_NOACCESS) |
| 681 return ReportError( | 709 return ReportError( |
| 682 "Untrusted request with content-transfer-encoding restriction", rv); | 710 "Untrusted request with content-transfer-encoding restriction", rv); |
| 683 #if !(defined __native_client__) | 711 |
| 684 rv = OpenTrusted(request); | |
| 685 if (rv != PP_OK) | |
| 686 return ReportError("Trusted request with content-transfer-encoding", rv); | |
| 687 #endif | |
| 688 PASS(); | 712 PASS(); |
| 689 } | 713 } |
| 690 | 714 |
| 715 // Trusted requests with custom transfer encodings should succeed. | |
| 716 std::string TestURLLoader::TestTrustedCustomContentTransferEncoding() { | |
| 717 pp::URLRequestInfo request(instance_); | |
| 718 request.SetCustomContentTransferEncoding("foo"); | |
| 719 | |
| 720 int32_t rv = OpenTrusted(request); | |
| 721 if (rv != PP_OK) | |
| 722 return ReportError("Trusted request with content-transfer-encoding failed", | |
| 723 rv); | |
| 724 PASS(); | |
| 725 } | |
| 726 | |
| 691 // This test should cause a redirect and ensure that the loader runs | 727 // This test should cause a redirect and ensure that the loader runs |
| 692 // the callback, rather than following the redirect. | 728 // the callback, rather than following the redirect. |
| 693 std::string TestURLLoader::TestAuditURLRedirect() { | 729 std::string TestURLLoader::TestAuditURLRedirect() { |
| 694 pp::URLRequestInfo request(instance_); | 730 pp::URLRequestInfo request(instance_); |
| 695 // This path will cause the server to return a 301 redirect. | 731 // This path will cause the server to return a 301 redirect. |
| 696 request.SetURL("/server-redirect?www.google.com"); | 732 request.SetURL("/server-redirect?www.google.com"); |
| 697 request.SetFollowRedirects(false); | 733 request.SetFollowRedirects(false); |
| 698 | 734 |
| 699 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 735 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 700 | 736 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 if (!error.empty()) | 857 if (!error.empty()) |
| 822 return error; | 858 return error; |
| 823 if (body != "hello\n") | 859 if (body != "hello\n") |
| 824 return ReportError("Couldn't read data", rv); | 860 return ReportError("Couldn't read data", rv); |
| 825 | 861 |
| 826 PASS(); | 862 PASS(); |
| 827 } | 863 } |
| 828 | 864 |
| 829 // TODO(viettrungluu): Add tests for FollowRedirect, | 865 // TODO(viettrungluu): Add tests for FollowRedirect, |
| 830 // Get{Upload,Download}Progress, Close (including abort tests if applicable). | 866 // Get{Upload,Download}Progress, Close (including abort tests if applicable). |
| OLD | NEW |