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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 EXPECT_FALSE(load_timing_info.socket_reused); | 56 EXPECT_FALSE(load_timing_info.socket_reused); |
57 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 57 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
58 | 58 |
59 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | 59 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
60 CONNECT_TIMING_HAS_DNS_TIMES); | 60 CONNECT_TIMING_HAS_DNS_TIMES); |
61 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 61 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
62 } | 62 } |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 class SpdyHttpStreamSpdy2Test : public testing::Test, | 66 class SpdyHttpStreamTest : public testing::Test, |
67 public testing::WithParamInterface<NextProto> { | 67 public testing::WithParamInterface<NextProto> { |
68 public: | 68 public: |
69 SpdyHttpStreamSpdy2Test() | 69 SpdyHttpStreamTest() |
70 : spdy_util_(GetParam()), | 70 : spdy_util_(GetParam()), |
71 session_deps_(GetParam()) { | 71 session_deps_(GetParam()) { |
72 session_deps_.net_log = &net_log_; | 72 session_deps_.net_log = &net_log_; |
73 } | 73 } |
74 | 74 |
75 DeterministicSocketData* deterministic_data() { | 75 DeterministicSocketData* deterministic_data() { |
76 return deterministic_data_.get(); | 76 return deterministic_data_.get(); |
77 } | 77 } |
78 | 78 |
79 OrderedSocketData* data() { return data_.get(); } | 79 OrderedSocketData* data() { return data_.get(); } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 scoped_refptr<HttpNetworkSession> http_session_; | 157 scoped_refptr<HttpNetworkSession> http_session_; |
158 scoped_refptr<SpdySession> session_; | 158 scoped_refptr<SpdySession> session_; |
159 scoped_refptr<TransportSocketParams> transport_params_; | 159 scoped_refptr<TransportSocketParams> transport_params_; |
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 SpdyHttpStreamSpdy2Test, | 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 > | 170 // TODO(akalin): Don't early-exit in the tests below for values > |
171 // kProtoSPDY3. | 171 // kProtoSPDY3. |
172 | 172 |
173 // SpdyHttpStream::GetUploadProgress() should still work even before the | 173 // SpdyHttpStream::GetUploadProgress() should still work even before the |
174 // stream is initialized. | 174 // stream is initialized. |
175 TEST_P(SpdyHttpStreamSpdy2Test, GetUploadProgressBeforeInitialization) { | 175 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { |
176 if (GetParam() > kProtoSPDY3) | 176 if (GetParam() > kProtoSPDY3) |
177 return; | 177 return; |
178 | 178 |
179 SpdyHttpStream stream(NULL, false); | 179 SpdyHttpStream stream(NULL, false); |
180 UploadProgress progress = stream.GetUploadProgress(); | 180 UploadProgress progress = stream.GetUploadProgress(); |
181 EXPECT_EQ(0u, progress.size()); | 181 EXPECT_EQ(0u, progress.size()); |
182 EXPECT_EQ(0u, progress.position()); | 182 EXPECT_EQ(0u, progress.position()); |
183 } | 183 } |
184 | 184 |
185 TEST_P(SpdyHttpStreamSpdy2Test, SendRequest) { | 185 TEST_P(SpdyHttpStreamTest, SendRequest) { |
186 if (GetParam() > kProtoSPDY3) | 186 if (GetParam() > kProtoSPDY3) |
187 return; | 187 return; |
188 | 188 |
189 scoped_ptr<SpdyFrame> req( | 189 scoped_ptr<SpdyFrame> req( |
190 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 190 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
191 MockWrite writes[] = { | 191 MockWrite writes[] = { |
192 CreateMockWrite(*req.get(), 1), | 192 CreateMockWrite(*req.get(), 1), |
193 }; | 193 }; |
194 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 194 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
195 MockRead reads[] = { | 195 MockRead reads[] = { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 EXPECT_TRUE(data()->at_read_eof()); | 242 EXPECT_TRUE(data()->at_read_eof()); |
243 EXPECT_TRUE(data()->at_write_eof()); | 243 EXPECT_TRUE(data()->at_write_eof()); |
244 | 244 |
245 TestLoadTimingNotReused(*http_stream); | 245 TestLoadTimingNotReused(*http_stream); |
246 http_stream->Close(true); | 246 http_stream->Close(true); |
247 // 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 |
248 // stream has been closed. | 248 // stream has been closed. |
249 TestLoadTimingNotReused(*http_stream); | 249 TestLoadTimingNotReused(*http_stream); |
250 } | 250 } |
251 | 251 |
252 TEST_P(SpdyHttpStreamSpdy2Test, LoadTimingTwoRequests) { | 252 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { |
253 if (GetParam() > kProtoSPDY3) | 253 if (GetParam() > kProtoSPDY3) |
254 return; | 254 return; |
255 | 255 |
256 scoped_ptr<SpdyFrame> req1( | 256 scoped_ptr<SpdyFrame> req1( |
257 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 257 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
258 scoped_ptr<SpdyFrame> req2( | 258 scoped_ptr<SpdyFrame> req2( |
259 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 259 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
260 MockWrite writes[] = { | 260 MockWrite writes[] = { |
261 CreateMockWrite(*req1, 0), | 261 CreateMockWrite(*req1, 0), |
262 CreateMockWrite(*req2, 1), | 262 CreateMockWrite(*req2, 1), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 scoped_refptr<IOBuffer> buf1(new IOBuffer(1)); | 343 scoped_refptr<IOBuffer> buf1(new IOBuffer(1)); |
344 ASSERT_EQ( | 344 ASSERT_EQ( |
345 0, http_stream1->ReadResponseBody(buf1.get(), 1, callback1.callback())); | 345 0, http_stream1->ReadResponseBody(buf1.get(), 1, callback1.callback())); |
346 | 346 |
347 // Stream 1 has been read to completion. | 347 // Stream 1 has been read to completion. |
348 TestLoadTimingNotReused(*http_stream1); | 348 TestLoadTimingNotReused(*http_stream1); |
349 // Stream 2 still has queued body data. | 349 // Stream 2 still has queued body data. |
350 TestLoadTimingReused(*http_stream2); | 350 TestLoadTimingReused(*http_stream2); |
351 } | 351 } |
352 | 352 |
353 TEST_P(SpdyHttpStreamSpdy2Test, SendChunkedPost) { | 353 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { |
354 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 354 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
355 | 355 |
356 scoped_ptr<SpdyFrame> initial_window_update( | 356 scoped_ptr<SpdyFrame> initial_window_update( |
357 framer.CreateWindowUpdate( | 357 framer.CreateWindowUpdate( |
358 kSessionFlowControlStreamId, | 358 kSessionFlowControlStreamId, |
359 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | 359 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); |
360 scoped_ptr<SpdyFrame> req( | 360 scoped_ptr<SpdyFrame> req( |
361 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 361 spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
362 scoped_ptr<SpdyFrame> body( | 362 scoped_ptr<SpdyFrame> body( |
363 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); | 363 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 420 |
421 // Because we abandoned the stream, we don't expect to find a session in the | 421 // Because we abandoned the stream, we don't expect to find a session in the |
422 // pool anymore. | 422 // pool anymore. |
423 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); | 423 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(key)); |
424 EXPECT_TRUE(data()->at_read_eof()); | 424 EXPECT_TRUE(data()->at_read_eof()); |
425 EXPECT_TRUE(data()->at_write_eof()); | 425 EXPECT_TRUE(data()->at_write_eof()); |
426 } | 426 } |
427 | 427 |
428 // Test to ensure the SpdyStream state machine does not get confused when a | 428 // Test to ensure the SpdyStream state machine does not get confused when a |
429 // chunk becomes available while a write is pending. | 429 // chunk becomes available while a write is pending. |
430 TEST_P(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPost) { | 430 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { |
431 if (GetParam() > kProtoSPDY3) | 431 if (GetParam() > kProtoSPDY3) |
432 return; | 432 return; |
433 | 433 |
434 const char kUploadData1[] = "12345678"; | 434 const char kUploadData1[] = "12345678"; |
435 const int kUploadData1Size = arraysize(kUploadData1)-1; | 435 const int kUploadData1Size = arraysize(kUploadData1)-1; |
436 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 436 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
437 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 437 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
438 scoped_ptr<SpdyFrame> chunk2( | 438 scoped_ptr<SpdyFrame> chunk2( |
439 spdy_util_.ConstructSpdyBodyFrame( | 439 spdy_util_.ConstructSpdyBodyFrame( |
440 1, kUploadData1, kUploadData1Size, false)); | 440 1, kUploadData1, kUploadData1Size, false)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 // Finish reading the |EOF|. | 530 // Finish reading the |EOF|. |
531 deterministic_data()->RunFor(1); | 531 deterministic_data()->RunFor(1); |
532 ASSERT_TRUE(response.headers.get()); | 532 ASSERT_TRUE(response.headers.get()); |
533 ASSERT_EQ(200, response.headers->response_code()); | 533 ASSERT_EQ(200, response.headers->response_code()); |
534 EXPECT_TRUE(deterministic_data()->at_read_eof()); | 534 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
535 EXPECT_TRUE(deterministic_data()->at_write_eof()); | 535 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
536 } | 536 } |
537 | 537 |
538 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | 538 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
539 // made available is handled correctly. | 539 // made available is handled correctly. |
540 TEST_P(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPostWithWindowUpdate) { | 540 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
541 if (GetParam() != kProtoSPDY3) | 541 if (GetParam() != kProtoSPDY3) |
542 return; | 542 return; |
543 | 543 |
544 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 544 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
545 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 545 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
546 MockWrite writes[] = { | 546 MockWrite writes[] = { |
547 CreateMockWrite(*req.get(), 0), | 547 CreateMockWrite(*req.get(), 0), |
548 CreateMockWrite(*chunk1, 1), | 548 CreateMockWrite(*chunk1, 1), |
549 }; | 549 }; |
550 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 550 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 647 |
648 // Finish reading the |EOF|. | 648 // Finish reading the |EOF|. |
649 data.RunFor(1); | 649 data.RunFor(1); |
650 ASSERT_TRUE(response.headers.get()); | 650 ASSERT_TRUE(response.headers.get()); |
651 ASSERT_EQ(200, response.headers->response_code()); | 651 ASSERT_EQ(200, response.headers->response_code()); |
652 EXPECT_TRUE(data.at_read_eof()); | 652 EXPECT_TRUE(data.at_read_eof()); |
653 EXPECT_TRUE(data.at_write_eof()); | 653 EXPECT_TRUE(data.at_write_eof()); |
654 } | 654 } |
655 | 655 |
656 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 656 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
657 TEST_P(SpdyHttpStreamSpdy2Test, SpdyURLTest) { | 657 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
658 if (GetParam() > kProtoSPDY3) | 658 if (GetParam() > kProtoSPDY3) |
659 return; | 659 return; |
660 | 660 |
661 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; | 661 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
662 const char * const base_url = "http://www.google.com/foo?query=what"; | 662 const char * const base_url = "http://www.google.com/foo?query=what"; |
663 scoped_ptr<SpdyFrame> req( | 663 scoped_ptr<SpdyFrame> req( |
664 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); | 664 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); |
665 MockWrite writes[] = { | 665 MockWrite writes[] = { |
666 CreateMockWrite(*req.get(), 1), | 666 CreateMockWrite(*req.get(), 1), |
667 }; | 667 }; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 } | 765 } |
766 | 766 |
767 } // namespace | 767 } // namespace |
768 | 768 |
769 // TODO(rch): When openssl supports server bound certifictes, this | 769 // TODO(rch): When openssl supports server bound certifictes, this |
770 // guard can be removed | 770 // guard can be removed |
771 #if !defined(USE_OPENSSL) | 771 #if !defined(USE_OPENSSL) |
772 // Test that if we request a resource for a new origin on a session that | 772 // Test that if we request a resource for a new origin on a session that |
773 // used domain bound certificates, that we send a CREDENTIAL frame for | 773 // used domain bound certificates, that we send a CREDENTIAL frame for |
774 // the new domain before we send the new request. | 774 // the new domain before we send the new request. |
775 void SpdyHttpStreamSpdy2Test::TestSendCredentials( | 775 void SpdyHttpStreamTest::TestSendCredentials( |
776 ServerBoundCertService* server_bound_cert_service, | 776 ServerBoundCertService* server_bound_cert_service, |
777 const std::string& cert, | 777 const std::string& cert, |
778 const std::string& proof) { | 778 const std::string& proof) { |
779 const char* kUrl1 = "https://www.google.com/"; | 779 const char* kUrl1 = "https://www.google.com/"; |
780 const char* kUrl2 = "https://www.gmail.com/"; | 780 const char* kUrl2 = "https://www.gmail.com/"; |
781 | 781 |
782 SpdyCredential cred; | 782 SpdyCredential cred; |
783 cred.slot = 2; | 783 cred.slot = 2; |
784 cred.proof = proof; | 784 cred.proof = proof; |
785 cred.certs.push_back(cert); | 785 cred.certs.push_back(cert); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 callback.WaitForResult(); | 889 callback.WaitForResult(); |
890 | 890 |
891 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( | 891 EXPECT_EQ(ERR_IO_PENDING, http_stream2->ReadResponseHeaders( |
892 callback.callback())); | 892 callback.callback())); |
893 data.RunFor(1); | 893 data.RunFor(1); |
894 EXPECT_EQ(OK, callback.WaitForResult()); | 894 EXPECT_EQ(OK, callback.WaitForResult()); |
895 ASSERT_TRUE(response.headers.get() != NULL); | 895 ASSERT_TRUE(response.headers.get() != NULL); |
896 ASSERT_EQ(200, response.headers->response_code()); | 896 ASSERT_EQ(200, response.headers->response_code()); |
897 } | 897 } |
898 | 898 |
899 TEST_P(SpdyHttpStreamSpdy2Test, SendCredentialsEC) { | 899 TEST_P(SpdyHttpStreamTest, SendCredentialsEC) { |
900 if (GetParam() != kProtoSPDY3) | 900 if (GetParam() != kProtoSPDY3) |
901 return; | 901 return; |
902 | 902 |
903 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 903 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
904 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 904 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
905 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 905 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
906 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 906 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
907 sequenced_worker_pool)); | 907 sequenced_worker_pool)); |
908 std::string cert; | 908 std::string cert; |
909 std::string proof; | 909 std::string proof; |
910 GetECServerBoundCertAndProof("www.gmail.com", | 910 GetECServerBoundCertAndProof("www.gmail.com", |
911 server_bound_cert_service.get(), | 911 server_bound_cert_service.get(), |
912 &cert, &proof); | 912 &cert, &proof); |
913 | 913 |
914 TestSendCredentials(server_bound_cert_service.get(), cert, proof); | 914 TestSendCredentials(server_bound_cert_service.get(), cert, proof); |
915 | 915 |
916 sequenced_worker_pool->Shutdown(); | 916 sequenced_worker_pool->Shutdown(); |
917 } | 917 } |
918 | 918 |
919 TEST_P(SpdyHttpStreamSpdy2Test, DontSendCredentialsForHttpUrlsEC) { | 919 TEST_P(SpdyHttpStreamTest, DontSendCredentialsForHttpUrlsEC) { |
920 if (GetParam() != kProtoSPDY3) | 920 if (GetParam() != kProtoSPDY3) |
921 return; | 921 return; |
922 | 922 |
923 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = | 923 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool = |
924 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); | 924 new base::SequencedWorkerPool(1, "SpdyHttpStreamSpdy3Test"); |
925 scoped_ptr<ServerBoundCertService> server_bound_cert_service( | 925 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
926 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), | 926 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL), |
927 sequenced_worker_pool)); | 927 sequenced_worker_pool)); |
928 std::string cert; | 928 std::string cert; |
929 std::string proof; | 929 std::string proof; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 data.RunFor(1); | 1047 data.RunFor(1); |
1048 sequenced_worker_pool->Shutdown(); | 1048 sequenced_worker_pool->Shutdown(); |
1049 } | 1049 } |
1050 | 1050 |
1051 #endif // !defined(USE_OPENSSL) | 1051 #endif // !defined(USE_OPENSSL) |
1052 | 1052 |
1053 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1053 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
1054 // methods. | 1054 // methods. |
1055 | 1055 |
1056 } // namespace net | 1056 } // namespace net |
OLD | NEW |