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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 data_->RunFor(1); | 1079 data_->RunFor(1); |
1080 EXPECT_FALSE(close_callback->have_result()); | 1080 EXPECT_FALSE(close_callback->have_result()); |
1081 | 1081 |
1082 close_stream->Close(false); | 1082 close_stream->Close(false); |
1083 close_stream.reset(); | 1083 close_stream.reset(); |
1084 close_callback.reset(); | 1084 close_callback.reset(); |
1085 | 1085 |
1086 MessageLoop::current()->RunAllPending(); | 1086 MessageLoop::current()->RunAllPending(); |
1087 } | 1087 } |
1088 | 1088 |
1089 TEST_F(HttpPipelinedConnectionImplTest, RecoverFromDrainOnRedirect) { | |
1090 MockWrite writes[] = { | |
1091 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | |
1092 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | |
1093 }; | |
1094 MockRead reads[] = { | |
1095 MockRead(false, 2, | |
1096 "HTTP/1.1 302 OK\r\n" | |
1097 "Content-Length: 8\r\n\r\n" | |
1098 "redirect"), | |
1099 MockRead(false, 3, | |
1100 "HTTP/1.1 200 OK\r\n" | |
1101 "Content-Length: 7\r\n\r\n" | |
1102 "ok.html"), | |
1103 }; | |
1104 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | |
1105 | |
1106 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | |
1107 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | |
1108 | |
1109 HttpRequestHeaders headers1; | |
1110 HttpResponseInfo response1; | |
1111 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); | |
1112 HttpRequestHeaders headers2; | |
1113 HttpResponseInfo response2; | |
1114 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); | |
1115 | |
1116 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); | |
1117 stream1.release()->Drain(NULL); | |
1118 | |
1119 EXPECT_EQ(OK, stream2->ReadResponseHeaders(&callback_)); | |
1120 ExpectResponse("ok.html", stream2, false); | |
1121 stream2->Close(false); | |
1122 } | |
1123 | |
1124 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) { | |
1125 MockWrite writes[] = { | |
1126 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | |
1127 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | |
1128 }; | |
1129 MockRead reads[] = { | |
1130 MockRead(false, 2, | |
1131 "HTTP/1.1 302 OK\r\n\r\n" | |
1132 "redirect"), | |
1133 }; | |
1134 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | |
1135 | |
1136 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | |
1137 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | |
1138 | |
1139 HttpRequestHeaders headers1; | |
1140 HttpResponseInfo response1; | |
1141 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); | |
1142 HttpRequestHeaders headers2; | |
1143 HttpResponseInfo response2; | |
1144 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); | |
1145 | |
1146 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); | |
1147 stream1.release()->Drain(NULL); | |
1148 | |
1149 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_)); | |
1150 stream2->Close(false); | |
1151 } | |
1152 | |
1153 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) { | |
1154 MockWrite writes[] = { | |
1155 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | |
1156 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | |
1157 }; | |
1158 MockRead reads[] = { | |
1159 MockRead(false, 2, | |
1160 "HTTP/1.1 302 OK\r\n" | |
1161 "Content-Length: 8\r\n\r\n"), | |
1162 MockRead(false, ERR_SOCKET_NOT_CONNECTED, 3), | |
1163 }; | |
1164 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | |
1165 | |
1166 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | |
1167 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | |
1168 | |
1169 HttpRequestHeaders headers1; | |
1170 HttpResponseInfo response1; | |
1171 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); | |
1172 HttpRequestHeaders headers2; | |
1173 HttpResponseInfo response2; | |
1174 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); | |
1175 | |
1176 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); | |
1177 stream1.release()->Drain(NULL); | |
1178 | |
1179 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_)); | |
1180 stream2->Close(false); | |
1181 } | |
1182 | |
1183 TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) { | |
1184 MockWrite writes[] = { | |
1185 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | |
1186 MockWrite(false, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | |
1187 }; | |
1188 MockRead reads[] = { | |
1189 MockRead(false, 2, | |
1190 "HTTP/1.1 302 OK\r\n" | |
1191 "Transfer-Encoding: chunked" | |
1192 "Content-Length: 8\r\n\r\n"), | |
mmenke
2011/11/28 18:39:10
Remove "Content-Length", as it's not allowed to ap
James Simonsen
2011/11/29 23:57:28
Done.
| |
1193 MockRead(false, 3, | |
1194 "jibberish"), | |
1195 }; | |
1196 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | |
1197 | |
1198 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | |
1199 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | |
1200 | |
1201 HttpRequestHeaders headers1; | |
1202 HttpResponseInfo response1; | |
1203 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_)); | |
1204 HttpRequestHeaders headers2; | |
1205 HttpResponseInfo response2; | |
1206 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_)); | |
1207 | |
1208 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_)); | |
1209 stream1.release()->Drain(NULL); | |
1210 | |
1211 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_)); | |
1212 stream2->Close(false); | |
1213 } | |
1214 | |
1089 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { | 1215 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { |
1090 MockWrite writes[] = { | 1216 MockWrite writes[] = { |
1091 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1217 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
1092 }; | 1218 }; |
1093 Initialize(NULL, 0, writes, arraysize(writes)); | 1219 Initialize(NULL, 0, writes, arraysize(writes)); |
1094 | 1220 |
1095 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); | 1221 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); |
1096 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1222 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
1097 | 1223 |
1098 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1224 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
(...skipping 20 matching lines...) Expand all Loading... | |
1119 | 1245 |
1120 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1246 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
1121 MessageLoop::current()->RunAllPending(); | 1247 MessageLoop::current()->RunAllPending(); |
1122 | 1248 |
1123 stream->Close(false); | 1249 stream->Close(false); |
1124 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1250 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
1125 stream.reset(NULL); | 1251 stream.reset(NULL); |
1126 } | 1252 } |
1127 | 1253 |
1128 } // namespace net | 1254 } // namespace net |
OLD | NEW |