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 <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/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 SpdyNetworkTransactionTestParams( | 63 SpdyNetworkTransactionTestParams( |
64 NextProto protocol, | 64 NextProto protocol, |
65 SpdyNetworkTransactionTestSSLType ssl_type) | 65 SpdyNetworkTransactionTestSSLType ssl_type) |
66 : protocol(protocol), | 66 : protocol(protocol), |
67 ssl_type(ssl_type) {} | 67 ssl_type(ssl_type) {} |
68 | 68 |
69 NextProto protocol; | 69 NextProto protocol; |
70 SpdyNetworkTransactionTestSSLType ssl_type; | 70 SpdyNetworkTransactionTestSSLType ssl_type; |
71 }; | 71 }; |
72 | 72 |
| 73 void UpdateSpdySessionDependencies( |
| 74 SpdyNetworkTransactionTestParams test_params, |
| 75 SpdySessionDependencies* session_deps) { |
| 76 switch (test_params.ssl_type) { |
| 77 case SPDYNPN: |
| 78 session_deps->http_server_properties.SetAlternateProtocol( |
| 79 HostPortPair("www.google.com", 80), 443, |
| 80 AlternateProtocolFromNextProto(test_params.protocol)); |
| 81 session_deps->use_alternate_protocols = true; |
| 82 session_deps->next_protos = SpdyNextProtos(); |
| 83 break; |
| 84 case SPDYNOSSL: |
| 85 session_deps->force_spdy_over_ssl = false; |
| 86 session_deps->force_spdy_always = true; |
| 87 break; |
| 88 case SPDYSSL: |
| 89 session_deps->force_spdy_over_ssl = true; |
| 90 session_deps->force_spdy_always = true; |
| 91 break; |
| 92 default: |
| 93 NOTREACHED(); |
| 94 } |
| 95 } |
| 96 |
73 SpdySessionDependencies* CreateSpdySessionDependencies( | 97 SpdySessionDependencies* CreateSpdySessionDependencies( |
74 SpdyNetworkTransactionTestParams test_params) { | 98 SpdyNetworkTransactionTestParams test_params) { |
75 return new SpdySessionDependencies(test_params.protocol); | 99 SpdySessionDependencies* session_deps = |
| 100 new SpdySessionDependencies(test_params.protocol); |
| 101 UpdateSpdySessionDependencies(test_params, session_deps); |
| 102 return session_deps; |
76 } | 103 } |
77 | 104 |
78 SpdySessionDependencies* CreateSpdySessionDependencies( | 105 SpdySessionDependencies* CreateSpdySessionDependencies( |
79 SpdyNetworkTransactionTestParams test_params, | 106 SpdyNetworkTransactionTestParams test_params, |
80 ProxyService* proxy_service) { | 107 ProxyService* proxy_service) { |
81 return new SpdySessionDependencies(test_params.protocol, proxy_service); | 108 SpdySessionDependencies* session_deps = |
| 109 new SpdySessionDependencies(test_params.protocol, proxy_service); |
| 110 UpdateSpdySessionDependencies(test_params, session_deps); |
| 111 return session_deps; |
82 } | 112 } |
83 | 113 |
84 } // namespace | 114 } // namespace |
85 | 115 |
86 class SpdyNetworkTransactionTest | 116 class SpdyNetworkTransactionTest |
87 : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { | 117 : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { |
88 protected: | 118 protected: |
89 SpdyNetworkTransactionTest() : spdy_util_(GetParam().protocol) { | 119 SpdyNetworkTransactionTest() : spdy_util_(GetParam().protocol) { |
90 LOG(INFO) << __FUNCTION__; | 120 LOG(INFO) << __FUNCTION__; |
91 } | 121 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 197 |
168 void SetSpdyDisabled() { | 198 void SetSpdyDisabled() { |
169 spdy_enabled_ = false; | 199 spdy_enabled_ = false; |
170 port_ = 80; | 200 port_ = 80; |
171 } | 201 } |
172 | 202 |
173 void RunPreTestSetup() { | 203 void RunPreTestSetup() { |
174 LOG(INFO) << __FUNCTION__; | 204 LOG(INFO) << __FUNCTION__; |
175 if (!session_deps_.get()) | 205 if (!session_deps_.get()) |
176 session_deps_.reset(CreateSpdySessionDependencies(test_params_)); | 206 session_deps_.reset(CreateSpdySessionDependencies(test_params_)); |
177 if (!session_.get()) | 207 if (!session_.get()) { |
178 session_ = SpdySessionDependencies::SpdyCreateSession( | 208 session_ = SpdySessionDependencies::SpdyCreateSession( |
179 session_deps_.get()); | 209 session_deps_.get()); |
180 HttpStreamFactory::set_use_alternate_protocols(false); | |
181 HttpStreamFactory::set_force_spdy_over_ssl(false); | |
182 HttpStreamFactory::set_force_spdy_always(false); | |
183 | |
184 std::vector<NextProto> next_protos = SpdyNextProtos(); | |
185 | |
186 switch (test_params_.ssl_type) { | |
187 case SPDYNPN: | |
188 session_->http_server_properties()->SetAlternateProtocol( | |
189 HostPortPair("www.google.com", 80), 443, | |
190 AlternateProtocolFromNextProto(test_params_.protocol)); | |
191 HttpStreamFactory::set_use_alternate_protocols(true); | |
192 HttpStreamFactory::SetNextProtos(next_protos); | |
193 break; | |
194 case SPDYNOSSL: | |
195 HttpStreamFactory::set_force_spdy_over_ssl(false); | |
196 HttpStreamFactory::set_force_spdy_always(true); | |
197 break; | |
198 case SPDYSSL: | |
199 HttpStreamFactory::set_force_spdy_over_ssl(true); | |
200 HttpStreamFactory::set_force_spdy_always(true); | |
201 break; | |
202 default: | |
203 NOTREACHED(); | |
204 } | 210 } |
205 | 211 |
206 // We're now ready to use SSL-npn SPDY. | 212 // We're now ready to use SSL-npn SPDY. |
207 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); | 213 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
208 LOG(INFO) << __FUNCTION__; | 214 LOG(INFO) << __FUNCTION__; |
209 } | 215 } |
210 | 216 |
211 // Start the transaction, read some data, finish. | 217 // Start the transaction, read some data, finish. |
212 void RunDefaultTest() { | 218 void RunDefaultTest() { |
213 LOG(INFO) << __FUNCTION__; | 219 LOG(INFO) << __FUNCTION__; |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 TestCompletionCallback callback1; | 1095 TestCompletionCallback callback1; |
1090 TestCompletionCallback callback2; | 1096 TestCompletionCallback callback2; |
1091 | 1097 |
1092 HttpRequestInfo httpreq = CreateGetRequest(); | 1098 HttpRequestInfo httpreq = CreateGetRequest(); |
1093 | 1099 |
1094 // Preconnect the first. | 1100 // Preconnect the first. |
1095 SSLConfig preconnect_ssl_config; | 1101 SSLConfig preconnect_ssl_config; |
1096 helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); | 1102 helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); |
1097 HttpStreamFactory* http_stream_factory = | 1103 HttpStreamFactory* http_stream_factory = |
1098 helper.session()->http_stream_factory(); | 1104 helper.session()->http_stream_factory(); |
1099 if (http_stream_factory->has_next_protos()) { | 1105 helper.session()->GetNextProtos(&preconnect_ssl_config.next_protos); |
1100 preconnect_ssl_config.next_protos = http_stream_factory->next_protos(); | |
1101 } | |
1102 | 1106 |
1103 http_stream_factory->PreconnectStreams( | 1107 http_stream_factory->PreconnectStreams( |
1104 1, httpreq, DEFAULT_PRIORITY, | 1108 1, httpreq, DEFAULT_PRIORITY, |
1105 preconnect_ssl_config, preconnect_ssl_config); | 1109 preconnect_ssl_config, preconnect_ssl_config); |
1106 | 1110 |
1107 out.rv = trans1->Start(&httpreq, callback1.callback(), log); | 1111 out.rv = trans1->Start(&httpreq, callback1.callback(), log); |
1108 ASSERT_EQ(ERR_IO_PENDING, out.rv); | 1112 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
1109 out.rv = trans2->Start(&httpreq, callback2.callback(), log); | 1113 out.rv = trans2->Start(&httpreq, callback2.callback(), log); |
1110 ASSERT_EQ(ERR_IO_PENDING, out.rv); | 1114 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
1111 | 1115 |
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2553 CreateMockRead(*resp2, 2), | 2557 CreateMockRead(*resp2, 2), |
2554 CreateMockRead(*body2, 3), | 2558 CreateMockRead(*body2, 3), |
2555 MockRead(ASYNC, 0, 0, 4) // EOF | 2559 MockRead(ASYNC, 0, 0, 4) // EOF |
2556 }; | 2560 }; |
2557 OrderedSocketData data(reads, arraysize(reads), | 2561 OrderedSocketData data(reads, arraysize(reads), |
2558 writes, arraysize(writes)); | 2562 writes, arraysize(writes)); |
2559 OrderedSocketData data2(reads2, arraysize(reads2), | 2563 OrderedSocketData data2(reads2, arraysize(reads2), |
2560 writes2, arraysize(writes2)); | 2564 writes2, arraysize(writes2)); |
2561 | 2565 |
2562 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN | 2566 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
2563 HttpStreamFactory::set_force_spdy_over_ssl(false); | |
2564 HttpStreamFactory::set_force_spdy_always(true); | |
2565 TestDelegate d; | 2567 TestDelegate d; |
2566 { | 2568 { |
2567 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); | 2569 SpdyURLRequestContext spdy_url_request_context( |
| 2570 GetParam().protocol, |
| 2571 false /* force_spdy_over_ssl*/, |
| 2572 true /* force_spdy_always */); |
2568 net::URLRequest r(GURL("http://www.google.com/"), | 2573 net::URLRequest r(GURL("http://www.google.com/"), |
2569 DEFAULT_PRIORITY, | 2574 DEFAULT_PRIORITY, |
2570 &d, | 2575 &d, |
2571 &spdy_url_request_context); | 2576 &spdy_url_request_context); |
2572 spdy_url_request_context.socket_factory(). | 2577 spdy_url_request_context.socket_factory(). |
2573 AddSocketDataProvider(&data); | 2578 AddSocketDataProvider(&data); |
2574 spdy_url_request_context.socket_factory(). | 2579 spdy_url_request_context.socket_factory(). |
2575 AddSocketDataProvider(&data2); | 2580 AddSocketDataProvider(&data2); |
2576 | 2581 |
2577 d.set_quit_on_redirect(true); | 2582 d.set_quit_on_redirect(true); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2647 CreateMockRead(*resp2, 2), | 2652 CreateMockRead(*resp2, 2), |
2648 CreateMockRead(*body2, 3), | 2653 CreateMockRead(*body2, 3), |
2649 MockRead(ASYNC, 0, 0, 5) // EOF | 2654 MockRead(ASYNC, 0, 0, 5) // EOF |
2650 }; | 2655 }; |
2651 OrderedSocketData data(reads, arraysize(reads), | 2656 OrderedSocketData data(reads, arraysize(reads), |
2652 writes, arraysize(writes)); | 2657 writes, arraysize(writes)); |
2653 OrderedSocketData data2(reads2, arraysize(reads2), | 2658 OrderedSocketData data2(reads2, arraysize(reads2), |
2654 writes2, arraysize(writes2)); | 2659 writes2, arraysize(writes2)); |
2655 | 2660 |
2656 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN | 2661 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
2657 HttpStreamFactory::set_force_spdy_over_ssl(false); | |
2658 HttpStreamFactory::set_force_spdy_always(true); | |
2659 TestDelegate d; | 2662 TestDelegate d; |
2660 TestDelegate d2; | 2663 TestDelegate d2; |
2661 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); | 2664 SpdyURLRequestContext spdy_url_request_context( |
| 2665 GetParam().protocol, |
| 2666 false /* force_spdy_over_ssl*/, |
| 2667 true /* force_spdy_always */); |
2662 { | 2668 { |
2663 net::URLRequest r(GURL("http://www.google.com/"), | 2669 net::URLRequest r(GURL("http://www.google.com/"), |
2664 DEFAULT_PRIORITY, | 2670 DEFAULT_PRIORITY, |
2665 &d, | 2671 &d, |
2666 &spdy_url_request_context); | 2672 &spdy_url_request_context); |
2667 spdy_url_request_context.socket_factory(). | 2673 spdy_url_request_context.socket_factory(). |
2668 AddSocketDataProvider(&data); | 2674 AddSocketDataProvider(&data); |
2669 | 2675 |
2670 r.Start(); | 2676 r.Start(); |
2671 base::RunLoop().Run(); | 2677 base::RunLoop().Run(); |
(...skipping 2324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4996 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 5002 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
4997 EXPECT_EQ("hello!", response_data); | 5003 EXPECT_EQ("hello!", response_data); |
4998 } | 5004 } |
4999 | 5005 |
5000 helper.VerifyDataConsumed(); | 5006 helper.VerifyDataConsumed(); |
5001 } | 5007 } |
5002 } | 5008 } |
5003 | 5009 |
5004 // Test that turning SPDY on and off works properly. | 5010 // Test that turning SPDY on and off works properly. |
5005 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { | 5011 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { |
5006 net::HttpStreamFactory::set_spdy_enabled(true); | 5012 HttpStreamFactory::set_spdy_enabled(true); |
5007 scoped_ptr<SpdyFrame> req( | 5013 scoped_ptr<SpdyFrame> req( |
5008 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5014 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
5009 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; | 5015 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
5010 | 5016 |
5011 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 5017 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
5012 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5018 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
5013 MockRead spdy_reads[] = { | 5019 MockRead spdy_reads[] = { |
5014 CreateMockRead(*resp), | 5020 CreateMockRead(*resp), |
5015 CreateMockRead(*body), | 5021 CreateMockRead(*body), |
5016 MockRead(ASYNC, 0, 0) // EOF | 5022 MockRead(ASYNC, 0, 0) // EOF |
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6701 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6707 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
6702 scoped_ptr<SSLSocketDataProvider> ssl_provider( | 6708 scoped_ptr<SSLSocketDataProvider> ssl_provider( |
6703 new SSLSocketDataProvider(ASYNC, OK)); | 6709 new SSLSocketDataProvider(ASYNC, OK)); |
6704 // Set to TLS_RSA_WITH_NULL_MD5 | 6710 // Set to TLS_RSA_WITH_NULL_MD5 |
6705 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6711 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
6706 | 6712 |
6707 RunTLSUsageCheckTest(ssl_provider.Pass()); | 6713 RunTLSUsageCheckTest(ssl_provider.Pass()); |
6708 } | 6714 } |
6709 | 6715 |
6710 } // namespace net | 6716 } // namespace net |
OLD | NEW |