Chromium Code Reviews| 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) { | 567 TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) { |
| 568 MockWrite writes[] = { | 568 MockWrite writes[] = { |
| 569 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 569 MockWrite(SYNCHRONOUS, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 570 MockWrite(SYNCHRONOUS, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"), | 570 MockWrite(SYNCHRONOUS, 1, "GET /read_evicted.html HTTP/1.1\r\n\r\n"), |
| 571 MockWrite(SYNCHRONOUS, 2, "GET /read_rejected.html HTTP/1.1\r\n\r\n"), | 571 MockWrite(SYNCHRONOUS, 2, "GET /read_rejected.html HTTP/1.1\r\n\r\n"), |
| 572 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5), | 572 MockWrite(ASYNC, ERR_SOCKET_NOT_CONNECTED, 5), |
| 573 }; | 573 }; |
| 574 MockRead reads[] = { | 574 MockRead reads[] = { |
| 575 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n\r\n"), | 575 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 576 MockRead(SYNCHRONOUS, 4, "ok.html"), | 576 MockRead(SYNCHRONOUS, 4, "ok.html"), |
| 577 MockRead(ASYNC, OK, 6), // Connection closed message. Not read before the | |
| 578 // ERR_SOCKET_NOT_CONNECTED. | |
|
mmenke
2013/01/07 21:57:15
Greedily reading data would run right off the end
| |
| 577 }; | 579 }; |
| 578 Initialize(reads, arraysize(reads), writes, arraysize(writes)); | 580 Initialize(reads, arraysize(reads), writes, arraysize(writes)); |
| 579 | 581 |
| 580 scoped_ptr<HttpStream> closed_stream(NewTestStream("ok.html")); | 582 scoped_ptr<HttpStream> closed_stream(NewTestStream("ok.html")); |
| 581 scoped_ptr<HttpStream> read_evicted_stream( | 583 scoped_ptr<HttpStream> read_evicted_stream( |
| 582 NewTestStream("read_evicted.html")); | 584 NewTestStream("read_evicted.html")); |
| 583 scoped_ptr<HttpStream> read_rejected_stream( | 585 scoped_ptr<HttpStream> read_rejected_stream( |
| 584 NewTestStream("read_rejected.html")); | 586 NewTestStream("read_rejected.html")); |
| 585 scoped_ptr<HttpStream> send_closed_stream( | 587 scoped_ptr<HttpStream> send_closed_stream( |
| 586 NewTestStream("send_closed.html")); | 588 NewTestStream("send_closed.html")); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 // 1. DoReadHeadersLoop, which will post: | 935 // 1. DoReadHeadersLoop, which will post: |
| 934 // 2. InvokeUserCallback | 936 // 2. InvokeUserCallback |
| 935 SuddenCloseObserver observer(evicted_stream.get(), 2); | 937 SuddenCloseObserver observer(evicted_stream.get(), 2); |
| 936 MessageLoop::current()->AddTaskObserver(&observer); | 938 MessageLoop::current()->AddTaskObserver(&observer); |
| 937 MessageLoop::current()->RunUntilIdle(); | 939 MessageLoop::current()->RunUntilIdle(); |
| 938 EXPECT_FALSE(evicted_callback.have_result()); | 940 EXPECT_FALSE(evicted_callback.have_result()); |
| 939 } | 941 } |
| 940 | 942 |
| 941 class StreamDeleter { | 943 class StreamDeleter { |
| 942 public: | 944 public: |
| 943 StreamDeleter(HttpStream* stream) : | 945 StreamDeleter(HttpStream* stream) |
| 944 stream_(stream), | 946 : stream_(stream), |
| 945 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( | 947 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( |
| 946 base::Bind(&StreamDeleter::OnIOComplete, base::Unretained(this)))) { | 948 base::Bind(&StreamDeleter::OnIOComplete, base::Unretained(this)))) { |
| 949 } | |
| 950 | |
| 951 ~StreamDeleter() { | |
| 952 EXPECT_FALSE(stream_); | |
| 947 } | 953 } |
| 948 | 954 |
| 949 const CompletionCallback& callback() { return callback_; } | 955 const CompletionCallback& callback() { return callback_; } |
| 950 | 956 |
| 951 private: | 957 private: |
| 952 void OnIOComplete(int result) { | 958 void OnIOComplete(int result) { |
| 953 delete stream_; | 959 // stream_->Close(true); |
| 960 stream_.reset(); | |
| 954 } | 961 } |
| 955 | 962 |
| 956 HttpStream* stream_; | 963 scoped_ptr<HttpStream> stream_; |
| 957 CompletionCallback callback_; | 964 CompletionCallback callback_; |
| 958 }; | 965 }; |
| 959 | 966 |
| 960 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) { | 967 TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) { |
| 961 MockWrite writes[] = { | 968 MockWrite writes[] = { |
| 962 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), | 969 MockWrite(ASYNC, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), |
| 963 }; | 970 }; |
| 964 Initialize(NULL, 0, writes, arraysize(writes)); | 971 Initialize(NULL, 0, writes, arraysize(writes)); |
| 965 | 972 |
| 966 HttpStream* stream(NewTestStream("ok.html")); | 973 HttpStream* stream(NewTestStream("ok.html")); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 callback_.callback())); | 1023 callback_.callback())); |
| 1017 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, &response, | 1024 EXPECT_EQ(OK, evicted_stream->SendRequest(headers, &response, |
| 1018 callback_.callback())); | 1025 callback_.callback())); |
| 1019 | 1026 |
| 1020 StreamDeleter failed_deleter(failed_stream); | 1027 StreamDeleter failed_deleter(failed_stream); |
| 1021 EXPECT_EQ(ERR_IO_PENDING, | 1028 EXPECT_EQ(ERR_IO_PENDING, |
| 1022 failed_stream->ReadResponseHeaders(failed_deleter.callback())); | 1029 failed_stream->ReadResponseHeaders(failed_deleter.callback())); |
| 1023 StreamDeleter evicted_deleter(evicted_stream); | 1030 StreamDeleter evicted_deleter(evicted_stream); |
| 1024 EXPECT_EQ(ERR_IO_PENDING, | 1031 EXPECT_EQ(ERR_IO_PENDING, |
| 1025 evicted_stream->ReadResponseHeaders(evicted_deleter.callback())); | 1032 evicted_stream->ReadResponseHeaders(evicted_deleter.callback())); |
| 1026 data_->RunFor(1); | 1033 data_->RunFor(1); |
|
mmenke
2013/01/07 21:57:15
This test was really weird - we have a stream fail
James Simonsen
2013/01/07 22:02:24
IIRC, this was the reproduction of a crash in the
| |
| 1027 } | 1034 } |
| 1028 | 1035 |
| 1029 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) { | 1036 TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) { |
| 1030 MockWrite writes[] = { | 1037 MockWrite writes[] = { |
| 1031 MockWrite(SYNCHRONOUS, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"), | 1038 MockWrite(SYNCHRONOUS, 0, "GET /deleter.html HTTP/1.1\r\n\r\n"), |
| 1032 MockWrite(SYNCHRONOUS, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"), | 1039 MockWrite(SYNCHRONOUS, 1, "GET /deleted.html HTTP/1.1\r\n\r\n"), |
| 1033 }; | 1040 }; |
| 1034 MockRead reads[] = { | 1041 MockRead reads[] = { |
| 1035 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), | 1042 MockRead(SYNCHRONOUS, 2, "HTTP/1.1 200 OK\r\n"), |
| 1036 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), | 1043 MockRead(ASYNC, 3, "Content-Length: 7\r\n\r\n"), |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1536 MessageLoop::current()->RunUntilIdle(); | 1543 MessageLoop::current()->RunUntilIdle(); |
| 1537 | 1544 |
| 1538 stream->Close(false); | 1545 stream->Close(false); |
| 1539 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); | 1546 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); |
| 1540 stream.reset(NULL); | 1547 stream.reset(NULL); |
| 1541 } | 1548 } |
| 1542 | 1549 |
| 1543 } // anonymous namespace | 1550 } // anonymous namespace |
| 1544 | 1551 |
| 1545 } // namespace net | 1552 } // namespace net |
| OLD | NEW |