| 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 "net/quic/quic_reliable_client_stream.h" | 5 #include "net/quic/quic_reliable_client_stream.h" |
| 6 | 6 |
| 7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/base/test_completion_callback.h" | 8 #include "net/base/test_completion_callback.h" |
| 9 #include "net/quic/quic_client_session.h" | 9 #include "net/quic/quic_client_session.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| 11 #include "net/quic/spdy_utils.h" | 11 #include "net/quic/spdy_utils.h" |
| 12 #include "net/quic/test_tools/quic_test_utils.h" | 12 #include "net/quic/test_tools/quic_test_utils.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 14 |
| 15 using testing::Return; | 15 using testing::Return; |
| 16 using testing::StrEq; | 16 using testing::StrEq; |
| 17 using testing::_; | 17 using testing::_; |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 namespace test { | 20 namespace test { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const QuicGuid kStreamId = 3; |
| 24 |
| 23 class MockDelegate : public QuicReliableClientStream::Delegate { | 25 class MockDelegate : public QuicReliableClientStream::Delegate { |
| 24 public: | 26 public: |
| 25 MockDelegate() {} | 27 MockDelegate() {} |
| 26 | 28 |
| 27 MOCK_METHOD0(OnSendData, int()); | 29 MOCK_METHOD0(OnSendData, int()); |
| 28 MOCK_METHOD2(OnSendDataComplete, int(int, bool*)); | 30 MOCK_METHOD2(OnSendDataComplete, int(int, bool*)); |
| 29 MOCK_METHOD2(OnDataReceived, int(const char*, int)); | 31 MOCK_METHOD2(OnDataReceived, int(const char*, int)); |
| 30 MOCK_METHOD1(OnClose, void(QuicErrorCode)); | 32 MOCK_METHOD1(OnClose, void(QuicErrorCode)); |
| 31 MOCK_METHOD1(OnError, void(int)); | 33 MOCK_METHOD1(OnError, void(int)); |
| 32 MOCK_METHOD0(HasSendHeadersComplete, bool()); | 34 MOCK_METHOD0(HasSendHeadersComplete, bool()); |
| 33 | 35 |
| 34 private: | 36 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(MockDelegate); | 37 DISALLOW_COPY_AND_ASSIGN(MockDelegate); |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 class QuicReliableClientStreamTest : public ::testing::Test { | 40 class QuicReliableClientStreamTest : public ::testing::Test { |
| 39 public: | 41 public: |
| 40 QuicReliableClientStreamTest() | 42 QuicReliableClientStreamTest() |
| 41 : session_(new MockConnection(1, IPEndPoint(), false), false), | 43 : session_(new MockConnection(1, IPEndPoint(), false), false), |
| 42 stream_(1, &session_, BoundNetLog()) { | 44 stream_(kStreamId, &session_, BoundNetLog()) { |
| 43 stream_.SetDelegate(&delegate_); | 45 stream_.SetDelegate(&delegate_); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void InitializeHeaders() { | 48 void InitializeHeaders() { |
| 47 headers_[":host"] = "www.google.com"; | 49 headers_[":host"] = "www.google.com"; |
| 48 headers_[":path"] = "/index.hml"; | 50 headers_[":path"] = "/index.hml"; |
| 49 headers_[":scheme"] = "https"; | 51 headers_[":scheme"] = "https"; |
| 50 headers_["cookie"] = | 52 headers_["cookie"] = |
| 51 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " | 53 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " |
| 52 "__utmc=160408618; " | 54 "__utmc=160408618; " |
| (...skipping 22 matching lines...) Expand all Loading... |
| 75 | 77 |
| 76 testing::StrictMock<MockDelegate> delegate_; | 78 testing::StrictMock<MockDelegate> delegate_; |
| 77 MockSession session_; | 79 MockSession session_; |
| 78 QuicReliableClientStream stream_; | 80 QuicReliableClientStream stream_; |
| 79 QuicCryptoClientConfig crypto_config_; | 81 QuicCryptoClientConfig crypto_config_; |
| 80 SpdyHeaderBlock headers_; | 82 SpdyHeaderBlock headers_; |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 TEST_F(QuicReliableClientStreamTest, OnFinRead) { | 85 TEST_F(QuicReliableClientStreamTest, OnFinRead) { |
| 84 InitializeHeaders(); | 86 InitializeHeaders(); |
| 85 const QuicGuid kStreamId = 1; | 87 QuicSpdyCompressor compressor; |
| 88 string compressed_headers = compressor.CompressHeaders(headers_); |
| 89 QuicStreamFrame frame1(kStreamId, false, 0, MakeIOVector(compressed_headers)); |
| 86 string uncompressed_headers = | 90 string uncompressed_headers = |
| 87 SpdyUtils::SerializeUncompressedHeaders(headers_); | 91 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 88 QuicStreamFrame frame1(kStreamId, false, 0, | |
| 89 MakeIOVector(uncompressed_headers)); | |
| 90 EXPECT_CALL(delegate_, OnDataReceived(StrEq(uncompressed_headers.data()), | 92 EXPECT_CALL(delegate_, OnDataReceived(StrEq(uncompressed_headers.data()), |
| 91 uncompressed_headers.size())); | 93 uncompressed_headers.size())); |
| 92 stream_.OnStreamFrame(frame1); | 94 stream_.OnStreamFrame(frame1); |
| 93 | 95 |
| 94 IOVector iov; | 96 IOVector iov; |
| 95 QuicStreamFrame frame2(kStreamId, true, uncompressed_headers.length(), iov); | 97 QuicStreamFrame frame2(kStreamId, true, compressed_headers.length(), iov); |
| 96 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); | 98 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); |
| 97 stream_.OnStreamFrame(frame2); | 99 stream_.OnStreamFrame(frame2); |
| 98 } | 100 } |
| 99 | 101 |
| 100 TEST_F(QuicReliableClientStreamTest, ProcessData) { | 102 TEST_F(QuicReliableClientStreamTest, ProcessData) { |
| 101 const char data[] = "hello world!"; | 103 const char data[] = "hello world!"; |
| 102 EXPECT_CALL(delegate_, OnDataReceived(StrEq(data), arraysize(data))); | 104 EXPECT_CALL(delegate_, OnDataReceived(StrEq(data), arraysize(data))); |
| 103 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); | 105 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); |
| 104 | 106 |
| 105 EXPECT_EQ(arraysize(data), stream_.ProcessData(data, arraysize(data))); | 107 EXPECT_EQ(arraysize(data), stream_.ProcessData(data, arraysize(data))); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 EXPECT_CALL(session_, WritevData(stream_.id(), _, _, _, _, _)).WillOnce( | 159 EXPECT_CALL(session_, WritevData(stream_.id(), _, _, _, _, _)).WillOnce( |
| 158 Return(QuicConsumedData(kDataLen, true))); | 160 Return(QuicConsumedData(kDataLen, true))); |
| 159 stream_.OnCanWrite(); | 161 stream_.OnCanWrite(); |
| 160 ASSERT_TRUE(callback.have_result()); | 162 ASSERT_TRUE(callback.have_result()); |
| 161 EXPECT_EQ(OK, callback.WaitForResult()); | 163 EXPECT_EQ(OK, callback.WaitForResult()); |
| 162 } | 164 } |
| 163 | 165 |
| 164 } // namespace | 166 } // namespace |
| 165 } // namespace test | 167 } // namespace test |
| 166 } // namespace net | 168 } // namespace net |
| OLD | NEW |