Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: net/http/http_stream_factory_impl_unittest.cc

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "net/http/http_stream_factory_impl.h" 5 #include "net/http/http_stream_factory_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "net/socket/client_socket_handle.h" 43 #include "net/socket/client_socket_handle.h"
44 #include "net/socket/mock_client_socket_pool_manager.h" 44 #include "net/socket/mock_client_socket_pool_manager.h"
45 #include "net/socket/next_proto.h" 45 #include "net/socket/next_proto.h"
46 #include "net/socket/socket_test_util.h" 46 #include "net/socket/socket_test_util.h"
47 #include "net/spdy/spdy_session.h" 47 #include "net/spdy/spdy_session.h"
48 #include "net/spdy/spdy_session_pool.h" 48 #include "net/spdy/spdy_session_pool.h"
49 #include "net/spdy/spdy_test_util_common.h" 49 #include "net/spdy/spdy_test_util_common.h"
50 #include "net/ssl/ssl_config_service.h" 50 #include "net/ssl/ssl_config_service.h"
51 #include "net/ssl/ssl_config_service_defaults.h" 51 #include "net/ssl/ssl_config_service_defaults.h"
52 #include "net/test/cert_test_util.h" 52 #include "net/test/cert_test_util.h"
53 #include "net/test/gtest_util.h"
53 #include "net/test/test_data_directory.h" 54 #include "net/test/test_data_directory.h"
54 55
55 // This file can be included from net/http even though 56 // This file can be included from net/http even though
56 // it is in net/websockets because it doesn't 57 // it is in net/websockets because it doesn't
57 // introduce any link dependency to net/websockets. 58 // introduce any link dependency to net/websockets.
58 #include "net/websockets/websocket_handshake_stream_base.h" 59 #include "net/websockets/websocket_handshake_stream_base.h"
60
61 #include "testing/gmock/include/gmock/gmock.h"
59 #include "testing/gtest/include/gtest/gtest.h" 62 #include "testing/gtest/include/gtest/gtest.h"
60 63
64 using net::test::IsError;
65 using net::test::IsOk;
66
61 namespace net { 67 namespace net {
62 68
63 class BidirectionalStreamImpl; 69 class BidirectionalStreamImpl;
64 70
65 namespace { 71 namespace {
66 72
67 class MockWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { 73 class MockWebSocketHandshakeStream : public WebSocketHandshakeStreamBase {
68 public: 74 public:
69 enum StreamType { 75 enum StreamType {
70 kStreamTypeBasic, 76 kStreamTypeBasic,
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 bidi_request_info.end_stream_on_headers = true; 1706 bidi_request_info.end_stream_on_headers = true;
1701 bidi_request_info.priority = LOWEST; 1707 bidi_request_info.priority = LOWEST;
1702 1708
1703 TestBidirectionalDelegate delegate; 1709 TestBidirectionalDelegate delegate;
1704 stream_impl->Start(&bidi_request_info, BoundNetLog(), 1710 stream_impl->Start(&bidi_request_info, BoundNetLog(),
1705 /*send_request_headers_automatically=*/true, &delegate, 1711 /*send_request_headers_automatically=*/true, &delegate,
1706 nullptr); 1712 nullptr);
1707 delegate.WaitUntilDone(); 1713 delegate.WaitUntilDone();
1708 1714
1709 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1); 1715 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1);
1710 EXPECT_EQ(OK, stream_impl->ReadData(buffer.get(), 1)); 1716 EXPECT_THAT(stream_impl->ReadData(buffer.get(), 1), IsOk());
1711 EXPECT_EQ(kProtoQUIC1SPDY3, stream_impl->GetProtocol()); 1717 EXPECT_EQ(kProtoQUIC1SPDY3, stream_impl->GetProtocol());
1712 EXPECT_EQ("200", delegate.response_headers().find(":status")->second); 1718 EXPECT_EQ("200", delegate.response_headers().find(":status")->second);
1713 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( 1719 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool(
1714 HttpNetworkSession::NORMAL_SOCKET_POOL))); 1720 HttpNetworkSession::NORMAL_SOCKET_POOL)));
1715 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( 1721 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool(
1716 HttpNetworkSession::NORMAL_SOCKET_POOL))); 1722 HttpNetworkSession::NORMAL_SOCKET_POOL)));
1717 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( 1723 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool(
1718 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); 1724 HttpNetworkSession::WEBSOCKET_SOCKET_POOL)));
1719 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( 1725 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool(
1720 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); 1726 HttpNetworkSession::WEBSOCKET_SOCKET_POOL)));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, 1758 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter,
1753 BoundNetLog())); 1759 BoundNetLog()));
1754 1760
1755 waiter.WaitForStream(); 1761 waiter.WaitForStream();
1756 EXPECT_TRUE(waiter.stream_done()); 1762 EXPECT_TRUE(waiter.stream_done());
1757 EXPECT_FALSE(waiter.websocket_stream()); 1763 EXPECT_FALSE(waiter.websocket_stream());
1758 ASSERT_FALSE(waiter.stream()); 1764 ASSERT_FALSE(waiter.stream());
1759 ASSERT_FALSE(waiter.bidirectional_stream_impl()); 1765 ASSERT_FALSE(waiter.bidirectional_stream_impl());
1760 // Since the alternative service job is not started, we will get the error 1766 // Since the alternative service job is not started, we will get the error
1761 // from the http job. 1767 // from the http job.
1762 ASSERT_EQ(ERR_CONNECTION_REFUSED, waiter.error_status()); 1768 ASSERT_THAT(waiter.error_status(), IsError(ERR_CONNECTION_REFUSED));
1763 } 1769 }
1764 1770
1765 // Tests that if Http job fails, but Quic job succeeds, we return 1771 // Tests that if Http job fails, but Quic job succeeds, we return
1766 // BidirectionalStreamQuicImpl. 1772 // BidirectionalStreamQuicImpl.
1767 TEST_P(HttpStreamFactoryBidirectionalQuicTest, 1773 TEST_P(HttpStreamFactoryBidirectionalQuicTest,
1768 RequestBidirectionalStreamImplHttpJobFailsQuicJobSucceeds) { 1774 RequestBidirectionalStreamImplHttpJobFailsQuicJobSucceeds) {
1769 // Set up Quic data. 1775 // Set up Quic data.
1770 MockQuicData mock_quic_data; 1776 MockQuicData mock_quic_data;
1771 SpdyPriority priority = 1777 SpdyPriority priority =
1772 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); 1778 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 bidi_request_info.priority = LOWEST; 1830 bidi_request_info.priority = LOWEST;
1825 1831
1826 TestBidirectionalDelegate delegate; 1832 TestBidirectionalDelegate delegate;
1827 stream_impl->Start(&bidi_request_info, BoundNetLog(), 1833 stream_impl->Start(&bidi_request_info, BoundNetLog(),
1828 /*send_request_headers_automatically=*/true, &delegate, 1834 /*send_request_headers_automatically=*/true, &delegate,
1829 nullptr); 1835 nullptr);
1830 delegate.WaitUntilDone(); 1836 delegate.WaitUntilDone();
1831 1837
1832 // Make sure the BidirectionalStream negotiated goes through QUIC. 1838 // Make sure the BidirectionalStream negotiated goes through QUIC.
1833 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1); 1839 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1);
1834 EXPECT_EQ(OK, stream_impl->ReadData(buffer.get(), 1)); 1840 EXPECT_THAT(stream_impl->ReadData(buffer.get(), 1), IsOk());
1835 EXPECT_EQ(kProtoQUIC1SPDY3, stream_impl->GetProtocol()); 1841 EXPECT_EQ(kProtoQUIC1SPDY3, stream_impl->GetProtocol());
1836 EXPECT_EQ("200", delegate.response_headers().find(":status")->second); 1842 EXPECT_EQ("200", delegate.response_headers().find(":status")->second);
1837 // There is no Http2 socket pool. 1843 // There is no Http2 socket pool.
1838 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( 1844 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool(
1839 HttpNetworkSession::NORMAL_SOCKET_POOL))); 1845 HttpNetworkSession::NORMAL_SOCKET_POOL)));
1840 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( 1846 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool(
1841 HttpNetworkSession::NORMAL_SOCKET_POOL))); 1847 HttpNetworkSession::NORMAL_SOCKET_POOL)));
1842 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( 1848 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool(
1843 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); 1849 HttpNetworkSession::WEBSOCKET_SOCKET_POOL)));
1844 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( 1850 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool(
(...skipping 27 matching lines...) Expand all
1872 request_info.load_flags = 0; 1878 request_info.load_flags = 0;
1873 1879
1874 SSLConfig ssl_config; 1880 SSLConfig ssl_config;
1875 StreamRequestWaiter waiter; 1881 StreamRequestWaiter waiter;
1876 std::unique_ptr<HttpStreamRequest> request( 1882 std::unique_ptr<HttpStreamRequest> request(
1877 session->http_stream_factory()->RequestBidirectionalStreamImpl( 1883 session->http_stream_factory()->RequestBidirectionalStreamImpl(
1878 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, 1884 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter,
1879 BoundNetLog())); 1885 BoundNetLog()));
1880 waiter.WaitForStream(); 1886 waiter.WaitForStream();
1881 EXPECT_TRUE(waiter.stream_done()); 1887 EXPECT_TRUE(waiter.stream_done());
1882 ASSERT_EQ(ERR_FAILED, waiter.error_status()); 1888 ASSERT_THAT(waiter.error_status(), IsError(ERR_FAILED));
1883 EXPECT_FALSE(waiter.websocket_stream()); 1889 EXPECT_FALSE(waiter.websocket_stream());
1884 ASSERT_FALSE(waiter.stream()); 1890 ASSERT_FALSE(waiter.stream());
1885 ASSERT_FALSE(waiter.bidirectional_stream_impl()); 1891 ASSERT_FALSE(waiter.bidirectional_stream_impl());
1886 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetTransportSocketPool( 1892 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetTransportSocketPool(
1887 HttpNetworkSession::NORMAL_SOCKET_POOL))); 1893 HttpNetworkSession::NORMAL_SOCKET_POOL)));
1888 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSSLSocketPool( 1894 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSSLSocketPool(
1889 HttpNetworkSession::NORMAL_SOCKET_POOL))); 1895 HttpNetworkSession::NORMAL_SOCKET_POOL)));
1890 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetTransportSocketPool( 1896 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetTransportSocketPool(
1891 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); 1897 HttpNetworkSession::WEBSOCKET_SOCKET_POOL)));
1892 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( 1898 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool(
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 session->GetTransportSocketPool( 2077 session->GetTransportSocketPool(
2072 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); 2078 HttpNetworkSession::WEBSOCKET_SOCKET_POOL)));
2073 EXPECT_EQ(1, GetSocketPoolGroupCount( 2079 EXPECT_EQ(1, GetSocketPoolGroupCount(
2074 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); 2080 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL)));
2075 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); 2081 EXPECT_TRUE(waiter.used_proxy_info().is_direct());
2076 } 2082 }
2077 2083
2078 } // namespace 2084 } // namespace
2079 2085
2080 } // namespace net 2086 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_proxy_client_socket_pool_unittest.cc ('k') | net/http/http_stream_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698