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

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: 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 void FinishDefaultTestWithoutVerification() { 261 void FinishDefaultTestWithoutVerification() {
262 output_.rv = callback_.WaitForResult(); 262 output_.rv = callback_.WaitForResult();
263 if (output_.rv != OK) 263 if (output_.rv != OK)
264 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); 264 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED);
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_) {
Bence 2015/05/19 12:08:52 This is not what you want for deterministic tests.
Ryan Hamilton 2015/05/19 14:31:22 Good point. I'm now verifying both vectors.
272 EXPECT_TRUE(provider->AllReadDataConsumed()); 272 EXPECT_TRUE(provider->AllReadDataConsumed());
273 EXPECT_TRUE(provider->AllWriteDataConsumed()); 273 EXPECT_TRUE(provider->AllWriteDataConsumed());
274 } 274 }
275 } 275 }
276 276
277 // Occasionally a test will expect to error out before certain reads are 277 // 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 278 // processed. In that case we want to explicitly ensure that the reads were
279 // not processed. 279 // not processed.
280 void VerifyDataNotConsumed() { 280 void VerifyDataNotConsumed() {
281 for (const SocketDataProvider* provider : data_vector_) { 281 for (const SocketDataProvider* provider : data_vector_) {
Bence 2015/05/19 12:08:52 Ditto. Since this member is only called from test
Ryan Hamilton 2015/05/19 14:31:22 In for a penny, in for a pound. I'm no verifying b
282 EXPECT_FALSE(provider->AllReadDataConsumed()); 282 EXPECT_FALSE(provider->AllReadDataConsumed());
283 EXPECT_FALSE(provider->AllWriteDataConsumed()); 283 EXPECT_FALSE(provider->AllWriteDataConsumed());
284 } 284 }
285 } 285 }
286 286
287 void RunToCompletion(SocketDataProvider* data) { 287 void RunToCompletion(SocketDataProvider* data) {
288 RunPreTestSetup(); 288 RunPreTestSetup();
289 AddData(data); 289 AddData(data);
290 RunDefaultTest(); 290 RunDefaultTest();
291 VerifyDataConsumed(); 291 VerifyDataConsumed();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 new StaticSocketDataProvider(NULL, 0, NULL, 0); 329 new StaticSocketDataProvider(NULL, 0, NULL, 0);
330 hanging_non_alt_svc_socket->set_connect_data(hanging_connect); 330 hanging_non_alt_svc_socket->set_connect_data(hanging_connect);
331 session_deps_->socket_factory->AddSocketDataProvider( 331 session_deps_->socket_factory->AddSocketDataProvider(
332 hanging_non_alt_svc_socket); 332 hanging_non_alt_svc_socket);
333 alternate_vector_.push_back(hanging_non_alt_svc_socket); 333 alternate_vector_.push_back(hanging_non_alt_svc_socket);
334 } 334 }
335 } 335 }
336 336
337 void AddDeterministicData(DeterministicSocketData* data) { 337 void AddDeterministicData(DeterministicSocketData* data) {
338 DCHECK(deterministic_); 338 DCHECK(deterministic_);
339 data_vector_.push_back(data); 339 deterministic_data_vector_.push_back(data);
340 SSLSocketDataProvider* ssl_provider = 340 SSLSocketDataProvider* ssl_provider =
341 new SSLSocketDataProvider(ASYNC, OK); 341 new SSLSocketDataProvider(ASYNC, OK);
342 ssl_provider->SetNextProto(test_params_.protocol); 342 ssl_provider->SetNextProto(test_params_.protocol);
343 ssl_provider->cert = 343 ssl_provider->cert =
344 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); 344 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem");
345 ssl_vector_.push_back(ssl_provider); 345 ssl_vector_.push_back(ssl_provider);
346 session_deps_->deterministic_socket_factory->AddSSLSocketDataProvider( 346 session_deps_->deterministic_socket_factory->AddSSLSocketDataProvider(
347 ssl_provider); 347 ssl_provider);
348 348
349 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); 349 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data);
350 if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { 350 if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) {
351 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); 351 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING);
352 DeterministicSocketData* hanging_non_alt_svc_socket = 352 DeterministicSocketData* hanging_non_alt_svc_socket =
353 new DeterministicSocketData(NULL, 0, NULL, 0); 353 new DeterministicSocketData(NULL, 0, NULL, 0);
354 hanging_non_alt_svc_socket->set_connect_data(hanging_connect); 354 hanging_non_alt_svc_socket->set_connect_data(hanging_connect);
355 session_deps_->deterministic_socket_factory->AddSocketDataProvider( 355 session_deps_->deterministic_socket_factory->AddSocketDataProvider(
356 hanging_non_alt_svc_socket); 356 hanging_non_alt_svc_socket);
357 alternate_vector_.push_back(hanging_non_alt_svc_socket); 357 alternate_deterministic_vector_.push_back(hanging_non_alt_svc_socket);
358 } 358 }
359 } 359 }
360 360
361 void SetSession(const scoped_refptr<HttpNetworkSession>& session) { 361 void SetSession(const scoped_refptr<HttpNetworkSession>& session) {
362 session_ = session; 362 session_ = session;
363 } 363 }
364 HttpNetworkTransaction* trans() { return trans_.get(); } 364 HttpNetworkTransaction* trans() { return trans_.get(); }
365 void ResetTrans() { trans_.reset(); } 365 void ResetTrans() { trans_.reset(); }
366 TransactionHelperResult& output() { return output_; } 366 TransactionHelperResult& output() { return output_; }
367 const HttpRequestInfo& request() const { return request_; } 367 const HttpRequestInfo& request() const { return request_; }
368 const scoped_refptr<HttpNetworkSession>& session() const { 368 const scoped_refptr<HttpNetworkSession>& session() const {
369 return session_; 369 return session_;
370 } 370 }
371 scoped_ptr<SpdySessionDependencies>& session_deps() { 371 scoped_ptr<SpdySessionDependencies>& session_deps() {
372 return session_deps_; 372 return session_deps_;
373 } 373 }
374 int port() const { return port_; } 374 int port() const { return port_; }
375 SpdyNetworkTransactionTestParams test_params() const { 375 SpdyNetworkTransactionTestParams test_params() const {
376 return test_params_; 376 return test_params_;
377 } 377 }
378 378
379 private: 379 private:
380 typedef std::vector<SocketDataProvider*> DataVector; 380 typedef std::vector<SocketDataProvider*> DataVector;
381 typedef std::vector<DeterministicSocketData*> DeterministicDataVector;
381 typedef ScopedVector<SSLSocketDataProvider> SSLVector; 382 typedef ScopedVector<SSLSocketDataProvider> SSLVector;
382 typedef ScopedVector<SocketDataProvider> AlternateVector; 383 typedef ScopedVector<SocketDataProvider> AlternateVector;
383 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector; 384 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector;
384 HttpRequestInfo request_; 385 HttpRequestInfo request_;
385 RequestPriority priority_; 386 RequestPriority priority_;
386 scoped_ptr<SpdySessionDependencies> session_deps_; 387 scoped_ptr<SpdySessionDependencies> session_deps_;
387 scoped_refptr<HttpNetworkSession> session_; 388 scoped_refptr<HttpNetworkSession> session_;
388 TransactionHelperResult output_; 389 TransactionHelperResult output_;
389 scoped_ptr<SocketDataProvider> first_transaction_; 390 scoped_ptr<SocketDataProvider> first_transaction_;
390 SSLVector ssl_vector_; 391 SSLVector ssl_vector_;
391 TestCompletionCallback callback_; 392 TestCompletionCallback callback_;
392 scoped_ptr<HttpNetworkTransaction> trans_; 393 scoped_ptr<HttpNetworkTransaction> trans_;
393 scoped_ptr<HttpNetworkTransaction> trans_http_; 394 scoped_ptr<HttpNetworkTransaction> trans_http_;
394 DataVector data_vector_; 395 DataVector data_vector_;
396 DeterministicDataVector deterministic_data_vector_;
395 AlternateVector alternate_vector_; 397 AlternateVector alternate_vector_;
396 AlternateDeterministicVector alternate_deterministic_vector_; 398 AlternateDeterministicVector alternate_deterministic_vector_;
397 const BoundNetLog log_; 399 const BoundNetLog log_;
398 SpdyNetworkTransactionTestParams test_params_; 400 SpdyNetworkTransactionTestParams test_params_;
399 int port_; 401 int port_;
400 bool deterministic_; 402 bool deterministic_;
401 bool spdy_enabled_; 403 bool spdy_enabled_;
402 }; 404 };
403 405
404 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, 406 void ConnectStatusHelperWithExpectedStatus(const MockRead& status,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 chunked_post_request_initialized_ = true; 548 chunked_post_request_initialized_ = true;
547 } 549 }
548 return chunked_post_request_; 550 return chunked_post_request_;
549 } 551 }
550 552
551 // Read the result of a particular transaction, knowing that we've got 553 // 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 554 // 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 555 // to skip over data destined for other transactions while we consume
554 // the data for |trans|. 556 // the data for |trans|.
555 int ReadResult(HttpNetworkTransaction* trans, 557 int ReadResult(HttpNetworkTransaction* trans,
556 SocketDataProvider* data,
557 std::string* result) { 558 std::string* result) {
558 const int kSize = 3000; 559 const int kSize = 3000;
559 560
560 int bytes_read = 0; 561 int bytes_read = 0;
561 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); 562 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize));
562 TestCompletionCallback callback; 563 TestCompletionCallback callback;
563 while (true) { 564 while (true) {
564 int rv = trans->Read(buf.get(), kSize, callback.callback()); 565 int rv = trans->Read(buf.get(), kSize, callback.callback());
565 if (rv == ERR_IO_PENDING) { 566 if (rv == ERR_IO_PENDING) {
566 rv = callback.WaitForResult(); 567 rv = callback.WaitForResult();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 rv = trans2->Start( 615 rv = trans2->Start(
615 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 616 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
616 EXPECT_EQ(ERR_IO_PENDING, rv); 617 EXPECT_EQ(ERR_IO_PENDING, rv);
617 base::RunLoop().RunUntilIdle(); 618 base::RunLoop().RunUntilIdle();
618 619
619 // The data for the pushed path may be coming in more than 1 frame. Compile 620 // The data for the pushed path may be coming in more than 1 frame. Compile
620 // the results into a single string. 621 // the results into a single string.
621 622
622 // Read the server push body. 623 // Read the server push body.
623 std::string result2; 624 std::string result2;
624 ReadResult(trans2.get(), data, &result2); 625 ReadResult(trans2.get(), &result2);
625 // Read the response body. 626 // Read the response body.
626 std::string result; 627 std::string result;
627 ReadResult(trans, data, &result); 628 ReadResult(trans, &result);
628 629
629 // Verify that we consumed all test data. 630 // Verify that we consumed all test data.
630 EXPECT_TRUE(data->AllReadDataConsumed()); 631 EXPECT_TRUE(data->AllReadDataConsumed());
631 EXPECT_TRUE(data->AllWriteDataConsumed()); 632 EXPECT_TRUE(data->AllWriteDataConsumed());
632 633
633 // Verify that the received push data is same as the expected push data. 634 // Verify that the received push data is same as the expected push data.
634 EXPECT_EQ(result2.compare(expected), 0) << "Received data: " 635 EXPECT_EQ(result2.compare(expected), 0) << "Received data: "
635 << result2 636 << result2
636 << "||||| Expected data: " 637 << "||||| Expected data: "
637 << expected; 638 << expected;
(...skipping 4499 matching lines...) Expand 10 before | Expand all | Expand 10 after
5137 scoped_ptr<HttpNetworkTransaction> trans2( 5138 scoped_ptr<HttpNetworkTransaction> trans2(
5138 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 5139 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
5139 rv = trans2->Start( 5140 rv = trans2->Start(
5140 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 5141 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5141 EXPECT_EQ(ERR_IO_PENDING, rv); 5142 EXPECT_EQ(ERR_IO_PENDING, rv);
5142 data.RunFor(3); 5143 data.RunFor(3);
5143 base::RunLoop().RunUntilIdle(); 5144 base::RunLoop().RunUntilIdle();
5144 5145
5145 // Read the server push body. 5146 // Read the server push body.
5146 std::string result2; 5147 std::string result2;
5147 ReadResult(trans2.get(), &data, &result2); 5148 ReadResult(trans2.get(), &result2);
5148 // Read the response body. 5149 // Read the response body.
5149 std::string result; 5150 std::string result;
5150 ReadResult(trans, &data, &result); 5151 ReadResult(trans, &result);
5151 5152
5152 // Verify that the received push data is same as the expected push data. 5153 // Verify that the received push data is same as the expected push data.
5153 EXPECT_EQ(result2.compare(expected_push_result), 0) 5154 EXPECT_EQ(result2.compare(expected_push_result), 0)
5154 << "Received data: " 5155 << "Received data: "
5155 << result2 5156 << result2
5156 << "||||| Expected data: " 5157 << "||||| Expected data: "
5157 << expected_push_result; 5158 << expected_push_result;
5158 5159
5159 // Verify the SYN_REPLY. 5160 // Verify the SYN_REPLY.
5160 // Copy the response info, because trans goes away. 5161 // 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( 5276 scoped_ptr<HttpNetworkTransaction> trans2(
5276 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 5277 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
5277 rv = trans2->Start( 5278 rv = trans2->Start(
5278 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 5279 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5279 EXPECT_EQ(ERR_IO_PENDING, rv); 5280 EXPECT_EQ(ERR_IO_PENDING, rv);
5280 data.RunFor(3); 5281 data.RunFor(3);
5281 base::RunLoop().RunUntilIdle(); 5282 base::RunLoop().RunUntilIdle();
5282 5283
5283 // Read the server push body. 5284 // Read the server push body.
5284 std::string result2; 5285 std::string result2;
5285 ReadResult(trans2.get(), &data, &result2); 5286 ReadResult(trans2.get(), &result2);
5286 // Read the response body. 5287 // Read the response body.
5287 std::string result; 5288 std::string result;
5288 ReadResult(trans, &data, &result); 5289 ReadResult(trans, &result);
5289 5290
5290 // Verify that the received push data is same as the expected push data. 5291 // Verify that the received push data is same as the expected push data.
5291 EXPECT_EQ(expected_push_result, result2); 5292 EXPECT_EQ(expected_push_result, result2);
5292 5293
5293 // Verify the SYN_REPLY. 5294 // Verify the SYN_REPLY.
5294 // Copy the response info, because trans goes away. 5295 // Copy the response info, because trans goes away.
5295 response = *trans->GetResponseInfo(); 5296 response = *trans->GetResponseInfo();
5296 response2 = *trans2->GetResponseInfo(); 5297 response2 = *trans2->GetResponseInfo();
5297 5298
5298 VerifyStreamsClosed(helper); 5299 VerifyStreamsClosed(helper);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
5391 scoped_ptr<HttpNetworkTransaction> trans2( 5392 scoped_ptr<HttpNetworkTransaction> trans2(
5392 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 5393 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
5393 rv = trans2->Start( 5394 rv = trans2->Start(
5394 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); 5395 &CreateGetPushRequest(), callback.callback(), BoundNetLog());
5395 EXPECT_EQ(ERR_IO_PENDING, rv); 5396 EXPECT_EQ(ERR_IO_PENDING, rv);
5396 data.RunFor(2); 5397 data.RunFor(2);
5397 base::RunLoop().RunUntilIdle(); 5398 base::RunLoop().RunUntilIdle();
5398 5399
5399 // Read the server push body. 5400 // Read the server push body.
5400 std::string result2; 5401 std::string result2;
5401 ReadResult(trans2.get(), &data, &result2); 5402 ReadResult(trans2.get(), &result2);
5402 // Read the response body. 5403 // Read the response body.
5403 std::string result; 5404 std::string result;
5404 ReadResult(trans, &data, &result); 5405 ReadResult(trans, &result);
5405 EXPECT_EQ("hello!", result); 5406 EXPECT_EQ("hello!", result);
5406 5407
5407 // Verify that we haven't received any push data. 5408 // Verify that we haven't received any push data.
5408 EXPECT_EQ("", result2); 5409 EXPECT_EQ("", result2);
5409 5410
5410 // Verify the SYN_REPLY. 5411 // Verify the SYN_REPLY.
5411 // Copy the response info, because trans goes away. 5412 // Copy the response info, because trans goes away.
5412 HttpResponseInfo response = *trans->GetResponseInfo(); 5413 HttpResponseInfo response = *trans->GetResponseInfo();
5413 5414
5414 VerifyStreamsClosed(helper); 5415 VerifyStreamsClosed(helper);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
5596 5597
5597 // Start the transaction with basic parameters. 5598 // Start the transaction with basic parameters.
5598 TestCompletionCallback callback; 5599 TestCompletionCallback callback;
5599 5600
5600 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 5601 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
5601 EXPECT_EQ(ERR_IO_PENDING, rv); 5602 EXPECT_EQ(ERR_IO_PENDING, rv);
5602 rv = callback.WaitForResult(); 5603 rv = callback.WaitForResult();
5603 5604
5604 // Read the response body. 5605 // Read the response body.
5605 std::string result; 5606 std::string result;
5606 ReadResult(trans, &data, &result); 5607 ReadResult(trans, &result);
5607 5608
5608 // Verify that we consumed all test data. 5609 // Verify that we consumed all test data.
5609 EXPECT_TRUE(data.AllReadDataConsumed()); 5610 EXPECT_TRUE(data.AllReadDataConsumed());
5610 EXPECT_TRUE(data.AllWriteDataConsumed()); 5611 EXPECT_TRUE(data.AllWriteDataConsumed());
5611 5612
5612 // Verify the SYN_REPLY. 5613 // Verify the SYN_REPLY.
5613 // Copy the response info, because trans goes away. 5614 // Copy the response info, because trans goes away.
5614 response = *trans->GetResponseInfo(); 5615 response = *trans->GetResponseInfo();
5615 5616
5616 VerifyStreamsClosed(helper); 5617 VerifyStreamsClosed(helper);
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
6586 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { 6587 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) {
6587 scoped_ptr<SSLSocketDataProvider> ssl_provider( 6588 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6588 new SSLSocketDataProvider(ASYNC, OK)); 6589 new SSLSocketDataProvider(ASYNC, OK));
6589 // Set to TLS_RSA_WITH_NULL_MD5 6590 // Set to TLS_RSA_WITH_NULL_MD5
6590 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); 6591 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6591 6592
6592 RunTLSUsageCheckTest(ssl_provider.Pass()); 6593 RunTLSUsageCheckTest(ssl_provider.Pass());
6593 } 6594 }
6594 6595
6595 } // namespace net 6596 } // 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