OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/spdy/bidirectional_stream_spdy_impl.h" | 5 #include "net/spdy/bidirectional_stream_spdy_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/timer/mock_timer.h" | 16 #include "base/timer/mock_timer.h" |
17 #include "net/base/load_timing_info.h" | 17 #include "net/base/load_timing_info.h" |
18 #include "net/base/load_timing_info_test_util.h" | 18 #include "net/base/load_timing_info_test_util.h" |
19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
20 #include "net/http/http_request_info.h" | 20 #include "net/http/http_request_info.h" |
21 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
22 #include "net/http/http_response_info.h" | 22 #include "net/http/http_response_info.h" |
23 #include "net/log/net_log.h" | 23 #include "net/log/net_log_source.h" |
24 #include "net/log/test_net_log.h" | 24 #include "net/log/test_net_log.h" |
25 #include "net/socket/socket_test_util.h" | 25 #include "net/socket/socket_test_util.h" |
26 #include "net/spdy/spdy_session.h" | 26 #include "net/spdy/spdy_session.h" |
27 #include "net/spdy/spdy_test_util_common.h" | 27 #include "net/spdy/spdy_test_util_common.h" |
28 #include "net/test/cert_test_util.h" | 28 #include "net/test/cert_test_util.h" |
29 #include "net/test/gtest_util.h" | 29 #include "net/test/gtest_util.h" |
30 #include "net/test/test_data_directory.h" | 30 #include "net/test/test_data_directory.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 | 33 |
34 using net::test::IsError; | 34 using net::test::IsError; |
35 using net::test::IsOk; | 35 using net::test::IsOk; |
36 | 36 |
37 namespace net { | 37 namespace net { |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 const char kBodyData[] = "Body data"; | 41 const char kBodyData[] = "Body data"; |
42 const size_t kBodyDataSize = arraysize(kBodyData); | 42 const size_t kBodyDataSize = arraysize(kBodyData); |
43 // Size of the buffer to be allocated for each read. | 43 // Size of the buffer to be allocated for each read. |
44 const size_t kReadBufferSize = 4096; | 44 const size_t kReadBufferSize = 4096; |
45 | 45 |
46 // Tests the load timing of a stream that's connected and is not the first | 46 // Tests the load timing of a stream that's connected and is not the first |
47 // request sent on a connection. | 47 // request sent on a connection. |
48 void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { | 48 void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
49 EXPECT_TRUE(load_timing_info.socket_reused); | 49 EXPECT_TRUE(load_timing_info.socket_reused); |
50 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 50 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
51 | 51 |
52 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 52 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
53 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 53 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
54 } | 54 } |
55 | 55 |
56 // Tests the load timing of a stream that's connected and using a fresh | 56 // Tests the load timing of a stream that's connected and using a fresh |
57 // connection. | 57 // connection. |
58 void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info) { | 58 void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info) { |
59 EXPECT_FALSE(load_timing_info.socket_reused); | 59 EXPECT_FALSE(load_timing_info.socket_reused); |
60 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 60 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
61 | 61 |
62 ExpectConnectTimingHasTimes( | 62 ExpectConnectTimingHasTimes( |
63 load_timing_info.connect_timing, | 63 load_timing_info.connect_timing, |
64 CONNECT_TIMING_HAS_SSL_TIMES | CONNECT_TIMING_HAS_DNS_TIMES); | 64 CONNECT_TIMING_HAS_SSL_TIMES | CONNECT_TIMING_HAS_DNS_TIMES); |
65 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 65 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
66 } | 66 } |
67 | 67 |
68 class TestDelegateBase : public BidirectionalStreamImpl::Delegate { | 68 class TestDelegateBase : public BidirectionalStreamImpl::Delegate { |
69 public: | 69 public: |
70 TestDelegateBase(base::WeakPtr<SpdySession> session, | 70 TestDelegateBase(base::WeakPtr<SpdySession> session, |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 EXPECT_EQ(0, delegate->on_data_sent_count()); | 426 EXPECT_EQ(0, delegate->on_data_sent_count()); |
427 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); | 427 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); |
428 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst| | 428 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst| |
429 // because it is sent after SpdyStream::Delegate::OnClose is called. | 429 // because it is sent after SpdyStream::Delegate::OnClose is called. |
430 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); | 430 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); |
431 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 431 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
432 delegate->GetTotalReceivedBytes()); | 432 delegate->GetTotalReceivedBytes()); |
433 } | 433 } |
434 | 434 |
435 } // namespace net | 435 } // namespace net |
OLD | NEW |