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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 // stream creation now completes. | 1271 // stream creation now completes. |
1272 stream3->Cancel(); | 1272 stream3->Cancel(); |
1273 base::RunLoop().RunUntilIdle(); | 1273 base::RunLoop().RunUntilIdle(); |
1274 | 1274 |
1275 EXPECT_EQ(1u, session_->num_created_streams()); | 1275 EXPECT_EQ(1u, session_->num_created_streams()); |
1276 EXPECT_EQ(0u, session_->pending_create_stream_queue_size(MEDIUM)); | 1276 EXPECT_EQ(0u, session_->pending_create_stream_queue_size(MEDIUM)); |
1277 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 1277 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1278 } | 1278 } |
1279 | 1279 |
1280 TEST_F(SpdySessionTest, DeleteExpiredPushStreams) { | 1280 TEST_F(SpdySessionTest, DeleteExpiredPushStreams) { |
| 1281 base::HistogramTester histogram_tester; |
1281 session_deps_.host_resolver->set_synchronous_mode(true); | 1282 session_deps_.host_resolver->set_synchronous_mode(true); |
1282 session_deps_.time_func = TheNearFuture; | 1283 session_deps_.time_func = TheNearFuture; |
1283 | 1284 |
1284 SpdySerializedFrame req( | 1285 SpdySerializedFrame req( |
1285 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true)); | 1286 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true)); |
1286 SpdySerializedFrame rst( | 1287 SpdySerializedFrame rst( |
1287 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | 1288 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
1288 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)}; | 1289 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)}; |
1289 | 1290 |
1290 SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush( | 1291 SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 | 1344 |
1344 // Verify that the session window reclaimed the evicted stream body. | 1345 // Verify that the session window reclaimed the evicted stream body. |
1345 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); | 1346 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); |
1346 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); | 1347 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); |
1347 | 1348 |
1348 // Read and process EOF. | 1349 // Read and process EOF. |
1349 EXPECT_TRUE(session_); | 1350 EXPECT_TRUE(session_); |
1350 data.Resume(); | 1351 data.Resume(); |
1351 base::RunLoop().RunUntilIdle(); | 1352 base::RunLoop().RunUntilIdle(); |
1352 EXPECT_FALSE(session_); | 1353 EXPECT_FALSE(session_); |
| 1354 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); |
| 1355 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", |
| 1356 6, 1); |
| 1357 } |
| 1358 |
| 1359 TEST_F(SpdySessionTest, MetricsCollectionOnPushStreams) { |
| 1360 base::HistogramTester histogram_tester; |
| 1361 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1362 session_deps_.time_func = TheNearFuture; |
| 1363 |
| 1364 SpdySerializedFrame req( |
| 1365 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true)); |
| 1366 SpdySerializedFrame rst( |
| 1367 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
| 1368 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)}; |
| 1369 |
| 1370 SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush( |
| 1371 nullptr, 0, 2, 1, "https://www.example.org/a.dat")); |
| 1372 SpdySerializedFrame push_a_body(spdy_util_.ConstructSpdyDataFrame(2, false)); |
| 1373 // In ascii "0" < "a". We use it to verify that we properly handle std::map |
| 1374 // iterators inside. See http://crbug.com/443490 |
| 1375 SpdySerializedFrame push_b(spdy_util_.ConstructSpdyPush( |
| 1376 nullptr, 0, 4, 1, "https://www.example.org/0.dat")); |
| 1377 SpdySerializedFrame push_c(spdy_util_.ConstructSpdyPush( |
| 1378 nullptr, 0, 6, 1, "https://www.example.org/1.dat")); |
| 1379 SpdySerializedFrame push_c_body(spdy_util_.ConstructSpdyDataFrame(6, false)); |
| 1380 |
| 1381 MockRead reads[] = { |
| 1382 CreateMockRead(push_a, 1), |
| 1383 CreateMockRead(push_a_body, 2), |
| 1384 MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 1385 CreateMockRead(push_b, 4), |
| 1386 MockRead(ASYNC, ERR_IO_PENDING, 6), |
| 1387 CreateMockRead(push_c, 7), |
| 1388 CreateMockRead(push_c_body, 8), |
| 1389 MockRead(ASYNC, ERR_IO_PENDING, 9), |
| 1390 MockRead(ASYNC, 0, 10) // EOF |
| 1391 }; |
| 1392 |
| 1393 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1394 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1395 |
| 1396 AddSSLSocketData(); |
| 1397 |
| 1398 CreateNetworkSession(); |
| 1399 CreateSecureSpdySession(); |
| 1400 |
| 1401 // Process the principal request, and the first push stream request & body. |
| 1402 base::WeakPtr<SpdyStream> spdy_stream = |
| 1403 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, |
| 1404 test_url_, MEDIUM, NetLogWithSource()); |
| 1405 test::StreamDelegateDoNothing delegate(spdy_stream); |
| 1406 spdy_stream->SetDelegate(&delegate); |
| 1407 |
| 1408 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
| 1409 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
| 1410 |
| 1411 base::RunLoop().RunUntilIdle(); |
| 1412 |
| 1413 // Verify that there is one unclaimed push stream. |
| 1414 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); |
| 1415 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url( |
| 1416 GURL("https://www.example.org/a.dat"))); |
| 1417 |
| 1418 // Unclaimed push body consumed bytes from the session window. |
| 1419 EXPECT_EQ(kDefaultInitialWindowSize - kUploadDataSize, |
| 1420 session_->session_recv_window_size_); |
| 1421 EXPECT_EQ(0, session_->session_unacked_recv_window_bytes_); |
| 1422 |
| 1423 // Shift time to expire the push stream. Read the second HEADERS, |
| 1424 // and verify a RST_STREAM was written. |
| 1425 g_time_delta = base::TimeDelta::FromSeconds(300); |
| 1426 data.Resume(); |
| 1427 base::RunLoop().RunUntilIdle(); |
| 1428 |
| 1429 // Verify that the second pushed stream evicted the first pushed stream. |
| 1430 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); |
| 1431 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url( |
| 1432 GURL("https://www.example.org/0.dat"))); |
| 1433 |
| 1434 // Verify that the session window reclaimed the evicted stream body. |
| 1435 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); |
| 1436 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); |
| 1437 |
| 1438 // Read the third PUSH, this will not be expired when the test tear down. |
| 1439 data.Resume(); |
| 1440 base::RunLoop().RunUntilIdle(); |
| 1441 |
| 1442 EXPECT_EQ(2u, session_->num_unclaimed_pushed_streams()); |
| 1443 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url( |
| 1444 GURL("https://www.example.org/1.dat"))); |
| 1445 |
| 1446 // Read and process EOF. |
| 1447 EXPECT_TRUE(session_); |
| 1448 data.Resume(); |
| 1449 base::RunLoop().RunUntilIdle(); |
| 1450 EXPECT_FALSE(session_); |
| 1451 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 12, 1); |
| 1452 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", |
| 1453 6, 1); |
1353 } | 1454 } |
1354 | 1455 |
1355 TEST_F(SpdySessionTest, FailedPing) { | 1456 TEST_F(SpdySessionTest, FailedPing) { |
1356 session_deps_.host_resolver->set_synchronous_mode(true); | 1457 session_deps_.host_resolver->set_synchronous_mode(true); |
1357 | 1458 |
1358 MockRead reads[] = { | 1459 MockRead reads[] = { |
1359 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 1460 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
1360 }; | 1461 }; |
1361 SpdySerializedFrame write_ping(spdy_util_.ConstructSpdyPing(1, false)); | 1462 SpdySerializedFrame write_ping(spdy_util_.ConstructSpdyPing(1, false)); |
1362 SpdySerializedFrame goaway( | 1463 SpdySerializedFrame goaway( |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 spdy_stream->SetDelegate(&delegate); | 1844 spdy_stream->SetDelegate(&delegate); |
1744 | 1845 |
1745 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); | 1846 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
1746 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 1847 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
1747 | 1848 |
1748 // Write request headers & capture resulting histogram update. | 1849 // Write request headers & capture resulting histogram update. |
1749 base::HistogramTester histogram_tester; | 1850 base::HistogramTester histogram_tester; |
1750 | 1851 |
1751 base::RunLoop().RunUntilIdle(); | 1852 base::RunLoop().RunUntilIdle(); |
1752 // Regression test of compression performance under the request fixture. | 1853 // Regression test of compression performance under the request fixture. |
1753 histogram_tester.ExpectBucketCount( | 1854 histogram_tester.ExpectBucketCount("Net.SpdySynStreamCompressionPercentage", |
1754 "Net.SpdySynStreamCompressionPercentage", 81, 1); | 1855 81, 1); |
1755 | 1856 |
1756 // Read and process EOF. | 1857 // Read and process EOF. |
1757 EXPECT_TRUE(session_); | 1858 EXPECT_TRUE(session_); |
1758 data.Resume(); | 1859 data.Resume(); |
1759 base::RunLoop().RunUntilIdle(); | 1860 base::RunLoop().RunUntilIdle(); |
1760 EXPECT_FALSE(session_); | 1861 EXPECT_FALSE(session_); |
1761 } | 1862 } |
1762 | 1863 |
1763 // Queue up a low-priority HEADERS followed by a high-priority | 1864 // Queue up a low-priority HEADERS followed by a high-priority |
1764 // one. The high priority one should still send first and receive | 1865 // one. The high priority one should still send first and receive |
(...skipping 3784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5549 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5650 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
5550 "spdy_pooling.pem"); | 5651 "spdy_pooling.pem"); |
5551 ssl_info.is_issued_by_known_root = true; | 5652 ssl_info.is_issued_by_known_root = true; |
5552 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5653 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
5553 | 5654 |
5554 EXPECT_TRUE(SpdySession::CanPool( | 5655 EXPECT_TRUE(SpdySession::CanPool( |
5555 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5656 &tss, ssl_info, "www.example.org", "mail.example.org")); |
5556 } | 5657 } |
5557 | 5658 |
5558 } // namespace net | 5659 } // namespace net |
OLD | NEW |