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_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 UnstallStreamSend(stream, delta_window_size); | 117 UnstallStreamSend(stream, delta_window_size); |
118 UnstallSessionSend(delta_window_size); | 118 UnstallSessionSend(delta_window_size); |
119 } | 119 } |
120 | 120 |
121 protected: | 121 protected: |
122 SpdySessionTest() | 122 SpdySessionTest() |
123 : old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( | 123 : old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
124 HttpNetworkSession::NORMAL_SOCKET_POOL)), | 124 HttpNetworkSession::NORMAL_SOCKET_POOL)), |
125 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( | 125 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
126 HttpNetworkSession::NORMAL_SOCKET_POOL)), | 126 HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 127 test_push_delegate_(nullptr), |
127 spdy_session_pool_(nullptr), | 128 spdy_session_pool_(nullptr), |
128 test_url_(kDefaultUrl), | 129 test_url_(kDefaultUrl), |
129 test_server_(test_url_), | 130 test_server_(test_url_), |
130 key_(HostPortPair::FromURL(test_url_), | 131 key_(HostPortPair::FromURL(test_url_), |
131 ProxyServer::Direct(), | 132 ProxyServer::Direct(), |
132 PRIVACY_MODE_DISABLED), | 133 PRIVACY_MODE_DISABLED), |
133 ssl_(SYNCHRONOUS, OK) {} | 134 ssl_(SYNCHRONOUS, OK) {} |
134 | 135 |
135 ~SpdySessionTest() override { | 136 ~SpdySessionTest() override { |
136 // Important to restore the per-pool limit first, since the pool limit must | 137 // Important to restore the per-pool limit first, since the pool limit must |
137 // always be greater than group limit, and the tests reduce both limits. | 138 // always be greater than group limit, and the tests reduce both limits. |
138 ClientSocketPoolManager::set_max_sockets_per_pool( | 139 ClientSocketPoolManager::set_max_sockets_per_pool( |
139 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); | 140 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
140 ClientSocketPoolManager::set_max_sockets_per_group( | 141 ClientSocketPoolManager::set_max_sockets_per_group( |
141 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); | 142 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
142 } | 143 } |
143 | 144 |
144 void SetUp() override { | 145 void SetUp() override { |
145 g_time_delta = base::TimeDelta(); | 146 g_time_delta = base::TimeDelta(); |
146 g_time_now = base::TimeTicks::Now(); | 147 g_time_now = base::TimeTicks::Now(); |
147 session_deps_.net_log = log_.bound().net_log(); | 148 session_deps_.net_log = log_.bound().net_log(); |
148 } | 149 } |
149 | 150 |
150 void CreateNetworkSession() { | 151 void CreateNetworkSession() { |
151 DCHECK(!http_session_); | 152 DCHECK(!http_session_); |
152 DCHECK(!spdy_session_pool_); | 153 DCHECK(!spdy_session_pool_); |
153 http_session_ = | 154 http_session_ = |
154 SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 155 SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 156 std::unique_ptr<TestServerPushDelegate> test_push_delegate( |
| 157 new TestServerPushDelegate()); |
| 158 test_push_delegate_ = test_push_delegate.get(); |
| 159 http_session_->SetServerPushDelegate(std::move(test_push_delegate)); |
155 spdy_session_pool_ = http_session_->spdy_session_pool(); | 160 spdy_session_pool_ = http_session_->spdy_session_pool(); |
156 } | 161 } |
157 | 162 |
158 void CreateInsecureSpdySession() { | 163 void CreateInsecureSpdySession() { |
159 DCHECK(!session_); | 164 DCHECK(!session_); |
160 session_ = ::net::CreateInsecureSpdySession(http_session_.get(), key_, | 165 session_ = ::net::CreateInsecureSpdySession(http_session_.get(), key_, |
161 log_.bound()); | 166 log_.bound()); |
162 } | 167 } |
163 | 168 |
164 void AddSSLSocketData() { | 169 void AddSSLSocketData() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 208 |
204 // Original socket limits. Some tests set these. Safest to always restore | 209 // Original socket limits. Some tests set these. Safest to always restore |
205 // them once each test has been run. | 210 // them once each test has been run. |
206 int old_max_group_sockets_; | 211 int old_max_group_sockets_; |
207 int old_max_pool_sockets_; | 212 int old_max_pool_sockets_; |
208 | 213 |
209 SpdyTestUtil spdy_util_; | 214 SpdyTestUtil spdy_util_; |
210 SpdySessionDependencies session_deps_; | 215 SpdySessionDependencies session_deps_; |
211 std::unique_ptr<HttpNetworkSession> http_session_; | 216 std::unique_ptr<HttpNetworkSession> http_session_; |
212 base::WeakPtr<SpdySession> session_; | 217 base::WeakPtr<SpdySession> session_; |
213 TestServerPushDelegate test_push_delegate_; | 218 TestServerPushDelegate* test_push_delegate_; |
214 SpdySessionPool* spdy_session_pool_; | 219 SpdySessionPool* spdy_session_pool_; |
215 const GURL test_url_; | 220 const GURL test_url_; |
216 const url::SchemeHostPort test_server_; | 221 const url::SchemeHostPort test_server_; |
217 SpdySessionKey key_; | 222 SpdySessionKey key_; |
218 SSLSocketDataProvider ssl_; | 223 SSLSocketDataProvider ssl_; |
219 BoundTestNetLog log_; | 224 BoundTestNetLog log_; |
220 }; | 225 }; |
221 | 226 |
222 // Try to create a SPDY session that will fail during | 227 // Try to create a SPDY session that will fail during |
223 // initialization. Nothing should blow up. | 228 // initialization. Nothing should blow up. |
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF | 1309 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF |
1305 }; | 1310 }; |
1306 | 1311 |
1307 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 1312 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
1308 session_deps_.socket_factory->AddSocketDataProvider(&data); | 1313 session_deps_.socket_factory->AddSocketDataProvider(&data); |
1309 | 1314 |
1310 AddSSLSocketData(); | 1315 AddSSLSocketData(); |
1311 | 1316 |
1312 CreateNetworkSession(); | 1317 CreateNetworkSession(); |
1313 CreateSecureSpdySession(); | 1318 CreateSecureSpdySession(); |
1314 session_->set_push_delegate(&test_push_delegate_); | |
1315 | 1319 |
1316 // Process the principal request, and the first push stream request & body. | 1320 // Process the principal request, and the first push stream request & body. |
1317 base::WeakPtr<SpdyStream> spdy_stream = | 1321 base::WeakPtr<SpdyStream> spdy_stream = |
1318 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, | 1322 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, |
1319 test_url_, MEDIUM, NetLogWithSource()); | 1323 test_url_, MEDIUM, NetLogWithSource()); |
1320 test::StreamDelegateDoNothing delegate(spdy_stream); | 1324 test::StreamDelegateDoNothing delegate(spdy_stream); |
1321 spdy_stream->SetDelegate(&delegate); | 1325 spdy_stream->SetDelegate(&delegate); |
1322 | 1326 |
1323 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); | 1327 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
1324 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 1328 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
(...skipping 27 matching lines...) Expand all Loading... |
1352 EXPECT_TRUE(session_); | 1356 EXPECT_TRUE(session_); |
1353 | 1357 |
1354 // Read and process EOF. | 1358 // Read and process EOF. |
1355 data.Resume(); | 1359 data.Resume(); |
1356 base::RunLoop().RunUntilIdle(); | 1360 base::RunLoop().RunUntilIdle(); |
1357 | 1361 |
1358 // Cancel the first push after session goes away. Verify the test doesn't | 1362 // Cancel the first push after session goes away. Verify the test doesn't |
1359 // crash. | 1363 // crash. |
1360 EXPECT_FALSE(session_); | 1364 EXPECT_FALSE(session_); |
1361 EXPECT_TRUE( | 1365 EXPECT_TRUE( |
1362 test_push_delegate_.CancelPush(GURL("https://www.example.org/a.dat"))); | 1366 test_push_delegate_->CancelPush(GURL("https://www.example.org/a.dat"))); |
1363 | 1367 |
1364 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); | 1368 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); |
1365 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", | 1369 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", |
1366 6, 1); | 1370 6, 1); |
1367 } | 1371 } |
1368 | 1372 |
1369 TEST_F(SpdySessionTest, CancelPushAfterExpired) { | 1373 TEST_F(SpdySessionTest, CancelPushAfterExpired) { |
1370 base::HistogramTester histogram_tester; | 1374 base::HistogramTester histogram_tester; |
1371 session_deps_.host_resolver->set_synchronous_mode(true); | 1375 session_deps_.host_resolver->set_synchronous_mode(true); |
1372 session_deps_.time_func = TheNearFuture; | 1376 session_deps_.time_func = TheNearFuture; |
(...skipping 17 matching lines...) Expand all Loading... |
1390 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF | 1394 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF |
1391 }; | 1395 }; |
1392 | 1396 |
1393 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 1397 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
1394 session_deps_.socket_factory->AddSocketDataProvider(&data); | 1398 session_deps_.socket_factory->AddSocketDataProvider(&data); |
1395 | 1399 |
1396 AddSSLSocketData(); | 1400 AddSSLSocketData(); |
1397 | 1401 |
1398 CreateNetworkSession(); | 1402 CreateNetworkSession(); |
1399 CreateSecureSpdySession(); | 1403 CreateSecureSpdySession(); |
1400 session_->set_push_delegate(&test_push_delegate_); | |
1401 | 1404 |
1402 // Process the principal request, and the first push stream request & body. | 1405 // Process the principal request, and the first push stream request & body. |
1403 base::WeakPtr<SpdyStream> spdy_stream = | 1406 base::WeakPtr<SpdyStream> spdy_stream = |
1404 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, | 1407 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, |
1405 test_url_, MEDIUM, NetLogWithSource()); | 1408 test_url_, MEDIUM, NetLogWithSource()); |
1406 test::StreamDelegateDoNothing delegate(spdy_stream); | 1409 test::StreamDelegateDoNothing delegate(spdy_stream); |
1407 spdy_stream->SetDelegate(&delegate); | 1410 spdy_stream->SetDelegate(&delegate); |
1408 | 1411 |
1409 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); | 1412 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
1410 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 1413 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
(...skipping 16 matching lines...) Expand all Loading... |
1427 data.Resume(); | 1430 data.Resume(); |
1428 base::RunLoop().RunUntilIdle(); | 1431 base::RunLoop().RunUntilIdle(); |
1429 | 1432 |
1430 // Verify that the second pushed stream evicted the first pushed stream. | 1433 // Verify that the second pushed stream evicted the first pushed stream. |
1431 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); | 1434 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); |
1432 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url( | 1435 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url( |
1433 GURL("https://www.example.org/0.dat"))); | 1436 GURL("https://www.example.org/0.dat"))); |
1434 | 1437 |
1435 // Cancel the first push after its expiration. | 1438 // Cancel the first push after its expiration. |
1436 EXPECT_TRUE( | 1439 EXPECT_TRUE( |
1437 test_push_delegate_.CancelPush(GURL("https://www.example.org/a.dat"))); | 1440 test_push_delegate_->CancelPush(GURL("https://www.example.org/a.dat"))); |
1438 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); | 1441 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); |
1439 EXPECT_TRUE(session_); | 1442 EXPECT_TRUE(session_); |
1440 | 1443 |
1441 // Verify that the session window reclaimed the evicted stream body. | 1444 // Verify that the session window reclaimed the evicted stream body. |
1442 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); | 1445 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); |
1443 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); | 1446 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); |
1444 EXPECT_TRUE(session_); | 1447 EXPECT_TRUE(session_); |
1445 | 1448 |
1446 // Read and process EOF. | 1449 // Read and process EOF. |
1447 data.Resume(); | 1450 data.Resume(); |
(...skipping 29 matching lines...) Expand all Loading... |
1477 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF | 1480 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF |
1478 }; | 1481 }; |
1479 | 1482 |
1480 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 1483 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
1481 session_deps_.socket_factory->AddSocketDataProvider(&data); | 1484 session_deps_.socket_factory->AddSocketDataProvider(&data); |
1482 | 1485 |
1483 AddSSLSocketData(); | 1486 AddSSLSocketData(); |
1484 | 1487 |
1485 CreateNetworkSession(); | 1488 CreateNetworkSession(); |
1486 CreateSecureSpdySession(); | 1489 CreateSecureSpdySession(); |
1487 session_->set_push_delegate(&test_push_delegate_); | |
1488 | 1490 |
1489 // Process the principal request, and the first push stream request & body. | 1491 // Process the principal request, and the first push stream request & body. |
1490 base::WeakPtr<SpdyStream> spdy_stream = | 1492 base::WeakPtr<SpdyStream> spdy_stream = |
1491 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, | 1493 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, |
1492 test_url_, MEDIUM, NetLogWithSource()); | 1494 test_url_, MEDIUM, NetLogWithSource()); |
1493 test::StreamDelegateDoNothing delegate(spdy_stream); | 1495 test::StreamDelegateDoNothing delegate(spdy_stream); |
1494 spdy_stream->SetDelegate(&delegate); | 1496 spdy_stream->SetDelegate(&delegate); |
1495 | 1497 |
1496 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); | 1498 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
1497 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 1499 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
(...skipping 20 matching lines...) Expand all Loading... |
1518 GURL pushed_url("https://www.example.org/0.dat"); | 1520 GURL pushed_url("https://www.example.org/0.dat"); |
1519 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); | 1521 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); |
1520 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); | 1522 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); |
1521 | 1523 |
1522 // Verify that the session window reclaimed the evicted stream body. | 1524 // Verify that the session window reclaimed the evicted stream body. |
1523 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); | 1525 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); |
1524 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); | 1526 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); |
1525 | 1527 |
1526 EXPECT_TRUE(session_); | 1528 EXPECT_TRUE(session_); |
1527 // Cancel the push before it's claimed. | 1529 // Cancel the push before it's claimed. |
1528 EXPECT_TRUE(test_push_delegate_.CancelPush(pushed_url)); | 1530 EXPECT_TRUE(test_push_delegate_->CancelPush(pushed_url)); |
1529 EXPECT_EQ(0u, session_->num_unclaimed_pushed_streams()); | 1531 EXPECT_EQ(0u, session_->num_unclaimed_pushed_streams()); |
1530 EXPECT_EQ(0u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); | 1532 EXPECT_EQ(0u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); |
1531 | 1533 |
1532 // Read and process EOF. | 1534 // Read and process EOF. |
1533 data.Resume(); | 1535 data.Resume(); |
1534 base::RunLoop().RunUntilIdle(); | 1536 base::RunLoop().RunUntilIdle(); |
1535 EXPECT_FALSE(session_); | 1537 EXPECT_FALSE(session_); |
1536 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); | 1538 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); |
1537 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", | 1539 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", |
1538 6, 1); | 1540 6, 1); |
(...skipping 4343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5882 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5884 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
5883 "spdy_pooling.pem"); | 5885 "spdy_pooling.pem"); |
5884 ssl_info.is_issued_by_known_root = true; | 5886 ssl_info.is_issued_by_known_root = true; |
5885 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5887 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
5886 | 5888 |
5887 EXPECT_TRUE(SpdySession::CanPool( | 5889 EXPECT_TRUE(SpdySession::CanPool( |
5888 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5890 &tss, ssl_info, "www.example.org", "mail.example.org")); |
5889 } | 5891 } |
5890 | 5892 |
5891 } // namespace net | 5893 } // namespace net |
OLD | NEW |