OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 MockRead data_reads[] = { | 1646 MockRead data_reads[] = { |
1647 MockRead(SYNCHRONOUS, OK), // EOF | 1647 MockRead(SYNCHRONOUS, OK), // EOF |
1648 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used | 1648 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
1649 MockRead("hello world"), | 1649 MockRead("hello world"), |
1650 MockRead(SYNCHRONOUS, OK), | 1650 MockRead(SYNCHRONOUS, OK), |
1651 }; | 1651 }; |
1652 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 1652 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
1653 arraysize(data_reads)); | 1653 arraysize(data_reads)); |
1654 EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); | 1654 EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
1655 } | 1655 } |
1656 // | |
1657 //// Test that network access can be deferred and resumed. | |
1658 // TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { | |
1659 // HttpRequestInfo request; | |
1660 // request.method = "GET"; | |
1661 // request.url = GURL("http://www.example.org/"); | |
1662 // request.load_flags = 0; | |
1663 // | |
1664 // std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1665 // std::unique_ptr<HttpTransaction> trans( | |
1666 // new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1667 // | |
1668 // // Defer on OnBeforeNetworkStart. | |
1669 // BeforeNetworkStartHandler net_start_handler(true); // defer | |
1670 // trans->SetBeforeNetworkStartCallback( | |
1671 // base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, | |
1672 // base::Unretained(&net_start_handler))); | |
1673 // | |
1674 // MockRead data_reads[] = { | |
1675 // MockRead("HTTP/1.0 200 OK\r\n"), | |
1676 // MockRead("Content-Length: 5\r\n\r\n"), | |
1677 // MockRead("hello"), | |
1678 // MockRead(SYNCHRONOUS, 0), | |
1679 // }; | |
1680 // StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
1681 // session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1682 // | |
1683 // TestCompletionCallback callback; | |
1684 // | |
1685 // int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1686 // EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
1687 // base::RunLoop().RunUntilIdle(); | |
1688 // | |
1689 // // Should have deferred for network start. | |
1690 // EXPECT_TRUE(net_start_handler.observed_before_network_start()); | |
1691 // EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); | |
1692 // | |
1693 // trans->ResumeNetworkStart(); | |
1694 // rv = callback.WaitForResult(); | |
1695 // EXPECT_THAT(rv, IsOk()); | |
1696 // EXPECT_TRUE(trans->GetResponseInfo()); | |
1697 // | |
1698 // scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); | |
1699 // rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); | |
1700 // if (rv == ERR_IO_PENDING) | |
1701 // rv = callback.WaitForResult(); | |
1702 // EXPECT_EQ(5, rv); | |
1703 // trans.reset(); | |
1704 //} | |
1705 // | |
1706 //// Test that network use can be deferred and canceled. | |
1707 // TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { | |
1708 // HttpRequestInfo request; | |
1709 // request.method = "GET"; | |
1710 // request.url = GURL("http://www.example.org/"); | |
1711 // request.load_flags = 0; | |
1712 // | |
1713 // std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
1714 // std::unique_ptr<HttpTransaction> trans( | |
1715 // new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
1716 // | |
1717 // // Defer on OnBeforeNetworkStart. | |
1718 // BeforeNetworkStartHandler net_start_handler(true); // defer | |
1719 // trans->SetBeforeNetworkStartCallback( | |
1720 // base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, | |
1721 // base::Unretained(&net_start_handler))); | |
1722 // | |
1723 // TestCompletionCallback callback; | |
1724 // | |
1725 // int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
1726 // EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
1727 // base::RunLoop().RunUntilIdle(); | |
1728 // | |
1729 // // Should have deferred for network start. | |
1730 // EXPECT_TRUE(net_start_handler.observed_before_network_start()); | |
1731 // EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); | |
1732 //} | |
1733 | 1656 |
1734 // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression | 1657 // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
1735 // tests. There was a bug causing HttpNetworkTransaction to hang in the | 1658 // tests. There was a bug causing HttpNetworkTransaction to hang in the |
1736 // destructor in such situations. | 1659 // destructor in such situations. |
1737 // See http://crbug.com/154712 and http://crbug.com/156609. | 1660 // See http://crbug.com/154712 and http://crbug.com/156609. |
1738 TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { | 1661 TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
1739 HttpRequestInfo request; | 1662 HttpRequestInfo request; |
1740 request.method = "GET"; | 1663 request.method = "GET"; |
1741 request.url = GURL("http://www.example.org/"); | 1664 request.url = GURL("http://www.example.org/"); |
1742 request.load_flags = 0; | 1665 request.load_flags = 0; |
(...skipping 14078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15821 base::RunLoop().RunUntilIdle(); | 15744 base::RunLoop().RunUntilIdle(); |
15822 | 15745 |
15823 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 15746 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
15824 HttpRequestHeaders headers; | 15747 HttpRequestHeaders headers; |
15825 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 15748 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
15826 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 15749 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
15827 } | 15750 } |
15828 #endif // !defined(OS_IOS) | 15751 #endif // !defined(OS_IOS) |
15829 | 15752 |
15830 } // namespace net | 15753 } // namespace net |
OLD | NEW |