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

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

Issue 1411383005: Initial implementation of RequestPriority-based HTTP/2 dependencies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated tests. Created 5 years, 1 month 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
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 "net/spdy/spdy_proxy_client_socket.h" 5 #include "net/spdy/spdy_proxy_client_socket.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
(...skipping 15 matching lines...) Expand all
26 #include "net/spdy/spdy_protocol.h" 26 #include "net/spdy/spdy_protocol.h"
27 #include "net/spdy/spdy_session_pool.h" 27 #include "net/spdy/spdy_session_pool.h"
28 #include "net/spdy/spdy_test_util_common.h" 28 #include "net/spdy/spdy_test_util_common.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "testing/platform_test.h" 30 #include "testing/platform_test.h"
31 31
32 //----------------------------------------------------------------------------- 32 //-----------------------------------------------------------------------------
33 33
34 namespace { 34 namespace {
35 35
36 enum TestCase {
37 // Test using the SPDY 3.1 protocol.
38 kTestCaseSPDY31,
39
40 // Test using the HTTP2 protocol, without specifying a stream
41 // dependency based on the RequestPriority.
42 kTestCaseHTTP2NoPriorityDependencies,
43
44 // Test using the HTTP2 protocol, specifying a stream
45 // dependency based on the RequestPriority.
46 kTestCaseHTTP2PriorityDependencies
47 };
48
36 static const char kRequestUrl[] = "https://www.google.com/"; 49 static const char kRequestUrl[] = "https://www.google.com/";
37 static const char kOriginHost[] = "www.google.com"; 50 static const char kOriginHost[] = "www.google.com";
38 static const int kOriginPort = 443; 51 static const int kOriginPort = 443;
39 static const char kOriginHostPort[] = "www.google.com:443"; 52 static const char kOriginHostPort[] = "www.google.com:443";
40 static const char kProxyUrl[] = "https://myproxy:6121/"; 53 static const char kProxyUrl[] = "https://myproxy:6121/";
41 static const char kProxyHost[] = "myproxy"; 54 static const char kProxyHost[] = "myproxy";
42 static const int kProxyPort = 6121; 55 static const int kProxyPort = 6121;
43 static const char kUserAgent[] = "Mozilla/1.0"; 56 static const char kUserAgent[] = "Mozilla/1.0";
44 57
45 static const int kStreamId = 1; 58 static const int kStreamId = 1;
46 59
47 static const char kMsg1[] = "\0hello!\xff"; 60 static const char kMsg1[] = "\0hello!\xff";
48 static const int kLen1 = 8; 61 static const int kLen1 = 8;
49 static const char kMsg2[] = "\0a2345678\0"; 62 static const char kMsg2[] = "\0a2345678\0";
50 static const int kLen2 = 10; 63 static const int kLen2 = 10;
51 static const char kMsg3[] = "bye!"; 64 static const char kMsg3[] = "bye!";
52 static const int kLen3 = 4; 65 static const int kLen3 = 4;
53 static const char kMsg33[] = "bye!bye!"; 66 static const char kMsg33[] = "bye!bye!";
54 static const int kLen33 = kLen3 + kLen3; 67 static const int kLen33 = kLen3 + kLen3;
55 static const char kMsg333[] = "bye!bye!bye!"; 68 static const char kMsg333[] = "bye!bye!bye!";
56 static const int kLen333 = kLen3 + kLen3 + kLen3; 69 static const int kLen333 = kLen3 + kLen3 + kLen3;
57 70
58 static const char kRedirectUrl[] = "https://example.com/"; 71 static const char kRedirectUrl[] = "https://example.com/";
59 72
60 } // anonymous namespace 73 } // anonymous namespace
61 74
62 namespace net { 75 namespace net {
63 76
64 class SpdyProxyClientSocketTest 77 class SpdyProxyClientSocketTest : public PlatformTest,
65 : public PlatformTest, 78 public testing::WithParamInterface<TestCase> {
66 public testing::WithParamInterface<NextProto> {
67 public: 79 public:
68 SpdyProxyClientSocketTest(); 80 SpdyProxyClientSocketTest();
81 ~SpdyProxyClientSocketTest();
69 82
70 void TearDown() override; 83 void TearDown() override;
71 84
72 protected: 85 protected:
86 NextProto GetProtocol() const;
87 bool GetDependenciesFromPriority() const;
88
73 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, 89 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes,
74 size_t writes_count); 90 size_t writes_count);
75 void PopulateConnectRequestIR(SpdyHeaderBlock* syn_ir); 91 void PopulateConnectRequestIR(SpdyHeaderBlock* syn_ir);
76 void PopulateConnectReplyIR(SpdyHeaderBlock* block, const char* status); 92 void PopulateConnectReplyIR(SpdyHeaderBlock* block, const char* status);
77 SpdyFrame* ConstructConnectRequestFrame(); 93 SpdyFrame* ConstructConnectRequestFrame();
78 SpdyFrame* ConstructConnectAuthRequestFrame(); 94 SpdyFrame* ConstructConnectAuthRequestFrame();
79 SpdyFrame* ConstructConnectReplyFrame(); 95 SpdyFrame* ConstructConnectReplyFrame();
80 SpdyFrame* ConstructConnectAuthReplyFrame(); 96 SpdyFrame* ConstructConnectAuthReplyFrame();
81 SpdyFrame* ConstructConnectRedirectReplyFrame(); 97 SpdyFrame* ConstructConnectRedirectReplyFrame();
82 SpdyFrame* ConstructConnectErrorReplyFrame(); 98 SpdyFrame* ConstructConnectErrorReplyFrame();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 std::string user_agent_; 149 std::string user_agent_;
134 GURL url_; 150 GURL url_;
135 HostPortPair proxy_host_port_; 151 HostPortPair proxy_host_port_;
136 HostPortPair endpoint_host_port_pair_; 152 HostPortPair endpoint_host_port_pair_;
137 ProxyServer proxy_; 153 ProxyServer proxy_;
138 SpdySessionKey endpoint_spdy_session_key_; 154 SpdySessionKey endpoint_spdy_session_key_;
139 155
140 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest); 156 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocketTest);
141 }; 157 };
142 158
143 INSTANTIATE_TEST_CASE_P(NextProto, 159 INSTANTIATE_TEST_CASE_P(TestCase,
144 SpdyProxyClientSocketTest, 160 SpdyProxyClientSocketTest,
145 testing::Values(kProtoSPDY31, 161 testing::Values(kTestCaseSPDY31,
146 kProtoHTTP2)); 162 kTestCaseHTTP2NoPriorityDependencies,
163 kTestCaseHTTP2PriorityDependencies));
147 164
148 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest() 165 SpdyProxyClientSocketTest::SpdyProxyClientSocketTest()
149 : spdy_util_(GetParam()), 166 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()),
150 read_buf_(NULL), 167 read_buf_(NULL),
151 session_deps_(GetParam()), 168 session_deps_(GetProtocol()),
152 connect_data_(SYNCHRONOUS, OK), 169 connect_data_(SYNCHRONOUS, OK),
153 framer_(spdy_util_.spdy_version(), false), 170 framer_(spdy_util_.spdy_version(), false),
154 user_agent_(kUserAgent), 171 user_agent_(kUserAgent),
155 url_(kRequestUrl), 172 url_(kRequestUrl),
156 proxy_host_port_(kProxyHost, kProxyPort), 173 proxy_host_port_(kProxyHost, kProxyPort),
157 endpoint_host_port_pair_(kOriginHost, kOriginPort), 174 endpoint_host_port_pair_(kOriginHost, kOriginPort),
158 proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_), 175 proxy_(ProxyServer::SCHEME_HTTPS, proxy_host_port_),
159 endpoint_spdy_session_key_(endpoint_host_port_pair_, 176 endpoint_spdy_session_key_(endpoint_host_port_pair_,
160 proxy_, 177 proxy_,
161 PRIVACY_MODE_DISABLED) { 178 PRIVACY_MODE_DISABLED) {
162 session_deps_.net_log = net_log_.bound().net_log(); 179 session_deps_.net_log = net_log_.bound().net_log();
180 SpdySession::SetPriorityDependencyDefaultForTesting(
181 GetDependenciesFromPriority());
182 }
183
184 SpdyProxyClientSocketTest::~SpdyProxyClientSocketTest() {
185 SpdySession::SetPriorityDependencyDefaultForTesting(false);
163 } 186 }
164 187
165 void SpdyProxyClientSocketTest::TearDown() { 188 void SpdyProxyClientSocketTest::TearDown() {
166 if (session_.get() != NULL) 189 if (session_.get() != NULL)
167 session_->spdy_session_pool()->CloseAllSessions(); 190 session_->spdy_session_pool()->CloseAllSessions();
168 191
169 // Empty the current queue. 192 // Empty the current queue.
170 base::MessageLoop::current()->RunUntilIdle(); 193 base::MessageLoop::current()->RunUntilIdle();
171 PlatformTest::TearDown(); 194 PlatformTest::TearDown();
172 } 195 }
173 196
197 NextProto SpdyProxyClientSocketTest::GetProtocol() const {
198 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2;
199 }
200
201 bool SpdyProxyClientSocketTest::GetDependenciesFromPriority() const {
202 return GetParam() == kTestCaseHTTP2PriorityDependencies;
203 }
204
174 void SpdyProxyClientSocketTest::Initialize(MockRead* reads, 205 void SpdyProxyClientSocketTest::Initialize(MockRead* reads,
175 size_t reads_count, 206 size_t reads_count,
176 MockWrite* writes, 207 MockWrite* writes,
177 size_t writes_count) { 208 size_t writes_count) {
178 data_.reset(new DeterministicSocketData(reads, reads_count, 209 data_.reset(new DeterministicSocketData(reads, reads_count,
179 writes, writes_count)); 210 writes, writes_count));
180 data_->set_connect_data(connect_data_); 211 data_->set_connect_data(connect_data_);
181 data_->SetStop(2); 212 data_->SetStop(2);
182 213
183 session_deps_.deterministic_socket_factory->AddSocketDataProvider( 214 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 1407
1377 EXPECT_FALSE(sock_.get()); 1408 EXPECT_FALSE(sock_.get());
1378 EXPECT_TRUE(read_callback.have_result()); 1409 EXPECT_TRUE(read_callback.have_result());
1379 EXPECT_FALSE(write_callback_.have_result()); 1410 EXPECT_FALSE(write_callback_.have_result());
1380 1411
1381 // Let the RST_STREAM write while |rst| is in-scope. 1412 // Let the RST_STREAM write while |rst| is in-scope.
1382 base::MessageLoop::current()->RunUntilIdle(); 1413 base::MessageLoop::current()->RunUntilIdle();
1383 } 1414 }
1384 1415
1385 } // namespace net 1416 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698