| 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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
| 10 #include "net/base/net_log_unittest.h" | 10 #include "net/base/net_log_unittest.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 SpdySessionPool* spdy_session_pool_; | 120 SpdySessionPool* spdy_session_pool_; |
| 121 GURL test_url_; | 121 GURL test_url_; |
| 122 HostPortPair test_host_port_pair_; | 122 HostPortPair test_host_port_pair_; |
| 123 HostPortProxyPair pair_; | 123 HostPortProxyPair pair_; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 TEST_F(SpdySessionSpdy3Test, GoAway) { | 126 TEST_F(SpdySessionSpdy3Test, GoAway) { |
| 127 session_deps_.host_resolver->set_synchronous_mode(true); | 127 session_deps_.host_resolver->set_synchronous_mode(true); |
| 128 | 128 |
| 129 MockConnect connect_data(SYNCHRONOUS, OK); | 129 MockConnect connect_data(SYNCHRONOUS, OK); |
| 130 scoped_ptr<SpdyFrame> goaway(ConstructSpdyGoAway()); | 130 scoped_ptr<SpdyFrame> goaway(ConstructSpdyGoAway(1)); |
| 131 MockRead reads[] = { | 131 MockRead reads[] = { |
| 132 CreateMockRead(*goaway), | 132 CreateMockRead(*goaway, 2), |
| 133 MockRead(SYNCHRONOUS, 0, 0) // EOF | 133 MockRead(ASYNC, 0, 3) // EOF |
| 134 }; | 134 }; |
| 135 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 135 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, MEDIUM)); |
| 136 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, MEDIUM)); |
| 137 MockWrite writes[] = { |
| 138 CreateMockWrite(*req1, 0), |
| 139 CreateMockWrite(*req2, 1), |
| 140 }; |
| 141 DeterministicSocketData data(reads, arraysize(reads), |
| 142 writes, arraysize(writes)); |
| 136 data.set_connect_data(connect_data); | 143 data.set_connect_data(connect_data); |
| 137 session_deps_.socket_factory->AddSocketDataProvider(&data); | 144 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 138 | 145 |
| 139 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 146 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 140 ssl.SetNextProto(kProtoSPDY3); | 147 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
| 141 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 142 | 148 |
| 143 CreateNetworkSession(); | 149 CreateDeterministicNetworkSession(); |
| 144 | 150 |
| 145 scoped_refptr<SpdySession> session = CreateInitializedSession(); | 151 scoped_refptr<SpdySession> session = CreateInitializedSession(); |
| 146 | 152 |
| 147 EXPECT_EQ(3, session->GetProtocolVersion()); | 153 EXPECT_EQ(3, session->GetProtocolVersion()); |
| 148 | 154 |
| 149 // Flush the SpdySession::OnReadComplete() task. | 155 GURL url("http://www.google.com"); |
| 150 MessageLoop::current()->RunUntilIdle(); | 156 scoped_refptr<SpdyStream> spdy_stream1 = |
| 157 CreateStreamSynchronously(session, url, MEDIUM, BoundNetLog()); |
| 158 |
| 159 scoped_refptr<SpdyStream> spdy_stream2 = |
| 160 CreateStreamSynchronously(session, url, MEDIUM, BoundNetLog()); |
| 161 |
| 162 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| 163 (*headers)[":method"] = "GET"; |
| 164 (*headers)[":scheme"] = url.scheme(); |
| 165 (*headers)[":host"] = url.host(); |
| 166 (*headers)[":path"] = url.path(); |
| 167 (*headers)[":version"] = "HTTP/1.1"; |
| 168 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock); |
| 169 *headers2 = *headers; |
| 170 |
| 171 spdy_stream1->set_spdy_headers(headers.Pass()); |
| 172 EXPECT_TRUE(spdy_stream1->HasUrl()); |
| 173 |
| 174 spdy_stream2->set_spdy_headers(headers2.Pass()); |
| 175 EXPECT_TRUE(spdy_stream2->HasUrl()); |
| 176 |
| 177 spdy_stream1->SendRequest(false); |
| 178 spdy_stream2->SendRequest(false); |
| 179 data.RunFor(2); |
| 180 |
| 181 EXPECT_EQ(1u, spdy_stream1->stream_id()); |
| 182 EXPECT_EQ(3u, spdy_stream2->stream_id()); |
| 183 |
| 184 EXPECT_TRUE(spdy_session_pool_->HasSession(pair_)); |
| 185 |
| 186 // Read and process the GOAWAY frame. |
| 187 data.RunFor(1); |
| 151 | 188 |
| 152 EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); | 189 EXPECT_FALSE(spdy_session_pool_->HasSession(pair_)); |
| 153 | 190 |
| 191 EXPECT_TRUE(session->IsStreamActive(1)); |
| 192 EXPECT_FALSE(session->IsStreamActive(3)); |
| 193 |
| 154 scoped_refptr<SpdySession> session2 = GetSession(pair_); | 194 scoped_refptr<SpdySession> session2 = GetSession(pair_); |
| 155 | 195 |
| 196 spdy_stream1->Close(); |
| 197 spdy_stream1 = NULL; |
| 198 spdy_stream2 = NULL; |
| 199 |
| 156 // Delete the first session. | 200 // Delete the first session. |
| 157 session = NULL; | 201 session = NULL; |
| 158 | 202 |
| 159 // Delete the second session. | 203 // Delete the second session. |
| 160 spdy_session_pool_->Remove(session2); | 204 spdy_session_pool_->Remove(session2); |
| 161 session2 = NULL; | 205 session2 = NULL; |
| 162 } | 206 } |
| 163 | 207 |
| 164 TEST_F(SpdySessionSpdy3Test, ClientPing) { | 208 TEST_F(SpdySessionSpdy3Test, ClientPing) { |
| 165 session_deps_.enable_ping = true; | 209 session_deps_.enable_ping = true; |
| (...skipping 2807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2973 EXPECT_EQ(0, delegate1.body_data_sent()); | 3017 EXPECT_EQ(0, delegate1.body_data_sent()); |
| 2974 | 3018 |
| 2975 EXPECT_TRUE(delegate2.send_headers_completed()); | 3019 EXPECT_TRUE(delegate2.send_headers_completed()); |
| 2976 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); | 3020 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); |
| 2977 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); | 3021 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); |
| 2978 EXPECT_EQ("", delegate2.received_data()); | 3022 EXPECT_EQ("", delegate2.received_data()); |
| 2979 EXPECT_EQ(0, delegate2.body_data_sent()); | 3023 EXPECT_EQ(0, delegate2.body_data_sent()); |
| 2980 } | 3024 } |
| 2981 | 3025 |
| 2982 } // namespace net | 3026 } // namespace net |
| OLD | NEW |