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