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) { | |
mmenke
2011/11/18 15:45:38
Could you add a content-length: 0 test, too, out o
James Simonsen
2011/11/22 01:24:20
Done. They all sounded good, so I added all of the
| |
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 | |
1089 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { | 1153 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { |
1090 MockWrite writes[] = { | 1154 MockWrite writes[] = { |
1091 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1155 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
1092 }; | 1156 }; |
1093 Initialize(NULL, 0, writes, arraysize(writes)); | 1157 Initialize(NULL, 0, writes, arraysize(writes)); |
1094 | 1158 |
1095 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); | 1159 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); |
1096 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1160 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
1097 | 1161 |
1098 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1162 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
(...skipping 20 matching lines...) Expand all Loading... | |
1119 | 1183 |
1120 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1184 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
1121 MessageLoop::current()->RunAllPending(); | 1185 MessageLoop::current()->RunAllPending(); |
1122 | 1186 |
1123 stream->Close(false); | 1187 stream->Close(false); |
1124 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1188 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
1125 stream.reset(NULL); | 1189 stream.reset(NULL); |
1126 } | 1190 } |
1127 | 1191 |
1128 } // namespace net | 1192 } // namespace net |
OLD | NEW |