| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 TestURLLoader::TestURLLoader(TestingInstance* instance) | 60 TestURLLoader::TestURLLoader(TestingInstance* instance) |
| 61 : TestCase(instance), | 61 : TestCase(instance), |
| 62 file_io_trusted_interface_(NULL), | 62 file_io_trusted_interface_(NULL), |
| 63 url_loader_trusted_interface_(NULL) { | 63 url_loader_trusted_interface_(NULL) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool TestURLLoader::Init() { | 66 bool TestURLLoader::Init() { |
| 67 if (!InitTestingInterface()) { |
| 68 instance_->AppendError("Testing interface not available"); |
| 69 return false; |
| 70 } |
| 71 |
| 72 const PPB_FileIO* file_io_interface = static_cast<const PPB_FileIO*>( |
| 73 pp::Module::Get()->GetBrowserInterface(PPB_FILEIO_INTERFACE)); |
| 74 if (testing_interface_->IsOutOfProcess() && file_io_interface) { |
| 75 instance_->AppendError( |
| 76 "FileIO interface is now supported by ppapi proxy: update this test!"); |
| 77 } else if (!testing_interface_->IsOutOfProcess() && !file_io_interface) { |
| 78 instance_->AppendError("FileIO interface not available"); |
| 79 } |
| 80 |
| 67 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( | 81 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( |
| 68 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); | 82 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); |
| 69 if (!file_io_trusted_interface_) { | |
| 70 instance_->AppendError("FileIOTrusted interface not available"); | |
| 71 } | |
| 72 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( | 83 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( |
| 73 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); | 84 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); |
| 74 if (!url_loader_trusted_interface_) { | 85 if (testing_interface_->IsOutOfProcess() && file_io_trusted_interface_) { |
| 75 instance_->AppendError("URLLoaderTrusted interface not available"); | 86 instance_->AppendError( |
| 87 "FileIOTrusted interface is now supported by ppapi proxy: " |
| 88 "update this test!"); |
| 89 } else if (!testing_interface_->IsOutOfProcess()) { |
| 90 // Trusted interfaces are not supported under NaCl. |
| 91 #if !(defined __native_client__) |
| 92 if (!file_io_trusted_interface_) |
| 93 instance_->AppendError("FileIOTrusted interface not available"); |
| 94 if (!url_loader_trusted_interface_) |
| 95 instance_->AppendError("URLLoaderTrusted interface not available"); |
| 96 #else |
| 97 if (file_io_trusted_interface_) |
| 98 instance_->AppendError("FileIOTrusted interface is supported by NaCl"); |
| 99 if (url_loader_trusted_interface_) |
| 100 instance_->AppendError("URLLoaderTrusted interface is supported by NaCl"); |
| 101 #endif |
| 76 } | 102 } |
| 77 return InitTestingInterface() && EnsureRunningOverHTTP(); | 103 return EnsureRunningOverHTTP(); |
| 78 } | 104 } |
| 79 | 105 |
| 80 void TestURLLoader::RunTests(const std::string& filter) { | 106 void TestURLLoader::RunTests(const std::string& filter) { |
| 81 RUN_TEST_FORCEASYNC_AND_NOT(BasicGET, filter); | 107 RUN_TEST_FORCEASYNC_AND_NOT(BasicGET, filter); |
| 82 RUN_TEST_FORCEASYNC_AND_NOT(BasicPOST, filter); | 108 RUN_TEST_FORCEASYNC_AND_NOT(BasicPOST, filter); |
| 83 RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter); | 109 // FileIO interface is not yet supported by ppapi/proxy. |
| 84 RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter); | 110 if (!testing_interface_->IsOutOfProcess()) { |
| 111 RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter); |
| 112 RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter); |
| 113 } |
| 85 RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter); | 114 RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter); |
| 86 RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter); | 115 RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter); |
| 87 RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter); | 116 RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter); |
| 88 RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter); | 117 RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter); |
| 89 RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter); | 118 RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter); |
| 90 // Disable portion of test which fails when the HTTP server's | 119 // Disable portion of test which fails when the HTTP server's |
| 91 // data_dir is moved to PRODUCT_DIR. | 120 // data_dir is moved to PRODUCT_DIR. |
| 92 // http://code.google.com/p/chromium/issues/detail?id=103690 | 121 // http://code.google.com/p/chromium/issues/detail?id=103690 |
| 93 // RUN_TEST_FORCEASYNC_AND_NOT(SameOriginRestriction, filter); | 122 // RUN_TEST_FORCEASYNC_AND_NOT(SameOriginRestriction, filter); |
| 94 // RUN_TEST_FORCEASYNC_AND_NOT(CrossOriginRequest, filter); | 123 // RUN_TEST_FORCEASYNC_AND_NOT(CrossOriginRequest, filter); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 return "URLResponseInfo::GetBody returned null"; | 456 return "URLResponseInfo::GetBody returned null"; |
| 428 | 457 |
| 429 rv = loader.FinishStreamingToFile(callback); | 458 rv = loader.FinishStreamingToFile(callback); |
| 430 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 459 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 431 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); | 460 return ReportError("URLLoader::FinishStreamingToFile force_async", rv); |
| 432 if (rv == PP_OK_COMPLETIONPENDING) | 461 if (rv == PP_OK_COMPLETIONPENDING) |
| 433 rv = callback.WaitForResult(); | 462 rv = callback.WaitForResult(); |
| 434 if (rv != PP_OK) | 463 if (rv != PP_OK) |
| 435 return ReportError("URLLoader::FinishStreamingToFile", rv); | 464 return ReportError("URLLoader::FinishStreamingToFile", rv); |
| 436 | 465 |
| 437 pp::FileIO reader(instance_); | 466 // FileIO is not yet supported by ppapi/proxy. |
| 438 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); | 467 if (!testing_interface_->IsOutOfProcess()) { |
| 439 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 468 pp::FileIO reader(instance_); |
| 440 return ReportError("FileIO::Open force_async", rv); | 469 rv = reader.Open(body, PP_FILEOPENFLAG_READ, callback); |
| 441 if (rv == PP_OK_COMPLETIONPENDING) | 470 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 442 rv = callback.WaitForResult(); | 471 return ReportError("FileIO::Open force_async", rv); |
| 443 if (rv != PP_OK) | 472 if (rv == PP_OK_COMPLETIONPENDING) |
| 444 return ReportError("FileIO::Open", rv); | 473 rv = callback.WaitForResult(); |
| 474 if (rv != PP_OK) |
| 475 return ReportError("FileIO::Open", rv); |
| 445 | 476 |
| 446 std::string data; | 477 std::string data; |
| 447 std::string error = ReadEntireFile(&reader, &data); | 478 std::string error = ReadEntireFile(&reader, &data); |
| 448 if (!error.empty()) | 479 if (!error.empty()) |
| 449 return error; | 480 return error; |
| 450 | 481 |
| 451 std::string expected_body = "hello\n"; | 482 std::string expected_body = "hello\n"; |
| 452 if (data.size() != expected_body.size()) | 483 if (data.size() != expected_body.size()) |
| 453 return "ReadEntireFile returned unexpected content length"; | 484 return "ReadEntireFile returned unexpected content length"; |
| 454 if (data != expected_body) | 485 if (data != expected_body) |
| 455 return "ReadEntireFile returned unexpected content"; | 486 return "ReadEntireFile returned unexpected content"; |
| 456 | 487 |
| 457 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( | 488 // FileIOTrusted is not supported by NaCl or ppapi/proxy. |
| 458 reader.pp_resource()); | 489 if (!testing_interface_->IsOutOfProcess()) { |
| 459 if (file_descriptor < 0) | 490 #if !(defined __native_client__) |
| 460 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; | 491 int32_t file_descriptor = file_io_trusted_interface_->GetOSFileDescriptor( |
| 461 | 492 reader.pp_resource()); |
| 493 if (file_descriptor < 0) |
| 494 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; |
| 495 #endif |
| 496 } |
| 497 } |
| 462 PASS(); | 498 PASS(); |
| 463 } | 499 } |
| 464 | 500 |
| 465 // If a cross-origin request is not specified, the load should fail only for | 501 // If a cross-origin request is not specified, the load should fail only for |
| 466 // untrusted loaders. | 502 // untrusted loaders. |
| 467 std::string TestURLLoader::TestSameOriginRestriction() { | 503 std::string TestURLLoader::TestSameOriginRestriction() { |
| 468 pp::URLRequestInfo request(instance_); | 504 pp::URLRequestInfo request(instance_); |
| 469 std::string cross_origin_url = GetReachableCrossOriginURL(); | 505 std::string cross_origin_url = GetReachableCrossOriginURL(); |
| 470 request.SetURL(cross_origin_url); | 506 request.SetURL(cross_origin_url); |
| 471 | 507 |
| 472 int32_t rv; | 508 int32_t rv; |
| 473 rv = OpenUntrusted(request); | 509 rv = OpenUntrusted(request); |
| 474 if (rv != PP_ERROR_NOACCESS) | 510 if (rv != PP_ERROR_NOACCESS) |
| 475 return ReportError( | 511 return ReportError( |
| 476 "Untrusted, unintended cross-origin request restriction", rv); | 512 "Untrusted, unintended cross-origin request restriction", rv); |
| 513 #if !(defined __native_client__) |
| 477 rv = OpenTrusted(request); | 514 rv = OpenTrusted(request); |
| 478 if (rv != PP_OK) | 515 if (rv != PP_OK) |
| 479 return ReportError("Trusted cross-origin request", rv); | 516 return ReportError("Trusted cross-origin request", rv); |
| 517 #endif |
| 480 | 518 |
| 481 PASS(); | 519 PASS(); |
| 482 } | 520 } |
| 483 | 521 |
| 484 // If a cross-origin request is specified, and the URL is reachable, the load | 522 // If a cross-origin request is specified, and the URL is reachable, the load |
| 485 // should succeed. | 523 // should succeed. |
| 486 std::string TestURLLoader::TestCrossOriginRequest() { | 524 std::string TestURLLoader::TestCrossOriginRequest() { |
| 487 pp::URLRequestInfo request(instance_); | 525 pp::URLRequestInfo request(instance_); |
| 488 std::string cross_origin_url = GetReachableCrossOriginURL(); | 526 std::string cross_origin_url = GetReachableCrossOriginURL(); |
| 489 request.SetURL(cross_origin_url); | 527 request.SetURL(cross_origin_url); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 504 // Javascript URLs are only reachable by trusted loaders. | 542 // Javascript URLs are only reachable by trusted loaders. |
| 505 std::string TestURLLoader::TestJavascriptURLRestriction() { | 543 std::string TestURLLoader::TestJavascriptURLRestriction() { |
| 506 pp::URLRequestInfo request(instance_); | 544 pp::URLRequestInfo request(instance_); |
| 507 request.SetURL("javascript:foo = bar"); | 545 request.SetURL("javascript:foo = bar"); |
| 508 | 546 |
| 509 int32_t rv; | 547 int32_t rv; |
| 510 rv = OpenUntrusted(request); | 548 rv = OpenUntrusted(request); |
| 511 if (rv != PP_ERROR_NOACCESS) | 549 if (rv != PP_ERROR_NOACCESS) |
| 512 return ReportError( | 550 return ReportError( |
| 513 "Untrusted Javascript URL request restriction", rv); | 551 "Untrusted Javascript URL request restriction", rv); |
| 552 #if !(defined __native_client__) |
| 514 // TODO(bbudge) Fix Javascript URLs for trusted loaders. | 553 // TODO(bbudge) Fix Javascript URLs for trusted loaders. |
| 515 // http://code.google.com/p/chromium/issues/detail?id=103062 | 554 // http://code.google.com/p/chromium/issues/detail?id=103062 |
| 516 // rv = OpenTrusted(request); | 555 // rv = OpenTrusted(request); |
| 517 // if (rv == PP_ERROR_NOACCESS) | 556 // if (rv == PP_ERROR_NOACCESS) |
| 518 // return ReportError( | 557 // return ReportError( |
| 519 // "Trusted Javascript URL request", rv); | 558 // "Trusted Javascript URL request", rv); |
| 559 #endif |
| 520 | 560 |
| 521 PASS(); | 561 PASS(); |
| 522 } | 562 } |
| 523 | 563 |
| 524 // HTTP methods are restricted only for untrusted loaders. Forbidden | 564 // HTTP methods are restricted only for untrusted loaders. Forbidden |
| 525 // methods are CONNECT, TRACE, and TRACK, and any string that is not a valid | 565 // methods are CONNECT, TRACE, and TRACK, and any string that is not a valid |
| 526 // token (containing special characters like CR, LF). | 566 // token (containing special characters like CR, LF). |
| 527 // http://www.w3.org/TR/XMLHttpRequest/ | 567 // http://www.w3.org/TR/XMLHttpRequest/ |
| 528 std::string TestURLLoader::TestMethodRestriction() { | 568 std::string TestURLLoader::TestMethodRestriction() { |
| 529 ASSERT_EQ(OpenUntrusted("cOnNeCt", ""), PP_ERROR_NOACCESS); | 569 ASSERT_EQ(OpenUntrusted("cOnNeCt", ""), PP_ERROR_NOACCESS); |
| 530 ASSERT_EQ(OpenUntrusted("tRaCk", ""), PP_ERROR_NOACCESS); | 570 ASSERT_EQ(OpenUntrusted("tRaCk", ""), PP_ERROR_NOACCESS); |
| 531 ASSERT_EQ(OpenUntrusted("tRaCe", ""), PP_ERROR_NOACCESS); | 571 ASSERT_EQ(OpenUntrusted("tRaCe", ""), PP_ERROR_NOACCESS); |
| 532 ASSERT_EQ(OpenUntrusted("POST\x0d\x0ax-csrf-token:\x20test1234", ""), | 572 ASSERT_EQ(OpenUntrusted("POST\x0d\x0ax-csrf-token:\x20test1234", ""), |
| 533 PP_ERROR_NOACCESS); | 573 PP_ERROR_NOACCESS); |
| 534 | 574 #if !(defined __native_client__) |
| 535 ASSERT_EQ(OpenTrusted("cOnNeCt", ""), PP_OK); | 575 ASSERT_EQ(OpenTrusted("cOnNeCt", ""), PP_OK); |
| 536 ASSERT_EQ(OpenTrusted("tRaCk", ""), PP_OK); | 576 ASSERT_EQ(OpenTrusted("tRaCk", ""), PP_OK); |
| 537 ASSERT_EQ(OpenTrusted("tRaCe", ""), PP_OK); | 577 ASSERT_EQ(OpenTrusted("tRaCe", ""), PP_OK); |
| 578 #endif |
| 538 | 579 |
| 539 PASS(); | 580 PASS(); |
| 540 } | 581 } |
| 541 | 582 |
| 542 // HTTP methods are restricted only for untrusted loaders. Try all headers | 583 // HTTP methods are restricted only for untrusted loaders. Try all headers |
| 543 // that are forbidden by http://www.w3.org/TR/XMLHttpRequest/. | 584 // that are forbidden by http://www.w3.org/TR/XMLHttpRequest/. |
| 544 std::string TestURLLoader::TestHeaderRestriction() { | 585 std::string TestURLLoader::TestHeaderRestriction() { |
| 545 ASSERT_EQ(OpenUntrusted("GET", "Accept-Charset:\n"), PP_ERROR_NOACCESS); | 586 ASSERT_EQ(OpenUntrusted("GET", "Accept-Charset:\n"), PP_ERROR_NOACCESS); |
| 546 ASSERT_EQ(OpenUntrusted("GET", "Accept-Encoding:\n"), PP_ERROR_NOACCESS); | 587 ASSERT_EQ(OpenUntrusted("GET", "Accept-Encoding:\n"), PP_ERROR_NOACCESS); |
| 547 ASSERT_EQ(OpenUntrusted("GET", "Connection:\n"), PP_ERROR_NOACCESS); | 588 ASSERT_EQ(OpenUntrusted("GET", "Connection:\n"), PP_ERROR_NOACCESS); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 559 ASSERT_EQ(OpenUntrusted("GET", "Trailer:\n"), PP_ERROR_NOACCESS); | 600 ASSERT_EQ(OpenUntrusted("GET", "Trailer:\n"), PP_ERROR_NOACCESS); |
| 560 ASSERT_EQ(OpenUntrusted("GET", "Transfer-Encoding:\n"), PP_ERROR_NOACCESS); | 601 ASSERT_EQ(OpenUntrusted("GET", "Transfer-Encoding:\n"), PP_ERROR_NOACCESS); |
| 561 ASSERT_EQ(OpenUntrusted("GET", "Upgrade:\n"), PP_ERROR_NOACCESS); | 602 ASSERT_EQ(OpenUntrusted("GET", "Upgrade:\n"), PP_ERROR_NOACCESS); |
| 562 ASSERT_EQ(OpenUntrusted("GET", "User-Agent:\n"), PP_ERROR_NOACCESS); | 603 ASSERT_EQ(OpenUntrusted("GET", "User-Agent:\n"), PP_ERROR_NOACCESS); |
| 563 ASSERT_EQ(OpenUntrusted("GET", "Via:\n"), PP_ERROR_NOACCESS); | 604 ASSERT_EQ(OpenUntrusted("GET", "Via:\n"), PP_ERROR_NOACCESS); |
| 564 ASSERT_EQ(OpenUntrusted( | 605 ASSERT_EQ(OpenUntrusted( |
| 565 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), | 606 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), |
| 566 PP_ERROR_NOACCESS); | 607 PP_ERROR_NOACCESS); |
| 567 ASSERT_EQ(OpenUntrusted("GET", "Sec-foo:\n"), PP_ERROR_NOACCESS); | 608 ASSERT_EQ(OpenUntrusted("GET", "Sec-foo:\n"), PP_ERROR_NOACCESS); |
| 568 | 609 |
| 610 #if !(defined __native_client__) |
| 569 ASSERT_EQ(OpenTrusted("GET", "Accept-Charset:\n"), PP_OK); | 611 ASSERT_EQ(OpenTrusted("GET", "Accept-Charset:\n"), PP_OK); |
| 570 ASSERT_EQ(OpenTrusted("GET", "Accept-Encoding:\n"), PP_OK); | 612 ASSERT_EQ(OpenTrusted("GET", "Accept-Encoding:\n"), PP_OK); |
| 571 ASSERT_EQ(OpenTrusted("GET", "Connection:\n"), PP_OK); | 613 ASSERT_EQ(OpenTrusted("GET", "Connection:\n"), PP_OK); |
| 572 ASSERT_EQ(OpenTrusted("GET", "Content-Length:\n"), PP_OK); | 614 ASSERT_EQ(OpenTrusted("GET", "Content-Length:\n"), PP_OK); |
| 573 ASSERT_EQ(OpenTrusted("GET", "Cookie:\n"), PP_OK); | 615 ASSERT_EQ(OpenTrusted("GET", "Cookie:\n"), PP_OK); |
| 574 ASSERT_EQ(OpenTrusted("GET", "Cookie2:\n"), PP_OK); | 616 ASSERT_EQ(OpenTrusted("GET", "Cookie2:\n"), PP_OK); |
| 575 ASSERT_EQ(OpenTrusted( | 617 ASSERT_EQ(OpenTrusted( |
| 576 "GET", "Content-Transfer-Encoding:\n"), PP_OK); | 618 "GET", "Content-Transfer-Encoding:\n"), PP_OK); |
| 577 ASSERT_EQ(OpenTrusted("GET", "Date:\n"), PP_OK); | 619 ASSERT_EQ(OpenTrusted("GET", "Date:\n"), PP_OK); |
| 578 ASSERT_EQ(OpenTrusted("GET", "Expect:\n"), PP_OK); | 620 ASSERT_EQ(OpenTrusted("GET", "Expect:\n"), PP_OK); |
| 579 ASSERT_EQ(OpenTrusted("GET", "Host:\n"), PP_OK); | 621 ASSERT_EQ(OpenTrusted("GET", "Host:\n"), PP_OK); |
| 580 ASSERT_EQ(OpenTrusted("GET", "Keep-Alive:\n"), PP_OK); | 622 ASSERT_EQ(OpenTrusted("GET", "Keep-Alive:\n"), PP_OK); |
| 581 ASSERT_EQ(OpenTrusted("GET", "Referer:\n"), PP_OK); | 623 ASSERT_EQ(OpenTrusted("GET", "Referer:\n"), PP_OK); |
| 582 ASSERT_EQ(OpenTrusted("GET", "TE:\n"), PP_OK); | 624 ASSERT_EQ(OpenTrusted("GET", "TE:\n"), PP_OK); |
| 583 ASSERT_EQ(OpenTrusted("GET", "Trailer:\n"), PP_OK); | 625 ASSERT_EQ(OpenTrusted("GET", "Trailer:\n"), PP_OK); |
| 584 ASSERT_EQ(OpenTrusted("GET", "Transfer-Encoding:\n"), PP_OK); | 626 ASSERT_EQ(OpenTrusted("GET", "Transfer-Encoding:\n"), PP_OK); |
| 585 ASSERT_EQ(OpenTrusted("GET", "Upgrade:\n"), PP_OK); | 627 ASSERT_EQ(OpenTrusted("GET", "Upgrade:\n"), PP_OK); |
| 586 ASSERT_EQ(OpenTrusted("GET", "User-Agent:\n"), PP_OK); | 628 ASSERT_EQ(OpenTrusted("GET", "User-Agent:\n"), PP_OK); |
| 587 ASSERT_EQ(OpenTrusted("GET", "Via:\n"), PP_OK); | 629 ASSERT_EQ(OpenTrusted("GET", "Via:\n"), PP_OK); |
| 588 ASSERT_EQ(OpenTrusted( | 630 ASSERT_EQ(OpenTrusted( |
| 589 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), PP_OK); | 631 "GET", "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==:\n"), PP_OK); |
| 590 ASSERT_EQ(OpenTrusted("GET", "Sec-foo:\n"), PP_OK); | 632 ASSERT_EQ(OpenTrusted("GET", "Sec-foo:\n"), PP_OK); |
| 633 #endif |
| 591 | 634 |
| 592 PASS(); | 635 PASS(); |
| 593 } | 636 } |
| 594 | 637 |
| 595 // Custom referrers are only allowed for trusted loaders. | 638 // Custom referrers are only allowed for trusted loaders. |
| 596 std::string TestURLLoader::TestCustomReferrer() { | 639 std::string TestURLLoader::TestCustomReferrer() { |
| 597 pp::URLRequestInfo request(instance_); | 640 pp::URLRequestInfo request(instance_); |
| 598 request.SetCustomReferrerURL("http://www.google.com/"); | 641 request.SetCustomReferrerURL("http://www.google.com/"); |
| 599 | 642 |
| 600 int32_t rv; | 643 int32_t rv; |
| 601 rv = OpenUntrusted(request); | 644 rv = OpenUntrusted(request); |
| 602 if (rv != PP_ERROR_NOACCESS) | 645 if (rv != PP_ERROR_NOACCESS) |
| 603 return ReportError( | 646 return ReportError( |
| 604 "Untrusted request with custom referrer restriction", rv); | 647 "Untrusted request with custom referrer restriction", rv); |
| 648 #if !(defined __native_client__) |
| 605 rv = OpenTrusted(request); | 649 rv = OpenTrusted(request); |
| 606 if (rv != PP_OK) | 650 if (rv != PP_OK) |
| 607 return ReportError("Trusted request with custom referrer", rv); | 651 return ReportError("Trusted request with custom referrer", rv); |
| 608 | 652 #endif |
| 609 PASS(); | 653 PASS(); |
| 610 } | 654 } |
| 611 | 655 |
| 612 // Custom transfer encodings are only allowed for trusted loaders. | 656 // Custom transfer encodings are only allowed for trusted loaders. |
| 613 std::string TestURLLoader::TestCustomContentTransferEncoding() { | 657 std::string TestURLLoader::TestCustomContentTransferEncoding() { |
| 614 pp::URLRequestInfo request(instance_); | 658 pp::URLRequestInfo request(instance_); |
| 615 request.SetCustomContentTransferEncoding("foo"); | 659 request.SetCustomContentTransferEncoding("foo"); |
| 616 | 660 |
| 617 int32_t rv; | 661 int32_t rv; |
| 618 rv = OpenUntrusted(request); | 662 rv = OpenUntrusted(request); |
| 619 if (rv != PP_ERROR_NOACCESS) | 663 if (rv != PP_ERROR_NOACCESS) |
| 620 return ReportError( | 664 return ReportError( |
| 621 "Untrusted request with content-transfer-encoding restriction", rv); | 665 "Untrusted request with content-transfer-encoding restriction", rv); |
| 666 #if !(defined __native_client__) |
| 622 rv = OpenTrusted(request); | 667 rv = OpenTrusted(request); |
| 623 if (rv != PP_OK) | 668 if (rv != PP_OK) |
| 624 return ReportError("Trusted request with content-transfer-encoding", rv); | 669 return ReportError("Trusted request with content-transfer-encoding", rv); |
| 625 | 670 #endif |
| 626 PASS(); | 671 PASS(); |
| 627 } | 672 } |
| 628 | 673 |
| 629 // This test should cause a redirect and ensure that the loader runs | 674 // This test should cause a redirect and ensure that the loader runs |
| 630 // the callback, rather than following the redirect. | 675 // the callback, rather than following the redirect. |
| 631 std::string TestURLLoader::TestAuditURLRedirect() { | 676 std::string TestURLLoader::TestAuditURLRedirect() { |
| 632 pp::URLRequestInfo request(instance_); | 677 pp::URLRequestInfo request(instance_); |
| 633 // This path will cause the server to return a 301 redirect. | 678 // This path will cause the server to return a 301 redirect. |
| 634 request.SetURL("/server-redirect?www.google.com"); | 679 request.SetURL("/server-redirect?www.google.com"); |
| 635 request.SetFollowRedirects(false); | 680 request.SetFollowRedirects(false); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 if (!error.empty()) | 804 if (!error.empty()) |
| 760 return error; | 805 return error; |
| 761 if (body != "hello\n") | 806 if (body != "hello\n") |
| 762 return ReportError("Couldn't read data", rv); | 807 return ReportError("Couldn't read data", rv); |
| 763 | 808 |
| 764 PASS(); | 809 PASS(); |
| 765 } | 810 } |
| 766 | 811 |
| 767 // TODO(viettrungluu): Add tests for FollowRedirect, | 812 // TODO(viettrungluu): Add tests for FollowRedirect, |
| 768 // Get{Upload,Download}Progress, Close (including abort tests if applicable). | 813 // Get{Upload,Download}Progress, Close (including abort tests if applicable). |
| OLD | NEW |