| 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_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 : public PlatformTest, | 64 : public PlatformTest, |
| 65 public testing::WithParamInterface<NextProto> { | 65 public testing::WithParamInterface<NextProto> { |
| 66 public: | 66 public: |
| 67 SpdyProxyClientSocketTest(); | 67 SpdyProxyClientSocketTest(); |
| 68 | 68 |
| 69 virtual void TearDown(); | 69 virtual void TearDown(); |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, | 72 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, |
| 73 size_t writes_count); | 73 size_t writes_count); |
| 74 void PopulateConnectRequestIR(SpdySynStreamIR* syn_ir); | 74 void PopulateConnectRequestIR(SpdyHeaderBlock* syn_ir); |
| 75 void PopulateConnectReplyIR(SpdyHeaderBlock* block, const char* status); | 75 void PopulateConnectReplyIR(SpdyHeaderBlock* block, const char* status); |
| 76 SpdyFrame* ConstructConnectRequestFrame(); | 76 SpdyFrame* ConstructConnectRequestFrame(); |
| 77 SpdyFrame* ConstructConnectAuthRequestFrame(); | 77 SpdyFrame* ConstructConnectAuthRequestFrame(); |
| 78 SpdyFrame* ConstructConnectReplyFrame(); | 78 SpdyFrame* ConstructConnectReplyFrame(); |
| 79 SpdyFrame* ConstructConnectAuthReplyFrame(); | 79 SpdyFrame* ConstructConnectAuthReplyFrame(); |
| 80 SpdyFrame* ConstructConnectRedirectReplyFrame(); | 80 SpdyFrame* ConstructConnectRedirectReplyFrame(); |
| 81 SpdyFrame* ConstructConnectErrorReplyFrame(); | 81 SpdyFrame* ConstructConnectErrorReplyFrame(); |
| 82 SpdyFrame* ConstructBodyFrame(const char* data, int length); | 82 SpdyFrame* ConstructBodyFrame(const char* data, int length); |
| 83 scoped_refptr<IOBufferWithSize> CreateBuffer(const char* data, int size); | 83 scoped_refptr<IOBufferWithSize> CreateBuffer(const char* data, int size); |
| 84 void AssertConnectSucceeds(); | 84 void AssertConnectSucceeds(); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 304 |
| 305 for (int i = 0; i < num_reads; i++) { | 305 for (int i = 0; i < num_reads; i++) { |
| 306 Run(1); | 306 Run(1); |
| 307 AssertSyncReadEquals(kMsg2, kLen2); | 307 AssertSyncReadEquals(kMsg2, kLen2); |
| 308 } | 308 } |
| 309 | 309 |
| 310 write_callback_.WaitForResult(); | 310 write_callback_.WaitForResult(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void SpdyProxyClientSocketTest::PopulateConnectRequestIR( | 313 void SpdyProxyClientSocketTest::PopulateConnectRequestIR( |
| 314 SpdySynStreamIR* syn_ir) { | 314 SpdyHeaderBlock* block) { |
| 315 spdy_util_.SetPriority(LOWEST, syn_ir); | 315 (*block)[spdy_util_.GetMethodKey()] = "CONNECT"; |
| 316 syn_ir->SetHeader(spdy_util_.GetMethodKey(), "CONNECT"); | 316 (*block)[spdy_util_.GetPathKey()] = kOriginHostPort; |
| 317 syn_ir->SetHeader(spdy_util_.GetPathKey(), kOriginHostPort); | 317 (*block)[spdy_util_.GetHostKey()] = kOriginHost; |
| 318 syn_ir->SetHeader(spdy_util_.GetHostKey(), kOriginHost); | 318 (*block)["user-agent"] = kUserAgent; |
| 319 syn_ir->SetHeader("user-agent", kUserAgent); | 319 spdy_util_.MaybeAddVersionHeader(block); |
| 320 spdy_util_.MaybeAddVersionHeader(syn_ir); | |
| 321 } | 320 } |
| 322 | 321 |
| 323 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdyHeaderBlock* block, | 322 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdyHeaderBlock* block, |
| 324 const char* status) { | 323 const char* status) { |
| 325 (*block)[spdy_util_.GetStatusKey()] = status; | 324 (*block)[spdy_util_.GetStatusKey()] = status; |
| 326 spdy_util_.MaybeAddVersionHeader(block); | 325 spdy_util_.MaybeAddVersionHeader(block); |
| 327 } | 326 } |
| 328 | 327 |
| 329 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 328 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
| 330 SpdyFrame* | 329 SpdyFrame* |
| 331 SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { | 330 SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { |
| 332 SpdySynStreamIR syn_ir(kStreamId); | 331 SpdyHeaderBlock block; |
| 333 PopulateConnectRequestIR(&syn_ir); | 332 PopulateConnectRequestIR(&block); |
| 334 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); | 333 return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false, false); |
| 335 } | 334 } |
| 336 | 335 |
| 337 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes | 336 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes |
| 338 // Proxy-Authorization headers. | 337 // Proxy-Authorization headers. |
| 339 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { | 338 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { |
| 340 SpdySynStreamIR syn_ir(kStreamId); | 339 SpdyHeaderBlock block; |
| 341 PopulateConnectRequestIR(&syn_ir); | 340 PopulateConnectRequestIR(&block); |
| 342 syn_ir.SetHeader("proxy-authorization", "Basic Zm9vOmJhcg=="); | 341 block["proxy-authorization"] = "Basic Zm9vOmJhcg=="; |
| 343 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); | 342 return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false, false); |
| 344 } | 343 } |
| 345 | 344 |
| 346 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. | 345 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. |
| 347 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { | 346 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { |
| 348 SpdyHeaderBlock block; | 347 SpdyHeaderBlock block; |
| 349 PopulateConnectReplyIR(&block, "200"); | 348 PopulateConnectReplyIR(&block, "200"); |
| 350 SpdySynReplyIR reply_ir(kStreamId); | 349 SpdySynReplyIR reply_ir(kStreamId); |
| 351 return spdy_util_.ConstructSpdyReply(kStreamId, block); | 350 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
| 352 } | 351 } |
| 353 | 352 |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 | 1375 |
| 1377 EXPECT_FALSE(sock_.get()); | 1376 EXPECT_FALSE(sock_.get()); |
| 1378 EXPECT_TRUE(read_callback.have_result()); | 1377 EXPECT_TRUE(read_callback.have_result()); |
| 1379 EXPECT_FALSE(write_callback_.have_result()); | 1378 EXPECT_FALSE(write_callback_.have_result()); |
| 1380 | 1379 |
| 1381 // Let the RST_STREAM write while |rst| is in-scope. | 1380 // Let the RST_STREAM write while |rst| is in-scope. |
| 1382 base::MessageLoop::current()->RunUntilIdle(); | 1381 base::MessageLoop::current()->RunUntilIdle(); |
| 1383 } | 1382 } |
| 1384 | 1383 |
| 1385 } // namespace net | 1384 } // namespace net |
| OLD | NEW |