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

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

Issue 10095024: Refuse to pipeline frames, prefetches, and downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit test Created 8 years, 7 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
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl_job.cc » ('j') | 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) 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 <string> 5 #include <string>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 DeterministicSocketData* data = new DeterministicSocketData( 106 DeterministicSocketData* data = new DeterministicSocketData(
107 reads, reads_count, writes, writes_count); 107 reads, reads_count, writes, writes_count);
108 data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); 108 data->set_connect_data(MockConnect(SYNCHRONOUS, OK));
109 if (reads_count || writes_count) { 109 if (reads_count || writes_count) {
110 data->StopAfter(reads_count + writes_count); 110 data->StopAfter(reads_count + writes_count);
111 } 111 }
112 factory_.AddSocketDataProvider(data); 112 factory_.AddSocketDataProvider(data);
113 data_vector_.push_back(data); 113 data_vector_.push_back(data);
114 } 114 }
115 115
116 HttpRequestInfo* GetRequestInfo(const char* filename) { 116 enum RequestInfoOptions {
117 REQUEST_DEFAULT,
118 REQUEST_MAIN_RESOURCE,
119 };
120
121 HttpRequestInfo* GetRequestInfo(
122 const char* filename, RequestInfoOptions options = REQUEST_DEFAULT) {
117 std::string url = StringPrintf("http://localhost/%s", filename); 123 std::string url = StringPrintf("http://localhost/%s", filename);
118 HttpRequestInfo* request_info = new HttpRequestInfo; 124 HttpRequestInfo* request_info = new HttpRequestInfo;
119 request_info->url = GURL(url); 125 request_info->url = GURL(url);
120 request_info->method = "GET"; 126 request_info->method = "GET";
127 if (options == REQUEST_MAIN_RESOURCE) {
128 request_info->load_flags = LOAD_MAIN_FRAME;
129 }
121 request_info_vector_.push_back(request_info); 130 request_info_vector_.push_back(request_info);
122 return request_info; 131 return request_info;
123 } 132 }
124 133
125 void ExpectResponse(const std::string& expected, 134 void ExpectResponse(const std::string& expected,
126 HttpNetworkTransaction& transaction, 135 HttpNetworkTransaction& transaction,
127 IoMode io_mode) { 136 IoMode io_mode) {
128 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); 137 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size()));
129 if (io_mode == ASYNC) { 138 if (io_mode == ASYNC) {
130 EXPECT_EQ(ERR_IO_PENDING, transaction.Read(buffer.get(), expected.size(), 139 EXPECT_EQ(ERR_IO_PENDING, transaction.Read(buffer.get(), expected.size(),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 data_vector_[data_index]->SetStop(10); 178 data_vector_[data_index]->SetStop(10);
170 std::string actual(buffer->data(), 8); 179 std::string actual(buffer->data(), 8);
171 EXPECT_THAT(actual, StrEq("one.html")); 180 EXPECT_THAT(actual, StrEq("one.html"));
172 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, 181 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8,
173 one_read_callback.callback())); 182 one_read_callback.callback()));
174 183
175 EXPECT_EQ(OK, two_callback.WaitForResult()); 184 EXPECT_EQ(OK, two_callback.WaitForResult());
176 ExpectResponse("two.html", two_transaction, SYNCHRONOUS); 185 ExpectResponse("two.html", two_transaction, SYNCHRONOUS);
177 } 186 }
178 187
179 void CompleteFourRequests() { 188 void CompleteFourRequests(RequestInfoOptions options) {
180 scoped_ptr<HttpNetworkTransaction> one_transaction( 189 scoped_ptr<HttpNetworkTransaction> one_transaction(
181 new HttpNetworkTransaction(session_.get())); 190 new HttpNetworkTransaction(session_.get()));
182 TestCompletionCallback one_callback; 191 TestCompletionCallback one_callback;
183 EXPECT_EQ(ERR_IO_PENDING, 192 EXPECT_EQ(ERR_IO_PENDING,
184 one_transaction->Start(GetRequestInfo("one.html"), 193 one_transaction->Start(GetRequestInfo("one.html", options),
185 one_callback.callback(), BoundNetLog())); 194 one_callback.callback(), BoundNetLog()));
186 EXPECT_EQ(OK, one_callback.WaitForResult()); 195 EXPECT_EQ(OK, one_callback.WaitForResult());
187 196
188 HttpNetworkTransaction two_transaction(session_.get()); 197 HttpNetworkTransaction two_transaction(session_.get());
189 TestCompletionCallback two_callback; 198 TestCompletionCallback two_callback;
190 EXPECT_EQ(ERR_IO_PENDING, 199 EXPECT_EQ(ERR_IO_PENDING,
191 two_transaction.Start(GetRequestInfo("two.html"), 200 two_transaction.Start(GetRequestInfo("two.html", options),
192 two_callback.callback(), BoundNetLog())); 201 two_callback.callback(), BoundNetLog()));
193 202
194 HttpNetworkTransaction three_transaction(session_.get()); 203 HttpNetworkTransaction three_transaction(session_.get());
195 TestCompletionCallback three_callback; 204 TestCompletionCallback three_callback;
196 EXPECT_EQ(ERR_IO_PENDING, 205 EXPECT_EQ(ERR_IO_PENDING,
197 three_transaction.Start(GetRequestInfo("three.html"), 206 three_transaction.Start(GetRequestInfo("three.html", options),
198 three_callback.callback(), 207 three_callback.callback(),
199 BoundNetLog())); 208 BoundNetLog()));
200 209
201 HttpNetworkTransaction four_transaction(session_.get()); 210 HttpNetworkTransaction four_transaction(session_.get());
202 TestCompletionCallback four_callback; 211 TestCompletionCallback four_callback;
203 EXPECT_EQ(ERR_IO_PENDING, 212 EXPECT_EQ(ERR_IO_PENDING,
204 four_transaction.Start(GetRequestInfo("four.html"), 213 four_transaction.Start(GetRequestInfo("four.html", options),
205 four_callback.callback(), BoundNetLog())); 214 four_callback.callback(), BoundNetLog()));
206 215
207 ExpectResponse("one.html", *one_transaction.get(), SYNCHRONOUS); 216 ExpectResponse("one.html", *one_transaction.get(), SYNCHRONOUS);
208 EXPECT_EQ(OK, two_callback.WaitForResult()); 217 EXPECT_EQ(OK, two_callback.WaitForResult());
209 ExpectResponse("two.html", two_transaction, SYNCHRONOUS); 218 ExpectResponse("two.html", two_transaction, SYNCHRONOUS);
210 EXPECT_EQ(OK, three_callback.WaitForResult()); 219 EXPECT_EQ(OK, three_callback.WaitForResult());
211 ExpectResponse("three.html", three_transaction, SYNCHRONOUS); 220 ExpectResponse("three.html", three_transaction, SYNCHRONOUS);
212 221
213 one_transaction.reset(); 222 one_transaction.reset();
214 EXPECT_EQ(OK, four_callback.WaitForResult()); 223 EXPECT_EQ(OK, four_callback.WaitForResult());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 MockRead(SYNCHRONOUS, 8, "two.html"), 318 MockRead(SYNCHRONOUS, 8, "two.html"),
310 MockRead(SYNCHRONOUS, 9, "HTTP/1.1 200 OK\r\n"), 319 MockRead(SYNCHRONOUS, 9, "HTTP/1.1 200 OK\r\n"),
311 MockRead(SYNCHRONOUS, 10, "Content-Length: 10\r\n\r\n"), 320 MockRead(SYNCHRONOUS, 10, "Content-Length: 10\r\n\r\n"),
312 MockRead(SYNCHRONOUS, 11, "three.html"), 321 MockRead(SYNCHRONOUS, 11, "three.html"),
313 MockRead(SYNCHRONOUS, 13, "HTTP/1.1 200 OK\r\n"), 322 MockRead(SYNCHRONOUS, 13, "HTTP/1.1 200 OK\r\n"),
314 MockRead(SYNCHRONOUS, 14, "Content-Length: 9\r\n\r\n"), 323 MockRead(SYNCHRONOUS, 14, "Content-Length: 9\r\n\r\n"),
315 MockRead(SYNCHRONOUS, 15, "four.html"), 324 MockRead(SYNCHRONOUS, 15, "four.html"),
316 }; 325 };
317 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); 326 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes));
318 327
319 CompleteFourRequests(); 328 CompleteFourRequests(REQUEST_DEFAULT);
320 329
321 ClientSocketPoolManager::set_max_sockets_per_group( 330 ClientSocketPoolManager::set_max_sockets_per_group(
322 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_sockets); 331 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_sockets);
332 }
333
334 TEST_F(HttpPipelinedNetworkTransactionTest, WontPipelineMainResource) {
335 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(
336 HttpNetworkSession::NORMAL_SOCKET_POOL);
337 ClientSocketPoolManager::set_max_sockets_per_group(
338 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
339 Initialize(false);
340
341 MockWrite writes[] = {
342 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n"
343 "Host: localhost\r\n"
344 "Connection: keep-alive\r\n\r\n"),
345 MockWrite(SYNCHRONOUS, 4, "GET /two.html HTTP/1.1\r\n"
346 "Host: localhost\r\n"
347 "Connection: keep-alive\r\n\r\n"),
348 MockWrite(SYNCHRONOUS, 8, "GET /three.html HTTP/1.1\r\n"
349 "Host: localhost\r\n"
350 "Connection: keep-alive\r\n\r\n"),
351 MockWrite(SYNCHRONOUS, 12, "GET /four.html HTTP/1.1\r\n"
352 "Host: localhost\r\n"
353 "Connection: keep-alive\r\n\r\n"),
354 };
355 MockRead reads[] = {
356 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n"),
357 MockRead(SYNCHRONOUS, 2, "Content-Length: 8\r\n\r\n"),
358 MockRead(SYNCHRONOUS, 3, "one.html"),
359 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"),
360 MockRead(SYNCHRONOUS, 6, "Content-Length: 8\r\n\r\n"),
361 MockRead(SYNCHRONOUS, 7, "two.html"),
362 MockRead(SYNCHRONOUS, 9, "HTTP/1.1 200 OK\r\n"),
363 MockRead(SYNCHRONOUS, 10, "Content-Length: 10\r\n\r\n"),
364 MockRead(SYNCHRONOUS, 11, "three.html"),
365 MockRead(SYNCHRONOUS, 13, "HTTP/1.1 200 OK\r\n"),
366 MockRead(SYNCHRONOUS, 14, "Content-Length: 9\r\n\r\n"),
367 MockRead(SYNCHRONOUS, 15, "four.html"),
368 };
369 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes));
370
371 CompleteFourRequests(REQUEST_MAIN_RESOURCE);
372
373 ClientSocketPoolManager::set_max_sockets_per_group(
374 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_sockets);
323 } 375 }
324 376
325 TEST_F(HttpPipelinedNetworkTransactionTest, UnknownSizeEvictsToNewPipeline) { 377 TEST_F(HttpPipelinedNetworkTransactionTest, UnknownSizeEvictsToNewPipeline) {
326 Initialize(false); 378 Initialize(false);
327 379
328 MockWrite writes[] = { 380 MockWrite writes[] = {
329 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n" 381 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n"
330 "Host: localhost\r\n" 382 "Host: localhost\r\n"
331 "Connection: keep-alive\r\n\r\n"), 383 "Connection: keep-alive\r\n\r\n"),
332 }; 384 };
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 MockRead(SYNCHRONOUS, 15, "four.html"), 714 MockRead(SYNCHRONOUS, 15, "four.html"),
663 MockRead(ASYNC, 18, "HTTP/1.1 200 OK\r\n"), 715 MockRead(ASYNC, 18, "HTTP/1.1 200 OK\r\n"),
664 MockRead(ASYNC, 19, "Content-Length: 24\r\n\r\n"), 716 MockRead(ASYNC, 19, "Content-Length: 24\r\n\r\n"),
665 MockRead(SYNCHRONOUS, 20, "second-pipeline-one.html"), 717 MockRead(SYNCHRONOUS, 20, "second-pipeline-one.html"),
666 MockRead(SYNCHRONOUS, 21, "HTTP/1.1 200 OK\r\n"), 718 MockRead(SYNCHRONOUS, 21, "HTTP/1.1 200 OK\r\n"),
667 MockRead(SYNCHRONOUS, 22, "Content-Length: 24\r\n\r\n"), 719 MockRead(SYNCHRONOUS, 22, "Content-Length: 24\r\n\r\n"),
668 MockRead(SYNCHRONOUS, 23, "second-pipeline-two.html"), 720 MockRead(SYNCHRONOUS, 23, "second-pipeline-two.html"),
669 }; 721 };
670 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); 722 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes));
671 723
672 CompleteFourRequests(); 724 CompleteFourRequests(REQUEST_DEFAULT);
673 725
674 HttpNetworkTransaction second_one_transaction(session_.get()); 726 HttpNetworkTransaction second_one_transaction(session_.get());
675 TestCompletionCallback second_one_callback; 727 TestCompletionCallback second_one_callback;
676 EXPECT_EQ(ERR_IO_PENDING, 728 EXPECT_EQ(ERR_IO_PENDING,
677 second_one_transaction.Start( 729 second_one_transaction.Start(
678 GetRequestInfo("second-pipeline-one.html"), 730 GetRequestInfo("second-pipeline-one.html"),
679 second_one_callback.callback(), BoundNetLog())); 731 second_one_callback.callback(), BoundNetLog()));
680 MessageLoop::current()->RunAllPending(); 732 MessageLoop::current()->RunAllPending();
681 733
682 HttpNetworkTransaction second_two_transaction(session_.get()); 734 HttpNetworkTransaction second_two_transaction(session_.get());
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 EXPECT_EQ(ERR_PIPELINE_EVICTION, two_callback.WaitForResult()); 1034 EXPECT_EQ(ERR_PIPELINE_EVICTION, two_callback.WaitForResult());
983 two_transaction.reset(); 1035 two_transaction.reset();
984 EXPECT_EQ(ERR_PIPELINE_EVICTION, three_callback.WaitForResult()); 1036 EXPECT_EQ(ERR_PIPELINE_EVICTION, three_callback.WaitForResult());
985 three_transaction.reset(); 1037 three_transaction.reset();
986 EXPECT_EQ(ERR_PIPELINE_EVICTION, four_callback.WaitForResult()); 1038 EXPECT_EQ(ERR_PIPELINE_EVICTION, four_callback.WaitForResult());
987 } 1039 }
988 1040
989 } // anonymous namespace 1041 } // anonymous namespace
990 1042
991 } // namespace net 1043 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698