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

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

Issue 8414010: Fix pipelining crash on canceled user callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Manually destruct Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_pipelined_connection_impl.h" 5 #include "net/http/http_pipelined_connection_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 EXPECT_EQ(OK, 1018 EXPECT_EQ(OK,
1019 deleted_stream->SendRequest(headers, NULL, &response, &callback_)); 1019 deleted_stream->SendRequest(headers, NULL, &response, &callback_));
1020 1020
1021 StreamDeleter deleter(deleted_stream); 1021 StreamDeleter deleter(deleted_stream);
1022 EXPECT_EQ(ERR_IO_PENDING, 1022 EXPECT_EQ(ERR_IO_PENDING,
1023 deleter_stream->ReadResponseHeaders(deleter.callback())); 1023 deleter_stream->ReadResponseHeaders(deleter.callback()));
1024 EXPECT_EQ(ERR_IO_PENDING, deleted_stream->ReadResponseHeaders(&callback_)); 1024 EXPECT_EQ(ERR_IO_PENDING, deleted_stream->ReadResponseHeaders(&callback_));
1025 data_->RunFor(1); 1025 data_->RunFor(1);
1026 } 1026 }
1027 1027
1028 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) {
1029 MockWrite writes[] = {
1030 MockWrite(true, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1031 MockWrite(true, 1, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1032 };
1033 Initialize(NULL, 0, writes, arraysize(writes));
1034
1035 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1036 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1037
1038 scoped_ptr<TestOldCompletionCallback> close_callback(
1039 new TestOldCompletionCallback);
1040 HttpRequestHeaders headers;
1041 HttpResponseInfo response;
1042 EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest(
1043 headers, NULL, &response, close_callback.get()));
1044
1045 data_->RunFor(1);
1046 EXPECT_FALSE(close_callback->have_result());
1047
1048 close_stream->Close(false);
1049 close_stream.reset();
1050 close_callback.reset();
1051
1052 MessageLoop::current()->RunAllPending();
1053 }
1054
1055 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) {
1056 MockWrite writes[] = {
1057 MockWrite(false, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1058 MockWrite(false, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1059 };
1060 MockRead reads[] = {
1061 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"),
1062 MockRead(true, 2, "Content-Length: 7\r\n\r\n"),
1063 };
1064 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1065
1066 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1067 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1068
1069 HttpRequestHeaders headers;
1070 HttpResponseInfo response;
1071 EXPECT_EQ(OK,
1072 close_stream->SendRequest(headers, NULL, &response, &callback_));
1073
1074 scoped_ptr<TestOldCompletionCallback> close_callback(
1075 new TestOldCompletionCallback);
1076 EXPECT_EQ(ERR_IO_PENDING,
1077 close_stream->ReadResponseHeaders(close_callback.get()));
1078
1079 data_->RunFor(1);
1080 EXPECT_FALSE(close_callback->have_result());
1081
1082 close_stream->Close(false);
1083 close_stream.reset();
1084 close_callback.reset();
1085
1086 MessageLoop::current()->RunAllPending();
1087 }
1088
1028 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { 1089 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
1029 MockWrite writes[] = { 1090 MockWrite writes[] = {
1030 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1091 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1031 }; 1092 };
1032 Initialize(NULL, 0, writes, arraysize(writes)); 1093 Initialize(NULL, 0, writes, arraysize(writes));
1033 1094
1034 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1095 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1035 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1096 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1036 1097
1037 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1098 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
(...skipping 20 matching lines...) Expand all
1058 1119
1059 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1120 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1060 MessageLoop::current()->RunAllPending(); 1121 MessageLoop::current()->RunAllPending();
1061 1122
1062 stream->Close(false); 1123 stream->Close(false);
1063 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1124 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1064 stream.reset(NULL); 1125 stream.reset(NULL);
1065 } 1126 }
1066 1127
1067 } // namespace net 1128 } // namespace net
OLDNEW
« net/http/http_pipelined_connection_impl.cc ('K') | « net/http/http_pipelined_connection_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698