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

Side by Side Diff: net/http/http_pipelined_connection_impl_unittest.cc

Issue 8591037: Implement Drain() on HttpPipelinedStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Skip on unusable Created 9 years 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 | Annotate | Revision Log
OLDNEW
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
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\r\n\r\n"),
1192 MockRead(false, 3,
1193 "jibberish"),
1194 };
1195 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1196
1197 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html"));
1198 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html"));
1199
1200 HttpRequestHeaders headers1;
1201 HttpResponseInfo response1;
1202 EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1, &callback_));
1203 HttpRequestHeaders headers2;
1204 HttpResponseInfo response2;
1205 EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2, &callback_));
1206
1207 EXPECT_EQ(OK, stream1->ReadResponseHeaders(&callback_));
1208 stream1.release()->Drain(NULL);
1209
1210 EXPECT_EQ(ERR_PIPELINE_EVICTION, stream2->ReadResponseHeaders(&callback_));
1211 stream2->Close(false);
1212 }
1213
1089 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { 1214 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
1090 MockWrite writes[] = { 1215 MockWrite writes[] = {
1091 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1216 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1092 }; 1217 };
1093 Initialize(NULL, 0, writes, arraysize(writes)); 1218 Initialize(NULL, 0, writes, arraysize(writes));
1094 1219
1095 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1220 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1096 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1221 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1097 1222
1098 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1223 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
(...skipping 20 matching lines...) Expand all
1119 1244
1120 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1245 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1121 MessageLoop::current()->RunAllPending(); 1246 MessageLoop::current()->RunAllPending();
1122 1247
1123 stream->Close(false); 1248 stream->Close(false);
1124 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1249 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1125 stream.reset(NULL); 1250 stream.reset(NULL);
1126 } 1251 }
1127 1252
1128 } // namespace net 1253 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_pipelined_connection_impl.cc ('k') | net/http/http_pipelined_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698