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

Side by Side Diff: net/spdy/spdy_network_transaction_unittest.cc

Issue 284423002: Remove HttpStreamFactory's NPN/SPDY globals, except for spdy_enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move comment to avoid merge conflicts Created 6 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 | Annotate | Revision Log
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/file_util.h" 10 #include "base/file_util.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 SpdyNetworkTransactionTestParams( 62 SpdyNetworkTransactionTestParams(
63 NextProto protocol, 63 NextProto protocol,
64 SpdyNetworkTransactionTestSSLType ssl_type) 64 SpdyNetworkTransactionTestSSLType ssl_type)
65 : protocol(protocol), 65 : protocol(protocol),
66 ssl_type(ssl_type) {} 66 ssl_type(ssl_type) {}
67 67
68 NextProto protocol; 68 NextProto protocol;
69 SpdyNetworkTransactionTestSSLType ssl_type; 69 SpdyNetworkTransactionTestSSLType ssl_type;
70 }; 70 };
71 71
72 void UpdateSpdySessionDependencies(
73 SpdyNetworkTransactionTestParams test_params,
74 SpdySessionDependencies* session_deps) {
75 switch (test_params.ssl_type) {
76 case SPDYNPN:
77 session_deps->http_server_properties.SetAlternateProtocol(
78 HostPortPair("www.google.com", 80), 443,
79 AlternateProtocolFromNextProto(test_params.protocol));
80 session_deps->use_alternate_protocols = true;
81 session_deps->next_protos = SpdyNextProtos();
82 break;
83 case SPDYNOSSL:
84 session_deps->force_spdy_over_ssl = false;
85 session_deps->force_spdy_always = true;
86 break;
87 case SPDYSSL:
88 session_deps->force_spdy_over_ssl = true;
89 session_deps->force_spdy_always = true;
90 break;
91 default:
92 NOTREACHED();
93 }
94 }
95
72 SpdySessionDependencies* CreateSpdySessionDependencies( 96 SpdySessionDependencies* CreateSpdySessionDependencies(
73 SpdyNetworkTransactionTestParams test_params) { 97 SpdyNetworkTransactionTestParams test_params) {
74 return new SpdySessionDependencies(test_params.protocol); 98 SpdySessionDependencies* session_deps =
99 new SpdySessionDependencies(test_params.protocol);
100 UpdateSpdySessionDependencies(test_params, session_deps);
101 return session_deps;
75 } 102 }
76 103
77 SpdySessionDependencies* CreateSpdySessionDependencies( 104 SpdySessionDependencies* CreateSpdySessionDependencies(
78 SpdyNetworkTransactionTestParams test_params, 105 SpdyNetworkTransactionTestParams test_params,
79 ProxyService* proxy_service) { 106 ProxyService* proxy_service) {
80 return new SpdySessionDependencies(test_params.protocol, proxy_service); 107 SpdySessionDependencies* session_deps =
108 new SpdySessionDependencies(test_params.protocol, proxy_service);
109 UpdateSpdySessionDependencies(test_params, session_deps);
110 return session_deps;
81 } 111 }
82 112
83 } // namespace 113 } // namespace
84 114
85 class SpdyNetworkTransactionTest 115 class SpdyNetworkTransactionTest
86 : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { 116 : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> {
87 protected: 117 protected:
88 SpdyNetworkTransactionTest() : spdy_util_(GetParam().protocol) { 118 SpdyNetworkTransactionTest() : spdy_util_(GetParam().protocol) {
89 LOG(INFO) << __FUNCTION__; 119 LOG(INFO) << __FUNCTION__;
90 } 120 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 196
167 void SetSpdyDisabled() { 197 void SetSpdyDisabled() {
168 spdy_enabled_ = false; 198 spdy_enabled_ = false;
169 port_ = 80; 199 port_ = 80;
170 } 200 }
171 201
172 void RunPreTestSetup() { 202 void RunPreTestSetup() {
173 LOG(INFO) << __FUNCTION__; 203 LOG(INFO) << __FUNCTION__;
174 if (!session_deps_.get()) 204 if (!session_deps_.get())
175 session_deps_.reset(CreateSpdySessionDependencies(test_params_)); 205 session_deps_.reset(CreateSpdySessionDependencies(test_params_));
176 if (!session_.get()) 206 if (!session_.get()) {
177 session_ = SpdySessionDependencies::SpdyCreateSession( 207 session_ = SpdySessionDependencies::SpdyCreateSession(
178 session_deps_.get()); 208 session_deps_.get());
179 HttpStreamFactory::set_use_alternate_protocols(false);
180 HttpStreamFactory::set_force_spdy_over_ssl(false);
181 HttpStreamFactory::set_force_spdy_always(false);
182
183 std::vector<NextProto> next_protos = SpdyNextProtos();
184
185 switch (test_params_.ssl_type) {
186 case SPDYNPN:
187 session_->http_server_properties()->SetAlternateProtocol(
188 HostPortPair("www.google.com", 80), 443,
189 AlternateProtocolFromNextProto(test_params_.protocol));
190 HttpStreamFactory::set_use_alternate_protocols(true);
191 HttpStreamFactory::SetNextProtos(next_protos);
192 break;
193 case SPDYNOSSL:
194 HttpStreamFactory::set_force_spdy_over_ssl(false);
195 HttpStreamFactory::set_force_spdy_always(true);
196 break;
197 case SPDYSSL:
198 HttpStreamFactory::set_force_spdy_over_ssl(true);
199 HttpStreamFactory::set_force_spdy_always(true);
200 break;
201 default:
202 NOTREACHED();
203 } 209 }
204 210
205 // We're now ready to use SSL-npn SPDY. 211 // We're now ready to use SSL-npn SPDY.
206 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); 212 trans_.reset(new HttpNetworkTransaction(priority_, session_.get()));
207 LOG(INFO) << __FUNCTION__; 213 LOG(INFO) << __FUNCTION__;
208 } 214 }
209 215
210 // Start the transaction, read some data, finish. 216 // Start the transaction, read some data, finish.
211 void RunDefaultTest() { 217 void RunDefaultTest() {
212 LOG(INFO) << __FUNCTION__; 218 LOG(INFO) << __FUNCTION__;
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 TestCompletionCallback callback1; 1076 TestCompletionCallback callback1;
1071 TestCompletionCallback callback2; 1077 TestCompletionCallback callback2;
1072 1078
1073 HttpRequestInfo httpreq = CreateGetRequest(); 1079 HttpRequestInfo httpreq = CreateGetRequest();
1074 1080
1075 // Preconnect the first. 1081 // Preconnect the first.
1076 SSLConfig preconnect_ssl_config; 1082 SSLConfig preconnect_ssl_config;
1077 helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); 1083 helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config);
1078 HttpStreamFactory* http_stream_factory = 1084 HttpStreamFactory* http_stream_factory =
1079 helper.session()->http_stream_factory(); 1085 helper.session()->http_stream_factory();
1080 if (http_stream_factory->has_next_protos()) { 1086 helper.session()->GetNextProtos(&preconnect_ssl_config.next_protos);
1081 preconnect_ssl_config.next_protos = http_stream_factory->next_protos();
1082 }
1083 1087
1084 http_stream_factory->PreconnectStreams( 1088 http_stream_factory->PreconnectStreams(
1085 1, httpreq, DEFAULT_PRIORITY, 1089 1, httpreq, DEFAULT_PRIORITY,
1086 preconnect_ssl_config, preconnect_ssl_config); 1090 preconnect_ssl_config, preconnect_ssl_config);
1087 1091
1088 out.rv = trans1->Start(&httpreq, callback1.callback(), log); 1092 out.rv = trans1->Start(&httpreq, callback1.callback(), log);
1089 ASSERT_EQ(ERR_IO_PENDING, out.rv); 1093 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1090 out.rv = trans2->Start(&httpreq, callback2.callback(), log); 1094 out.rv = trans2->Start(&httpreq, callback2.callback(), log);
1091 ASSERT_EQ(ERR_IO_PENDING, out.rv); 1095 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1092 1096
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 CreateMockRead(*resp2, 2), 2538 CreateMockRead(*resp2, 2),
2535 CreateMockRead(*body2, 3), 2539 CreateMockRead(*body2, 3),
2536 MockRead(ASYNC, 0, 0, 4) // EOF 2540 MockRead(ASYNC, 0, 0, 4) // EOF
2537 }; 2541 };
2538 OrderedSocketData data(reads, arraysize(reads), 2542 OrderedSocketData data(reads, arraysize(reads),
2539 writes, arraysize(writes)); 2543 writes, arraysize(writes));
2540 OrderedSocketData data2(reads2, arraysize(reads2), 2544 OrderedSocketData data2(reads2, arraysize(reads2),
2541 writes2, arraysize(writes2)); 2545 writes2, arraysize(writes2));
2542 2546
2543 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN 2547 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN
2544 HttpStreamFactory::set_force_spdy_over_ssl(false);
2545 HttpStreamFactory::set_force_spdy_always(true);
2546 TestDelegate d; 2548 TestDelegate d;
2547 { 2549 {
2548 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); 2550 SpdyURLRequestContext spdy_url_request_context(
2551 GetParam().protocol,
2552 false /* force_spdy_over_ssl*/,
2553 true /* force_spdy_always */);
2549 net::URLRequest r(GURL("http://www.google.com/"), 2554 net::URLRequest r(GURL("http://www.google.com/"),
2550 DEFAULT_PRIORITY, 2555 DEFAULT_PRIORITY,
2551 &d, 2556 &d,
2552 &spdy_url_request_context); 2557 &spdy_url_request_context);
2553 spdy_url_request_context.socket_factory(). 2558 spdy_url_request_context.socket_factory().
2554 AddSocketDataProvider(&data); 2559 AddSocketDataProvider(&data);
2555 spdy_url_request_context.socket_factory(). 2560 spdy_url_request_context.socket_factory().
2556 AddSocketDataProvider(&data2); 2561 AddSocketDataProvider(&data2);
2557 2562
2558 d.set_quit_on_redirect(true); 2563 d.set_quit_on_redirect(true);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 CreateMockRead(*resp2, 2), 2633 CreateMockRead(*resp2, 2),
2629 CreateMockRead(*body2, 3), 2634 CreateMockRead(*body2, 3),
2630 MockRead(ASYNC, 0, 0, 5) // EOF 2635 MockRead(ASYNC, 0, 0, 5) // EOF
2631 }; 2636 };
2632 OrderedSocketData data(reads, arraysize(reads), 2637 OrderedSocketData data(reads, arraysize(reads),
2633 writes, arraysize(writes)); 2638 writes, arraysize(writes));
2634 OrderedSocketData data2(reads2, arraysize(reads2), 2639 OrderedSocketData data2(reads2, arraysize(reads2),
2635 writes2, arraysize(writes2)); 2640 writes2, arraysize(writes2));
2636 2641
2637 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN 2642 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN
2638 HttpStreamFactory::set_force_spdy_over_ssl(false);
2639 HttpStreamFactory::set_force_spdy_always(true);
2640 TestDelegate d; 2643 TestDelegate d;
2641 TestDelegate d2; 2644 TestDelegate d2;
2642 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); 2645 SpdyURLRequestContext spdy_url_request_context(
2646 GetParam().protocol,
2647 false /* force_spdy_over_ssl*/,
2648 true /* force_spdy_always */);
2643 { 2649 {
2644 net::URLRequest r(GURL("http://www.google.com/"), 2650 net::URLRequest r(GURL("http://www.google.com/"),
2645 DEFAULT_PRIORITY, 2651 DEFAULT_PRIORITY,
2646 &d, 2652 &d,
2647 &spdy_url_request_context); 2653 &spdy_url_request_context);
2648 spdy_url_request_context.socket_factory(). 2654 spdy_url_request_context.socket_factory().
2649 AddSocketDataProvider(&data); 2655 AddSocketDataProvider(&data);
2650 2656
2651 r.Start(); 2657 r.Start();
2652 base::RunLoop().Run(); 2658 base::RunLoop().Run();
(...skipping 2324 matching lines...) Expand 10 before | Expand all | Expand 10 after
4977 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 4983 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4978 EXPECT_EQ("hello!", response_data); 4984 EXPECT_EQ("hello!", response_data);
4979 } 4985 }
4980 4986
4981 helper.VerifyDataConsumed(); 4987 helper.VerifyDataConsumed();
4982 } 4988 }
4983 } 4989 }
4984 4990
4985 // Test that turning SPDY on and off works properly. 4991 // Test that turning SPDY on and off works properly.
4986 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { 4992 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) {
4987 net::HttpStreamFactory::set_spdy_enabled(true); 4993 HttpStreamFactory::set_spdy_enabled(true);
4988 scoped_ptr<SpdyFrame> req( 4994 scoped_ptr<SpdyFrame> req(
4989 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 4995 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4990 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; 4996 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
4991 4997
4992 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 4998 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
4993 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 4999 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
4994 MockRead spdy_reads[] = { 5000 MockRead spdy_reads[] = {
4995 CreateMockRead(*resp), 5001 CreateMockRead(*resp),
4996 CreateMockRead(*body), 5002 CreateMockRead(*body),
4997 MockRead(ASYNC, 0, 0) // EOF 5003 MockRead(ASYNC, 0, 0) // EOF
(...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after
6573 // since we're send-stalled. 6579 // since we're send-stalled.
6574 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); 6580 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control());
6575 6581
6576 // Read in WINDOW_UPDATE or SETTINGS frame. 6582 // Read in WINDOW_UPDATE or SETTINGS frame.
6577 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8); 6583 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8);
6578 rv = callback.WaitForResult(); 6584 rv = callback.WaitForResult();
6579 helper.VerifyDataConsumed(); 6585 helper.VerifyDataConsumed();
6580 } 6586 }
6581 6587
6582 } // namespace net 6588 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698