| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 53 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 54 | 54 |
| 55 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | 55 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 56 CONNECT_TIMING_HAS_DNS_TIMES); | 56 CONNECT_TIMING_HAS_DNS_TIMES); |
| 57 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 57 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
| 58 } | 58 } |
| 59 | 59 |
| 60 class MockPipelineDelegate : public HttpPipelinedConnection::Delegate { | 60 class MockPipelineDelegate : public HttpPipelinedConnection::Delegate { |
| 61 public: | 61 public: |
| 62 MOCK_METHOD1(OnPipelineHasCapacity, void(HttpPipelinedConnection* pipeline)); | 62 MOCK_METHOD1(OnPipelineHasCapacity, void(HttpPipelinedConnection* pipeline)); |
| 63 MOCK_METHOD2(OnPipelineFeedback, void( | 63 MOCK_METHOD2(OnPipelineFeedback, |
| 64 HttpPipelinedConnection* pipeline, | 64 void(HttpPipelinedConnection* pipeline, |
| 65 HttpPipelinedConnection::Feedback feedback)); | 65 HttpPipelinedConnection::Feedback feedback)); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class SuddenCloseObserver : public base::MessageLoop::TaskObserver { | 68 class SuddenCloseObserver : public base::MessageLoop::TaskObserver { |
| 69 public: | 69 public: |
| 70 SuddenCloseObserver(HttpStream* stream, int close_before_task) | 70 SuddenCloseObserver(HttpStream* stream, int close_before_task) |
| 71 : stream_(stream), | 71 : stream_(stream), |
| 72 close_before_task_(close_before_task), | 72 close_before_task_(close_before_task), |
| 73 current_task_(0) { } | 73 current_task_(0) {} |
| 74 | 74 |
| 75 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 75 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
| 76 ++current_task_; | 76 ++current_task_; |
| 77 if (current_task_ == close_before_task_) { | 77 if (current_task_ == close_before_task_) { |
| 78 stream_->Close(false); | 78 stream_->Close(false); |
| 79 base::MessageLoop::current()->RemoveTaskObserver(this); | 79 base::MessageLoop::current()->RemoveTaskObserver(this); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {} | 83 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {} |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 HttpStream* stream_; | 86 HttpStream* stream_; |
| 87 int close_before_task_; | 87 int close_before_task_; |
| 88 int current_task_; | 88 int current_task_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 class HttpPipelinedConnectionImplTest : public testing::Test { | 91 class HttpPipelinedConnectionImplTest : public testing::Test { |
| 92 public: | 92 public: |
| 93 HttpPipelinedConnectionImplTest() | 93 HttpPipelinedConnectionImplTest() |
| 94 : histograms_("a"), | 94 : histograms_("a"), |
| 95 pool_(1, 1, &histograms_, &factory_), | 95 pool_(1, 1, &histograms_, &factory_), |
| 96 origin_("host", 123) { | 96 origin_("host", 123) {} |
| 97 } | |
| 98 | 97 |
| 99 void TearDown() { | 98 void TearDown() { base::MessageLoop::current()->RunUntilIdle(); } |
| 100 base::MessageLoop::current()->RunUntilIdle(); | |
| 101 } | |
| 102 | 99 |
| 103 void Initialize(MockRead* reads, size_t reads_count, | 100 void Initialize(MockRead* reads, |
| 104 MockWrite* writes, size_t writes_count) { | 101 size_t reads_count, |
| 105 data_.reset(new DeterministicSocketData(reads, reads_count, | 102 MockWrite* writes, |
| 106 writes, writes_count)); | 103 size_t writes_count) { |
| 104 data_.reset( |
| 105 new DeterministicSocketData(reads, reads_count, writes, writes_count)); |
| 107 data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 106 data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 108 if (reads_count || writes_count) { | 107 if (reads_count || writes_count) { |
| 109 data_->StopAfter(reads_count + writes_count); | 108 data_->StopAfter(reads_count + writes_count); |
| 110 } | 109 } |
| 111 factory_.AddSocketDataProvider(data_.get()); | 110 factory_.AddSocketDataProvider(data_.get()); |
| 112 scoped_refptr<MockTransportSocketParams> params; | 111 scoped_refptr<MockTransportSocketParams> params; |
| 113 ClientSocketHandle* connection = new ClientSocketHandle; | 112 ClientSocketHandle* connection = new ClientSocketHandle; |
| 114 // Only give the connection a real NetLog to make sure that LoadTiming uses | 113 // Only give the connection a real NetLog to make sure that LoadTiming uses |
| 115 // the connection's ID, rather than the pipeline's. Since pipelines are | 114 // the connection's ID, rather than the pipeline's. Since pipelines are |
| 116 // destroyed when they've responded to all requests, but the connection | 115 // destroyed when they've responded to all requests, but the connection |
| 117 // lives on, this is an important behavior. | 116 // lives on, this is an important behavior. |
| 118 connection->Init("a", params, MEDIUM, CompletionCallback(), &pool_, | 117 connection->Init( |
| 119 net_log_.bound()); | 118 "a", params, MEDIUM, CompletionCallback(), &pool_, net_log_.bound()); |
| 120 pipeline_.reset(new HttpPipelinedConnectionImpl( | 119 pipeline_.reset(new HttpPipelinedConnectionImpl(connection, |
| 121 connection, &delegate_, origin_, ssl_config_, proxy_info_, | 120 &delegate_, |
| 122 BoundNetLog(), false, kProtoUnknown)); | 121 origin_, |
| 122 ssl_config_, |
| 123 proxy_info_, |
| 124 BoundNetLog(), |
| 125 false, |
| 126 kProtoUnknown)); |
| 123 } | 127 } |
| 124 | 128 |
| 125 HttpRequestInfo* GetRequestInfo(const std::string& filename) { | 129 HttpRequestInfo* GetRequestInfo(const std::string& filename) { |
| 126 HttpRequestInfo* request_info = new HttpRequestInfo; | 130 HttpRequestInfo* request_info = new HttpRequestInfo; |
| 127 request_info->url = GURL("http://localhost/" + filename); | 131 request_info->url = GURL("http://localhost/" + filename); |
| 128 request_info->method = "GET"; | 132 request_info->method = "GET"; |
| 129 request_info_vector_.push_back(request_info); | 133 request_info_vector_.push_back(request_info); |
| 130 return request_info; | 134 return request_info; |
| 131 } | 135 } |
| 132 | 136 |
| 133 HttpStream* NewTestStream(const std::string& filename) { | 137 HttpStream* NewTestStream(const std::string& filename) { |
| 134 HttpStream* stream = pipeline_->CreateNewStream(); | 138 HttpStream* stream = pipeline_->CreateNewStream(); |
| 135 HttpRequestInfo* request_info = GetRequestInfo(filename); | 139 HttpRequestInfo* request_info = GetRequestInfo(filename); |
| 136 int rv = stream->InitializeStream( | 140 int rv = stream->InitializeStream( |
| 137 request_info, DEFAULT_PRIORITY, BoundNetLog(), CompletionCallback()); | 141 request_info, DEFAULT_PRIORITY, BoundNetLog(), CompletionCallback()); |
| 138 DCHECK_EQ(OK, rv); | 142 DCHECK_EQ(OK, rv); |
| 139 return stream; | 143 return stream; |
| 140 } | 144 } |
| 141 | 145 |
| 142 void ExpectResponse(const std::string& expected, | 146 void ExpectResponse(const std::string& expected, |
| 143 scoped_ptr<HttpStream>& stream, bool async) { | 147 scoped_ptr<HttpStream>& stream, |
| 148 bool async) { |
| 144 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); | 149 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); |
| 145 | 150 |
| 146 if (async) { | 151 if (async) { |
| 147 EXPECT_EQ(ERR_IO_PENDING, | 152 EXPECT_EQ(ERR_IO_PENDING, |
| 148 stream->ReadResponseBody(buffer.get(), expected.size(), | 153 stream->ReadResponseBody( |
| 149 callback_.callback())); | 154 buffer.get(), expected.size(), callback_.callback())); |
| 150 data_->RunFor(1); | 155 data_->RunFor(1); |
| 151 EXPECT_EQ(static_cast<int>(expected.size()), callback_.WaitForResult()); | 156 EXPECT_EQ(static_cast<int>(expected.size()), callback_.WaitForResult()); |
| 152 } else { | 157 } else { |
| 153 EXPECT_EQ(static_cast<int>(expected.size()), | 158 EXPECT_EQ(static_cast<int>(expected.size()), |
| 154 stream->ReadResponseBody(buffer.get(), expected.size(), | 159 stream->ReadResponseBody( |
| 155 callback_.callback())); | 160 buffer.get(), expected.size(), callback_.callback())); |
| 156 } | 161 } |
| 157 std::string actual(buffer->data(), expected.size()); | 162 std::string actual(buffer->data(), expected.size()); |
| 158 EXPECT_THAT(actual, StrEq(expected)); | 163 EXPECT_THAT(actual, StrEq(expected)); |
| 159 } | 164 } |
| 160 | 165 |
| 161 void TestSyncRequest(scoped_ptr<HttpStream>& stream, | 166 void TestSyncRequest(scoped_ptr<HttpStream>& stream, |
| 162 const std::string& filename) { | 167 const std::string& filename) { |
| 163 HttpRequestHeaders headers; | 168 HttpRequestHeaders headers; |
| 164 HttpResponseInfo response; | 169 HttpResponseInfo response; |
| 165 EXPECT_EQ(OK, stream->SendRequest(headers, &response, | 170 EXPECT_EQ(OK, |
| 166 callback_.callback())); | 171 stream->SendRequest(headers, &response, callback_.callback())); |
| 167 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); | 172 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 168 ExpectResponse(filename, stream, false); | 173 ExpectResponse(filename, stream, false); |
| 169 | 174 |
| 170 stream->Close(false); | 175 stream->Close(false); |
| 171 } | 176 } |
| 172 | 177 |
| 173 CapturingBoundNetLog net_log_; | 178 CapturingBoundNetLog net_log_; |
| 174 DeterministicMockClientSocketFactory factory_; | 179 DeterministicMockClientSocketFactory factory_; |
| 175 ClientSocketPoolHistograms histograms_; | 180 ClientSocketPoolHistograms histograms_; |
| 176 MockTransportClientSocketPool pool_; | 181 MockTransportClientSocketPool pool_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 202 | 207 |
| 203 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 208 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 204 | 209 |
| 205 TestLoadTimingNotReused(*stream); | 210 TestLoadTimingNotReused(*stream); |
| 206 stream->Close(false); | 211 stream->Close(false); |
| 207 TestLoadTimingNotReused(*stream); | 212 TestLoadTimingNotReused(*stream); |
| 208 } | 213 } |
| 209 | 214 |
| 210 TEST_F(HttpPipelinedConnectionImplTest, SyncSingleRequest) { | 215 TEST_F(HttpPipelinedConnectionImplTest, SyncSingleRequest) { |
| 211 MockWrite writes[] = { | 216 MockWrite writes[] = { |
| 212 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 217 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 213 }; | 218 }; |
| 214 MockRead reads[] = { | 219 MockRead reads[] = { |
| 215 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 220 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 216 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), | 221 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), |
| 217 MockRead(SYNCHRONOUS, 3, "ok.html"), | 222 MockRead(SYNCHRONOUS, 3, "ok.html"), |
| 218 }; | 223 }; |
| 219 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 224 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 220 | 225 |
| 221 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 226 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 222 TestLoadTimingNotReused(*stream); | 227 TestLoadTimingNotReused(*stream); |
| 223 TestSyncRequest(stream, "ok.html"); | 228 TestSyncRequest(stream, "ok.html"); |
| 224 TestLoadTimingNotReused(*stream); | 229 TestLoadTimingNotReused(*stream); |
| 225 } | 230 } |
| 226 | 231 |
| 227 TEST_F(HttpPipelinedConnectionImplTest, AsyncSingleRequest) { | 232 TEST_F(HttpPipelinedConnectionImplTest, AsyncSingleRequest) { |
| 228 MockWrite writes[] = { | 233 MockWrite writes[] = { |
| 229 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 234 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 230 }; | 235 }; |
| 231 MockRead reads[] = { | 236 MockRead reads[] = { |
| 232 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 237 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
| 233 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), | 238 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), |
| 234 MockRead(ASYNC, 3, "ok.html"), | 239 MockRead(ASYNC, 3, "ok.html"), |
| 235 }; | 240 }; |
| 236 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 241 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 237 | 242 |
| 238 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 243 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 239 | 244 |
| 240 HttpRequestHeaders headers; | 245 HttpRequestHeaders headers; |
| 241 HttpResponseInfo response; | 246 HttpResponseInfo response; |
| 242 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, &response, | 247 EXPECT_EQ(ERR_IO_PENDING, |
| 243 callback_.callback())); | 248 stream->SendRequest(headers, &response, callback_.callback())); |
| 244 data_->RunFor(1); | 249 data_->RunFor(1); |
| 245 EXPECT_LE(OK, callback_.WaitForResult()); | 250 EXPECT_LE(OK, callback_.WaitForResult()); |
| 246 TestLoadTimingNotReused(*stream); | 251 TestLoadTimingNotReused(*stream); |
| 247 | 252 |
| 248 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); | 253 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 249 data_->RunFor(2); | 254 data_->RunFor(2); |
| 250 EXPECT_LE(OK, callback_.WaitForResult()); | 255 EXPECT_LE(OK, callback_.WaitForResult()); |
| 251 TestLoadTimingNotReused(*stream); | 256 TestLoadTimingNotReused(*stream); |
| 252 | 257 |
| 253 ExpectResponse("ok.html", stream, true); | 258 ExpectResponse("ok.html", stream, true); |
| 254 TestLoadTimingNotReused(*stream); | 259 TestLoadTimingNotReused(*stream); |
| 255 | 260 |
| 256 stream->Close(false); | 261 stream->Close(false); |
| 257 } | 262 } |
| 258 | 263 |
| 259 TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) { | 264 TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) { |
| 260 MockWrite writes[] = { | 265 MockWrite writes[] = { |
| 261 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 266 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 262 MockWrite(ASYNC, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), | 267 MockWrite(ASYNC, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 263 }; | 268 }; |
| 264 MockRead reads[] = { | 269 MockRead reads[] = { |
| 265 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n"), | 270 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n"), |
| 266 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), | 271 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), |
| 267 MockRead(ASYNC, 4, "ok.html"), | 272 MockRead(ASYNC, 4, "ok.html"), |
| 268 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), | 273 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), |
| 269 MockRead(ASYNC, 6, "Content-Length: 7\r\n\r\n"), | 274 MockRead(ASYNC, 6, "Content-Length: 7\r\n\r\n"), |
| 270 MockRead(ASYNC, 7, "ko.html"), | 275 MockRead(ASYNC, 7, "ko.html"), |
| 271 }; | 276 }; |
| 272 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 277 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 273 | 278 |
| 274 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); | 279 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); |
| 275 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); | 280 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); |
| 276 | 281 |
| 277 HttpRequestHeaders headers1; | 282 HttpRequestHeaders headers1; |
| 278 HttpResponseInfo response1; | 283 HttpResponseInfo response1; |
| 279 EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, &response1, | 284 EXPECT_EQ(ERR_IO_PENDING, |
| 280 callback_.callback())); | 285 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 281 TestLoadTimingNotReused(*stream1); | 286 TestLoadTimingNotReused(*stream1); |
| 282 | 287 |
| 283 HttpRequestHeaders headers2; | 288 HttpRequestHeaders headers2; |
| 284 HttpResponseInfo response2; | 289 HttpResponseInfo response2; |
| 285 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(headers2, &response2, | 290 EXPECT_EQ(ERR_IO_PENDING, |
| 286 callback_.callback())); | 291 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 287 TestLoadTimingReused(*stream2); | 292 TestLoadTimingReused(*stream2); |
| 288 | 293 |
| 289 data_->RunFor(1); | 294 data_->RunFor(1); |
| 290 EXPECT_LE(OK, callback_.WaitForResult()); | 295 EXPECT_LE(OK, callback_.WaitForResult()); |
| 291 data_->RunFor(1); | 296 data_->RunFor(1); |
| 292 EXPECT_LE(OK, callback_.WaitForResult()); | 297 EXPECT_LE(OK, callback_.WaitForResult()); |
| 293 | 298 |
| 294 EXPECT_EQ(ERR_IO_PENDING, stream1->ReadResponseHeaders(callback_.callback())); | 299 EXPECT_EQ(ERR_IO_PENDING, stream1->ReadResponseHeaders(callback_.callback())); |
| 295 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback())); | 300 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback())); |
| 296 | 301 |
| 297 data_->RunFor(2); | 302 data_->RunFor(2); |
| 298 EXPECT_LE(OK, callback_.WaitForResult()); | 303 EXPECT_LE(OK, callback_.WaitForResult()); |
| 299 | 304 |
| 300 ExpectResponse("ok.html", stream1, true); | 305 ExpectResponse("ok.html", stream1, true); |
| 301 | 306 |
| 302 TestLoadTimingNotReused(*stream1); | 307 TestLoadTimingNotReused(*stream1); |
| 303 LoadTimingInfo load_timing_info1; | 308 LoadTimingInfo load_timing_info1; |
| 304 EXPECT_TRUE(stream1->GetLoadTimingInfo(&load_timing_info1)); | 309 EXPECT_TRUE(stream1->GetLoadTimingInfo(&load_timing_info1)); |
| 305 stream1->Close(false); | 310 stream1->Close(false); |
| 306 | 311 |
| 307 data_->RunFor(2); | 312 data_->RunFor(2); |
| 308 EXPECT_LE(OK, callback_.WaitForResult()); | 313 EXPECT_LE(OK, callback_.WaitForResult()); |
| 309 | 314 |
| 310 ExpectResponse("ko.html", stream2, true); | 315 ExpectResponse("ko.html", stream2, true); |
| 311 | 316 |
| 312 TestLoadTimingReused(*stream2); | 317 TestLoadTimingReused(*stream2); |
| 313 LoadTimingInfo load_timing_info2; | 318 LoadTimingInfo load_timing_info2; |
| 314 EXPECT_TRUE(stream2->GetLoadTimingInfo(&load_timing_info2)); | 319 EXPECT_TRUE(stream2->GetLoadTimingInfo(&load_timing_info2)); |
| 315 EXPECT_EQ(load_timing_info1.socket_log_id, | 320 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 316 load_timing_info2.socket_log_id); | |
| 317 stream2->Close(false); | 321 stream2->Close(false); |
| 318 } | 322 } |
| 319 | 323 |
| 320 TEST_F(HttpPipelinedConnectionImplTest, TwoResponsesInOnePacket) { | 324 TEST_F(HttpPipelinedConnectionImplTest, TwoResponsesInOnePacket) { |
| 321 MockWrite writes[] = { | 325 MockWrite writes[] = { |
| 322 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 326 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 323 MockWrite(SYNCHRONOUS, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), | 327 MockWrite(SYNCHRONOUS, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 324 }; | 328 }; |
| 325 MockRead reads[] = { | 329 MockRead reads[] = { |
| 326 MockRead(SYNCHRONOUS, 2, | 330 MockRead(SYNCHRONOUS, |
| 327 "HTTP/1.1 200 OK\r\n" | 331 2, |
| 328 "Content-Length: 7\r\n\r\n" | 332 "HTTP/1.1 200 OK\r\n" |
| 329 "ok.html" | 333 "Content-Length: 7\r\n\r\n" |
| 330 "HTTP/1.1 200 OK\r\n" | 334 "ok.html" |
| 331 "Content-Length: 7\r\n\r\n" | 335 "HTTP/1.1 200 OK\r\n" |
| 332 "ko.html"), | 336 "Content-Length: 7\r\n\r\n" |
| 337 "ko.html"), |
| 333 }; | 338 }; |
| 334 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 339 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 335 | 340 |
| 336 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); | 341 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); |
| 337 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); | 342 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); |
| 338 | 343 |
| 339 HttpRequestHeaders headers1; | 344 HttpRequestHeaders headers1; |
| 340 HttpResponseInfo response1; | 345 HttpResponseInfo response1; |
| 341 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 346 EXPECT_EQ(OK, |
| 342 &response1, callback_.callback())); | 347 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 343 HttpRequestHeaders headers2; | 348 HttpRequestHeaders headers2; |
| 344 HttpResponseInfo response2; | 349 HttpResponseInfo response2; |
| 345 EXPECT_EQ(OK, stream2->SendRequest(headers2, | 350 EXPECT_EQ(OK, |
| 346 &response2, callback_.callback())); | 351 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 347 | 352 |
| 348 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 353 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 349 ExpectResponse("ok.html", stream1, false); | 354 ExpectResponse("ok.html", stream1, false); |
| 350 stream1->Close(false); | 355 stream1->Close(false); |
| 351 | 356 |
| 352 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); | 357 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); |
| 353 ExpectResponse("ko.html", stream2, false); | 358 ExpectResponse("ko.html", stream2, false); |
| 354 stream2->Close(false); | 359 stream2->Close(false); |
| 355 } | 360 } |
| 356 | 361 |
| 357 TEST_F(HttpPipelinedConnectionImplTest, SendOrderSwapped) { | 362 TEST_F(HttpPipelinedConnectionImplTest, SendOrderSwapped) { |
| 358 MockWrite writes[] = { | 363 MockWrite writes[] = { |
| 359 MockWrite(SYNCHRONOUS, 0, "GET /ko.html HTTP/1.1\r\n\r\n"), | 364 MockWrite(SYNCHRONOUS, 0, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 360 MockWrite(SYNCHRONOUS, 4, "GET /ok.html HTTP/1.1\r\n\r\n"), | 365 MockWrite(SYNCHRONOUS, 4, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 361 }; | 366 }; |
| 362 MockRead reads[] = { | 367 MockRead reads[] = { |
| 363 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 368 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 364 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), | 369 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), |
| 365 MockRead(SYNCHRONOUS, 3, "ko.html"), | 370 MockRead(SYNCHRONOUS, 3, "ko.html"), |
| 366 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), | 371 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), |
| 367 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), | 372 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), |
| 368 MockRead(SYNCHRONOUS, 7, "ok.html"), | 373 MockRead(SYNCHRONOUS, 7, "ok.html"), |
| 369 }; | 374 }; |
| 370 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 375 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 371 | 376 |
| 372 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); | 377 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); |
| 373 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); | 378 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); |
| 374 | 379 |
| 375 TestSyncRequest(stream2, "ko.html"); | 380 TestSyncRequest(stream2, "ko.html"); |
| 376 TestSyncRequest(stream1, "ok.html"); | 381 TestSyncRequest(stream1, "ok.html"); |
| 377 TestLoadTimingNotReused(*stream1); | 382 TestLoadTimingNotReused(*stream1); |
| 378 TestLoadTimingReused(*stream2); | 383 TestLoadTimingReused(*stream2); |
| 379 } | 384 } |
| 380 | 385 |
| 381 TEST_F(HttpPipelinedConnectionImplTest, ReadOrderSwapped) { | 386 TEST_F(HttpPipelinedConnectionImplTest, ReadOrderSwapped) { |
| 382 MockWrite writes[] = { | 387 MockWrite writes[] = { |
| 383 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 388 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 384 MockWrite(SYNCHRONOUS, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), | 389 MockWrite(SYNCHRONOUS, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 385 }; | 390 }; |
| 386 MockRead reads[] = { | 391 MockRead reads[] = { |
| 387 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 392 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 388 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), | 393 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), |
| 389 MockRead(SYNCHRONOUS, 4, "ok.html"), | 394 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 390 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), | 395 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), |
| 391 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), | 396 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), |
| 392 MockRead(SYNCHRONOUS, 7, "ko.html"), | 397 MockRead(SYNCHRONOUS, 7, "ko.html"), |
| 393 }; | 398 }; |
| 394 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 399 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 395 | 400 |
| 396 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); | 401 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); |
| 397 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); | 402 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); |
| 398 | 403 |
| 399 HttpRequestHeaders headers1; | 404 HttpRequestHeaders headers1; |
| 400 HttpResponseInfo response1; | 405 HttpResponseInfo response1; |
| 401 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 406 EXPECT_EQ(OK, |
| 402 &response1, callback_.callback())); | 407 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 403 | 408 |
| 404 HttpRequestHeaders headers2; | 409 HttpRequestHeaders headers2; |
| 405 HttpResponseInfo response2; | 410 HttpResponseInfo response2; |
| 406 EXPECT_EQ(OK, stream2->SendRequest(headers2, | 411 EXPECT_EQ(OK, |
| 407 &response2, callback_.callback())); | 412 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 408 | 413 |
| 409 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback())); | 414 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback())); |
| 410 | 415 |
| 411 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 416 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 412 ExpectResponse("ok.html", stream1, false); | 417 ExpectResponse("ok.html", stream1, false); |
| 413 | 418 |
| 414 stream1->Close(false); | 419 stream1->Close(false); |
| 415 | 420 |
| 416 EXPECT_LE(OK, callback_.WaitForResult()); | 421 EXPECT_LE(OK, callback_.WaitForResult()); |
| 417 ExpectResponse("ko.html", stream2, false); | 422 ExpectResponse("ko.html", stream2, false); |
| 418 | 423 |
| 419 stream2->Close(false); | 424 stream2->Close(false); |
| 420 } | 425 } |
| 421 | 426 |
| 422 TEST_F(HttpPipelinedConnectionImplTest, SendWhileReading) { | 427 TEST_F(HttpPipelinedConnectionImplTest, SendWhileReading) { |
| 423 MockWrite writes[] = { | 428 MockWrite writes[] = { |
| 424 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 429 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 425 MockWrite(SYNCHRONOUS, 3, "GET /ko.html HTTP/1.1\r\n\r\n"), | 430 MockWrite(SYNCHRONOUS, 3, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 426 }; | 431 }; |
| 427 MockRead reads[] = { | 432 MockRead reads[] = { |
| 428 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 433 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 429 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), | 434 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), |
| 430 MockRead(SYNCHRONOUS, 4, "ok.html"), | 435 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 431 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), | 436 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), |
| 432 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), | 437 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), |
| 433 MockRead(SYNCHRONOUS, 7, "ko.html"), | 438 MockRead(SYNCHRONOUS, 7, "ko.html"), |
| 434 }; | 439 }; |
| 435 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 440 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 436 | 441 |
| 437 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); | 442 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); |
| 438 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); | 443 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); |
| 439 | 444 |
| 440 HttpRequestHeaders headers1; | 445 HttpRequestHeaders headers1; |
| 441 HttpResponseInfo response1; | 446 HttpResponseInfo response1; |
| 442 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 447 EXPECT_EQ(OK, |
| 443 &response1, callback_.callback())); | 448 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 444 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 449 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 445 | 450 |
| 446 HttpRequestHeaders headers2; | 451 HttpRequestHeaders headers2; |
| 447 HttpResponseInfo response2; | 452 HttpResponseInfo response2; |
| 448 EXPECT_EQ(OK, stream2->SendRequest(headers2, | 453 EXPECT_EQ(OK, |
| 449 &response2, callback_.callback())); | 454 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 450 | 455 |
| 451 ExpectResponse("ok.html", stream1, false); | 456 ExpectResponse("ok.html", stream1, false); |
| 452 stream1->Close(false); | 457 stream1->Close(false); |
| 453 | 458 |
| 454 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); | 459 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); |
| 455 ExpectResponse("ko.html", stream2, false); | 460 ExpectResponse("ko.html", stream2, false); |
| 456 stream2->Close(false); | 461 stream2->Close(false); |
| 457 } | 462 } |
| 458 | 463 |
| 459 TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) { | 464 TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) { |
| 460 MockWrite writes[] = { | 465 MockWrite writes[] = { |
| 461 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 466 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 462 MockWrite(ASYNC, 3, "GET /ko.html HTTP/1.1\r\n\r\n"), | 467 MockWrite(ASYNC, 3, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 463 }; | 468 }; |
| 464 MockRead reads[] = { | 469 MockRead reads[] = { |
| 465 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 470 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 466 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), | 471 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), |
| 467 MockRead(ASYNC, 4, "ok.html"), | 472 MockRead(ASYNC, 4, "ok.html"), |
| 468 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), | 473 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), |
| 469 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), | 474 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), |
| 470 MockRead(SYNCHRONOUS, 7, "ko.html"), | 475 MockRead(SYNCHRONOUS, 7, "ko.html"), |
| 471 }; | 476 }; |
| 472 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 477 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 473 | 478 |
| 474 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); | 479 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); |
| 475 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); | 480 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); |
| 476 | 481 |
| 477 HttpRequestHeaders headers1; | 482 HttpRequestHeaders headers1; |
| 478 HttpResponseInfo response1; | 483 HttpResponseInfo response1; |
| 479 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 484 EXPECT_EQ(OK, |
| 480 &response1, callback_.callback())); | 485 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 481 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 486 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 482 TestCompletionCallback callback1; | 487 TestCompletionCallback callback1; |
| 483 std::string expected = "ok.html"; | 488 std::string expected = "ok.html"; |
| 484 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); | 489 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); |
| 485 EXPECT_EQ(ERR_IO_PENDING, | 490 EXPECT_EQ(ERR_IO_PENDING, |
| 486 stream1->ReadResponseBody(buffer.get(), expected.size(), | 491 stream1->ReadResponseBody( |
| 487 callback1.callback())); | 492 buffer.get(), expected.size(), callback1.callback())); |
| 488 | 493 |
| 489 HttpRequestHeaders headers2; | 494 HttpRequestHeaders headers2; |
| 490 HttpResponseInfo response2; | 495 HttpResponseInfo response2; |
| 491 TestCompletionCallback callback2; | 496 TestCompletionCallback callback2; |
| 492 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(headers2, &response2, | 497 EXPECT_EQ(ERR_IO_PENDING, |
| 493 callback2.callback())); | 498 stream2->SendRequest(headers2, &response2, callback2.callback())); |
| 494 | 499 |
| 495 data_->RunFor(1); | 500 data_->RunFor(1); |
| 496 EXPECT_LE(OK, callback2.WaitForResult()); | 501 EXPECT_LE(OK, callback2.WaitForResult()); |
| 497 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback2.callback())); | 502 EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback2.callback())); |
| 498 | 503 |
| 499 data_->RunFor(1); | 504 data_->RunFor(1); |
| 500 EXPECT_EQ(static_cast<int>(expected.size()), callback1.WaitForResult()); | 505 EXPECT_EQ(static_cast<int>(expected.size()), callback1.WaitForResult()); |
| 501 std::string actual(buffer->data(), expected.size()); | 506 std::string actual(buffer->data(), expected.size()); |
| 502 EXPECT_THAT(actual, StrEq(expected)); | 507 EXPECT_THAT(actual, StrEq(expected)); |
| 503 stream1->Close(false); | 508 stream1->Close(false); |
| 504 | 509 |
| 505 data_->StopAfter(8); | 510 data_->StopAfter(8); |
| 506 EXPECT_LE(OK, callback2.WaitForResult()); | 511 EXPECT_LE(OK, callback2.WaitForResult()); |
| 507 ExpectResponse("ko.html", stream2, false); | 512 ExpectResponse("ko.html", stream2, false); |
| 508 stream2->Close(false); | 513 stream2->Close(false); |
| 509 } | 514 } |
| 510 | 515 |
| 511 TEST_F(HttpPipelinedConnectionImplTest, UnusedStreamAllowsLaterUse) { | 516 TEST_F(HttpPipelinedConnectionImplTest, UnusedStreamAllowsLaterUse) { |
| 512 MockWrite writes[] = { | 517 MockWrite writes[] = { |
| 513 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 518 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 514 }; | 519 }; |
| 515 MockRead reads[] = { | 520 MockRead reads[] = { |
| 516 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 521 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 517 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), | 522 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n\r\n"), |
| 518 MockRead(SYNCHRONOUS, 3, "ok.html"), | 523 MockRead(SYNCHRONOUS, 3, "ok.html"), |
| 519 }; | 524 }; |
| 520 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 525 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 521 | 526 |
| 522 scoped_ptr<HttpStream> unused_stream(NewTestStream("unused.html")); | 527 scoped_ptr<HttpStream> unused_stream(NewTestStream("unused.html")); |
| 523 unused_stream->Close(false); | 528 unused_stream->Close(false); |
| 524 | 529 |
| 525 scoped_ptr<HttpStream> later_stream(NewTestStream("ok.html")); | 530 scoped_ptr<HttpStream> later_stream(NewTestStream("ok.html")); |
| 526 TestSyncRequest(later_stream, "ok.html"); | 531 TestSyncRequest(later_stream, "ok.html"); |
| 527 } | 532 } |
| 528 | 533 |
| 529 TEST_F(HttpPipelinedConnectionImplTest, UnsentStreamAllowsLaterUse) { | 534 TEST_F(HttpPipelinedConnectionImplTest, UnsentStreamAllowsLaterUse) { |
| 530 MockWrite writes[] = { | 535 MockWrite writes[] = { |
| 531 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 536 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 532 MockWrite(SYNCHRONOUS, 4, "GET /ko.html HTTP/1.1\r\n\r\n"), | 537 MockWrite(SYNCHRONOUS, 4, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 533 }; | 538 }; |
| 534 MockRead reads[] = { | 539 MockRead reads[] = { |
| 535 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 540 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
| 536 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), | 541 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), |
| 537 MockRead(ASYNC, 3, "ok.html"), | 542 MockRead(ASYNC, 3, "ok.html"), |
| 538 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), | 543 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), |
| 539 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), | 544 MockRead(SYNCHRONOUS, 6, "Content-Length: 7\r\n\r\n"), |
| 540 MockRead(SYNCHRONOUS, 7, "ko.html"), | 545 MockRead(SYNCHRONOUS, 7, "ko.html"), |
| 541 }; | 546 }; |
| 542 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 547 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 543 | 548 |
| 544 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 549 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 545 | 550 |
| 546 HttpRequestHeaders headers; | 551 HttpRequestHeaders headers; |
| 547 HttpResponseInfo response; | 552 HttpResponseInfo response; |
| 548 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, &response, | 553 EXPECT_EQ(ERR_IO_PENDING, |
| 549 callback_.callback())); | 554 stream->SendRequest(headers, &response, callback_.callback())); |
| 550 | 555 |
| 551 scoped_ptr<HttpStream> unsent_stream(NewTestStream("unsent.html")); | 556 scoped_ptr<HttpStream> unsent_stream(NewTestStream("unsent.html")); |
| 552 HttpRequestHeaders unsent_headers; | 557 HttpRequestHeaders unsent_headers; |
| 553 HttpResponseInfo unsent_response; | 558 HttpResponseInfo unsent_response; |
| 554 EXPECT_EQ(ERR_IO_PENDING, unsent_stream->SendRequest(unsent_headers, | 559 EXPECT_EQ(ERR_IO_PENDING, |
| 555 &unsent_response, | 560 unsent_stream->SendRequest( |
| 556 callback_.callback())); | 561 unsent_headers, &unsent_response, callback_.callback())); |
| 557 unsent_stream->Close(false); | 562 unsent_stream->Close(false); |
| 558 | 563 |
| 559 data_->RunFor(1); | 564 data_->RunFor(1); |
| 560 EXPECT_LE(OK, callback_.WaitForResult()); | 565 EXPECT_LE(OK, callback_.WaitForResult()); |
| 561 | 566 |
| 562 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); | 567 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 563 data_->RunFor(2); | 568 data_->RunFor(2); |
| 564 EXPECT_LE(OK, callback_.WaitForResult()); | 569 EXPECT_LE(OK, callback_.WaitForResult()); |
| 565 | 570 |
| 566 ExpectResponse("ok.html", stream, true); | 571 ExpectResponse("ok.html", stream, true); |
| 567 | 572 |
| 568 stream->Close(false); | 573 stream->Close(false); |
| 569 | 574 |
| 570 data_->StopAfter(8); | 575 data_->StopAfter(8); |
| 571 scoped_ptr<HttpStream> later_stream(NewTestStream("ko.html")); | 576 scoped_ptr<HttpStream> later_stream(NewTestStream("ko.html")); |
| 572 TestSyncRequest(later_stream, "ko.html"); | 577 TestSyncRequest(later_stream, "ko.html"); |
| 573 } | 578 } |
| 574 | 579 |
| 575 TEST_F(HttpPipelinedConnectionImplTest, FailedSend) { | 580 TEST_F(HttpPipelinedConnectionImplTest, FailedSend) { |
| 576 MockWrite writes[] = { | 581 MockWrite writes[] = { |
| 577 MockWrite(ASYNC, ERR_FAILED), | 582 MockWrite(ASYNC, ERR_FAILED), |
| 578 }; | 583 }; |
| 579 Initialize(NULL, 0, writes, arraysize(writes)); | 584 Initialize(NULL, 0, writes, arraysize(writes)); |
| 580 | 585 |
| 581 scoped_ptr<HttpStream> failed_stream(NewTestStream("ok.html")); | 586 scoped_ptr<HttpStream> failed_stream(NewTestStream("ok.html")); |
| 582 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 587 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 583 scoped_ptr<HttpStream> closed_stream(NewTestStream("closed.html")); | 588 scoped_ptr<HttpStream> closed_stream(NewTestStream("closed.html")); |
| 584 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); | 589 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); |
| 585 | 590 |
| 586 HttpRequestHeaders headers; | 591 HttpRequestHeaders headers; |
| 587 HttpResponseInfo response; | 592 HttpResponseInfo response; |
| 588 TestCompletionCallback failed_callback; | 593 TestCompletionCallback failed_callback; |
| 589 EXPECT_EQ(ERR_IO_PENDING, | 594 EXPECT_EQ(ERR_IO_PENDING, |
| 590 failed_stream->SendRequest(headers, &response, | 595 failed_stream->SendRequest( |
| 591 failed_callback.callback())); | 596 headers, &response, failed_callback.callback())); |
| 592 TestCompletionCallback evicted_callback; | 597 TestCompletionCallback evicted_callback; |
| 593 EXPECT_EQ(ERR_IO_PENDING, | 598 EXPECT_EQ(ERR_IO_PENDING, |
| 594 evicted_stream->SendRequest(headers, &response, | 599 evicted_stream->SendRequest( |
| 595 evicted_callback.callback())); | 600 headers, &response, evicted_callback.callback())); |
| 596 EXPECT_EQ(ERR_IO_PENDING, closed_stream->SendRequest(headers, &response, | 601 EXPECT_EQ( |
| 597 callback_.callback())); | 602 ERR_IO_PENDING, |
| 603 closed_stream->SendRequest(headers, &response, callback_.callback())); |
| 598 closed_stream->Close(false); | 604 closed_stream->Close(false); |
| 599 | 605 |
| 600 data_->RunFor(1); | 606 data_->RunFor(1); |
| 601 EXPECT_EQ(ERR_FAILED, failed_callback.WaitForResult()); | 607 EXPECT_EQ(ERR_FAILED, failed_callback.WaitForResult()); |
| 602 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); | 608 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 603 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 609 EXPECT_EQ( |
| 604 rejected_stream->SendRequest(headers, &response, | 610 ERR_PIPELINE_EVICTION, |
| 605 callback_.callback())); | 611 rejected_stream->SendRequest(headers, &response, callback_.callback())); |
| 606 | 612 |
| 607 failed_stream->Close(true); | 613 failed_stream->Close(true); |
| 608 evicted_stream->Close(true); | 614 evicted_stream->Close(true); |
| 609 rejected_stream->Close(true); | 615 rejected_stream->Close(true); |
| 610 } | 616 } |
| 611 | 617 |
| 612 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) { | 618 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) { |
| 613 MockWrite writes[] = { | 619 MockWrite writes[] = { |
| 614 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 620 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 615 MockWrite(SYNCHRONOUS, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"), | 621 MockWrite(SYNCHRONOUS, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"), |
| 616 MockWrite(SYNCHRONOUS, 2, "GET /read_rejected.html HTTP/1.1\r\n\r\n"), | 622 MockWrite(SYNCHRONOUS, 2, "GET /read_rejected.html HTTP/1.1\r\n\r\n"), |
| 617 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5), | 623 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5), |
| 618 }; | 624 }; |
| 619 MockRead reads[] = { | 625 MockRead reads[] = { |
| 620 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n\r\n"), | 626 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 621 MockRead(SYNCHRONOUS, 4, "ok.html"), | 627 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 622 MockRead(ASYNC, OK, 6), // Connection closed message. Not read before the | 628 MockRead( |
| 623 // ERR_SOCKET_NOT_CONNECTED. | 629 ASYNC, OK, 6), // Connection closed message. Not read before the |
| 630 // ERR_SOCKET_NOT_CONNECTED. |
| 624 }; | 631 }; |
| 625 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 632 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 626 | 633 |
| 627 scoped_ptr<HttpStream> closed_stream(NewTestStream("ok.html")); | 634 scoped_ptr<HttpStream> closed_stream(NewTestStream("ok.html")); |
| 628 scoped_ptr<HttpStream> read_evicted_stream( | 635 scoped_ptr<HttpStream> read_evicted_stream( |
| 629 NewTestStream("read_evicted.html")); | 636 NewTestStream("read_evicted.html")); |
| 630 scoped_ptr<HttpStream> read_rejected_stream( | 637 scoped_ptr<HttpStream> read_rejected_stream( |
| 631 NewTestStream("read_rejected.html")); | 638 NewTestStream("read_rejected.html")); |
| 632 scoped_ptr<HttpStream> send_closed_stream( | 639 scoped_ptr<HttpStream> send_closed_stream(NewTestStream("send_closed.html")); |
| 633 NewTestStream("send_closed.html")); | |
| 634 scoped_ptr<HttpStream> send_evicted_stream( | 640 scoped_ptr<HttpStream> send_evicted_stream( |
| 635 NewTestStream("send_evicted.html")); | 641 NewTestStream("send_evicted.html")); |
| 636 scoped_ptr<HttpStream> send_rejected_stream( | 642 scoped_ptr<HttpStream> send_rejected_stream( |
| 637 NewTestStream("send_rejected.html")); | 643 NewTestStream("send_rejected.html")); |
| 638 | 644 |
| 639 HttpRequestHeaders headers; | 645 HttpRequestHeaders headers; |
| 640 HttpResponseInfo response; | 646 HttpResponseInfo response; |
| 641 EXPECT_EQ(OK, closed_stream->SendRequest(headers, | 647 EXPECT_EQ( |
| 642 &response, callback_.callback())); | 648 OK, closed_stream->SendRequest(headers, &response, callback_.callback())); |
| 643 EXPECT_EQ(OK, read_evicted_stream->SendRequest(headers, &response, | 649 EXPECT_EQ(OK, |
| 644 callback_.callback())); | 650 read_evicted_stream->SendRequest( |
| 645 EXPECT_EQ(OK, read_rejected_stream->SendRequest(headers, &response, | 651 headers, &response, callback_.callback())); |
| 646 callback_.callback())); | 652 EXPECT_EQ(OK, |
| 653 read_rejected_stream->SendRequest( |
| 654 headers, &response, callback_.callback())); |
| 647 TestCompletionCallback send_closed_callback; | 655 TestCompletionCallback send_closed_callback; |
| 648 EXPECT_EQ(ERR_IO_PENDING, | 656 EXPECT_EQ(ERR_IO_PENDING, |
| 649 send_closed_stream->SendRequest(headers, &response, | 657 send_closed_stream->SendRequest( |
| 650 send_closed_callback.callback())); | 658 headers, &response, send_closed_callback.callback())); |
| 651 TestCompletionCallback send_evicted_callback; | 659 TestCompletionCallback send_evicted_callback; |
| 652 EXPECT_EQ(ERR_IO_PENDING, | 660 EXPECT_EQ(ERR_IO_PENDING, |
| 653 send_evicted_stream->SendRequest(headers, &response, | 661 send_evicted_stream->SendRequest( |
| 654 send_evicted_callback.callback())); | 662 headers, &response, send_evicted_callback.callback())); |
| 655 | 663 |
| 656 TestCompletionCallback read_evicted_callback; | 664 TestCompletionCallback read_evicted_callback; |
| 657 EXPECT_EQ(ERR_IO_PENDING, | 665 EXPECT_EQ(ERR_IO_PENDING, |
| 658 read_evicted_stream->ReadResponseHeaders( | 666 read_evicted_stream->ReadResponseHeaders( |
| 659 read_evicted_callback.callback())); | 667 read_evicted_callback.callback())); |
| 660 | 668 |
| 661 EXPECT_EQ(OK, closed_stream->ReadResponseHeaders(callback_.callback())); | 669 EXPECT_EQ(OK, closed_stream->ReadResponseHeaders(callback_.callback())); |
| 662 ExpectResponse("ok.html", closed_stream, false); | 670 ExpectResponse("ok.html", closed_stream, false); |
| 663 closed_stream->Close(true); | 671 closed_stream->Close(true); |
| 664 | 672 |
| 665 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_evicted_callback.WaitForResult()); | 673 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_evicted_callback.WaitForResult()); |
| 666 read_evicted_stream->Close(true); | 674 read_evicted_stream->Close(true); |
| 667 | 675 |
| 668 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 676 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 669 read_rejected_stream->ReadResponseHeaders(callback_.callback())); | 677 read_rejected_stream->ReadResponseHeaders(callback_.callback())); |
| 670 read_rejected_stream->Close(true); | 678 read_rejected_stream->Close(true); |
| 671 | 679 |
| 672 data_->RunFor(1); | 680 data_->RunFor(1); |
| 673 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, send_closed_callback.WaitForResult()); | 681 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, send_closed_callback.WaitForResult()); |
| 674 send_closed_stream->Close(true); | 682 send_closed_stream->Close(true); |
| 675 | 683 |
| 676 EXPECT_EQ(ERR_PIPELINE_EVICTION, send_evicted_callback.WaitForResult()); | 684 EXPECT_EQ(ERR_PIPELINE_EVICTION, send_evicted_callback.WaitForResult()); |
| 677 send_evicted_stream->Close(true); | 685 send_evicted_stream->Close(true); |
| 678 | 686 |
| 679 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 687 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 680 send_rejected_stream->SendRequest(headers, &response, | 688 send_rejected_stream->SendRequest( |
| 681 callback_.callback())); | 689 headers, &response, callback_.callback())); |
| 682 send_rejected_stream->Close(true); | 690 send_rejected_stream->Close(true); |
| 683 } | 691 } |
| 684 | 692 |
| 685 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) { | 693 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) { |
| 686 MockWrite writes[] = { | 694 MockWrite writes[] = { |
| 687 MockWrite(ASYNC, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), | 695 MockWrite(ASYNC, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), |
| 688 }; | 696 }; |
| 689 Initialize(NULL, 0, writes, arraysize(writes)); | 697 Initialize(NULL, 0, writes, arraysize(writes)); |
| 690 | 698 |
| 691 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); | 699 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); |
| 692 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 700 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 693 | 701 |
| 694 HttpRequestHeaders headers; | 702 HttpRequestHeaders headers; |
| 695 HttpResponseInfo response; | 703 HttpResponseInfo response; |
| 696 TestCompletionCallback aborted_callback; | 704 TestCompletionCallback aborted_callback; |
| 697 EXPECT_EQ(ERR_IO_PENDING, | 705 EXPECT_EQ(ERR_IO_PENDING, |
| 698 aborted_stream->SendRequest(headers, &response, | 706 aborted_stream->SendRequest( |
| 699 aborted_callback.callback())); | 707 headers, &response, aborted_callback.callback())); |
| 700 TestCompletionCallback evicted_callback; | 708 TestCompletionCallback evicted_callback; |
| 701 EXPECT_EQ(ERR_IO_PENDING, | 709 EXPECT_EQ(ERR_IO_PENDING, |
| 702 evicted_stream->SendRequest(headers, &response, | 710 evicted_stream->SendRequest( |
| 703 evicted_callback.callback())); | 711 headers, &response, evicted_callback.callback())); |
| 704 | 712 |
| 705 aborted_stream->Close(true); | 713 aborted_stream->Close(true); |
| 706 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); | 714 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 707 evicted_stream->Close(true); | 715 evicted_stream->Close(true); |
| 708 EXPECT_FALSE(aborted_callback.have_result()); | 716 EXPECT_FALSE(aborted_callback.have_result()); |
| 709 } | 717 } |
| 710 | 718 |
| 711 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) { | 719 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) { |
| 712 MockWrite writes[] = { | 720 MockWrite writes[] = { |
| 713 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 721 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 714 MockWrite(ASYNC, 1, "GET /aborts.html HTTP/1.1\r\n\r\n"), | 722 MockWrite(ASYNC, 1, "GET /aborts.html HTTP/1.1\r\n\r\n"), |
| 715 }; | 723 }; |
| 716 Initialize(NULL, 0, writes, arraysize(writes)); | 724 Initialize(NULL, 0, writes, arraysize(writes)); |
| 717 | 725 |
| 718 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); | 726 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 719 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); | 727 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); |
| 720 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 728 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 721 | 729 |
| 722 HttpRequestHeaders headers; | 730 HttpRequestHeaders headers; |
| 723 HttpResponseInfo response; | 731 HttpResponseInfo response; |
| 724 TestCompletionCallback ok_callback; | 732 TestCompletionCallback ok_callback; |
| 725 EXPECT_EQ(ERR_IO_PENDING, ok_stream->SendRequest(headers, &response, | 733 EXPECT_EQ(ERR_IO_PENDING, |
| 726 ok_callback.callback())); | 734 ok_stream->SendRequest(headers, &response, ok_callback.callback())); |
| 727 TestCompletionCallback aborted_callback; | 735 TestCompletionCallback aborted_callback; |
| 728 EXPECT_EQ(ERR_IO_PENDING, | 736 EXPECT_EQ(ERR_IO_PENDING, |
| 729 aborted_stream->SendRequest(headers, &response, | 737 aborted_stream->SendRequest( |
| 730 aborted_callback.callback())); | 738 headers, &response, aborted_callback.callback())); |
| 731 TestCompletionCallback evicted_callback; | 739 TestCompletionCallback evicted_callback; |
| 732 EXPECT_EQ(ERR_IO_PENDING, | 740 EXPECT_EQ(ERR_IO_PENDING, |
| 733 evicted_stream->SendRequest(headers, &response, | 741 evicted_stream->SendRequest( |
| 734 evicted_callback.callback())); | 742 headers, &response, evicted_callback.callback())); |
| 735 | 743 |
| 736 data_->RunFor(1); | 744 data_->RunFor(1); |
| 737 EXPECT_LE(OK, ok_callback.WaitForResult()); | 745 EXPECT_LE(OK, ok_callback.WaitForResult()); |
| 738 base::MessageLoop::current()->RunUntilIdle(); | 746 base::MessageLoop::current()->RunUntilIdle(); |
| 739 aborted_stream->Close(true); | 747 aborted_stream->Close(true); |
| 740 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); | 748 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 741 evicted_stream->Close(true); | 749 evicted_stream->Close(true); |
| 742 EXPECT_FALSE(aborted_callback.have_result()); | 750 EXPECT_FALSE(aborted_callback.have_result()); |
| 743 ok_stream->Close(true); | 751 ok_stream->Close(true); |
| 744 } | 752 } |
| 745 | 753 |
| 746 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) { | 754 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) { |
| 747 MockWrite writes[] = { | 755 MockWrite writes[] = { |
| 748 MockWrite(SYNCHRONOUS, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), | 756 MockWrite(SYNCHRONOUS, 0, "GET /aborts.html HTTP/1.1\r\n\r\n"), |
| 749 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), | 757 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 750 }; | 758 }; |
| 751 MockRead reads[] = { | 759 MockRead reads[] = { |
| 752 MockRead(ASYNC, ERR_FAILED, 2), | 760 MockRead(ASYNC, ERR_FAILED, 2), |
| 753 }; | 761 }; |
| 754 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 762 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 755 | 763 |
| 756 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); | 764 scoped_ptr<HttpStream> aborted_stream(NewTestStream("aborts.html")); |
| 757 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 765 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 758 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); | 766 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); |
| 759 | 767 |
| 760 HttpRequestHeaders headers; | 768 HttpRequestHeaders headers; |
| 761 HttpResponseInfo response; | 769 HttpResponseInfo response; |
| 762 EXPECT_EQ(OK, | 770 EXPECT_EQ( |
| 763 aborted_stream->SendRequest(headers, &response, | 771 OK, |
| 764 callback_.callback())); | 772 aborted_stream->SendRequest(headers, &response, callback_.callback())); |
| 765 EXPECT_EQ(OK, | 773 EXPECT_EQ( |
| 766 evicted_stream->SendRequest(headers, &response, | 774 OK, |
| 767 callback_.callback())); | 775 evicted_stream->SendRequest(headers, &response, callback_.callback())); |
| 768 | 776 |
| 769 EXPECT_EQ(ERR_IO_PENDING, | 777 EXPECT_EQ(ERR_IO_PENDING, |
| 770 aborted_stream->ReadResponseHeaders(callback_.callback())); | 778 aborted_stream->ReadResponseHeaders(callback_.callback())); |
| 771 TestCompletionCallback evicted_callback; | 779 TestCompletionCallback evicted_callback; |
| 772 EXPECT_EQ(ERR_IO_PENDING, | 780 EXPECT_EQ(ERR_IO_PENDING, |
| 773 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); | 781 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); |
| 774 | 782 |
| 775 aborted_stream->Close(true); | 783 aborted_stream->Close(true); |
| 776 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); | 784 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 777 evicted_stream->Close(true); | 785 evicted_stream->Close(true); |
| 778 | 786 |
| 779 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 787 EXPECT_EQ( |
| 780 rejected_stream->SendRequest(headers, &response, | 788 ERR_PIPELINE_EVICTION, |
| 781 callback_.callback())); | 789 rejected_stream->SendRequest(headers, &response, callback_.callback())); |
| 782 rejected_stream->Close(true); | 790 rejected_stream->Close(true); |
| 783 } | 791 } |
| 784 | 792 |
| 785 TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) { | 793 TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) { |
| 786 MockWrite writes[] = { | 794 MockWrite writes[] = { |
| 787 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 795 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 788 MockWrite(SYNCHRONOUS, 1, "GET /abandoned.html HTTP/1.1\r\n\r\n"), | 796 MockWrite(SYNCHRONOUS, 1, "GET /abandoned.html HTTP/1.1\r\n\r\n"), |
| 789 MockWrite(SYNCHRONOUS, 2, "GET /evicted.html HTTP/1.1\r\n\r\n"), | 797 MockWrite(SYNCHRONOUS, 2, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 790 }; | 798 }; |
| 791 MockRead reads[] = { | 799 MockRead reads[] = { |
| 792 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), | 800 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 793 MockRead(SYNCHRONOUS, 4, "Content-Length: 7\r\n\r\n"), | 801 MockRead(SYNCHRONOUS, 4, "Content-Length: 7\r\n\r\n"), |
| 794 MockRead(SYNCHRONOUS, 5, "ok.html"), | 802 MockRead(SYNCHRONOUS, 5, "ok.html"), |
| 795 }; | 803 }; |
| 796 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 804 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 797 | 805 |
| 798 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); | 806 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 799 scoped_ptr<HttpStream> abandoned_stream(NewTestStream("abandoned.html")); | 807 scoped_ptr<HttpStream> abandoned_stream(NewTestStream("abandoned.html")); |
| 800 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 808 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 801 | 809 |
| 802 HttpRequestHeaders headers; | 810 HttpRequestHeaders headers; |
| 803 HttpResponseInfo response; | 811 HttpResponseInfo response; |
| 804 EXPECT_EQ(OK, ok_stream->SendRequest(headers, &response, | 812 EXPECT_EQ(OK, |
| 805 callback_.callback())); | 813 ok_stream->SendRequest(headers, &response, callback_.callback())); |
| 806 EXPECT_EQ(OK, abandoned_stream->SendRequest(headers, &response, | 814 EXPECT_EQ( |
| 807 callback_.callback())); | 815 OK, |
| 808 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, &response, | 816 abandoned_stream->SendRequest(headers, &response, callback_.callback())); |
| 809 callback_.callback())); | 817 EXPECT_EQ( |
| 818 OK, |
| 819 evicted_stream->SendRequest(headers, &response, callback_.callback())); |
| 810 | 820 |
| 811 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); | 821 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); |
| 812 TestCompletionCallback abandoned_callback; | 822 TestCompletionCallback abandoned_callback; |
| 813 EXPECT_EQ(ERR_IO_PENDING, abandoned_stream->ReadResponseHeaders( | 823 EXPECT_EQ( |
| 814 abandoned_callback.callback())); | 824 ERR_IO_PENDING, |
| 825 abandoned_stream->ReadResponseHeaders(abandoned_callback.callback())); |
| 815 TestCompletionCallback evicted_callback; | 826 TestCompletionCallback evicted_callback; |
| 816 EXPECT_EQ(ERR_IO_PENDING, | 827 EXPECT_EQ(ERR_IO_PENDING, |
| 817 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); | 828 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); |
| 818 | 829 |
| 819 abandoned_stream->Close(false); | 830 abandoned_stream->Close(false); |
| 820 | 831 |
| 821 ExpectResponse("ok.html", ok_stream, false); | 832 ExpectResponse("ok.html", ok_stream, false); |
| 822 ok_stream->Close(false); | 833 ok_stream->Close(false); |
| 823 | 834 |
| 824 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); | 835 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 825 evicted_stream->Close(true); | 836 evicted_stream->Close(true); |
| 826 EXPECT_FALSE(evicted_stream->IsConnectionReusable()); | 837 EXPECT_FALSE(evicted_stream->IsConnectionReusable()); |
| 827 } | 838 } |
| 828 | 839 |
| 829 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedAfterOneRequestRecovery) { | 840 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedAfterOneRequestRecovery) { |
| 830 MockWrite writes[] = { | 841 MockWrite writes[] = { |
| 831 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 842 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 832 MockWrite(SYNCHRONOUS, 1, "GET /rejected.html HTTP/1.1\r\n\r\n"), | 843 MockWrite(SYNCHRONOUS, 1, "GET /rejected.html HTTP/1.1\r\n\r\n"), |
| 833 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5), | 844 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5), |
| 834 MockWrite(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 7), | 845 MockWrite(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 7), |
| 835 }; | 846 }; |
| 836 MockRead reads[] = { | 847 MockRead reads[] = { |
| 837 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 848 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 838 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), | 849 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), |
| 839 MockRead(SYNCHRONOUS, 4, "ok.html"), | 850 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 840 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 6), | 851 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 6), |
| 841 }; | 852 }; |
| 842 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 853 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 843 | 854 |
| 844 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); | 855 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 845 scoped_ptr<HttpStream> rejected_read_stream(NewTestStream("rejected.html")); | 856 scoped_ptr<HttpStream> rejected_read_stream(NewTestStream("rejected.html")); |
| 846 scoped_ptr<HttpStream> evicted_send_stream(NewTestStream("evicted.html")); | 857 scoped_ptr<HttpStream> evicted_send_stream(NewTestStream("evicted.html")); |
| 847 scoped_ptr<HttpStream> rejected_send_stream(NewTestStream("rejected.html")); | 858 scoped_ptr<HttpStream> rejected_send_stream(NewTestStream("rejected.html")); |
| 848 | 859 |
| 849 HttpRequestHeaders headers; | 860 HttpRequestHeaders headers; |
| 850 HttpResponseInfo response; | 861 HttpResponseInfo response; |
| 851 EXPECT_EQ(OK, ok_stream->SendRequest(headers, | 862 EXPECT_EQ(OK, |
| 852 &response, callback_.callback())); | 863 ok_stream->SendRequest(headers, &response, callback_.callback())); |
| 853 EXPECT_EQ(OK, rejected_read_stream->SendRequest(headers, &response, | 864 EXPECT_EQ(OK, |
| 854 callback_.callback())); | 865 rejected_read_stream->SendRequest( |
| 866 headers, &response, callback_.callback())); |
| 855 | 867 |
| 856 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); | 868 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); |
| 857 ExpectResponse("ok.html", ok_stream, false); | 869 ExpectResponse("ok.html", ok_stream, false); |
| 858 ok_stream->Close(false); | 870 ok_stream->Close(false); |
| 859 | 871 |
| 860 TestCompletionCallback read_callback; | 872 TestCompletionCallback read_callback; |
| 861 EXPECT_EQ(ERR_IO_PENDING, | 873 EXPECT_EQ(ERR_IO_PENDING, |
| 862 evicted_send_stream->SendRequest(headers, &response, | 874 evicted_send_stream->SendRequest( |
| 863 read_callback.callback())); | 875 headers, &response, read_callback.callback())); |
| 864 data_->RunFor(1); | 876 data_->RunFor(1); |
| 865 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_callback.WaitForResult()); | 877 EXPECT_EQ(ERR_PIPELINE_EVICTION, read_callback.WaitForResult()); |
| 866 | 878 |
| 867 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 879 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 868 rejected_read_stream->ReadResponseHeaders(callback_.callback())); | 880 rejected_read_stream->ReadResponseHeaders(callback_.callback())); |
| 869 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 881 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 870 rejected_send_stream->SendRequest(headers, &response, | 882 rejected_send_stream->SendRequest( |
| 871 callback_.callback())); | 883 headers, &response, callback_.callback())); |
| 872 | 884 |
| 873 rejected_read_stream->Close(true); | 885 rejected_read_stream->Close(true); |
| 874 rejected_send_stream->Close(true); | 886 rejected_send_stream->Close(true); |
| 875 } | 887 } |
| 876 | 888 |
| 877 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) { | 889 TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) { |
| 878 MockWrite writes[] = { | 890 MockWrite writes[] = { |
| 879 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 891 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 880 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), | 892 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 881 }; | 893 }; |
| 882 MockRead reads[] = { | 894 MockRead reads[] = { |
| 883 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 895 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 884 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), | 896 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), |
| 885 MockRead(SYNCHRONOUS, 4, "ok.html"), | 897 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 886 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5), | 898 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5), |
| 887 }; | 899 }; |
| 888 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 900 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 889 | 901 |
| 890 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); | 902 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 891 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 903 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 892 | 904 |
| 893 HttpRequestHeaders headers; | 905 HttpRequestHeaders headers; |
| 894 HttpResponseInfo response; | 906 HttpResponseInfo response; |
| 895 EXPECT_EQ(OK, ok_stream->SendRequest(headers, | 907 EXPECT_EQ(OK, |
| 896 &response, callback_.callback())); | 908 ok_stream->SendRequest(headers, &response, callback_.callback())); |
| 897 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, &response, | 909 EXPECT_EQ( |
| 898 callback_.callback())); | 910 OK, |
| 911 evicted_stream->SendRequest(headers, &response, callback_.callback())); |
| 899 | 912 |
| 900 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); | 913 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); |
| 901 ExpectResponse("ok.html", ok_stream, false); | 914 ExpectResponse("ok.html", ok_stream, false); |
| 902 | 915 |
| 903 TestCompletionCallback evicted_callback; | 916 TestCompletionCallback evicted_callback; |
| 904 EXPECT_EQ(ERR_IO_PENDING, | 917 EXPECT_EQ(ERR_IO_PENDING, |
| 905 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); | 918 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); |
| 906 | 919 |
| 907 ok_stream->Close(false); | 920 ok_stream->Close(false); |
| 908 | 921 |
| 909 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); | 922 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 910 evicted_stream->Close(false); | 923 evicted_stream->Close(false); |
| 911 } | 924 } |
| 912 | 925 |
| 913 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) { | 926 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) { |
| 914 MockWrite writes[] = { | 927 MockWrite writes[] = { |
| 915 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 928 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 916 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), | 929 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 917 }; | 930 }; |
| 918 MockRead reads[] = { | 931 MockRead reads[] = { |
| 919 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 932 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 920 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), | 933 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), |
| 921 MockRead(SYNCHRONOUS, 4, "ok.html"), | 934 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 922 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5), | 935 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5), |
| 923 }; | 936 }; |
| 924 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 937 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 925 | 938 |
| 926 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); | 939 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 927 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 940 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 928 | 941 |
| 929 HttpRequestHeaders headers; | 942 HttpRequestHeaders headers; |
| 930 HttpResponseInfo response; | 943 HttpResponseInfo response; |
| 931 EXPECT_EQ(OK, ok_stream->SendRequest(headers, | 944 EXPECT_EQ(OK, |
| 932 &response, callback_.callback())); | 945 ok_stream->SendRequest(headers, &response, callback_.callback())); |
| 933 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, &response, | 946 EXPECT_EQ( |
| 934 callback_.callback())); | 947 OK, |
| 948 evicted_stream->SendRequest(headers, &response, callback_.callback())); |
| 935 | 949 |
| 936 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); | 950 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); |
| 937 ExpectResponse("ok.html", ok_stream, false); | 951 ExpectResponse("ok.html", ok_stream, false); |
| 938 | 952 |
| 939 TestCompletionCallback evicted_callback; | 953 TestCompletionCallback evicted_callback; |
| 940 EXPECT_EQ(ERR_IO_PENDING, | 954 EXPECT_EQ(ERR_IO_PENDING, |
| 941 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); | 955 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); |
| 942 | 956 |
| 943 ok_stream->Close(false); | 957 ok_stream->Close(false); |
| 944 evicted_stream->Close(false); | 958 evicted_stream->Close(false); |
| 945 } | 959 } |
| 946 | 960 |
| 947 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) { | 961 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) { |
| 948 MockWrite writes[] = { | 962 MockWrite writes[] = { |
| 949 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 963 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 950 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), | 964 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 951 }; | 965 }; |
| 952 MockRead reads[] = { | 966 MockRead reads[] = { |
| 953 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 967 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 954 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), | 968 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), |
| 955 MockRead(SYNCHRONOUS, 4, "ok.html"), | 969 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 956 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5), | 970 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 5), |
| 957 }; | 971 }; |
| 958 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 972 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 959 | 973 |
| 960 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); | 974 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 961 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 975 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 962 | 976 |
| 963 HttpRequestHeaders headers; | 977 HttpRequestHeaders headers; |
| 964 HttpResponseInfo response; | 978 HttpResponseInfo response; |
| 965 EXPECT_EQ(OK, ok_stream->SendRequest(headers, | 979 EXPECT_EQ(OK, |
| 966 &response, callback_.callback())); | 980 ok_stream->SendRequest(headers, &response, callback_.callback())); |
| 967 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, &response, | 981 EXPECT_EQ( |
| 968 callback_.callback())); | 982 OK, |
| 983 evicted_stream->SendRequest(headers, &response, callback_.callback())); |
| 969 | 984 |
| 970 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); | 985 EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback())); |
| 971 ExpectResponse("ok.html", ok_stream, false); | 986 ExpectResponse("ok.html", ok_stream, false); |
| 972 | 987 |
| 973 TestCompletionCallback evicted_callback; | 988 TestCompletionCallback evicted_callback; |
| 974 EXPECT_EQ(ERR_IO_PENDING, | 989 EXPECT_EQ(ERR_IO_PENDING, |
| 975 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); | 990 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); |
| 976 | 991 |
| 977 ok_stream->Close(false); | 992 ok_stream->Close(false); |
| 978 | 993 |
| 979 // The posted tasks should be: | 994 // The posted tasks should be: |
| 980 // 1. DoReadHeadersLoop, which will post: | 995 // 1. DoReadHeadersLoop, which will post: |
| 981 // 2. InvokeUserCallback | 996 // 2. InvokeUserCallback |
| 982 SuddenCloseObserver observer(evicted_stream.get(), 2); | 997 SuddenCloseObserver observer(evicted_stream.get(), 2); |
| 983 base::MessageLoop::current()->AddTaskObserver(&observer); | 998 base::MessageLoop::current()->AddTaskObserver(&observer); |
| 984 base::MessageLoop::current()->RunUntilIdle(); | 999 base::MessageLoop::current()->RunUntilIdle(); |
| 985 EXPECT_FALSE(evicted_callback.have_result()); | 1000 EXPECT_FALSE(evicted_callback.have_result()); |
| 986 } | 1001 } |
| 987 | 1002 |
| 988 class StreamDeleter { | 1003 class StreamDeleter { |
| 989 public: | 1004 public: |
| 990 StreamDeleter(HttpStream* stream) | 1005 StreamDeleter(HttpStream* stream) |
| 991 : stream_(stream), | 1006 : stream_(stream), |
| 992 callback_(base::Bind(&StreamDeleter::OnIOComplete, | 1007 callback_( |
| 993 base::Unretained(this))) { | 1008 base::Bind(&StreamDeleter::OnIOComplete, base::Unretained(this))) {} |
| 994 } | |
| 995 | 1009 |
| 996 ~StreamDeleter() { | 1010 ~StreamDeleter() { EXPECT_FALSE(stream_); } |
| 997 EXPECT_FALSE(stream_); | |
| 998 } | |
| 999 | 1011 |
| 1000 const CompletionCallback& callback() { return callback_; } | 1012 const CompletionCallback& callback() { return callback_; } |
| 1001 | 1013 |
| 1002 private: | 1014 private: |
| 1003 void OnIOComplete(int result) { | 1015 void OnIOComplete(int result) { |
| 1004 stream_->Close(true); | 1016 stream_->Close(true); |
| 1005 stream_.reset(); | 1017 stream_.reset(); |
| 1006 } | 1018 } |
| 1007 | 1019 |
| 1008 scoped_ptr<HttpStream> stream_; | 1020 scoped_ptr<HttpStream> stream_; |
| 1009 CompletionCallback callback_; | 1021 CompletionCallback callback_; |
| 1010 }; | 1022 }; |
| 1011 | 1023 |
| 1012 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) { | 1024 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) { |
| 1013 MockWrite writes[] = { | 1025 MockWrite writes[] = { |
| 1014 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1026 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1015 }; | 1027 }; |
| 1016 Initialize(NULL, 0, writes, arraysize(writes)); | 1028 Initialize(NULL, 0, writes, arraysize(writes)); |
| 1017 | 1029 |
| 1018 HttpStream* stream(NewTestStream("ok.html")); | 1030 HttpStream* stream(NewTestStream("ok.html")); |
| 1019 | 1031 |
| 1020 StreamDeleter deleter(stream); | 1032 StreamDeleter deleter(stream); |
| 1021 HttpRequestHeaders headers; | 1033 HttpRequestHeaders headers; |
| 1022 HttpResponseInfo response; | 1034 HttpResponseInfo response; |
| 1023 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, &response, | 1035 EXPECT_EQ(ERR_IO_PENDING, |
| 1024 deleter.callback())); | 1036 stream->SendRequest(headers, &response, deleter.callback())); |
| 1025 data_->RunFor(1); | 1037 data_->RunFor(1); |
| 1026 } | 1038 } |
| 1027 | 1039 |
| 1028 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringReadCallback) { | 1040 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringReadCallback) { |
| 1029 MockWrite writes[] = { | 1041 MockWrite writes[] = { |
| 1030 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1042 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1031 }; | 1043 }; |
| 1032 MockRead reads[] = { | 1044 MockRead reads[] = { |
| 1033 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 1045 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 1034 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), | 1046 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), |
| 1035 }; | 1047 }; |
| 1036 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1048 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1037 | 1049 |
| 1038 HttpStream* stream(NewTestStream("ok.html")); | 1050 HttpStream* stream(NewTestStream("ok.html")); |
| 1039 | 1051 |
| 1040 HttpRequestHeaders headers; | 1052 HttpRequestHeaders headers; |
| 1041 HttpResponseInfo response; | 1053 HttpResponseInfo response; |
| 1042 EXPECT_EQ(OK, stream->SendRequest(headers, | 1054 EXPECT_EQ(OK, stream->SendRequest(headers, &response, callback_.callback())); |
| 1043 &response, callback_.callback())); | |
| 1044 | 1055 |
| 1045 StreamDeleter deleter(stream); | 1056 StreamDeleter deleter(stream); |
| 1046 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback())); | 1057 EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback())); |
| 1047 data_->RunFor(1); | 1058 data_->RunFor(1); |
| 1048 } | 1059 } |
| 1049 | 1060 |
| 1050 TEST_F(HttpPipelinedConnectionImplTest, | 1061 TEST_F(HttpPipelinedConnectionImplTest, |
| 1051 CloseCalledDuringReadCallbackWithPendingRead) { | 1062 CloseCalledDuringReadCallbackWithPendingRead) { |
| 1052 MockWrite writes[] = { | 1063 MockWrite writes[] = { |
| 1053 MockWrite(SYNCHRONOUS, 0, "GET /failed.html HTTP/1.1\r\n\r\n"), | 1064 MockWrite(SYNCHRONOUS, 0, "GET /failed.html HTTP/1.1\r\n\r\n"), |
| 1054 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), | 1065 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 1055 }; | 1066 }; |
| 1056 MockRead reads[] = { | 1067 MockRead reads[] = { |
| 1057 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 1068 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 1058 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), | 1069 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), |
| 1059 }; | 1070 }; |
| 1060 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1071 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1061 | 1072 |
| 1062 HttpStream* failed_stream(NewTestStream("failed.html")); | 1073 HttpStream* failed_stream(NewTestStream("failed.html")); |
| 1063 HttpStream* evicted_stream(NewTestStream("evicted.html")); | 1074 HttpStream* evicted_stream(NewTestStream("evicted.html")); |
| 1064 | 1075 |
| 1065 HttpRequestHeaders headers; | 1076 HttpRequestHeaders headers; |
| 1066 HttpResponseInfo response; | 1077 HttpResponseInfo response; |
| 1067 EXPECT_EQ(OK, failed_stream->SendRequest(headers, &response, | 1078 EXPECT_EQ( |
| 1068 callback_.callback())); | 1079 OK, failed_stream->SendRequest(headers, &response, callback_.callback())); |
| 1069 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, &response, | 1080 EXPECT_EQ( |
| 1070 callback_.callback())); | 1081 OK, |
| 1082 evicted_stream->SendRequest(headers, &response, callback_.callback())); |
| 1071 | 1083 |
| 1072 StreamDeleter failed_deleter(failed_stream); | 1084 StreamDeleter failed_deleter(failed_stream); |
| 1073 EXPECT_EQ(ERR_IO_PENDING, | 1085 EXPECT_EQ(ERR_IO_PENDING, |
| 1074 failed_stream->ReadResponseHeaders(failed_deleter.callback())); | 1086 failed_stream->ReadResponseHeaders(failed_deleter.callback())); |
| 1075 StreamDeleter evicted_deleter(evicted_stream); | 1087 StreamDeleter evicted_deleter(evicted_stream); |
| 1076 EXPECT_EQ(ERR_IO_PENDING, | 1088 EXPECT_EQ(ERR_IO_PENDING, |
| 1077 evicted_stream->ReadResponseHeaders(evicted_deleter.callback())); | 1089 evicted_stream->ReadResponseHeaders(evicted_deleter.callback())); |
| 1078 data_->RunFor(1); | 1090 data_->RunFor(1); |
| 1079 } | 1091 } |
| 1080 | 1092 |
| 1081 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) { | 1093 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) { |
| 1082 MockWrite writes[] = { | 1094 MockWrite writes[] = { |
| 1083 MockWrite(SYNCHRONOUS, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"), | 1095 MockWrite(SYNCHRONOUS, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"), |
| 1084 MockWrite(SYNCHRONOUS, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"), | 1096 MockWrite(SYNCHRONOUS, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"), |
| 1085 }; | 1097 }; |
| 1086 MockRead reads[] = { | 1098 MockRead reads[] = { |
| 1087 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 1099 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 1088 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), | 1100 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), |
| 1089 }; | 1101 }; |
| 1090 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1102 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1091 | 1103 |
| 1092 scoped_ptr<HttpStream> deleter_stream(NewTestStream("deleter.html")); | 1104 scoped_ptr<HttpStream> deleter_stream(NewTestStream("deleter.html")); |
| 1093 HttpStream* deleted_stream(NewTestStream("deleted.html")); | 1105 HttpStream* deleted_stream(NewTestStream("deleted.html")); |
| 1094 | 1106 |
| 1095 HttpRequestHeaders headers; | 1107 HttpRequestHeaders headers; |
| 1096 HttpResponseInfo response; | 1108 HttpResponseInfo response; |
| 1097 EXPECT_EQ(OK, deleter_stream->SendRequest(headers, | 1109 EXPECT_EQ( |
| 1098 &response, callback_.callback())); | 1110 OK, |
| 1099 EXPECT_EQ(OK, deleted_stream->SendRequest(headers, | 1111 deleter_stream->SendRequest(headers, &response, callback_.callback())); |
| 1100 &response, callback_.callback())); | 1112 EXPECT_EQ( |
| 1113 OK, |
| 1114 deleted_stream->SendRequest(headers, &response, callback_.callback())); |
| 1101 | 1115 |
| 1102 StreamDeleter deleter(deleted_stream); | 1116 StreamDeleter deleter(deleted_stream); |
| 1103 EXPECT_EQ(ERR_IO_PENDING, | 1117 EXPECT_EQ(ERR_IO_PENDING, |
| 1104 deleter_stream->ReadResponseHeaders(deleter.callback())); | 1118 deleter_stream->ReadResponseHeaders(deleter.callback())); |
| 1105 EXPECT_EQ(ERR_IO_PENDING, | 1119 EXPECT_EQ(ERR_IO_PENDING, |
| 1106 deleted_stream->ReadResponseHeaders(callback_.callback())); | 1120 deleted_stream->ReadResponseHeaders(callback_.callback())); |
| 1107 data_->RunFor(1); | 1121 data_->RunFor(1); |
| 1108 } | 1122 } |
| 1109 | 1123 |
| 1110 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) { | 1124 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) { |
| 1111 MockWrite writes[] = { | 1125 MockWrite writes[] = { |
| 1112 MockWrite(ASYNC, 0, "GET /close.html HTTP/1.1\r\n\r\n"), | 1126 MockWrite(ASYNC, 0, "GET /close.html HTTP/1.1\r\n\r\n"), |
| 1113 MockWrite(ASYNC, 1, "GET /dummy.html HTTP/1.1\r\n\r\n"), | 1127 MockWrite(ASYNC, 1, "GET /dummy.html HTTP/1.1\r\n\r\n"), |
| 1114 }; | 1128 }; |
| 1115 Initialize(NULL, 0, writes, arraysize(writes)); | 1129 Initialize(NULL, 0, writes, arraysize(writes)); |
| 1116 | 1130 |
| 1117 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); | 1131 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); |
| 1118 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); | 1132 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); |
| 1119 | 1133 |
| 1120 scoped_ptr<TestCompletionCallback> close_callback( | 1134 scoped_ptr<TestCompletionCallback> close_callback(new TestCompletionCallback); |
| 1121 new TestCompletionCallback); | |
| 1122 HttpRequestHeaders headers; | 1135 HttpRequestHeaders headers; |
| 1123 HttpResponseInfo response; | 1136 HttpResponseInfo response; |
| 1124 EXPECT_EQ(ERR_IO_PENDING, | 1137 EXPECT_EQ(ERR_IO_PENDING, |
| 1125 close_stream->SendRequest(headers, | 1138 close_stream->SendRequest( |
| 1126 &response, close_callback->callback())); | 1139 headers, &response, close_callback->callback())); |
| 1127 | 1140 |
| 1128 data_->RunFor(1); | 1141 data_->RunFor(1); |
| 1129 EXPECT_FALSE(close_callback->have_result()); | 1142 EXPECT_FALSE(close_callback->have_result()); |
| 1130 | 1143 |
| 1131 close_stream->Close(false); | 1144 close_stream->Close(false); |
| 1132 close_stream.reset(); | 1145 close_stream.reset(); |
| 1133 close_callback.reset(); | 1146 close_callback.reset(); |
| 1134 | 1147 |
| 1135 base::MessageLoop::current()->RunUntilIdle(); | 1148 base::MessageLoop::current()->RunUntilIdle(); |
| 1136 } | 1149 } |
| 1137 | 1150 |
| 1138 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) { | 1151 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) { |
| 1139 MockWrite writes[] = { | 1152 MockWrite writes[] = { |
| 1140 MockWrite(SYNCHRONOUS, 0, "GET /close.html HTTP/1.1\r\n\r\n"), | 1153 MockWrite(SYNCHRONOUS, 0, "GET /close.html HTTP/1.1\r\n\r\n"), |
| 1141 MockWrite(SYNCHRONOUS, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"), | 1154 MockWrite(SYNCHRONOUS, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"), |
| 1142 }; | 1155 }; |
| 1143 MockRead reads[] = { | 1156 MockRead reads[] = { |
| 1144 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 1157 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 1145 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), | 1158 MockRead(ASYNC, 2, "Content-Length: 7\r\n\r\n"), |
| 1146 }; | 1159 }; |
| 1147 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1160 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1148 | 1161 |
| 1149 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); | 1162 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); |
| 1150 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); | 1163 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); |
| 1151 | 1164 |
| 1152 HttpRequestHeaders headers; | 1165 HttpRequestHeaders headers; |
| 1153 HttpResponseInfo response; | 1166 HttpResponseInfo response; |
| 1154 EXPECT_EQ(OK, close_stream->SendRequest(headers, | 1167 EXPECT_EQ( |
| 1155 &response, callback_.callback())); | 1168 OK, close_stream->SendRequest(headers, &response, callback_.callback())); |
| 1156 | 1169 |
| 1157 scoped_ptr<TestCompletionCallback> close_callback( | 1170 scoped_ptr<TestCompletionCallback> close_callback(new TestCompletionCallback); |
| 1158 new TestCompletionCallback); | |
| 1159 EXPECT_EQ(ERR_IO_PENDING, | 1171 EXPECT_EQ(ERR_IO_PENDING, |
| 1160 close_stream->ReadResponseHeaders(close_callback->callback())); | 1172 close_stream->ReadResponseHeaders(close_callback->callback())); |
| 1161 | 1173 |
| 1162 data_->RunFor(1); | 1174 data_->RunFor(1); |
| 1163 EXPECT_FALSE(close_callback->have_result()); | 1175 EXPECT_FALSE(close_callback->have_result()); |
| 1164 | 1176 |
| 1165 close_stream->Close(false); | 1177 close_stream->Close(false); |
| 1166 close_stream.reset(); | 1178 close_stream.reset(); |
| 1167 close_callback.reset(); | 1179 close_callback.reset(); |
| 1168 | 1180 |
| 1169 base::MessageLoop::current()->RunUntilIdle(); | 1181 base::MessageLoop::current()->RunUntilIdle(); |
| 1170 } | 1182 } |
| 1171 | 1183 |
| 1172 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendQueued) { | 1184 TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendQueued) { |
| 1173 MockWrite writes[] = { | 1185 MockWrite writes[] = { |
| 1174 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1186 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1175 MockWrite(ASYNC, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), | 1187 MockWrite(ASYNC, 1, "GET /ko.html HTTP/1.1\r\n\r\n"), |
| 1176 }; | 1188 }; |
| 1177 Initialize(NULL, 0, writes, arraysize(writes)); | 1189 Initialize(NULL, 0, writes, arraysize(writes)); |
| 1178 | 1190 |
| 1179 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); | 1191 scoped_ptr<HttpStream> stream1(NewTestStream("ok.html")); |
| 1180 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); | 1192 scoped_ptr<HttpStream> stream2(NewTestStream("ko.html")); |
| 1181 | 1193 |
| 1182 HttpRequestHeaders headers1; | 1194 HttpRequestHeaders headers1; |
| 1183 HttpResponseInfo response1; | 1195 HttpResponseInfo response1; |
| 1184 TestCompletionCallback callback1; | 1196 TestCompletionCallback callback1; |
| 1185 EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, &response1, | 1197 EXPECT_EQ(ERR_IO_PENDING, |
| 1186 callback1.callback())); | 1198 stream1->SendRequest(headers1, &response1, callback1.callback())); |
| 1187 | 1199 |
| 1188 HttpRequestHeaders headers2; | 1200 HttpRequestHeaders headers2; |
| 1189 HttpResponseInfo response2; | 1201 HttpResponseInfo response2; |
| 1190 TestCompletionCallback callback2; | 1202 TestCompletionCallback callback2; |
| 1191 EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(headers2, &response2, | 1203 EXPECT_EQ(ERR_IO_PENDING, |
| 1192 callback2.callback())); | 1204 stream2->SendRequest(headers2, &response2, callback2.callback())); |
| 1193 | 1205 |
| 1194 stream2.reset(); | 1206 stream2.reset(); |
| 1195 stream1->Close(true); | 1207 stream1->Close(true); |
| 1196 | 1208 |
| 1197 EXPECT_FALSE(callback2.have_result()); | 1209 EXPECT_FALSE(callback2.have_result()); |
| 1198 } | 1210 } |
| 1199 | 1211 |
| 1200 TEST_F(HttpPipelinedConnectionImplTest, NoGapBetweenCloseAndEviction) { | 1212 TEST_F(HttpPipelinedConnectionImplTest, NoGapBetweenCloseAndEviction) { |
| 1201 MockWrite writes[] = { | 1213 MockWrite writes[] = { |
| 1202 MockWrite(SYNCHRONOUS, 0, "GET /close.html HTTP/1.1\r\n\r\n"), | 1214 MockWrite(SYNCHRONOUS, 0, "GET /close.html HTTP/1.1\r\n\r\n"), |
| 1203 MockWrite(SYNCHRONOUS, 2, "GET /dummy.html HTTP/1.1\r\n\r\n"), | 1215 MockWrite(SYNCHRONOUS, 2, "GET /dummy.html HTTP/1.1\r\n\r\n"), |
| 1204 }; | 1216 }; |
| 1205 MockRead reads[] = { | 1217 MockRead reads[] = { |
| 1206 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 1218 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 1207 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), | 1219 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), |
| 1208 }; | 1220 }; |
| 1209 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1221 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1210 | 1222 |
| 1211 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); | 1223 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html")); |
| 1212 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); | 1224 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html")); |
| 1213 | 1225 |
| 1214 HttpRequestHeaders headers; | 1226 HttpRequestHeaders headers; |
| 1215 HttpResponseInfo response; | 1227 HttpResponseInfo response; |
| 1216 EXPECT_EQ(OK, close_stream->SendRequest(headers, &response, | 1228 EXPECT_EQ( |
| 1217 callback_.callback())); | 1229 OK, close_stream->SendRequest(headers, &response, callback_.callback())); |
| 1218 | 1230 |
| 1219 TestCompletionCallback close_callback; | 1231 TestCompletionCallback close_callback; |
| 1220 EXPECT_EQ(ERR_IO_PENDING, | 1232 EXPECT_EQ(ERR_IO_PENDING, |
| 1221 close_stream->ReadResponseHeaders(close_callback.callback())); | 1233 close_stream->ReadResponseHeaders(close_callback.callback())); |
| 1222 | 1234 |
| 1223 EXPECT_EQ(OK, dummy_stream->SendRequest(headers, &response, | 1235 EXPECT_EQ( |
| 1224 callback_.callback())); | 1236 OK, dummy_stream->SendRequest(headers, &response, callback_.callback())); |
| 1225 | 1237 |
| 1226 TestCompletionCallback dummy_callback; | 1238 TestCompletionCallback dummy_callback; |
| 1227 EXPECT_EQ(ERR_IO_PENDING, | 1239 EXPECT_EQ(ERR_IO_PENDING, |
| 1228 dummy_stream->ReadResponseHeaders(dummy_callback.callback())); | 1240 dummy_stream->ReadResponseHeaders(dummy_callback.callback())); |
| 1229 | 1241 |
| 1230 close_stream->Close(true); | 1242 close_stream->Close(true); |
| 1231 close_stream.reset(); | 1243 close_stream.reset(); |
| 1232 | 1244 |
| 1233 EXPECT_TRUE(dummy_callback.have_result()); | 1245 EXPECT_TRUE(dummy_callback.have_result()); |
| 1234 EXPECT_EQ(ERR_PIPELINE_EVICTION, dummy_callback.WaitForResult()); | 1246 EXPECT_EQ(ERR_PIPELINE_EVICTION, dummy_callback.WaitForResult()); |
| 1235 dummy_stream->Close(true); | 1247 dummy_stream->Close(true); |
| 1236 dummy_stream.reset(); | 1248 dummy_stream.reset(); |
| 1237 pipeline_.reset(); | 1249 pipeline_.reset(); |
| 1238 } | 1250 } |
| 1239 | 1251 |
| 1240 TEST_F(HttpPipelinedConnectionImplTest, RecoverFromDrainOnRedirect) { | 1252 TEST_F(HttpPipelinedConnectionImplTest, RecoverFromDrainOnRedirect) { |
| 1241 MockWrite writes[] = { | 1253 MockWrite writes[] = { |
| 1242 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | 1254 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), |
| 1243 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1255 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1244 }; | 1256 }; |
| 1245 MockRead reads[] = { | 1257 MockRead reads[] = { |
| 1246 MockRead(SYNCHRONOUS, 2, | 1258 MockRead(SYNCHRONOUS, |
| 1247 "HTTP/1.1 302 OK\r\n" | 1259 2, |
| 1248 "Content-Length: 8\r\n\r\n" | 1260 "HTTP/1.1 302 OK\r\n" |
| 1249 "redirect"), | 1261 "Content-Length: 8\r\n\r\n" |
| 1250 MockRead(SYNCHRONOUS, 3, | 1262 "redirect"), |
| 1251 "HTTP/1.1 200 OK\r\n" | 1263 MockRead(SYNCHRONOUS, |
| 1252 "Content-Length: 7\r\n\r\n" | 1264 3, |
| 1253 "ok.html"), | 1265 "HTTP/1.1 200 OK\r\n" |
| 1266 "Content-Length: 7\r\n\r\n" |
| 1267 "ok.html"), |
| 1254 }; | 1268 }; |
| 1255 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1269 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1256 | 1270 |
| 1257 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | 1271 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); |
| 1258 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | 1272 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); |
| 1259 | 1273 |
| 1260 HttpRequestHeaders headers1; | 1274 HttpRequestHeaders headers1; |
| 1261 HttpResponseInfo response1; | 1275 HttpResponseInfo response1; |
| 1262 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 1276 EXPECT_EQ(OK, |
| 1263 &response1, callback_.callback())); | 1277 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 1264 HttpRequestHeaders headers2; | 1278 HttpRequestHeaders headers2; |
| 1265 HttpResponseInfo response2; | 1279 HttpResponseInfo response2; |
| 1266 EXPECT_EQ(OK, stream2->SendRequest(headers2, | 1280 EXPECT_EQ(OK, |
| 1267 &response2, callback_.callback())); | 1281 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 1268 | 1282 |
| 1269 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 1283 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 1270 stream1.release()->Drain(NULL); | 1284 stream1.release()->Drain(NULL); |
| 1271 | 1285 |
| 1272 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); | 1286 EXPECT_EQ(OK, stream2->ReadResponseHeaders(callback_.callback())); |
| 1273 ExpectResponse("ok.html", stream2, false); | 1287 ExpectResponse("ok.html", stream2, false); |
| 1274 stream2->Close(false); | 1288 stream2->Close(false); |
| 1275 } | 1289 } |
| 1276 | 1290 |
| 1277 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) { | 1291 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) { |
| 1278 MockWrite writes[] = { | 1292 MockWrite writes[] = { |
| 1279 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | 1293 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), |
| 1280 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1294 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1281 }; | 1295 }; |
| 1282 MockRead reads[] = { | 1296 MockRead reads[] = { |
| 1283 MockRead(SYNCHRONOUS, 2, | 1297 MockRead(SYNCHRONOUS, |
| 1284 "HTTP/1.1 302 OK\r\n\r\n" | 1298 2, |
| 1285 "redirect"), | 1299 "HTTP/1.1 302 OK\r\n\r\n" |
| 1300 "redirect"), |
| 1286 }; | 1301 }; |
| 1287 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1302 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1288 | 1303 |
| 1289 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | 1304 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); |
| 1290 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | 1305 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); |
| 1291 | 1306 |
| 1292 HttpRequestHeaders headers1; | 1307 HttpRequestHeaders headers1; |
| 1293 HttpResponseInfo response1; | 1308 HttpResponseInfo response1; |
| 1294 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 1309 EXPECT_EQ(OK, |
| 1295 &response1, callback_.callback())); | 1310 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 1296 HttpRequestHeaders headers2; | 1311 HttpRequestHeaders headers2; |
| 1297 HttpResponseInfo response2; | 1312 HttpResponseInfo response2; |
| 1298 EXPECT_EQ(OK, stream2->SendRequest(headers2, | 1313 EXPECT_EQ(OK, |
| 1299 &response2, callback_.callback())); | 1314 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 1300 | 1315 |
| 1301 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 1316 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 1302 stream1.release()->Drain(NULL); | 1317 stream1.release()->Drain(NULL); |
| 1303 | 1318 |
| 1304 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 1319 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 1305 stream2->ReadResponseHeaders(callback_.callback())); | 1320 stream2->ReadResponseHeaders(callback_.callback())); |
| 1306 stream2->Close(false); | 1321 stream2->Close(false); |
| 1307 } | 1322 } |
| 1308 | 1323 |
| 1309 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) { | 1324 TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) { |
| 1310 MockWrite writes[] = { | 1325 MockWrite writes[] = { |
| 1311 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | 1326 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), |
| 1312 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1327 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1313 }; | 1328 }; |
| 1314 MockRead reads[] = { | 1329 MockRead reads[] = { |
| 1315 MockRead(SYNCHRONOUS, 2, | 1330 MockRead(SYNCHRONOUS, |
| 1316 "HTTP/1.1 302 OK\r\n" | 1331 2, |
| 1317 "Content-Length: 8\r\n\r\n"), | 1332 "HTTP/1.1 302 OK\r\n" |
| 1318 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 3), | 1333 "Content-Length: 8\r\n\r\n"), |
| 1334 MockRead(SYNCHRONOUS, ERR_SOCKET_NOT_CONNECTED, 3), |
| 1319 }; | 1335 }; |
| 1320 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1336 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1321 | 1337 |
| 1322 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | 1338 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); |
| 1323 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | 1339 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); |
| 1324 | 1340 |
| 1325 HttpRequestHeaders headers1; | 1341 HttpRequestHeaders headers1; |
| 1326 HttpResponseInfo response1; | 1342 HttpResponseInfo response1; |
| 1327 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 1343 EXPECT_EQ(OK, |
| 1328 &response1, callback_.callback())); | 1344 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 1329 HttpRequestHeaders headers2; | 1345 HttpRequestHeaders headers2; |
| 1330 HttpResponseInfo response2; | 1346 HttpResponseInfo response2; |
| 1331 EXPECT_EQ(OK, stream2->SendRequest(headers2, | 1347 EXPECT_EQ(OK, |
| 1332 &response2, callback_.callback())); | 1348 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 1333 | |
| 1334 | 1349 |
| 1335 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 1350 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 1336 stream1.release()->Drain(NULL); | 1351 stream1.release()->Drain(NULL); |
| 1337 | 1352 |
| 1338 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 1353 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 1339 stream2->ReadResponseHeaders(callback_.callback())); | 1354 stream2->ReadResponseHeaders(callback_.callback())); |
| 1340 stream2->Close(false); | 1355 stream2->Close(false); |
| 1341 } | 1356 } |
| 1342 | 1357 |
| 1343 TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) { | 1358 TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) { |
| 1344 MockWrite writes[] = { | 1359 MockWrite writes[] = { |
| 1345 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), | 1360 MockWrite(SYNCHRONOUS, 0, "GET /redirect.html HTTP/1.1\r\n\r\n"), |
| 1346 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1361 MockWrite(SYNCHRONOUS, 1, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1347 }; | 1362 }; |
| 1348 MockRead reads[] = { | 1363 MockRead reads[] = { |
| 1349 MockRead(SYNCHRONOUS, 2, | 1364 MockRead(SYNCHRONOUS, |
| 1350 "HTTP/1.1 302 OK\r\n" | 1365 2, |
| 1351 "Transfer-Encoding: chunked\r\n\r\n"), | 1366 "HTTP/1.1 302 OK\r\n" |
| 1352 MockRead(SYNCHRONOUS, 3, | 1367 "Transfer-Encoding: chunked\r\n\r\n"), |
| 1353 "jibberish"), | 1368 MockRead(SYNCHRONOUS, 3, "jibberish"), |
| 1354 }; | 1369 }; |
| 1355 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1370 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1356 | 1371 |
| 1357 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); | 1372 scoped_ptr<HttpStream> stream1(NewTestStream("redirect.html")); |
| 1358 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); | 1373 scoped_ptr<HttpStream> stream2(NewTestStream("ok.html")); |
| 1359 | 1374 |
| 1360 HttpRequestHeaders headers1; | 1375 HttpRequestHeaders headers1; |
| 1361 HttpResponseInfo response1; | 1376 HttpResponseInfo response1; |
| 1362 EXPECT_EQ(OK, stream1->SendRequest(headers1, | 1377 EXPECT_EQ(OK, |
| 1363 &response1, callback_.callback())); | 1378 stream1->SendRequest(headers1, &response1, callback_.callback())); |
| 1364 HttpRequestHeaders headers2; | 1379 HttpRequestHeaders headers2; |
| 1365 HttpResponseInfo response2; | 1380 HttpResponseInfo response2; |
| 1366 EXPECT_EQ(OK, stream2->SendRequest(headers2, | 1381 EXPECT_EQ(OK, |
| 1367 &response2, callback_.callback())); | 1382 stream2->SendRequest(headers2, &response2, callback_.callback())); |
| 1368 | |
| 1369 | 1383 |
| 1370 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); | 1384 EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 1371 stream1.release()->Drain(NULL); | 1385 stream1.release()->Drain(NULL); |
| 1372 | 1386 |
| 1373 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 1387 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 1374 stream2->ReadResponseHeaders(callback_.callback())); | 1388 stream2->ReadResponseHeaders(callback_.callback())); |
| 1375 stream2->Close(false); | 1389 stream2->Close(false); |
| 1376 } | 1390 } |
| 1377 | 1391 |
| 1378 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) { | 1392 TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) { |
| 1379 MockWrite writes[] = { | 1393 MockWrite writes[] = { |
| 1380 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1394 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1381 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), | 1395 MockWrite(SYNCHRONOUS, 1, "GET /evicted.html HTTP/1.1\r\n\r\n"), |
| 1382 MockWrite(SYNCHRONOUS, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"), | 1396 MockWrite(SYNCHRONOUS, 2, "GET /rejected.html HTTP/1.1\r\n\r\n"), |
| 1383 }; | 1397 }; |
| 1384 MockRead reads[] = { | 1398 MockRead reads[] = { |
| 1385 MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), | 1399 MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1386 MockRead(SYNCHRONOUS, 4, "ok.html"), | 1400 MockRead(SYNCHRONOUS, 4, "ok.html"), MockRead(SYNCHRONOUS, OK, 5), |
| 1387 MockRead(SYNCHRONOUS, OK, 5), | |
| 1388 }; | 1401 }; |
| 1389 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1402 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1390 | 1403 |
| 1391 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); | 1404 scoped_ptr<HttpStream> ok_stream(NewTestStream("ok.html")); |
| 1392 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); | 1405 scoped_ptr<HttpStream> evicted_stream(NewTestStream("evicted.html")); |
| 1393 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); | 1406 scoped_ptr<HttpStream> rejected_stream(NewTestStream("rejected.html")); |
| 1394 | 1407 |
| 1395 HttpRequestHeaders headers; | 1408 HttpRequestHeaders headers; |
| 1396 HttpResponseInfo response; | 1409 HttpResponseInfo response; |
| 1397 EXPECT_EQ(OK, ok_stream->SendRequest(headers, | 1410 EXPECT_EQ(OK, |
| 1398 &response, callback_.callback())); | 1411 ok_stream->SendRequest(headers, &response, callback_.callback())); |
| 1399 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, | 1412 EXPECT_EQ( |
| 1400 &response, callback_.callback())); | 1413 OK, |
| 1401 EXPECT_EQ(OK, rejected_stream->SendRequest(headers, | 1414 evicted_stream->SendRequest(headers, &response, callback_.callback())); |
| 1402 &response, callback_.callback())); | 1415 EXPECT_EQ( |
| 1416 OK, |
| 1417 rejected_stream->SendRequest(headers, &response, callback_.callback())); |
| 1403 | 1418 |
| 1404 TestCompletionCallback ok_callback; | 1419 TestCompletionCallback ok_callback; |
| 1405 EXPECT_EQ(ERR_IO_PENDING, | 1420 EXPECT_EQ(ERR_IO_PENDING, |
| 1406 ok_stream->ReadResponseHeaders(ok_callback.callback())); | 1421 ok_stream->ReadResponseHeaders(ok_callback.callback())); |
| 1407 | 1422 |
| 1408 TestCompletionCallback evicted_callback; | 1423 TestCompletionCallback evicted_callback; |
| 1409 EXPECT_EQ(ERR_IO_PENDING, | 1424 EXPECT_EQ(ERR_IO_PENDING, |
| 1410 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); | 1425 evicted_stream->ReadResponseHeaders(evicted_callback.callback())); |
| 1411 | 1426 |
| 1412 data_->RunFor(1); | 1427 data_->RunFor(1); |
| 1413 EXPECT_LE(OK, ok_callback.WaitForResult()); | 1428 EXPECT_LE(OK, ok_callback.WaitForResult()); |
| 1414 data_->StopAfter(10); | 1429 data_->StopAfter(10); |
| 1415 | 1430 |
| 1416 ExpectResponse("ok.html", ok_stream, false); | 1431 ExpectResponse("ok.html", ok_stream, false); |
| 1417 ok_stream->Close(false); | 1432 ok_stream->Close(false); |
| 1418 | 1433 |
| 1419 EXPECT_EQ(ERR_PIPELINE_EVICTION, | 1434 EXPECT_EQ(ERR_PIPELINE_EVICTION, |
| 1420 rejected_stream->ReadResponseHeaders(callback_.callback())); | 1435 rejected_stream->ReadResponseHeaders(callback_.callback())); |
| 1421 rejected_stream->Close(true); | 1436 rejected_stream->Close(true); |
| 1422 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); | 1437 EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult()); |
| 1423 evicted_stream->Close(true); | 1438 evicted_stream->Close(true); |
| 1424 } | 1439 } |
| 1425 | 1440 |
| 1426 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) { | 1441 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) { |
| 1427 MockWrite writes[] = { | 1442 MockWrite writes[] = { |
| 1428 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1443 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1429 }; | 1444 }; |
| 1430 MockRead reads[] = { | 1445 MockRead reads[] = { |
| 1431 MockRead(SYNCHRONOUS, ERR_FAILED, 1), | 1446 MockRead(SYNCHRONOUS, ERR_FAILED, 1), |
| 1432 }; | 1447 }; |
| 1433 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1448 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1434 | 1449 |
| 1435 EXPECT_CALL(delegate_, | 1450 EXPECT_CALL(delegate_, |
| 1436 OnPipelineFeedback( | 1451 OnPipelineFeedback( |
| 1437 pipeline_.get(), | 1452 pipeline_.get(), |
| 1438 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR)) | 1453 HttpPipelinedConnection::PIPELINE_SOCKET_ERROR)).Times(1); |
| 1439 .Times(1); | |
| 1440 | 1454 |
| 1441 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1455 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1442 HttpRequestHeaders headers; | 1456 HttpRequestHeaders headers; |
| 1443 HttpResponseInfo response; | 1457 HttpResponseInfo response; |
| 1444 EXPECT_EQ(OK, stream->SendRequest(headers, | 1458 EXPECT_EQ(OK, stream->SendRequest(headers, &response, callback_.callback())); |
| 1445 &response, callback_.callback())); | |
| 1446 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(callback_.callback())); | 1459 EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(callback_.callback())); |
| 1447 } | 1460 } |
| 1448 | 1461 |
| 1449 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoInternetConnection) { | 1462 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoInternetConnection) { |
| 1450 MockWrite writes[] = { | 1463 MockWrite writes[] = { |
| 1451 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1464 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1452 }; | 1465 }; |
| 1453 MockRead reads[] = { | 1466 MockRead reads[] = { |
| 1454 MockRead(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED, 1), | 1467 MockRead(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED, 1), |
| 1455 }; | 1468 }; |
| 1456 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1469 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1457 | 1470 |
| 1458 EXPECT_CALL(delegate_, OnPipelineFeedback(_, _)) | 1471 EXPECT_CALL(delegate_, OnPipelineFeedback(_, _)).Times(0); |
| 1459 .Times(0); | |
| 1460 | 1472 |
| 1461 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1473 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1462 HttpRequestHeaders headers; | 1474 HttpRequestHeaders headers; |
| 1463 HttpResponseInfo response; | 1475 HttpResponseInfo response; |
| 1464 EXPECT_EQ(OK, stream->SendRequest(headers, | 1476 EXPECT_EQ(OK, stream->SendRequest(headers, &response, callback_.callback())); |
| 1465 &response, callback_.callback())); | |
| 1466 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, | 1477 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1467 stream->ReadResponseHeaders(callback_.callback())); | 1478 stream->ReadResponseHeaders(callback_.callback())); |
| 1468 } | 1479 } |
| 1469 | 1480 |
| 1470 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) { | 1481 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnHttp10) { |
| 1471 MockWrite writes[] = { | 1482 MockWrite writes[] = { |
| 1472 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1483 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1473 }; | 1484 }; |
| 1474 MockRead reads[] = { | 1485 MockRead reads[] = { |
| 1475 MockRead(SYNCHRONOUS, 1, "HTTP/1.0 200 OK\r\n"), | 1486 MockRead(SYNCHRONOUS, 1, "HTTP/1.0 200 OK\r\n"), |
| 1476 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n"), | 1487 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n"), |
| 1477 MockRead(SYNCHRONOUS, 3, "Connection: keep-alive\r\n\r\n"), | 1488 MockRead(SYNCHRONOUS, 3, "Connection: keep-alive\r\n\r\n"), |
| 1478 MockRead(SYNCHRONOUS, 4, "ok.html"), | 1489 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 1479 }; | 1490 }; |
| 1480 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1491 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1481 | 1492 |
| 1482 EXPECT_CALL(delegate_, | 1493 EXPECT_CALL(delegate_, |
| 1483 OnPipelineFeedback(pipeline_.get(), | 1494 OnPipelineFeedback(pipeline_.get(), |
| 1484 HttpPipelinedConnection::OLD_HTTP_VERSION)) | 1495 HttpPipelinedConnection::OLD_HTTP_VERSION)) |
| 1485 .Times(1); | 1496 .Times(1); |
| 1486 | 1497 |
| 1487 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1498 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1488 TestSyncRequest(stream, "ok.html"); | 1499 TestSyncRequest(stream, "ok.html"); |
| 1489 } | 1500 } |
| 1490 | 1501 |
| 1491 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnMustClose) { | 1502 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnMustClose) { |
| 1492 MockWrite writes[] = { | 1503 MockWrite writes[] = { |
| 1493 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1504 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1494 }; | 1505 }; |
| 1495 MockRead reads[] = { | 1506 MockRead reads[] = { |
| 1496 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), | 1507 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"), |
| 1497 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n"), | 1508 MockRead(SYNCHRONOUS, 2, "Content-Length: 7\r\n"), |
| 1498 MockRead(SYNCHRONOUS, 3, "Connection: close\r\n\r\n"), | 1509 MockRead(SYNCHRONOUS, 3, "Connection: close\r\n\r\n"), |
| 1499 MockRead(SYNCHRONOUS, 4, "ok.html"), | 1510 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 1500 }; | 1511 }; |
| 1501 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1512 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1502 | 1513 |
| 1503 EXPECT_CALL(delegate_, | 1514 EXPECT_CALL(delegate_, |
| 1504 OnPipelineFeedback( | 1515 OnPipelineFeedback( |
| 1505 pipeline_.get(), | 1516 pipeline_.get(), |
| 1506 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)) | 1517 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)).Times(1); |
| 1507 .Times(1); | |
| 1508 | 1518 |
| 1509 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1519 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1510 TestSyncRequest(stream, "ok.html"); | 1520 TestSyncRequest(stream, "ok.html"); |
| 1511 } | 1521 } |
| 1512 | 1522 |
| 1513 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoContentLength) { | 1523 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoContentLength) { |
| 1514 MockWrite writes[] = { | 1524 MockWrite writes[] = { |
| 1515 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1525 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1516 }; | 1526 }; |
| 1517 MockRead reads[] = { | 1527 MockRead reads[] = { |
| 1518 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), | 1528 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1519 MockRead(SYNCHRONOUS, 2, "ok.html"), | 1529 MockRead(SYNCHRONOUS, 2, "ok.html"), |
| 1520 }; | 1530 }; |
| 1521 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1531 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1522 | 1532 |
| 1523 EXPECT_CALL(delegate_, | 1533 EXPECT_CALL(delegate_, |
| 1524 OnPipelineFeedback( | 1534 OnPipelineFeedback( |
| 1525 pipeline_.get(), | 1535 pipeline_.get(), |
| 1526 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)) | 1536 HttpPipelinedConnection::MUST_CLOSE_CONNECTION)).Times(1); |
| 1527 .Times(1); | |
| 1528 | 1537 |
| 1529 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1538 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1530 TestSyncRequest(stream, "ok.html"); | 1539 TestSyncRequest(stream, "ok.html"); |
| 1531 } | 1540 } |
| 1532 | 1541 |
| 1533 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnAuthenticationRequired) { | 1542 TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnAuthenticationRequired) { |
| 1534 MockWrite writes[] = { | 1543 MockWrite writes[] = { |
| 1535 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1544 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1536 }; | 1545 }; |
| 1537 MockRead reads[] = { | 1546 MockRead reads[] = { |
| 1538 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 401 Unauthorized\r\n"), | 1547 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 1539 MockRead(SYNCHRONOUS, 2, "WWW-Authenticate: NTLM\r\n"), | 1548 MockRead(SYNCHRONOUS, 2, "WWW-Authenticate: NTLM\r\n"), |
| 1540 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), | 1549 MockRead(SYNCHRONOUS, 3, "Content-Length: 7\r\n\r\n"), |
| 1541 MockRead(SYNCHRONOUS, 4, "ok.html"), | 1550 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 1542 }; | 1551 }; |
| 1543 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 1552 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 1544 | 1553 |
| 1545 EXPECT_CALL(delegate_, | 1554 EXPECT_CALL(delegate_, |
| 1546 OnPipelineFeedback( | 1555 OnPipelineFeedback( |
| 1547 pipeline_.get(), | 1556 pipeline_.get(), |
| 1548 HttpPipelinedConnection::AUTHENTICATION_REQUIRED)) | 1557 HttpPipelinedConnection::AUTHENTICATION_REQUIRED)).Times(1); |
| 1549 .Times(1); | |
| 1550 | 1558 |
| 1551 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1559 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1552 TestSyncRequest(stream, "ok.html"); | 1560 TestSyncRequest(stream, "ok.html"); |
| 1553 } | 1561 } |
| 1554 | 1562 |
| 1555 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { | 1563 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { |
| 1556 MockWrite writes[] = { | 1564 MockWrite writes[] = { |
| 1557 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1565 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1558 }; | 1566 }; |
| 1559 Initialize(NULL, 0, writes, arraysize(writes)); | 1567 Initialize(NULL, 0, writes, arraysize(writes)); |
| 1560 | 1568 |
| 1561 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); | 1569 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); |
| 1562 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1570 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1563 | 1571 |
| 1564 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1572 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
| 1565 HttpRequestHeaders headers; | 1573 HttpRequestHeaders headers; |
| 1566 HttpResponseInfo response; | 1574 HttpResponseInfo response; |
| 1567 EXPECT_EQ(OK, stream->SendRequest(headers, | 1575 EXPECT_EQ(OK, stream->SendRequest(headers, &response, callback_.callback())); |
| 1568 &response, callback_.callback())); | |
| 1569 | 1576 |
| 1570 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); | 1577 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); |
| 1571 base::MessageLoop::current()->RunUntilIdle(); | 1578 base::MessageLoop::current()->RunUntilIdle(); |
| 1572 | 1579 |
| 1573 stream->Close(false); | 1580 stream->Close(false); |
| 1574 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1581 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
| 1575 stream.reset(NULL); | 1582 stream.reset(NULL); |
| 1576 } | 1583 } |
| 1577 | 1584 |
| 1578 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacityWithoutSend) { | 1585 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacityWithoutSend) { |
| 1579 MockWrite writes[] = { | 1586 MockWrite writes[] = { |
| 1580 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 1587 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 1581 }; | 1588 }; |
| 1582 Initialize(NULL, 0, writes, arraysize(writes)); | 1589 Initialize(NULL, 0, writes, arraysize(writes)); |
| 1583 | 1590 |
| 1584 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); | 1591 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); |
| 1585 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); | 1592 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); |
| 1586 | 1593 |
| 1587 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1594 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
| 1588 base::MessageLoop::current()->RunUntilIdle(); | 1595 base::MessageLoop::current()->RunUntilIdle(); |
| 1589 | 1596 |
| 1590 stream->Close(false); | 1597 stream->Close(false); |
| 1591 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1598 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
| 1592 stream.reset(NULL); | 1599 stream.reset(NULL); |
| 1593 } | 1600 } |
| 1594 | 1601 |
| 1595 } // anonymous namespace | 1602 } // anonymous namespace |
| 1596 | 1603 |
| 1597 } // namespace net | 1604 } // namespace net |
| OLD | NEW |