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 <cstddef> | 5 #include <cstddef> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc | 29 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc |
30 // | 30 // |
31 namespace net { | 31 namespace net { |
32 | 32 |
33 namespace test { | 33 namespace test { |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
| 37 enum TestCase { |
| 38 // Test using the SPDY 3.1 protocol. |
| 39 kTestCaseSPDY31, |
| 40 |
| 41 // Test using the HTTP2 protocol, without specifying a stream |
| 42 // dependency based on the RequestPriority. |
| 43 kTestCaseHTTP2NoPriorityDependencies, |
| 44 |
| 45 // Test using the HTTP2 protocol, specifying a stream |
| 46 // dependency based on the RequestPriority. |
| 47 kTestCaseHTTP2PriorityDependencies |
| 48 }; |
| 49 |
37 const char kStreamUrl[] = "http://www.example.org/"; | 50 const char kStreamUrl[] = "http://www.example.org/"; |
38 const char kPostBody[] = "\0hello!\xff"; | 51 const char kPostBody[] = "\0hello!\xff"; |
39 const size_t kPostBodyLength = arraysize(kPostBody); | 52 const size_t kPostBodyLength = arraysize(kPostBody); |
40 const base::StringPiece kPostBodyStringPiece(kPostBody, kPostBodyLength); | 53 const base::StringPiece kPostBodyStringPiece(kPostBody, kPostBodyLength); |
41 | 54 |
42 class SpdyStreamTest : public ::testing::Test, | 55 class SpdyStreamTest : public ::testing::Test, |
43 public ::testing::WithParamInterface<NextProto> { | 56 public ::testing::WithParamInterface<TestCase> { |
44 protected: | 57 protected: |
45 // A function that takes a SpdyStream and the number of bytes which | 58 // A function that takes a SpdyStream and the number of bytes which |
46 // will unstall the next frame completely. | 59 // will unstall the next frame completely. |
47 typedef base::Callback<void(const base::WeakPtr<SpdyStream>&, int32)> | 60 typedef base::Callback<void(const base::WeakPtr<SpdyStream>&, int32)> |
48 UnstallFunction; | 61 UnstallFunction; |
49 | 62 |
50 SpdyStreamTest() | 63 SpdyStreamTest() |
51 : spdy_util_(GetParam()), | 64 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
52 session_deps_(GetParam()), | 65 session_deps_(GetProtocol()), |
53 offset_(0) {} | 66 offset_(0) { |
| 67 SpdySession::SetPriorityDependencyDefaultForTesting( |
| 68 GetDependenciesFromPriority()); |
| 69 } |
| 70 |
| 71 ~SpdyStreamTest() { |
| 72 SpdySession::SetPriorityDependencyDefaultForTesting(false); |
| 73 } |
54 | 74 |
55 base::WeakPtr<SpdySession> CreateDefaultSpdySession() { | 75 base::WeakPtr<SpdySession> CreateDefaultSpdySession() { |
56 SpdySessionKey key(HostPortPair("www.example.org", 80), | 76 SpdySessionKey key(HostPortPair("www.example.org", 80), |
57 ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 77 ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
58 return CreateInsecureSpdySession(session_.get(), key, BoundNetLog()); | 78 return CreateInsecureSpdySession(session_.get(), key, BoundNetLog()); |
59 } | 79 } |
60 | 80 |
61 void TearDown() override { base::MessageLoop::current()->RunUntilIdle(); } | 81 void TearDown() override { base::MessageLoop::current()->RunUntilIdle(); } |
62 | 82 |
| 83 NextProto GetProtocol() const { |
| 84 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 85 } |
| 86 |
| 87 bool GetDependenciesFromPriority() const { |
| 88 return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 89 } |
| 90 |
63 void RunResumeAfterUnstallRequestResponseTest( | 91 void RunResumeAfterUnstallRequestResponseTest( |
64 const UnstallFunction& unstall_function); | 92 const UnstallFunction& unstall_function); |
65 | 93 |
66 void RunResumeAfterUnstallBidirectionalTest( | 94 void RunResumeAfterUnstallBidirectionalTest( |
67 const UnstallFunction& unstall_function); | 95 const UnstallFunction& unstall_function); |
68 | 96 |
69 // Add{Read,Write}() populates lists that are eventually passed to a | 97 // Add{Read,Write}() populates lists that are eventually passed to a |
70 // SocketData class. |frame| must live for the whole test. | 98 // SocketData class. |frame| must live for the whole test. |
71 | 99 |
72 void AddRead(const SpdyFrame& frame) { | 100 void AddRead(const SpdyFrame& frame) { |
(...skipping 28 matching lines...) Expand all Loading... |
101 SpdySessionDependencies session_deps_; | 129 SpdySessionDependencies session_deps_; |
102 scoped_ptr<HttpNetworkSession> session_; | 130 scoped_ptr<HttpNetworkSession> session_; |
103 | 131 |
104 private: | 132 private: |
105 // Used by Add{Read,Write}() above. | 133 // Used by Add{Read,Write}() above. |
106 std::vector<MockWrite> writes_; | 134 std::vector<MockWrite> writes_; |
107 std::vector<MockRead> reads_; | 135 std::vector<MockRead> reads_; |
108 int offset_; | 136 int offset_; |
109 }; | 137 }; |
110 | 138 |
111 INSTANTIATE_TEST_CASE_P(NextProto, | 139 INSTANTIATE_TEST_CASE_P(TestCase, |
112 SpdyStreamTest, | 140 SpdyStreamTest, |
113 testing::Values(kProtoSPDY31, | 141 testing::Values(kTestCaseSPDY31, |
114 kProtoHTTP2)); | 142 kTestCaseHTTP2NoPriorityDependencies, |
| 143 kTestCaseHTTP2PriorityDependencies)); |
115 | 144 |
116 TEST_P(SpdyStreamTest, SendDataAfterOpen) { | 145 TEST_P(SpdyStreamTest, SendDataAfterOpen) { |
117 GURL url(kStreamUrl); | 146 GURL url(kStreamUrl); |
118 | 147 |
119 session_ = | 148 session_ = |
120 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); | 149 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); |
121 | 150 |
122 scoped_ptr<SpdyFrame> req( | 151 scoped_ptr<SpdyFrame> req( |
123 spdy_util_.ConstructSpdyPost( | 152 spdy_util_.ConstructSpdyPost( |
124 kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); | 153 kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 data.RunFor(1); // FIN | 1154 data.RunFor(1); // FIN |
1126 | 1155 |
1127 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 1156 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
1128 } | 1157 } |
1129 | 1158 |
1130 } // namespace | 1159 } // namespace |
1131 | 1160 |
1132 } // namespace test | 1161 } // namespace test |
1133 | 1162 |
1134 } // namespace net | 1163 } // namespace net |
OLD | NEW |