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 "crypto/ec_private_key.h" | 7 #include "crypto/ec_private_key.h" |
8 #include "crypto/ec_signature_creator.h" | 8 #include "crypto/ec_signature_creator.h" |
9 #include "crypto/signature_creator.h" | 9 #include "crypto/signature_creator.h" |
10 #include "net/base/asn1_util.h" | 10 #include "net/base/asn1_util.h" |
11 #include "net/base/default_origin_bound_cert_store.h" | 11 #include "net/base/default_origin_bound_cert_store.h" |
12 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
13 #include "net/http/http_response_info.h" | 13 #include "net/http/http_response_info.h" |
14 #include "net/spdy/spdy_session.h" | 14 #include "net/spdy/spdy_session.h" |
15 #include "net/spdy/spdy_test_util_spdy3.h" | 15 #include "net/spdy/spdy_test_util_spdy3.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 using namespace net::test_spdy3; | 18 using namespace net::test_spdy3; |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 class SpdyHttpStreamSpdy3Test : public testing::Test { | 22 class SpdyHttpStreamSpdy3Test : public testing::Test { |
23 public: | 23 public: |
24 OrderedSocketData* data() { return data_.get(); } | 24 OrderedSocketData* data() { return data_.get(); } |
25 protected: | 25 protected: |
26 SpdyHttpStreamSpdy3Test() {} | 26 SpdyHttpStreamSpdy3Test() {} |
27 | 27 |
28 void EnableCompression(bool enabled) { | |
29 spdy::SpdyFramer::set_enable_compression_default(enabled); | |
30 } | |
31 | |
32 virtual void SetUp() { | 28 virtual void SetUp() { |
33 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY3); | 29 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY3); |
34 } | 30 } |
35 | 31 |
36 virtual void TearDown() { | 32 virtual void TearDown() { |
37 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); | 33 crypto::ECSignatureCreator::SetFactoryForTesting(NULL); |
38 MessageLoop::current()->RunAllPending(); | 34 MessageLoop::current()->RunAllPending(); |
39 } | 35 } |
40 | 36 |
41 int InitSession(MockRead* reads, size_t reads_count, | 37 int InitSession(MockRead* reads, size_t reads_count, |
(...skipping 25 matching lines...) Expand all Loading... |
67 ServerBoundCertService* server_bound_cert_service, | 63 ServerBoundCertService* server_bound_cert_service, |
68 const std::string& cert, | 64 const std::string& cert, |
69 const std::string& proof, | 65 const std::string& proof, |
70 SSLClientCertType type); | 66 SSLClientCertType type); |
71 | 67 |
72 SpdySessionDependencies session_deps_; | 68 SpdySessionDependencies session_deps_; |
73 scoped_ptr<OrderedSocketData> data_; | 69 scoped_ptr<OrderedSocketData> data_; |
74 scoped_refptr<HttpNetworkSession> http_session_; | 70 scoped_refptr<HttpNetworkSession> http_session_; |
75 scoped_refptr<SpdySession> session_; | 71 scoped_refptr<SpdySession> session_; |
76 scoped_refptr<TransportSocketParams> transport_params_; | 72 scoped_refptr<TransportSocketParams> transport_params_; |
| 73 |
| 74 private: |
| 75 SpdyTestStateHelper spdy_state_; |
77 }; | 76 }; |
78 | 77 |
79 TEST_F(SpdyHttpStreamSpdy3Test, SendRequest) { | 78 TEST_F(SpdyHttpStreamSpdy3Test, SendRequest) { |
80 EnableCompression(false); | |
81 | |
82 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 79 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
83 MockWrite writes[] = { | 80 MockWrite writes[] = { |
84 CreateMockWrite(*req.get(), 1), | 81 CreateMockWrite(*req.get(), 1), |
85 }; | 82 }; |
86 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 83 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
87 MockRead reads[] = { | 84 MockRead reads[] = { |
88 CreateMockRead(*resp, 2), | 85 CreateMockRead(*resp, 2), |
89 MockRead(SYNCHRONOUS, 0, 3) // EOF | 86 MockRead(SYNCHRONOUS, 0, 3) // EOF |
90 }; | 87 }; |
91 | 88 |
(...skipping 26 matching lines...) Expand all Loading... |
118 data()->CompleteRead(); | 115 data()->CompleteRead(); |
119 | 116 |
120 // Because we abandoned the stream, we don't expect to find a session in the | 117 // Because we abandoned the stream, we don't expect to find a session in the |
121 // pool anymore. | 118 // pool anymore. |
122 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); | 119 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
123 EXPECT_TRUE(data()->at_read_eof()); | 120 EXPECT_TRUE(data()->at_read_eof()); |
124 EXPECT_TRUE(data()->at_write_eof()); | 121 EXPECT_TRUE(data()->at_write_eof()); |
125 } | 122 } |
126 | 123 |
127 TEST_F(SpdyHttpStreamSpdy3Test, SendChunkedPost) { | 124 TEST_F(SpdyHttpStreamSpdy3Test, SendChunkedPost) { |
128 EnableCompression(false); | |
129 UploadDataStream::set_merge_chunks(false); | 125 UploadDataStream::set_merge_chunks(false); |
130 | 126 |
131 scoped_ptr<spdy::SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); | 127 scoped_ptr<spdy::SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0)); |
132 scoped_ptr<spdy::SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); | 128 scoped_ptr<spdy::SpdyFrame> chunk1(ConstructSpdyBodyFrame(1, false)); |
133 scoped_ptr<spdy::SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); | 129 scoped_ptr<spdy::SpdyFrame> chunk2(ConstructSpdyBodyFrame(1, true)); |
134 MockWrite writes[] = { | 130 MockWrite writes[] = { |
135 CreateMockWrite(*req.get(), 1), | 131 CreateMockWrite(*req.get(), 1), |
136 CreateMockWrite(*chunk1, 2), // POST upload frames | 132 CreateMockWrite(*chunk1, 2), // POST upload frames |
137 CreateMockWrite(*chunk2, 3), | 133 CreateMockWrite(*chunk2, 3), |
138 }; | 134 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 177 |
182 // Because we abandoned the stream, we don't expect to find a session in the | 178 // Because we abandoned the stream, we don't expect to find a session in the |
183 // pool anymore. | 179 // pool anymore. |
184 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); | 180 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
185 EXPECT_TRUE(data()->at_read_eof()); | 181 EXPECT_TRUE(data()->at_read_eof()); |
186 EXPECT_TRUE(data()->at_write_eof()); | 182 EXPECT_TRUE(data()->at_write_eof()); |
187 } | 183 } |
188 | 184 |
189 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 185 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
190 TEST_F(SpdyHttpStreamSpdy3Test, SpdyURLTest) { | 186 TEST_F(SpdyHttpStreamSpdy3Test, SpdyURLTest) { |
191 EnableCompression(false); | |
192 | |
193 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; | 187 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; |
194 const char * const base_url = "http://www.google.com/foo?query=what"; | 188 const char * const base_url = "http://www.google.com/foo?query=what"; |
195 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); | 189 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); |
196 MockWrite writes[] = { | 190 MockWrite writes[] = { |
197 CreateMockWrite(*req.get(), 1), | 191 CreateMockWrite(*req.get(), 1), |
198 }; | 192 }; |
199 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 193 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
200 MockRead reads[] = { | 194 MockRead reads[] = { |
201 CreateMockRead(*resp, 2), | 195 CreateMockRead(*resp, 2), |
202 MockRead(SYNCHRONOUS, 0, 3) // EOF | 196 MockRead(SYNCHRONOUS, 0, 3) // EOF |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // guard can be removed | 284 // guard can be removed |
291 #if !defined(USE_OPENSSL) | 285 #if !defined(USE_OPENSSL) |
292 // Test that if we request a resource for a new origin on a session that | 286 // Test that if we request a resource for a new origin on a session that |
293 // used domain bound certificates, that we send a CREDENTIAL frame for | 287 // used domain bound certificates, that we send a CREDENTIAL frame for |
294 // the new domain before we send the new request. | 288 // the new domain before we send the new request. |
295 void SpdyHttpStreamSpdy3Test::TestSendCredentials( | 289 void SpdyHttpStreamSpdy3Test::TestSendCredentials( |
296 ServerBoundCertService* server_bound_cert_service, | 290 ServerBoundCertService* server_bound_cert_service, |
297 const std::string& cert, | 291 const std::string& cert, |
298 const std::string& proof, | 292 const std::string& proof, |
299 SSLClientCertType type) { | 293 SSLClientCertType type) { |
300 EnableCompression(false); | |
301 | |
302 spdy::SpdyCredential cred; | 294 spdy::SpdyCredential cred; |
303 cred.slot = 1; | 295 cred.slot = 1; |
304 cred.proof = proof; | 296 cred.proof = proof; |
305 cred.certs.push_back(cert); | 297 cred.certs.push_back(cert); |
306 | 298 |
307 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 299 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
308 scoped_ptr<spdy::SpdyFrame> credential(ConstructSpdyCredential(cred)); | 300 scoped_ptr<spdy::SpdyFrame> credential(ConstructSpdyCredential(cred)); |
309 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet("http://www.gmail.com", | 301 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet("http://www.gmail.com", |
310 false, 3, LOWEST)); | 302 false, 3, LOWEST)); |
311 MockWrite writes[] = { | 303 MockWrite writes[] = { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 TestSendCredentials(server_bound_cert_service.get(), cert, proof, | 460 TestSendCredentials(server_bound_cert_service.get(), cert, proof, |
469 CLIENT_CERT_ECDSA_SIGN); | 461 CLIENT_CERT_ECDSA_SIGN); |
470 } | 462 } |
471 | 463 |
472 #endif // !defined(USE_OPENSSL) | 464 #endif // !defined(USE_OPENSSL) |
473 | 465 |
474 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 466 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
475 // methods. | 467 // methods. |
476 | 468 |
477 } // namespace net | 469 } // namespace net |
OLD | NEW |