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

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

Issue 7289006: Basic HTTP pipelining support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change pool API Created 9 years, 2 months 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_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 spdy::SpdyFramer::set_enable_compression_default(true); 136 spdy::SpdyFramer::set_enable_compression_default(true);
137 // Empty the current queue. 137 // Empty the current queue.
138 MessageLoop::current()->RunAllPending(); 138 MessageLoop::current()->RunAllPending();
139 PlatformTest::TearDown(); 139 PlatformTest::TearDown();
140 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 140 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
141 MessageLoop::current()->RunAllPending(); 141 MessageLoop::current()->RunAllPending();
142 } 142 }
143 143
144 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); 144 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure);
145 145
146 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], 146 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[],
147 size_t reads_count) { 147 size_t data_count) {
148 SimpleGetHelperResult out; 148 SimpleGetHelperResult out;
149 149
150 HttpRequestInfo request; 150 HttpRequestInfo request;
151 request.method = "GET"; 151 request.method = "GET";
152 request.url = GURL("http://www.google.com/"); 152 request.url = GURL("http://www.google.com/");
153 request.load_flags = 0; 153 request.load_flags = 0;
154 154
155 SessionDependencies session_deps; 155 SessionDependencies session_deps;
156 scoped_ptr<HttpTransaction> trans( 156 scoped_ptr<HttpTransaction> trans(
157 new HttpNetworkTransaction(CreateSession(&session_deps))); 157 new HttpNetworkTransaction(CreateSession(&session_deps)));
158 158
159 StaticSocketDataProvider data(data_reads, reads_count, NULL, 0); 159 for (size_t i = 0; i < data_count; ++i) {
160 session_deps.socket_factory.AddSocketDataProvider(&data); 160 session_deps.socket_factory.AddSocketDataProvider(data[i]);
161 }
161 162
162 TestCompletionCallback callback; 163 TestCompletionCallback callback;
163 164
164 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 165 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
165 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); 166 EXPECT_TRUE(log.bound().IsLoggingAllEvents());
166 int rv = trans->Start(&request, &callback, log.bound()); 167 int rv = trans->Start(&request, &callback, log.bound());
167 EXPECT_EQ(ERR_IO_PENDING, rv); 168 EXPECT_EQ(ERR_IO_PENDING, rv);
168 169
169 out.rv = callback.WaitForResult(); 170 out.rv = callback.WaitForResult();
170 if (out.rv != OK) 171 if (out.rv != OK)
(...skipping 28 matching lines...) Expand all
199 NetLogHttpRequestParameter* request_params = 200 NetLogHttpRequestParameter* request_params =
200 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get()); 201 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get());
201 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine()); 202 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine());
202 EXPECT_EQ("Host: www.google.com\r\n" 203 EXPECT_EQ("Host: www.google.com\r\n"
203 "Connection: keep-alive\r\n\r\n", 204 "Connection: keep-alive\r\n\r\n",
204 request_params->GetHeaders().ToString()); 205 request_params->GetHeaders().ToString());
205 206
206 return out; 207 return out;
207 } 208 }
208 209
210 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[],
211 size_t reads_count) {
212 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0);
213 StaticSocketDataProvider* data[] = { &reads };
214 return SimpleGetHelperForData(data, 1);
215 }
216
209 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, 217 void ConnectStatusHelperWithExpectedStatus(const MockRead& status,
210 int expected_status); 218 int expected_status);
211 219
212 void ConnectStatusHelper(const MockRead& status); 220 void ConnectStatusHelper(const MockRead& status);
213 }; 221 };
214 222
215 // Fill |str| with a long header list that consumes >= |size| bytes. 223 // Fill |str| with a long header list that consumes >= |size| bytes.
216 void FillLargeHeadersString(std::string* str, int size) { 224 void FillLargeHeadersString(std::string* str, int size) {
217 const char* row = 225 const char* row =
218 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; 226 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n";
(...skipping 8678 matching lines...) Expand 10 before | Expand all | Expand 10 after
8897 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8905 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8898 EXPECT_TRUE(response->was_fetched_via_spdy); 8906 EXPECT_TRUE(response->was_fetched_via_spdy);
8899 EXPECT_TRUE(response->was_npn_negotiated); 8907 EXPECT_TRUE(response->was_npn_negotiated);
8900 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); 8908 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
8901 EXPECT_EQ("hello!", response_data); 8909 EXPECT_EQ("hello!", response_data);
8902 8910
8903 HttpStreamFactory::set_next_protos(""); 8911 HttpStreamFactory::set_next_protos("");
8904 HttpStreamFactory::set_use_alternate_protocols(false); 8912 HttpStreamFactory::set_use_alternate_protocols(false);
8905 } 8913 }
8906 8914
8915 TEST_F(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) {
8916 MockRead data_reads1[] = {
8917 MockRead(false, ERR_PIPELINE_EVICTION),
8918 };
8919 MockRead data_reads2[] = {
8920 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
8921 MockRead("hello world"),
8922 MockRead(false, OK),
8923 };
8924 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), NULL, 0);
8925 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), NULL, 0);
8926 StaticSocketDataProvider* data[] = { &data1, &data2 };
8927
8928 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
8929
8930 EXPECT_EQ(OK, out.rv);
8931 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
8932 EXPECT_EQ("hello world", out.response_data);
8933 }
8934
8935 TEST_F(HttpNetworkTransactionTest, SendPipelineEvictionFallback) {
8936 MockWrite data_writes1[] = {
8937 MockWrite(false, ERR_PIPELINE_EVICTION),
8938 };
8939 MockWrite data_writes2[] = {
8940 MockWrite("GET / HTTP/1.1\r\n"
8941 "Host: www.google.com\r\n"
8942 "Connection: keep-alive\r\n\r\n"),
8943 };
8944 MockRead data_reads2[] = {
8945 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
8946 MockRead("hello world"),
8947 MockRead(false, OK),
8948 };
8949 StaticSocketDataProvider data1(NULL, 0,
8950 data_writes1, arraysize(data_writes1));
8951 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
8952 data_writes2, arraysize(data_writes2));
8953 StaticSocketDataProvider* data[] = { &data1, &data2 };
8954
8955 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
8956
8957 EXPECT_EQ(OK, out.rv);
8958 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
8959 EXPECT_EQ("hello world", out.response_data);
8960 }
8961
8907 } // namespace net 8962 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698