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

Side by Side Diff: net/spdy/spdy_network_transaction_unittest.cc

Issue 1142893003: Remove unused SocketDataProvider argument from SpdyNetworkTransactionTest::ReadResult (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments Created 5 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
« no previous file with comments | « no previous file | 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) 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 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 265 }
266 266
267 // Most tests will want to call this function. In particular, the MockReads 267 // Most tests will want to call this function. In particular, the MockReads
268 // should end with an empty read, and that read needs to be processed to 268 // should end with an empty read, and that read needs to be processed to
269 // ensure proper deletion of the spdy_session_pool. 269 // ensure proper deletion of the spdy_session_pool.
270 void VerifyDataConsumed() { 270 void VerifyDataConsumed() {
271 for (const SocketDataProvider* provider : data_vector_) { 271 for (const SocketDataProvider* provider : data_vector_) {
272 EXPECT_TRUE(provider->AllReadDataConsumed()); 272 EXPECT_TRUE(provider->AllReadDataConsumed());
273 EXPECT_TRUE(provider->AllWriteDataConsumed()); 273 EXPECT_TRUE(provider->AllWriteDataConsumed());
274 } 274 }
275 for (const SocketDataProvider* provider : deterministic_data_vector_) {
276 EXPECT_TRUE(provider->AllReadDataConsumed());
277 EXPECT_TRUE(provider->AllWriteDataConsumed());
278 }
275 } 279 }
276 280
277 // Occasionally a test will expect to error out before certain reads are 281 // Occasionally a test will expect to error out before certain reads are
278 // processed. In that case we want to explicitly ensure that the reads were 282 // processed. In that case we want to explicitly ensure that the reads were
279 // not processed. 283 // not processed.
280 void VerifyDataNotConsumed() { 284 void VerifyDataNotConsumed() {
281 for (const SocketDataProvider* provider : data_vector_) { 285 for (const SocketDataProvider* provider : data_vector_) {
282 EXPECT_FALSE(provider->AllReadDataConsumed()); 286 EXPECT_FALSE(provider->AllReadDataConsumed());
283 EXPECT_FALSE(provider->AllWriteDataConsumed()); 287 EXPECT_FALSE(provider->AllWriteDataConsumed());
284 } 288 }
289 for (const SocketDataProvider* provider : deterministic_data_vector_) {
290 EXPECT_FALSE(provider->AllReadDataConsumed());
291 EXPECT_FALSE(provider->AllWriteDataConsumed());
292 }
285 } 293 }
286 294
287 void RunToCompletion(SocketDataProvider* data) { 295 void RunToCompletion(SocketDataProvider* data) {
288 RunPreTestSetup(); 296 RunPreTestSetup();
289 AddData(data); 297 AddData(data);
290 RunDefaultTest(); 298 RunDefaultTest();
291 VerifyDataConsumed(); 299 VerifyDataConsumed();
292 } 300 }
293 301
294 void RunToCompletionWithSSLData( 302 void RunToCompletionWithSSLData(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 new StaticSocketDataProvider(NULL, 0, NULL, 0); 337 new StaticSocketDataProvider(NULL, 0, NULL, 0);
330 hanging_non_alt_svc_socket->set_connect_data(hanging_connect); 338 hanging_non_alt_svc_socket->set_connect_data(hanging_connect);
331 session_deps_->socket_factory->AddSocketDataProvider( 339 session_deps_->socket_factory->AddSocketDataProvider(
332 hanging_non_alt_svc_socket); 340 hanging_non_alt_svc_socket);
333 alternate_vector_.push_back(hanging_non_alt_svc_socket); 341 alternate_vector_.push_back(hanging_non_alt_svc_socket);
334 } 342 }
335 } 343 }
336 344
337 void AddDeterministicData(DeterministicSocketData* data) { 345 void AddDeterministicData(DeterministicSocketData* data) {
338 DCHECK(deterministic_); 346 DCHECK(deterministic_);
339 data_vector_.push_back(data); 347 deterministic_data_vector_.push_back(data);
340 SSLSocketDataProvider* ssl_provider = 348 SSLSocketDataProvider* ssl_provider =
341 new SSLSocketDataProvider(ASYNC, OK); 349 new SSLSocketDataProvider(ASYNC, OK);
342 ssl_provider->SetNextProto(test_params_.protocol); 350 ssl_provider->SetNextProto(test_params_.protocol);
343 ssl_provider->cert = 351 ssl_provider->cert =
344 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); 352 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem");
345 ssl_vector_.push_back(ssl_provider); 353 ssl_vector_.push_back(ssl_provider);
346 session_deps_->deterministic_socket_factory->AddSSLSocketDataProvider( 354 session_deps_->deterministic_socket_factory->AddSSLSocketDataProvider(
347 ssl_provider); 355 ssl_provider);
348 356
349 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); 357 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data);
350 if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { 358 if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) {
351 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); 359 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING);
352 DeterministicSocketData* hanging_non_alt_svc_socket = 360 DeterministicSocketData* hanging_non_alt_svc_socket =
353 new DeterministicSocketData(NULL, 0, NULL, 0); 361 new DeterministicSocketData(NULL, 0, NULL, 0);
354 hanging_non_alt_svc_socket->set_connect_data(hanging_connect); 362 hanging_non_alt_svc_socket->set_connect_data(hanging_connect);
355 session_deps_->deterministic_socket_factory->AddSocketDataProvider( 363 session_deps_->deterministic_socket_factory->AddSocketDataProvider(
356 hanging_non_alt_svc_socket); 364 hanging_non_alt_svc_socket);
357 alternate_vector_.push_back(hanging_non_alt_svc_socket); 365 alternate_deterministic_vector_.push_back(hanging_non_alt_svc_socket);
358 } 366 }
359 } 367 }
360 368
361 void SetSession(const scoped_refptr<HttpNetworkSession>& session) { 369 void SetSession(const scoped_refptr<HttpNetworkSession>& session) {
362 session_ = session; 370 session_ = session;
363 } 371 }
364 HttpNetworkTransaction* trans() { return trans_.get(); } 372 HttpNetworkTransaction* trans() { return trans_.get(); }
365 void ResetTrans() { trans_.reset(); } 373 void ResetTrans() { trans_.reset(); }
366 TransactionHelperResult& output() { return output_; } 374 TransactionHelperResult& output() { return output_; }
367 const HttpRequestInfo& request() const { return request_; } 375 const HttpRequestInfo& request() const { return request_; }
368 const scoped_refptr<HttpNetworkSession>& session() const { 376 const scoped_refptr<HttpNetworkSession>& session() const {
369 return session_; 377 return session_;
370 } 378 }
371 scoped_ptr<SpdySessionDependencies>& session_deps() { 379 scoped_ptr<SpdySessionDependencies>& session_deps() {
372 return session_deps_; 380 return session_deps_;
373 } 381 }
374 int port() const { return port_; } 382 int port() const { return port_; }
375 SpdyNetworkTransactionTestParams test_params() const { 383 SpdyNetworkTransactionTestParams test_params() const {
376 return test_params_; 384 return test_params_;
377 } 385 }
378 386
379 private: 387 private:
380 typedef std::vector<SocketDataProvider*> DataVector; 388 typedef std::vector<SocketDataProvider*> DataVector;
389 typedef std::vector<DeterministicSocketData*> DeterministicDataVector;
381 typedef ScopedVector<SSLSocketDataProvider> SSLVector; 390 typedef ScopedVector<SSLSocketDataProvider> SSLVector;
382 typedef ScopedVector<SocketDataProvider> AlternateVector; 391 typedef ScopedVector<SocketDataProvider> AlternateVector;
383 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector; 392 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector;
384 HttpRequestInfo request_; 393 HttpRequestInfo request_;
385 RequestPriority priority_; 394 RequestPriority priority_;
386 scoped_ptr<SpdySessionDependencies> session_deps_; 395 scoped_ptr<SpdySessionDependencies> session_deps_;
387 scoped_refptr<HttpNetworkSession> session_; 396 scoped_refptr<HttpNetworkSession> session_;
388 TransactionHelperResult output_; 397 TransactionHelperResult output_;
389 scoped_ptr<SocketDataProvider> first_transaction_; 398 scoped_ptr<SocketDataProvider> first_transaction_;
390 SSLVector ssl_vector_; 399 SSLVector ssl_vector_;
391 TestCompletionCallback callback_; 400 TestCompletionCallback callback_;
392 scoped_ptr<HttpNetworkTransaction> trans_; 401 scoped_ptr<HttpNetworkTransaction> trans_;
393 scoped_ptr<HttpNetworkTransaction> trans_http_; 402 scoped_ptr<HttpNetworkTransaction> trans_http_;
394 DataVector data_vector_; 403 DataVector data_vector_;
404 DeterministicDataVector deterministic_data_vector_;
395 AlternateVector alternate_vector_; 405 AlternateVector alternate_vector_;
396 AlternateDeterministicVector alternate_deterministic_vector_; 406 AlternateDeterministicVector alternate_deterministic_vector_;
397 const BoundNetLog log_; 407 const BoundNetLog log_;
398 SpdyNetworkTransactionTestParams test_params_; 408 SpdyNetworkTransactionTestParams test_params_;
399 int port_; 409 int port_;
400 bool deterministic_; 410 bool deterministic_;
401 bool spdy_enabled_; 411 bool spdy_enabled_;
402 }; 412 };
403 413
404 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, 414 void ConnectStatusHelperWithExpectedStatus(const MockRead& status,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 chunked_post_request_initialized_ = true; 556 chunked_post_request_initialized_ = true;
547 } 557 }
548 return chunked_post_request_; 558 return chunked_post_request_;
549 } 559 }
550 560
551 // Read the result of a particular transaction, knowing that we've got 561 // Read the result of a particular transaction, knowing that we've got
552 // multiple transactions in the read pipeline; so as we read, we may have 562 // multiple transactions in the read pipeline; so as we read, we may have
553 // to skip over data destined for other transactions while we consume 563 // to skip over data destined for other transactions while we consume
554 // the data for |trans|. 564 // the data for |trans|.
555 int ReadResult(HttpNetworkTransaction* trans, 565 int ReadResult(HttpNetworkTransaction* trans,
556 SocketDataProvider* data,
557 std::string* result) { 566 std::string* result) {
558 const int kSize = 3000; 567 const int kSize = 3000;
559 568
560 int bytes_read = 0; 569 int bytes_read = 0;
561 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); 570 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize));
562 TestCompletionCallback callback; 571 TestCompletionCallback callback;
563 while (true) { 572 while (true) {
564 int rv = trans->Read(buf.get(), kSize, callback.callback()); 573 int rv = trans->Read(buf.get(), kSize, callback.callback());
565 if (rv == ERR_IO_PENDING) { 574 if (rv == ERR_IO_PENDING) {
566 rv = callback.WaitForResult(); 575 rv = callback.WaitForResult();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 rv = trans2->Start( 623 rv = trans2->Start(
615 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 624 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
616 EXPECT_EQ(ERR_IO_PENDING, rv); 625 EXPECT_EQ(ERR_IO_PENDING, rv);
617 base::RunLoop().RunUntilIdle(); 626 base::RunLoop().RunUntilIdle();
618 627
619 // The data for the pushed path may be coming in more than 1 frame. Compile 628 // The data for the pushed path may be coming in more than 1 frame. Compile
620 // the results into a single string. 629 // the results into a single string.
621 630
622 // Read the server push body. 631 // Read the server push body.
623 std::string result2; 632 std::string result2;
624 ReadResult(trans2.get(), data, &result2); 633 ReadResult(trans2.get(), &result2);
625 // Read the response body. 634 // Read the response body.
626 std::string result; 635 std::string result;
627 ReadResult(trans, data, &result); 636 ReadResult(trans, &result);
628 637
629 // Verify that we consumed all test data. 638 // Verify that we consumed all test data.
630 EXPECT_TRUE(data->AllReadDataConsumed()); 639 EXPECT_TRUE(data->AllReadDataConsumed());
631 EXPECT_TRUE(data->AllWriteDataConsumed()); 640 EXPECT_TRUE(data->AllWriteDataConsumed());
632 641
633 // Verify that the received push data is same as the expected push data. 642 // Verify that the received push data is same as the expected push data.
634 EXPECT_EQ(result2.compare(expected), 0) << "Received data: " 643 EXPECT_EQ(result2.compare(expected), 0) << "Received data: "
635 << result2 644 << result2
636 << "||||| Expected data: " 645 << "||||| Expected data: "
637 << expected; 646 << expected;
(...skipping 4499 matching lines...) Expand 10 before | Expand all | Expand 10 after
5137 scoped_ptr<HttpNetworkTransaction> trans2( 5146 scoped_ptr<HttpNetworkTransaction> trans2(
5138 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 5147 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
5139 rv = trans2->Start( 5148 rv = trans2->Start(
5140 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 5149 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5141 EXPECT_EQ(ERR_IO_PENDING, rv); 5150 EXPECT_EQ(ERR_IO_PENDING, rv);
5142 data.RunFor(3); 5151 data.RunFor(3);
5143 base::RunLoop().RunUntilIdle(); 5152 base::RunLoop().RunUntilIdle();
5144 5153
5145 // Read the server push body. 5154 // Read the server push body.
5146 std::string result2; 5155 std::string result2;
5147 ReadResult(trans2.get(), &data, &result2); 5156 ReadResult(trans2.get(), &result2);
5148 // Read the response body. 5157 // Read the response body.
5149 std::string result; 5158 std::string result;
5150 ReadResult(trans, &data, &result); 5159 ReadResult(trans, &result);
5151 5160
5152 // Verify that the received push data is same as the expected push data. 5161 // Verify that the received push data is same as the expected push data.
5153 EXPECT_EQ(result2.compare(expected_push_result), 0) 5162 EXPECT_EQ(result2.compare(expected_push_result), 0)
5154 << "Received data: " 5163 << "Received data: "
5155 << result2 5164 << result2
5156 << "||||| Expected data: " 5165 << "||||| Expected data: "
5157 << expected_push_result; 5166 << expected_push_result;
5158 5167
5159 // Verify the SYN_REPLY. 5168 // Verify the SYN_REPLY.
5160 // Copy the response info, because trans goes away. 5169 // Copy the response info, because trans goes away.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
5275 scoped_ptr<HttpNetworkTransaction> trans2( 5284 scoped_ptr<HttpNetworkTransaction> trans2(
5276 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 5285 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
5277 rv = trans2->Start( 5286 rv = trans2->Start(
5278 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 5287 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5279 EXPECT_EQ(ERR_IO_PENDING, rv); 5288 EXPECT_EQ(ERR_IO_PENDING, rv);
5280 data.RunFor(3); 5289 data.RunFor(3);
5281 base::RunLoop().RunUntilIdle(); 5290 base::RunLoop().RunUntilIdle();
5282 5291
5283 // Read the server push body. 5292 // Read the server push body.
5284 std::string result2; 5293 std::string result2;
5285 ReadResult(trans2.get(), &data, &result2); 5294 ReadResult(trans2.get(), &result2);
5286 // Read the response body. 5295 // Read the response body.
5287 std::string result; 5296 std::string result;
5288 ReadResult(trans, &data, &result); 5297 ReadResult(trans, &result);
5289 5298
5290 // Verify that the received push data is same as the expected push data. 5299 // Verify that the received push data is same as the expected push data.
5291 EXPECT_EQ(expected_push_result, result2); 5300 EXPECT_EQ(expected_push_result, result2);
5292 5301
5293 // Verify the SYN_REPLY. 5302 // Verify the SYN_REPLY.
5294 // Copy the response info, because trans goes away. 5303 // Copy the response info, because trans goes away.
5295 response = *trans->GetResponseInfo(); 5304 response = *trans->GetResponseInfo();
5296 response2 = *trans2->GetResponseInfo(); 5305 response2 = *trans2->GetResponseInfo();
5297 5306
5298 VerifyStreamsClosed(helper); 5307 VerifyStreamsClosed(helper);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
5391 scoped_ptr<HttpNetworkTransaction> trans2( 5400 scoped_ptr<HttpNetworkTransaction> trans2(
5392 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 5401 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
5393 rv = trans2->Start( 5402 rv = trans2->Start(
5394 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 5403 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5395 EXPECT_EQ(ERR_IO_PENDING, rv); 5404 EXPECT_EQ(ERR_IO_PENDING, rv);
5396 data.RunFor(2); 5405 data.RunFor(2);
5397 base::RunLoop().RunUntilIdle(); 5406 base::RunLoop().RunUntilIdle();
5398 5407
5399 // Read the server push body. 5408 // Read the server push body.
5400 std::string result2; 5409 std::string result2;
5401 ReadResult(trans2.get(), &data, &result2); 5410 ReadResult(trans2.get(), &result2);
5402 // Read the response body. 5411 // Read the response body.
5403 std::string result; 5412 std::string result;
5404 ReadResult(trans, &data, &result); 5413 ReadResult(trans, &result);
5405 EXPECT_EQ("hello!", result); 5414 EXPECT_EQ("hello!", result);
5406 5415
5407 // Verify that we haven't received any push data. 5416 // Verify that we haven't received any push data.
5408 EXPECT_EQ("", result2); 5417 EXPECT_EQ("", result2);
5409 5418
5410 // Verify the SYN_REPLY. 5419 // Verify the SYN_REPLY.
5411 // Copy the response info, because trans goes away. 5420 // Copy the response info, because trans goes away.
5412 HttpResponseInfo response = *trans->GetResponseInfo(); 5421 HttpResponseInfo response = *trans->GetResponseInfo();
5413 5422
5414 VerifyStreamsClosed(helper); 5423 VerifyStreamsClosed(helper);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
5596 5605
5597 // Start the transaction with basic parameters. 5606 // Start the transaction with basic parameters.
5598 TestCompletionCallback callback; 5607 TestCompletionCallback callback;
5599 5608
5600 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5609 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5601 EXPECT_EQ(ERR_IO_PENDING, rv); 5610 EXPECT_EQ(ERR_IO_PENDING, rv);
5602 rv = callback.WaitForResult(); 5611 rv = callback.WaitForResult();
5603 5612
5604 // Read the response body. 5613 // Read the response body.
5605 std::string result; 5614 std::string result;
5606 ReadResult(trans, &data, &result); 5615 ReadResult(trans, &result);
5607 5616
5608 // Verify that we consumed all test data. 5617 // Verify that we consumed all test data.
5609 EXPECT_TRUE(data.AllReadDataConsumed()); 5618 EXPECT_TRUE(data.AllReadDataConsumed());
5610 EXPECT_TRUE(data.AllWriteDataConsumed()); 5619 EXPECT_TRUE(data.AllWriteDataConsumed());
5611 5620
5612 // Verify the SYN_REPLY. 5621 // Verify the SYN_REPLY.
5613 // Copy the response info, because trans goes away. 5622 // Copy the response info, because trans goes away.
5614 response = *trans->GetResponseInfo(); 5623 response = *trans->GetResponseInfo();
5615 5624
5616 VerifyStreamsClosed(helper); 5625 VerifyStreamsClosed(helper);
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
6586 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { 6595 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) {
6587 scoped_ptr<SSLSocketDataProvider> ssl_provider( 6596 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6588 new SSLSocketDataProvider(ASYNC, OK)); 6597 new SSLSocketDataProvider(ASYNC, OK));
6589 // Set to TLS_RSA_WITH_NULL_MD5 6598 // Set to TLS_RSA_WITH_NULL_MD5
6590 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); 6599 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6591 6600
6592 RunTLSUsageCheckTest(ssl_provider.Pass()); 6601 RunTLSUsageCheckTest(ssl_provider.Pass());
6593 } 6602 }
6594 6603
6595 } // namespace net 6604 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698