Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: net/spdy/spdy_proxy_client_socket_unittest.cc

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_proxy_client_socket.cc ('k') | net/spdy/spdy_read_queue_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 "/"); 115 "/");
116 } 116 }
117 117
118 void ResumeAndRun() { 118 void ResumeAndRun() {
119 // Run until the pause, if the provider isn't paused yet. 119 // Run until the pause, if the provider isn't paused yet.
120 data_->RunUntilPaused(); 120 data_->RunUntilPaused();
121 data_->Resume(); 121 data_->Resume();
122 base::RunLoop().RunUntilIdle(); 122 base::RunLoop().RunUntilIdle();
123 } 123 }
124 124
125 void CloseSpdySession(Error error, const std::string& description) { 125 void CloseSpdySession(Error error, const SpdyString& description) {
126 spdy_session_->CloseSessionOnError(error, description); 126 spdy_session_->CloseSessionOnError(error, description);
127 } 127 }
128 128
129 SpdyTestUtil spdy_util_; 129 SpdyTestUtil spdy_util_;
130 std::unique_ptr<SpdyProxyClientSocket> sock_; 130 std::unique_ptr<SpdyProxyClientSocket> sock_;
131 TestCompletionCallback read_callback_; 131 TestCompletionCallback read_callback_;
132 TestCompletionCallback write_callback_; 132 TestCompletionCallback write_callback_;
133 std::unique_ptr<SequencedSocketData> data_; 133 std::unique_ptr<SequencedSocketData> data_;
134 BoundTestNetLog net_log_; 134 BoundTestNetLog net_log_;
135 135
136 private: 136 private:
137 std::unique_ptr<HttpNetworkSession> session_; 137 std::unique_ptr<HttpNetworkSession> session_;
138 scoped_refptr<IOBuffer> read_buf_; 138 scoped_refptr<IOBuffer> read_buf_;
139 SpdySessionDependencies session_deps_; 139 SpdySessionDependencies session_deps_;
140 MockConnect connect_data_; 140 MockConnect connect_data_;
141 base::WeakPtr<SpdySession> spdy_session_; 141 base::WeakPtr<SpdySession> spdy_session_;
142 std::string user_agent_; 142 SpdyString user_agent_;
143 GURL url_; 143 GURL url_;
144 HostPortPair proxy_host_port_; 144 HostPortPair proxy_host_port_;
145 HostPortPair endpoint_host_port_pair_; 145 HostPortPair endpoint_host_port_pair_;
146 ProxyServer proxy_; 146 ProxyServer proxy_;
147 SpdySessionKey endpoint_spdy_session_key_; 147 SpdySessionKey endpoint_spdy_session_key_;
148 148
149 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest); 149 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest);
150 }; 150 };
151 151
152 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() 152 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest()
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 void SpdyProxyClientSocketTest::AssertConnectionEstablished() { 235 void SpdyProxyClientSocketTest::AssertConnectionEstablished() {
236 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); 236 const HttpResponseInfo* response = sock_->GetConnectResponseInfo();
237 ASSERT_TRUE(response != NULL); 237 ASSERT_TRUE(response != NULL);
238 ASSERT_EQ(200, response->headers->response_code()); 238 ASSERT_EQ(200, response->headers->response_code());
239 } 239 }
240 240
241 void SpdyProxyClientSocketTest::AssertSyncReadEquals(const char* data, 241 void SpdyProxyClientSocketTest::AssertSyncReadEquals(const char* data,
242 int len) { 242 int len) {
243 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); 243 scoped_refptr<IOBuffer> buf(new IOBuffer(len));
244 ASSERT_EQ(len, sock_->Read(buf.get(), len, CompletionCallback())); 244 ASSERT_EQ(len, sock_->Read(buf.get(), len, CompletionCallback()));
245 ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); 245 ASSERT_EQ(SpdyString(data, len), SpdyString(buf->data(), len));
246 ASSERT_TRUE(sock_->IsConnected()); 246 ASSERT_TRUE(sock_->IsConnected());
247 } 247 }
248 248
249 void SpdyProxyClientSocketTest::AssertAsyncReadEquals(const char* data, 249 void SpdyProxyClientSocketTest::AssertAsyncReadEquals(const char* data,
250 int len) { 250 int len) {
251 // Issue the read, which will be completed asynchronously 251 // Issue the read, which will be completed asynchronously
252 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); 252 scoped_refptr<IOBuffer> buf(new IOBuffer(len));
253 ASSERT_EQ(ERR_IO_PENDING, 253 ASSERT_EQ(ERR_IO_PENDING,
254 sock_->Read(buf.get(), len, read_callback_.callback())); 254 sock_->Read(buf.get(), len, read_callback_.callback()));
255 EXPECT_TRUE(sock_->IsConnected()); 255 EXPECT_TRUE(sock_->IsConnected());
256 256
257 ResumeAndRun(); 257 ResumeAndRun();
258 258
259 EXPECT_EQ(len, read_callback_.WaitForResult()); 259 EXPECT_EQ(len, read_callback_.WaitForResult());
260 EXPECT_TRUE(sock_->IsConnected()); 260 EXPECT_TRUE(sock_->IsConnected());
261 ASSERT_EQ(std::string(data, len), std::string(buf->data(), len)); 261 ASSERT_EQ(SpdyString(data, len), SpdyString(buf->data(), len));
262 } 262 }
263 263
264 void SpdyProxyClientSocketTest::AssertReadStarts(const char* data, int len) { 264 void SpdyProxyClientSocketTest::AssertReadStarts(const char* data, int len) {
265 // Issue the read, which will be completed asynchronously. 265 // Issue the read, which will be completed asynchronously.
266 read_buf_ = new IOBuffer(len); 266 read_buf_ = new IOBuffer(len);
267 ASSERT_EQ(ERR_IO_PENDING, 267 ASSERT_EQ(ERR_IO_PENDING,
268 sock_->Read(read_buf_.get(), len, read_callback_.callback())); 268 sock_->Read(read_buf_.get(), len, read_callback_.callback()));
269 EXPECT_TRUE(sock_->IsConnected()); 269 EXPECT_TRUE(sock_->IsConnected());
270 } 270 }
271 271
272 void SpdyProxyClientSocketTest::AssertReadReturns(const char* data, int len) { 272 void SpdyProxyClientSocketTest::AssertReadReturns(const char* data, int len) {
273 EXPECT_TRUE(sock_->IsConnected()); 273 EXPECT_TRUE(sock_->IsConnected());
274 274
275 // Now the read will return 275 // Now the read will return
276 EXPECT_EQ(len, read_callback_.WaitForResult()); 276 EXPECT_EQ(len, read_callback_.WaitForResult());
277 ASSERT_EQ(std::string(data, len), std::string(read_buf_->data(), len)); 277 ASSERT_EQ(SpdyString(data, len), SpdyString(read_buf_->data(), len));
278 } 278 }
279 279
280 void SpdyProxyClientSocketTest::AssertAsyncWriteSucceeds(const char* data, 280 void SpdyProxyClientSocketTest::AssertAsyncWriteSucceeds(const char* data,
281 int len) { 281 int len) {
282 AssertWriteReturns(data, len, ERR_IO_PENDING); 282 AssertWriteReturns(data, len, ERR_IO_PENDING);
283 AssertWriteLength(len); 283 AssertWriteLength(len);
284 } 284 }
285 285
286 void SpdyProxyClientSocketTest::AssertWriteReturns(const char* data, 286 void SpdyProxyClientSocketTest::AssertWriteReturns(const char* data,
287 int len, 287 int len,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 AssertConnectFails(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); 447 AssertConnectFails(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
448 448
449 const HttpResponseInfo* response = sock_->GetConnectResponseInfo(); 449 const HttpResponseInfo* response = sock_->GetConnectResponseInfo();
450 ASSERT_TRUE(response != NULL); 450 ASSERT_TRUE(response != NULL);
451 451
452 const HttpResponseHeaders* headers = response->headers.get(); 452 const HttpResponseHeaders* headers = response->headers.get();
453 ASSERT_EQ(302, headers->response_code()); 453 ASSERT_EQ(302, headers->response_code());
454 ASSERT_FALSE(headers->HasHeader("set-cookie")); 454 ASSERT_FALSE(headers->HasHeader("set-cookie"));
455 ASSERT_TRUE(headers->HasHeaderValue("content-length", "0")); 455 ASSERT_TRUE(headers->HasHeaderValue("content-length", "0"));
456 456
457 std::string location; 457 SpdyString location;
458 ASSERT_TRUE(headers->IsRedirect(&location)); 458 ASSERT_TRUE(headers->IsRedirect(&location));
459 ASSERT_EQ(location, kRedirectUrl); 459 ASSERT_EQ(location, kRedirectUrl);
460 460
461 // Let the RST_STREAM write while |rst| is in-scope. 461 // Let the RST_STREAM write while |rst| is in-scope.
462 base::RunLoop().RunUntilIdle(); 462 base::RunLoop().RunUntilIdle();
463 } 463 }
464 464
465 TEST_F(SpdyProxyClientSocketTest, ConnectFails) { 465 TEST_F(SpdyProxyClientSocketTest, ConnectFails) {
466 SpdySerializedFrame conn(ConstructConnectRequestFrame()); 466 SpdySerializedFrame conn(ConstructConnectRequestFrame());
467 MockWrite writes[] = { 467 MockWrite writes[] = {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 561
562 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 562 Initialize(reads, arraysize(reads), writes, arraysize(writes));
563 563
564 AssertConnectSucceeds(); 564 AssertConnectSucceeds();
565 565
566 AssertAsyncWriteSucceeds(kMsg1, kLen1); 566 AssertAsyncWriteSucceeds(kMsg1, kLen1);
567 AssertAsyncWriteSucceeds(kMsg2, kLen2); 567 AssertAsyncWriteSucceeds(kMsg2, kLen2);
568 } 568 }
569 569
570 TEST_F(SpdyProxyClientSocketTest, WriteSplitsLargeDataIntoMultipleFrames) { 570 TEST_F(SpdyProxyClientSocketTest, WriteSplitsLargeDataIntoMultipleFrames) {
571 std::string chunk_data(kMaxSpdyFrameChunkSize, 'x'); 571 SpdyString chunk_data(kMaxSpdyFrameChunkSize, 'x');
572 SpdySerializedFrame conn(ConstructConnectRequestFrame()); 572 SpdySerializedFrame conn(ConstructConnectRequestFrame());
573 SpdySerializedFrame chunk( 573 SpdySerializedFrame chunk(
574 ConstructBodyFrame(chunk_data.data(), chunk_data.length())); 574 ConstructBodyFrame(chunk_data.data(), chunk_data.length()));
575 MockWrite writes[] = {CreateMockWrite(conn, 0, SYNCHRONOUS), 575 MockWrite writes[] = {CreateMockWrite(conn, 0, SYNCHRONOUS),
576 CreateMockWrite(chunk, 3, SYNCHRONOUS), 576 CreateMockWrite(chunk, 3, SYNCHRONOUS),
577 CreateMockWrite(chunk, 4, SYNCHRONOUS), 577 CreateMockWrite(chunk, 4, SYNCHRONOUS),
578 CreateMockWrite(chunk, 5, SYNCHRONOUS)}; 578 CreateMockWrite(chunk, 5, SYNCHRONOUS)};
579 579
580 SpdySerializedFrame resp(ConstructConnectReplyFrame()); 580 SpdySerializedFrame resp(ConstructConnectReplyFrame());
581 MockRead reads[] = { 581 MockRead reads[] = {
582 CreateMockRead(resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2), 582 CreateMockRead(resp, 1, ASYNC), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2),
583 }; 583 };
584 584
585 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 585 Initialize(reads, arraysize(reads), writes, arraysize(writes));
586 586
587 AssertConnectSucceeds(); 587 AssertConnectSucceeds();
588 588
589 std::string big_data(kMaxSpdyFrameChunkSize * 3, 'x'); 589 SpdyString big_data(kMaxSpdyFrameChunkSize * 3, 'x');
590 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(big_data.data(), 590 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(big_data.data(),
591 big_data.length())); 591 big_data.length()));
592 592
593 EXPECT_EQ(ERR_IO_PENDING, 593 EXPECT_EQ(ERR_IO_PENDING,
594 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); 594 sock_->Write(buf.get(), buf->size(), write_callback_.callback()));
595 EXPECT_EQ(buf->size(), write_callback_.WaitForResult()); 595 EXPECT_EQ(buf->size(), write_callback_.WaitForResult());
596 } 596 }
597 597
598 // ----------- Read 598 // ----------- Read
599 599
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 789
790 // SpdySession consumes the next read and sends it to sock_ to be buffered. 790 // SpdySession consumes the next read and sends it to sock_ to be buffered.
791 ResumeAndRun(); 791 ResumeAndRun();
792 // The payload from the single large data frame will be read across 792 // The payload from the single large data frame will be read across
793 // two different reads. 793 // two different reads.
794 AssertSyncReadEquals(kMsg33, kLen33); 794 AssertSyncReadEquals(kMsg33, kLen33);
795 795
796 // Now attempt to do a read of more data than remains buffered 796 // Now attempt to do a read of more data than remains buffered
797 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33)); 797 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33));
798 ASSERT_EQ(kLen3, sock_->Read(buf.get(), kLen33, read_callback_.callback())); 798 ASSERT_EQ(kLen3, sock_->Read(buf.get(), kLen33, read_callback_.callback()));
799 ASSERT_EQ(std::string(kMsg3, kLen3), std::string(buf->data(), kLen3)); 799 ASSERT_EQ(SpdyString(kMsg3, kLen3), SpdyString(buf->data(), kLen3));
800 ASSERT_TRUE(sock_->IsConnected()); 800 ASSERT_TRUE(sock_->IsConnected());
801 } 801 }
802 802
803 TEST_F(SpdyProxyClientSocketTest, ReadAuthResponseBody) { 803 TEST_F(SpdyProxyClientSocketTest, ReadAuthResponseBody) {
804 SpdySerializedFrame conn(ConstructConnectRequestFrame()); 804 SpdySerializedFrame conn(ConstructConnectRequestFrame());
805 MockWrite writes[] = { 805 MockWrite writes[] = {
806 CreateMockWrite(conn, 0, SYNCHRONOUS), 806 CreateMockWrite(conn, 0, SYNCHRONOUS),
807 }; 807 };
808 808
809 SpdySerializedFrame resp(ConstructConnectAuthReplyFrame()); 809 SpdySerializedFrame resp(ConstructConnectAuthReplyFrame());
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 1018
1019 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1019 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1020 1020
1021 AssertConnectSucceeds(); 1021 AssertConnectSucceeds();
1022 1022
1023 ResumeAndRun(); 1023 ResumeAndRun();
1024 1024
1025 ASSERT_FALSE(sock_->IsConnected()); 1025 ASSERT_FALSE(sock_->IsConnected());
1026 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1)); 1026 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1));
1027 ASSERT_EQ(kLen1, sock_->Read(buf.get(), kLen1, CompletionCallback())); 1027 ASSERT_EQ(kLen1, sock_->Read(buf.get(), kLen1, CompletionCallback()));
1028 ASSERT_EQ(std::string(kMsg1, kLen1), std::string(buf->data(), kLen1)); 1028 ASSERT_EQ(SpdyString(kMsg1, kLen1), SpdyString(buf->data(), kLen1));
1029 1029
1030 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); 1030 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback()));
1031 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback())); 1031 ASSERT_EQ(0, sock_->Read(NULL, 1, CompletionCallback()));
1032 sock_->Disconnect(); 1032 sock_->Disconnect();
1033 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED, 1033 ASSERT_EQ(ERR_SOCKET_NOT_CONNECTED,
1034 sock_->Read(NULL, 1, CompletionCallback())); 1034 sock_->Read(NULL, 1, CompletionCallback()));
1035 } 1035 }
1036 1036
1037 // Calling Write() on a closed socket is an error 1037 // Calling Write() on a closed socket is an error
1038 TEST_F(SpdyProxyClientSocketTest, WriteOnClosedStream) { 1038 TEST_F(SpdyProxyClientSocketTest, WriteOnClosedStream) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 AssertConnectSucceeds(); 1107 AssertConnectSucceeds();
1108 1108
1109 EXPECT_TRUE(sock_->IsConnected()); 1109 EXPECT_TRUE(sock_->IsConnected());
1110 1110
1111 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1)); 1111 scoped_refptr<IOBufferWithSize> buf(CreateBuffer(kMsg1, kLen1));
1112 EXPECT_EQ(ERR_IO_PENDING, 1112 EXPECT_EQ(ERR_IO_PENDING,
1113 sock_->Write(buf.get(), buf->size(), write_callback_.callback())); 1113 sock_->Write(buf.get(), buf->size(), write_callback_.callback()));
1114 // Make sure the write actually starts. 1114 // Make sure the write actually starts.
1115 base::RunLoop().RunUntilIdle(); 1115 base::RunLoop().RunUntilIdle();
1116 1116
1117 CloseSpdySession(ERR_ABORTED, std::string()); 1117 CloseSpdySession(ERR_ABORTED, SpdyString());
1118 1118
1119 EXPECT_THAT(write_callback_.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); 1119 EXPECT_THAT(write_callback_.WaitForResult(), IsError(ERR_CONNECTION_CLOSED));
1120 } 1120 }
1121 1121
1122 // If the socket is Disconnected with a pending Write(), the callback 1122 // If the socket is Disconnected with a pending Write(), the callback
1123 // should not be called. 1123 // should not be called.
1124 TEST_F(SpdyProxyClientSocketTest, DisconnectWithWritePending) { 1124 TEST_F(SpdyProxyClientSocketTest, DisconnectWithWritePending) {
1125 SpdySerializedFrame conn(ConstructConnectRequestFrame()); 1125 SpdySerializedFrame conn(ConstructConnectRequestFrame());
1126 SpdySerializedFrame rst( 1126 SpdySerializedFrame rst(
1127 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); 1127 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL));
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 1355
1356 EXPECT_FALSE(sock_.get()); 1356 EXPECT_FALSE(sock_.get());
1357 EXPECT_TRUE(read_callback.have_result()); 1357 EXPECT_TRUE(read_callback.have_result());
1358 EXPECT_FALSE(write_callback_.have_result()); 1358 EXPECT_FALSE(write_callback_.have_result());
1359 1359
1360 // Let the RST_STREAM write while |rst| is in-scope. 1360 // Let the RST_STREAM write while |rst| is in-scope.
1361 base::RunLoop().RunUntilIdle(); 1361 base::RunLoop().RunUntilIdle();
1362 } 1362 }
1363 1363
1364 } // namespace net 1364 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_proxy_client_socket.cc ('k') | net/spdy/spdy_read_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698