| 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 <cstddef> | 5 #include <cstddef> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 MockConnect connect_data(SYNCHRONOUS, OK); | 111 MockConnect connect_data(SYNCHRONOUS, OK); |
| 112 data.set_connect_data(connect_data); | 112 data.set_connect_data(connect_data); |
| 113 | 113 |
| 114 session_deps_.socket_factory->AddSocketDataProvider(&data); | 114 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 115 | 115 |
| 116 scoped_refptr<SpdySession> session(CreateSpdySession()); | 116 scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 117 | 117 |
| 118 InitializeSpdySession(session, host_port_pair_); | 118 InitializeSpdySession(session, host_port_pair_); |
| 119 | 119 |
| 120 base::WeakPtr<SpdyStream> stream = | 120 base::WeakPtr<SpdyStream> stream = |
| 121 CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); | 121 CreateStreamSynchronously( |
| 122 SPDY_BIDIRECTIONAL_STREAM, session, url, LOWEST, BoundNetLog()); |
| 122 ASSERT_TRUE(stream.get() != NULL); | 123 ASSERT_TRUE(stream.get() != NULL); |
| 123 | 124 |
| 124 StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); | 125 StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); |
| 125 stream->SetDelegate(&delegate); | 126 stream->SetDelegate(&delegate); |
| 126 | 127 |
| 127 EXPECT_FALSE(stream->HasUrl()); | 128 EXPECT_FALSE(stream->HasUrl()); |
| 128 | 129 |
| 129 scoped_ptr<SpdyHeaderBlock> headers( | 130 scoped_ptr<SpdyHeaderBlock> headers( |
| 130 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); | 131 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 131 EXPECT_EQ(ERR_IO_PENDING, | 132 EXPECT_EQ(ERR_IO_PENDING, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 154 OrderedSocketData data(reads, arraysize(reads), NULL, 0); | 155 OrderedSocketData data(reads, arraysize(reads), NULL, 0); |
| 155 MockConnect connect_data(SYNCHRONOUS, OK); | 156 MockConnect connect_data(SYNCHRONOUS, OK); |
| 156 data.set_connect_data(connect_data); | 157 data.set_connect_data(connect_data); |
| 157 | 158 |
| 158 session_deps_.socket_factory->AddSocketDataProvider(&data); | 159 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 159 | 160 |
| 160 InitializeSpdySession(spdy_session, host_port_pair_); | 161 InitializeSpdySession(spdy_session, host_port_pair_); |
| 161 BoundNetLog net_log; | 162 BoundNetLog net_log; |
| 162 | 163 |
| 163 // Conjure up a stream. | 164 // Conjure up a stream. |
| 164 SpdyStream stream(spdy_session, | 165 SpdyStream stream(SPDY_PUSH_STREAM, |
| 166 spdy_session, |
| 165 std::string(), | 167 std::string(), |
| 166 DEFAULT_PRIORITY, | 168 DEFAULT_PRIORITY, |
| 167 kSpdyStreamInitialWindowSize, | 169 kSpdyStreamInitialWindowSize, |
| 168 kSpdyStreamInitialWindowSize, | 170 kSpdyStreamInitialWindowSize, |
| 169 true, | |
| 170 net_log); | 171 net_log); |
| 171 stream.set_stream_id(2); | 172 stream.set_stream_id(2); |
| 172 EXPECT_FALSE(stream.response_received()); | 173 EXPECT_FALSE(stream.response_received()); |
| 173 EXPECT_FALSE(stream.HasUrl()); | 174 EXPECT_FALSE(stream.HasUrl()); |
| 174 | 175 |
| 175 // Set a couple of headers. | 176 // Set a couple of headers. |
| 176 SpdyHeaderBlock response; | 177 SpdyHeaderBlock response; |
| 177 response["url"] = kStreamUrl; | 178 response["url"] = kStreamUrl; |
| 178 stream.OnResponseReceived(response); | 179 stream.OnResponseReceived(response); |
| 179 | 180 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 MockConnect connect_data(SYNCHRONOUS, OK); | 225 MockConnect connect_data(SYNCHRONOUS, OK); |
| 225 data.set_connect_data(connect_data); | 226 data.set_connect_data(connect_data); |
| 226 | 227 |
| 227 session_deps_.socket_factory->AddSocketDataProvider(&data); | 228 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 228 | 229 |
| 229 scoped_refptr<SpdySession> session(CreateSpdySession()); | 230 scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 230 | 231 |
| 231 InitializeSpdySession(session, host_port_pair_); | 232 InitializeSpdySession(session, host_port_pair_); |
| 232 | 233 |
| 233 base::WeakPtr<SpdyStream> stream = | 234 base::WeakPtr<SpdyStream> stream = |
| 234 CreateStreamSynchronously(session, url, LOWEST, log.bound()); | 235 CreateStreamSynchronously( |
| 236 SPDY_BIDIRECTIONAL_STREAM, session, url, LOWEST, log.bound()); |
| 235 ASSERT_TRUE(stream.get() != NULL); | 237 ASSERT_TRUE(stream.get() != NULL); |
| 236 | 238 |
| 237 StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); | 239 StreamDelegateSendImmediate delegate(stream, kPostBodyStringPiece); |
| 238 stream->SetDelegate(&delegate); | 240 stream->SetDelegate(&delegate); |
| 239 | 241 |
| 240 EXPECT_FALSE(stream->HasUrl()); | 242 EXPECT_FALSE(stream->HasUrl()); |
| 241 | 243 |
| 242 scoped_ptr<SpdyHeaderBlock> headers( | 244 scoped_ptr<SpdyHeaderBlock> headers( |
| 243 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); | 245 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 244 EXPECT_EQ(ERR_IO_PENDING, | 246 EXPECT_EQ(ERR_IO_PENDING, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 MockConnect connect_data(SYNCHRONOUS, OK); | 309 MockConnect connect_data(SYNCHRONOUS, OK); |
| 308 data.set_connect_data(connect_data); | 310 data.set_connect_data(connect_data); |
| 309 | 311 |
| 310 session_deps_.socket_factory->AddSocketDataProvider(&data); | 312 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 311 | 313 |
| 312 scoped_refptr<SpdySession> session(CreateSpdySession()); | 314 scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 313 | 315 |
| 314 InitializeSpdySession(session, host_port_pair_); | 316 InitializeSpdySession(session, host_port_pair_); |
| 315 | 317 |
| 316 base::WeakPtr<SpdyStream> stream = | 318 base::WeakPtr<SpdyStream> stream = |
| 317 CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); | 319 CreateStreamSynchronously( |
| 320 SPDY_REQUEST_RESPONSE_STREAM, session, url, LOWEST, BoundNetLog()); |
| 318 ASSERT_TRUE(stream.get() != NULL); | 321 ASSERT_TRUE(stream.get() != NULL); |
| 319 | 322 |
| 320 std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); | 323 std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); |
| 321 StreamDelegateWithBody delegate(stream, body_data); | 324 StreamDelegateWithBody delegate(stream, body_data); |
| 322 stream->SetDelegate(&delegate); | 325 stream->SetDelegate(&delegate); |
| 323 | 326 |
| 324 EXPECT_FALSE(stream->HasUrl()); | 327 EXPECT_FALSE(stream->HasUrl()); |
| 325 | 328 |
| 326 scoped_ptr<SpdyHeaderBlock> headers( | 329 scoped_ptr<SpdyHeaderBlock> headers( |
| 327 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); | 330 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 MockConnect connect_data(SYNCHRONOUS, OK); | 373 MockConnect connect_data(SYNCHRONOUS, OK); |
| 371 data.set_connect_data(connect_data); | 374 data.set_connect_data(connect_data); |
| 372 | 375 |
| 373 session_deps_.socket_factory->AddSocketDataProvider(&data); | 376 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 374 | 377 |
| 375 scoped_refptr<SpdySession> session(CreateSpdySession()); | 378 scoped_refptr<SpdySession> session(CreateSpdySession()); |
| 376 | 379 |
| 377 InitializeSpdySession(session, host_port_pair_); | 380 InitializeSpdySession(session, host_port_pair_); |
| 378 | 381 |
| 379 base::WeakPtr<SpdyStream> stream = | 382 base::WeakPtr<SpdyStream> stream = |
| 380 CreateStreamSynchronously(session, url, LOWEST, BoundNetLog()); | 383 CreateStreamSynchronously( |
| 384 SPDY_BIDIRECTIONAL_STREAM, session, url, LOWEST, BoundNetLog()); |
| 381 ASSERT_TRUE(stream.get() != NULL); | 385 ASSERT_TRUE(stream.get() != NULL); |
| 382 | 386 |
| 383 std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); | 387 std::string body_data(3 * kMaxSpdyFrameChunkSize, 'x'); |
| 384 StreamDelegateSendImmediate delegate(stream, body_data); | 388 StreamDelegateSendImmediate delegate(stream, body_data); |
| 385 stream->SetDelegate(&delegate); | 389 stream->SetDelegate(&delegate); |
| 386 | 390 |
| 387 EXPECT_FALSE(stream->HasUrl()); | 391 EXPECT_FALSE(stream->HasUrl()); |
| 388 | 392 |
| 389 scoped_ptr<SpdyHeaderBlock> headers( | 393 scoped_ptr<SpdyHeaderBlock> headers( |
| 390 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); | 394 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kPostBodyLength)); |
| 391 EXPECT_EQ(ERR_IO_PENDING, | 395 EXPECT_EQ(ERR_IO_PENDING, |
| 392 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); | 396 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); |
| 393 EXPECT_TRUE(stream->HasUrl()); | 397 EXPECT_TRUE(stream->HasUrl()); |
| 394 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); | 398 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 395 | 399 |
| 396 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 400 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| 397 | 401 |
| 398 EXPECT_TRUE(delegate.send_headers_completed()); | 402 EXPECT_TRUE(delegate.send_headers_completed()); |
| 399 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); | 403 EXPECT_EQ("200", delegate.GetResponseHeaderValue("status")); |
| 400 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); | 404 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue("version")); |
| 401 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); | 405 EXPECT_EQ(std::string(), delegate.TakeReceivedData()); |
| 402 EXPECT_TRUE(data.at_write_eof()); | 406 EXPECT_TRUE(data.at_write_eof()); |
| 403 } | 407 } |
| 404 | 408 |
| 405 } // namespace | 409 } // namespace |
| 406 | 410 |
| 407 } // namespace test | 411 } // namespace test |
| 408 | 412 |
| 409 } // namespace net | 413 } // namespace net |
| OLD | NEW |