OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/http/http_pipelined_connection_impl.h" | 5 #include "net/http/http_pipelined_connection_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 class DummySocketParams : public base::RefCounted<DummySocketParams> { | 26 class DummySocketParams : public base::RefCounted<DummySocketParams> { |
27 private: | 27 private: |
28 friend class base::RefCounted<DummySocketParams>; | 28 friend class base::RefCounted<DummySocketParams>; |
29 }; | 29 }; |
30 | 30 |
31 REGISTER_SOCKET_PARAMS_FOR_POOL(MockTransportClientSocketPool, | 31 REGISTER_SOCKET_PARAMS_FOR_POOL(MockTransportClientSocketPool, |
32 DummySocketParams); | 32 DummySocketParams); |
33 | 33 |
34 class MockPipelineDelegate : public HttpPipelinedConnectionImpl::Delegate { | 34 class MockPipelineDelegate : public HttpPipelinedConnection::Delegate { |
35 public: | 35 public: |
36 MOCK_METHOD1(OnPipelineHasCapacity, void(HttpPipelinedConnection* pipeline)); | 36 MOCK_METHOD1(OnPipelineHasCapacity, void(HttpPipelinedConnection* pipeline)); |
| 37 MOCK_METHOD2(OnPipelineFeedback, void( |
| 38 HttpPipelinedConnection* pipeline, |
| 39 HttpPipelinedConnection::Feedback feedback)); |
37 }; | 40 }; |
38 | 41 |
39 class SuddenCloseObserver : public MessageLoop::TaskObserver { | 42 class SuddenCloseObserver : public MessageLoop::TaskObserver { |
40 public: | 43 public: |
41 SuddenCloseObserver(HttpStream* stream, int close_before_task) | 44 SuddenCloseObserver(HttpStream* stream, int close_before_task) |
42 : stream_(stream), | 45 : stream_(stream), |
43 close_before_task_(close_before_task), | 46 close_before_task_(close_before_task), |
44 current_task_(0) { } | 47 current_task_(0) { } |
45 | 48 |
46 virtual void WillProcessTask(base::TimeTicks) OVERRIDE { | 49 virtual void WillProcessTask(base::TimeTicks) OVERRIDE { |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 data_->RunFor(1); | 1082 data_->RunFor(1); |
1080 EXPECT_FALSE(close_callback->have_result()); | 1083 EXPECT_FALSE(close_callback->have_result()); |
1081 | 1084 |
1082 close_stream->Close(false); | 1085 close_stream->Close(false); |
1083 close_stream.reset(); | 1086 close_stream.reset(); |
1084 close_callback.reset(); | 1087 close_callback.reset(); |
1085 | 1088 |
1086 MessageLoop::current()->RunAllPending(); | 1089 MessageLoop::current()->RunAllPending(); |
1087 } | 1090 } |
1088 | 1091 |
| 1092 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) { |
| 1093 MockWrite writes[] = { |
| 1094 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1095 MockWrite(false, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 1096 MockWrite(false, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"), |
| 1097 }; |
| 1098 MockRead reads[] = { |
| 1099 MockRead(true, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1100 MockRead(false, 4, "ok.html"), |
| 1101 MockRead(false, OK, 5), |
| 1102 }; |
| 1103 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1104 |
| 1105 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 1106 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 1107 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); |
| 1108 |
| 1109 HttpRequestHeaders headers; |
| 1110 HttpResponseInfo response; |
| 1111 EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response, &callback_)); |
| 1112 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response, |
| 1113 &callback_)); |
| 1114 EXPECT_EQ(OK, rejected_stream->SendRequest(headers, NULL, &response, |
| 1115 &callback_)); |
| 1116 |
| 1117 TestOldCompletionCallback ok_callback; |
| 1118 EXPECT_EQ(ERR_IO_PENDING, ok_stream->ReadResponseHeaders(&ok_callback)); |
| 1119 |
| 1120 TestOldCompletionCallback evicted_callback; |
| 1121 EXPECT_EQ(ERR_IO_PENDING, |
| 1122 evicted_stream->ReadResponseHeaders(&evicted_callback)); |
| 1123 |
| 1124 data_->RunFor(1); |
| 1125 EXPECT_LE(OK, ok_callback.WaitForResult()); |
| 1126 data_->StopAfter(10); |
| 1127 |
| 1128 ExpectResponse("ok.html", ok_stream, false); |
| 1129 ok_stream->Close(false); |
| 1130 |
| 1131 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 1132 rejected_stream->ReadResponseHeaders(&callback_)); |
| 1133 rejected_stream->Close(true); |
| 1134 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 1135 evicted_stream->Close(true); |
| 1136 } |
| 1137 |
| 1138 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) { |
| 1139 MockWrite writes[] = { |
| 1140 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1141 }; |
| 1142 MockRead reads[] = { |
| 1143 MockRead(false, ERR_FAILED, 1), |
| 1144 }; |
| 1145 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1146 |
| 1147 EXPECT_CALL(delegate_, |
| 1148 OnPipelineFeedback(pipeline_.get(), |
| 1149 HttpPipelinedConnection::SOCKET_ERROR)) |
| 1150 .Times(1); |
| 1151 |
| 1152 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1153 HttpRequestHeaders headers; |
| 1154 HttpResponseInfo response; |
| 1155 EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response, &callback_)); |
| 1156 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(&callback_)); |
| 1157 } |
| 1158 |
| 1159 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) { |
| 1160 MockWrite writes[] = { |
| 1161 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1162 }; |
| 1163 MockRead reads[] = { |
| 1164 MockRead(false, 1, "HTTP/1.0 200 OK\r\n"), |
| 1165 MockRead(false, 2, "Content-Length: 7\r\n"), |
| 1166 MockRead(false, 3, "Connection: keep-alive\r\n\r\n"), |
| 1167 MockRead(false, 4, "ok.html"), |
| 1168 }; |
| 1169 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1170 |
| 1171 EXPECT_CALL(delegate_, |
| 1172 OnPipelineFeedback(pipeline_.get(), |
| 1173 HttpPipelinedConnection::OLD_HTTP_VERSION)) |
| 1174 .Times(1); |
| 1175 |
| 1176 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1177 TestSyncRequest(stream, "ok.html"); |
| 1178 } |
| 1179 |
| 1180 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnMustClose) { |
| 1181 MockWrite writes[] = { |
| 1182 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1183 }; |
| 1184 MockRead reads[] = { |
| 1185 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), |
| 1186 MockRead(false, 2, "Content-Length: 7\r\n"), |
| 1187 MockRead(false, 3, "Connection: close\r\n\r\n"), |
| 1188 MockRead(false, 4, "ok.html"), |
| 1189 }; |
| 1190 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1191 |
| 1192 EXPECT_CALL(delegate_, |
| 1193 OnPipelineFeedback( |
| 1194 pipeline_.get(), |
| 1195 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)) |
| 1196 .Times(1); |
| 1197 |
| 1198 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1199 TestSyncRequest(stream, "ok.html"); |
| 1200 } |
| 1201 |
| 1202 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoContentLength) { |
| 1203 MockWrite writes[] = { |
| 1204 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1205 }; |
| 1206 MockRead reads[] = { |
| 1207 MockRead(false, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1208 MockRead(false, 2, "ok.html"), |
| 1209 }; |
| 1210 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1211 |
| 1212 EXPECT_CALL(delegate_, |
| 1213 OnPipelineFeedback( |
| 1214 pipeline_.get(), |
| 1215 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)) |
| 1216 .Times(1); |
| 1217 |
| 1218 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1219 TestSyncRequest(stream, "ok.html"); |
| 1220 } |
| 1221 |
1089 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { | 1222 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { |
1090 MockWrite writes[] = { | 1223 MockWrite writes[] = { |
1091 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1224 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
1092 }; | 1225 }; |
1093 Initialize(NULL, 0, writes, arraysize(writes)); | 1226 Initialize(NULL, 0, writes, arraysize(writes)); |
1094 | 1227 |
1095 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); | 1228 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); |
1096 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1229 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
1097 | 1230 |
1098 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1231 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
(...skipping 20 matching lines...) Expand all Loading... |
1119 | 1252 |
1120 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1253 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
1121 MessageLoop::current()->RunAllPending(); | 1254 MessageLoop::current()->RunAllPending(); |
1122 | 1255 |
1123 stream->Close(false); | 1256 stream->Close(false); |
1124 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1257 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
1125 stream.reset(NULL); | 1258 stream.reset(NULL); |
1126 } | 1259 } |
1127 | 1260 |
1128 } // namespace net | 1261 } // namespace net |
OLD | NEW |