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

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: 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
« no previous file with comments | « net/http/http_pipelined_connection_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 TestOldCompletionCallback close_callback;
1039 HttpRequestHeaders headers;
1040 HttpResponseInfo response;
1041 EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest(
1042 headers, NULL, &response, &close_callback));
1043
1044 data_->RunFor(1);
1045 EXPECT_FALSE(close_callback.have_result());
1046
1047 close_stream->Close(false);
mmenke 2011/10/28 00:54:09 Add "MessageLoop::current()->RunAllPending();" to
1048 }
1049
1050 TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) {
1051 MockWrite writes[] = {
1052 MockWrite(false, 0, "GET /close.html HTTP/1.1\r\n\r\n"),
1053 MockWrite(false, 3, "GET /dummy.html HTTP/1.1\r\n\r\n"),
1054 };
1055 MockRead reads[] = {
1056 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"),
1057 MockRead(true, 2, "Content-Length: 7\r\n\r\n"),
1058 };
1059 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1060
1061 scoped_ptr<HttpStream> close_stream(NewTestStream("close.html"));
1062 scoped_ptr<HttpStream> dummy_stream(NewTestStream("dummy.html"));
1063
1064 HttpRequestHeaders headers;
1065 HttpResponseInfo response;
1066 EXPECT_EQ(OK,
1067 close_stream->SendRequest(headers, NULL, &response, &callback_));
1068
1069 TestOldCompletionCallback close_callback;
1070 EXPECT_EQ(ERR_IO_PENDING,
1071 close_stream->ReadResponseHeaders(&close_callback));
1072
1073 data_->RunFor(1);
1074 EXPECT_FALSE(close_callback.have_result());
1075
1076 close_stream->Close(false);
1077 }
1078
1028 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) { 1079 TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
1029 MockWrite writes[] = { 1080 MockWrite writes[] = {
1030 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"), 1081 MockWrite(false, 0, "GET /ok.html HTTP/1.1\r\n\r\n"),
1031 }; 1082 };
1032 Initialize(NULL, 0, writes, arraysize(writes)); 1083 Initialize(NULL, 0, writes, arraysize(writes));
1033 1084
1034 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0); 1085 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
1035 scoped_ptr<HttpStream> stream(NewTestStream("ok.html")); 1086 scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
1036 1087
1037 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1088 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
(...skipping 20 matching lines...) Expand all
1058 1109
1059 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1110 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1060 MessageLoop::current()->RunAllPending(); 1111 MessageLoop::current()->RunAllPending();
1061 1112
1062 stream->Close(false); 1113 stream->Close(false);
1063 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1); 1114 EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
1064 stream.reset(NULL); 1115 stream.reset(NULL);
1065 } 1116 }
1066 1117
1067 } // namespace net 1118 } // namespace net
OLDNEW
« no previous file with comments | « 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