| OLD | NEW |
| 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 "net/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 MockECSignatureCreatorFactory ec_signature_creator_factory_; | 162 MockECSignatureCreatorFactory ec_signature_creator_factory_; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 INSTANTIATE_TEST_CASE_P( | 165 INSTANTIATE_TEST_CASE_P( |
| 166 NextProto, | 166 NextProto, |
| 167 SpdyHttpStreamTest, | 167 SpdyHttpStreamTest, |
| 168 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); | 168 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); |
| 169 | 169 |
| 170 // TODO(akalin): Don't early-exit in the tests below for values > | |
| 171 // kProtoSPDY3. | |
| 172 | |
| 173 // SpdyHttpStream::GetUploadProgress() should still work even before the | 170 // SpdyHttpStream::GetUploadProgress() should still work even before the |
| 174 // stream is initialized. | 171 // stream is initialized. |
| 175 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { | 172 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { |
| 176 if (GetParam() > kProtoSPDY3) | |
| 177 return; | |
| 178 | |
| 179 MockRead reads[] = { | 173 MockRead reads[] = { |
| 180 MockRead(ASYNC, 0, 0) // EOF | 174 MockRead(ASYNC, 0, 0) // EOF |
| 181 }; | 175 }; |
| 182 | 176 |
| 183 HostPortPair host_port_pair("www.google.com", 80); | 177 HostPortPair host_port_pair("www.google.com", 80); |
| 184 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 178 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
| 185 kPrivacyModeDisabled); | 179 kPrivacyModeDisabled); |
| 186 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), NULL, 0, host_port_pair)); | 180 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), NULL, 0, host_port_pair)); |
| 187 | 181 |
| 188 SpdyHttpStream stream(session_.get(), false); | 182 SpdyHttpStream stream(session_.get(), false); |
| 189 UploadProgress progress = stream.GetUploadProgress(); | 183 UploadProgress progress = stream.GetUploadProgress(); |
| 190 EXPECT_EQ(0u, progress.size()); | 184 EXPECT_EQ(0u, progress.size()); |
| 191 EXPECT_EQ(0u, progress.position()); | 185 EXPECT_EQ(0u, progress.position()); |
| 192 } | 186 } |
| 193 | 187 |
| 194 TEST_P(SpdyHttpStreamTest, SendRequest) { | 188 TEST_P(SpdyHttpStreamTest, SendRequest) { |
| 195 if (GetParam() > kProtoSPDY3) | |
| 196 return; | |
| 197 | |
| 198 scoped_ptr<SpdyFrame> req( | 189 scoped_ptr<SpdyFrame> req( |
| 199 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 190 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 200 MockWrite writes[] = { | 191 MockWrite writes[] = { |
| 201 CreateMockWrite(*req.get(), 1), | 192 CreateMockWrite(*req.get(), 1), |
| 202 }; | 193 }; |
| 203 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 194 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 204 MockRead reads[] = { | 195 MockRead reads[] = { |
| 205 CreateMockRead(*resp, 2), | 196 CreateMockRead(*resp, 2), |
| 206 MockRead(SYNCHRONOUS, 0, 3) // EOF | 197 MockRead(SYNCHRONOUS, 0, 3) // EOF |
| 207 }; | 198 }; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 EXPECT_TRUE(data()->at_write_eof()); | 243 EXPECT_TRUE(data()->at_write_eof()); |
| 253 | 244 |
| 254 TestLoadTimingNotReused(*http_stream); | 245 TestLoadTimingNotReused(*http_stream); |
| 255 http_stream->Close(true); | 246 http_stream->Close(true); |
| 256 // Test that there's no crash when trying to get the load timing after the | 247 // Test that there's no crash when trying to get the load timing after the |
| 257 // stream has been closed. | 248 // stream has been closed. |
| 258 TestLoadTimingNotReused(*http_stream); | 249 TestLoadTimingNotReused(*http_stream); |
| 259 } | 250 } |
| 260 | 251 |
| 261 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { | 252 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { |
| 262 if (GetParam() > kProtoSPDY3) | |
| 263 return; | |
| 264 | |
| 265 scoped_ptr<SpdyFrame> req1( | 253 scoped_ptr<SpdyFrame> req1( |
| 266 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 254 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 267 scoped_ptr<SpdyFrame> req2( | 255 scoped_ptr<SpdyFrame> req2( |
| 268 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 256 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 269 MockWrite writes[] = { | 257 MockWrite writes[] = { |
| 270 CreateMockWrite(*req1, 0), | 258 CreateMockWrite(*req1, 0), |
| 271 CreateMockWrite(*req2, 1), | 259 CreateMockWrite(*req2, 1), |
| 272 }; | 260 }; |
| 273 scoped_ptr<SpdyFrame> resp1( | 261 scoped_ptr<SpdyFrame> resp1( |
| 274 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 262 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 343 |
| 356 // Stream 1 has been read to completion. | 344 // Stream 1 has been read to completion. |
| 357 TestLoadTimingNotReused(*http_stream1); | 345 TestLoadTimingNotReused(*http_stream1); |
| 358 // Stream 2 still has queued body data. | 346 // Stream 2 still has queued body data. |
| 359 TestLoadTimingReused(*http_stream2); | 347 TestLoadTimingReused(*http_stream2); |
| 360 } | 348 } |
| 361 | 349 |
| 362 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { | 350 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { |
| 363 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 351 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 364 | 352 |
| 365 scoped_ptr<SpdyFrame> initial_window_update( | |
| 366 framer.CreateWindowUpdate( | |
| 367 kSessionFlowControlStreamId, | |
| 368 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 369 scoped_ptr<SpdyFrame> req( | 353 scoped_ptr<SpdyFrame> req( |
| 370 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 354 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 371 scoped_ptr<SpdyFrame> body( | 355 scoped_ptr<SpdyFrame> body( |
| 372 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); | 356 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); |
| 373 std::vector<MockWrite> writes; | 357 std::vector<MockWrite> writes; |
| 374 int seq = 0; | 358 int seq = 0; |
| 375 if (GetParam() >= kProtoSPDY31) { | |
| 376 writes.push_back(CreateMockWrite(*initial_window_update, seq++)); | |
| 377 } | |
| 378 writes.push_back(CreateMockWrite(*req, seq++)); | 359 writes.push_back(CreateMockWrite(*req, seq++)); |
| 379 writes.push_back(CreateMockWrite(*body, seq++)); // POST upload frame | 360 writes.push_back(CreateMockWrite(*body, seq++)); // POST upload frame |
| 380 | 361 |
| 381 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 362 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 382 std::vector<MockRead> reads; | 363 std::vector<MockRead> reads; |
| 383 reads.push_back(CreateMockRead(*resp, seq++)); | 364 reads.push_back(CreateMockRead(*resp, seq++)); |
| 384 reads.push_back(CreateMockRead(*body, seq++)); | 365 reads.push_back(CreateMockRead(*body, seq++)); |
| 385 reads.push_back(MockRead(SYNCHRONOUS, 0, seq++)); // EOF | 366 reads.push_back(MockRead(SYNCHRONOUS, 0, seq++)); // EOF |
| 386 | 367 |
| 387 HostPortPair host_port_pair("www.google.com", 80); | 368 HostPortPair host_port_pair("www.google.com", 80); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // Because we abandoned the stream, we don't expect to find a session in the | 411 // Because we abandoned the stream, we don't expect to find a session in the |
| 431 // pool anymore. | 412 // pool anymore. |
| 432 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); | 413 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); |
| 433 EXPECT_TRUE(data()->at_read_eof()); | 414 EXPECT_TRUE(data()->at_read_eof()); |
| 434 EXPECT_TRUE(data()->at_write_eof()); | 415 EXPECT_TRUE(data()->at_write_eof()); |
| 435 } | 416 } |
| 436 | 417 |
| 437 // Test to ensure the SpdyStream state machine does not get confused when a | 418 // Test to ensure the SpdyStream state machine does not get confused when a |
| 438 // chunk becomes available while a write is pending. | 419 // chunk becomes available while a write is pending. |
| 439 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { | 420 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { |
| 440 if (GetParam() > kProtoSPDY3) | |
| 441 return; | |
| 442 | |
| 443 const char kUploadData1[] = "12345678"; | 421 const char kUploadData1[] = "12345678"; |
| 444 const int kUploadData1Size = arraysize(kUploadData1)-1; | 422 const int kUploadData1Size = arraysize(kUploadData1)-1; |
| 445 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 423 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 446 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 424 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 447 scoped_ptr<SpdyFrame> chunk2( | 425 scoped_ptr<SpdyFrame> chunk2( |
| 448 spdy_util_.ConstructSpdyBodyFrame( | 426 spdy_util_.ConstructSpdyBodyFrame( |
| 449 1, kUploadData1, kUploadData1Size, false)); | 427 1, kUploadData1, kUploadData1Size, false)); |
| 450 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 428 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 451 MockWrite writes[] = { | 429 MockWrite writes[] = { |
| 452 CreateMockWrite(*req.get(), 0), | 430 CreateMockWrite(*req.get(), 0), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 deterministic_data()->RunFor(1); | 518 deterministic_data()->RunFor(1); |
| 541 ASSERT_TRUE(response.headers.get()); | 519 ASSERT_TRUE(response.headers.get()); |
| 542 ASSERT_EQ(200, response.headers->response_code()); | 520 ASSERT_EQ(200, response.headers->response_code()); |
| 543 EXPECT_TRUE(deterministic_data()->at_read_eof()); | 521 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
| 544 EXPECT_TRUE(deterministic_data()->at_write_eof()); | 522 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
| 545 } | 523 } |
| 546 | 524 |
| 547 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | 525 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
| 548 // made available is handled correctly. | 526 // made available is handled correctly. |
| 549 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | 527 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
| 550 if (GetParam() != kProtoSPDY3) | 528 if (GetParam() < kProtoSPDY3) |
| 551 return; | 529 return; |
| 552 | 530 |
| 553 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 531 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 554 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 532 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 555 MockWrite writes[] = { | 533 MockWrite writes[] = { |
| 556 CreateMockWrite(*req.get(), 0), | 534 CreateMockWrite(*req.get(), 0), |
| 557 CreateMockWrite(*chunk1, 1), | 535 CreateMockWrite(*chunk1, 1), |
| 558 }; | 536 }; |
| 559 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 537 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 560 scoped_ptr<SpdyFrame> window_update( | 538 scoped_ptr<SpdyFrame> window_update( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 // Finish reading the |EOF|. | 635 // Finish reading the |EOF|. |
| 658 data.RunFor(1); | 636 data.RunFor(1); |
| 659 ASSERT_TRUE(response.headers.get()); | 637 ASSERT_TRUE(response.headers.get()); |
| 660 ASSERT_EQ(200, response.headers->response_code()); | 638 ASSERT_EQ(200, response.headers->response_code()); |
| 661 EXPECT_TRUE(data.at_read_eof()); | 639 EXPECT_TRUE(data.at_read_eof()); |
| 662 EXPECT_TRUE(data.at_write_eof()); | 640 EXPECT_TRUE(data.at_write_eof()); |
| 663 } | 641 } |
| 664 | 642 |
| 665 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 643 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
| 666 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { | 644 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
| 667 if (GetParam() > kProtoSPDY3) | |
| 668 return; | |
| 669 | |
| 670 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; | 645 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
| 671 const char * const base_url = "http://www.google.com/foo?query=what"; | 646 const char * const base_url = "http://www.google.com/foo?query=what"; |
| 672 scoped_ptr<SpdyFrame> req( | 647 scoped_ptr<SpdyFrame> req( |
| 673 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); | 648 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); |
| 674 MockWrite writes[] = { | 649 MockWrite writes[] = { |
| 675 CreateMockWrite(*req.get(), 1), | 650 CreateMockWrite(*req.get(), 1), |
| 676 }; | 651 }; |
| 677 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 652 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 678 MockRead reads[] = { | 653 MockRead reads[] = { |
| 679 CreateMockRead(*resp, 2), | 654 CreateMockRead(*resp, 2), |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 | 874 |
| 900 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( | 875 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( |
| 901 callback.callback())); | 876 callback.callback())); |
| 902 data.RunFor(1); | 877 data.RunFor(1); |
| 903 EXPECT_EQ(OK, callback.WaitForResult()); | 878 EXPECT_EQ(OK, callback.WaitForResult()); |
| 904 ASSERT_TRUE(response.headers.get() != NULL); | 879 ASSERT_TRUE(response.headers.get() != NULL); |
| 905 ASSERT_EQ(200, response.headers->response_code()); | 880 ASSERT_EQ(200, response.headers->response_code()); |
| 906 } | 881 } |
| 907 | 882 |
| 908 TEST_P(SpdyHttpStreamTest, SendCredentialsEC) { | 883 TEST_P(SpdyHttpStreamTest, SendCredentialsEC) { |
| 909 if (GetParam() != kProtoSPDY3) | 884 if (GetParam() < kProtoSPDY3) |
| 910 return; | 885 return; |
| 911 | 886 |
| 912 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 887 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
| 913 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 888 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
| 914 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 889 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
| 915 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 890 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
| 916 sequenced_worker_pool)); | 891 sequenced_worker_pool)); |
| 917 std::string cert; | 892 std::string cert; |
| 918 std::string proof; | 893 std::string proof; |
| 919 GetECServerBoundCertAndProof("www.gmail.com", | 894 GetECServerBoundCertAndProof("www.gmail.com", |
| 920 server_bound_cert_service.get(), | 895 server_bound_cert_service.get(), |
| 921 &cert, &proof); | 896 &cert, &proof); |
| 922 | 897 |
| 923 TestSendCredentials(server_bound_cert_service.get(), cert, proof); | 898 TestSendCredentials(server_bound_cert_service.get(), cert, proof); |
| 924 | 899 |
| 925 sequenced_worker_pool->Shutdown(); | 900 sequenced_worker_pool->Shutdown(); |
| 926 } | 901 } |
| 927 | 902 |
| 928 TEST_P(SpdyHttpStreamTest, DontSendCredentialsForHttpUrlsEC) { | 903 TEST_P(SpdyHttpStreamTest, DontSendCredentialsForHttpUrlsEC) { |
| 929 if (GetParam() != kProtoSPDY3) | 904 if (GetParam() < kProtoSPDY3) |
| 930 return; | 905 return; |
| 931 | 906 |
| 932 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 907 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
| 933 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 908 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
| 934 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 909 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
| 935 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 910 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
| 936 sequenced_worker_pool)); | 911 sequenced_worker_pool)); |
| 937 std::string cert; | 912 std::string cert; |
| 938 std::string proof; | 913 std::string proof; |
| 939 GetECServerBoundCertAndProof("proxy.google.com", | 914 GetECServerBoundCertAndProof("proxy.google.com", |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 data.RunFor(1); | 1031 data.RunFor(1); |
| 1057 sequenced_worker_pool->Shutdown(); | 1032 sequenced_worker_pool->Shutdown(); |
| 1058 } | 1033 } |
| 1059 | 1034 |
| 1060 #endif // !defined(USE_OPENSSL) | 1035 #endif // !defined(USE_OPENSSL) |
| 1061 | 1036 |
| 1062 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1037 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 1063 // methods. | 1038 // methods. |
| 1064 | 1039 |
| 1065 } // namespace net | 1040 } // namespace net |
| OLD | NEW |