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

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

Issue 2458793002: Server push cancellation: add PushPromiseHelper which reflects information on the push promise. (Closed)
Patch Set: sync and fix tests Created 4 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
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/tools/quic/test_tools/push_promise_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 base::TimeTicks InstantaneousReads() { 71 base::TimeTicks InstantaneousReads() {
72 return g_time_now; 72 return g_time_now;
73 } 73 }
74 74
75 class MockRequireCTDelegate : public TransportSecurityState::RequireCTDelegate { 75 class MockRequireCTDelegate : public TransportSecurityState::RequireCTDelegate {
76 public: 76 public:
77 MOCK_METHOD1(IsCTRequiredForHost, 77 MOCK_METHOD1(IsCTRequiredForHost,
78 CTRequirementLevel(const std::string& host)); 78 CTRequirementLevel(const std::string& host));
79 }; 79 };
80 80
81 class TestServerPushDelegate : public ServerPushDelegate {
82 public:
83 explicit TestServerPushDelegate() {}
84
85 void OnPush(std::unique_ptr<ServerPushHelper> push_helper) override {
86 push_helpers[push_helper->GetURL()] = std::move(push_helper);
87 }
88
89 bool CancelPush(GURL url) {
90 auto itr = push_helpers.find(url);
91 if (itr == push_helpers.end())
92 return false;
93
94 itr->second->Cancel();
95 push_helpers.erase(itr);
96 return true;
97 }
98
99 private:
100 std::map<GURL, std::unique_ptr<ServerPushHelper>> push_helpers;
101 };
102
81 } // namespace 103 } // namespace
82 104
83 class SpdySessionTest : public PlatformTest { 105 class SpdySessionTest : public PlatformTest {
84 public: 106 public:
85 // Functions used with RunResumeAfterUnstallTest(). 107 // Functions used with RunResumeAfterUnstallTest().
86 108
87 void StallSessionOnly(SpdyStream* stream) { StallSessionSend(); } 109 void StallSessionOnly(SpdyStream* stream) { StallSessionSend(); }
88 110
89 void StallStreamOnly(SpdyStream* stream) { StallStreamSend(stream); } 111 void StallStreamOnly(SpdyStream* stream) { StallStreamSend(stream); }
90 112
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 223
202 // Original socket limits. Some tests set these. Safest to always restore 224 // Original socket limits. Some tests set these. Safest to always restore
203 // them once each test has been run. 225 // them once each test has been run.
204 int old_max_group_sockets_; 226 int old_max_group_sockets_;
205 int old_max_pool_sockets_; 227 int old_max_pool_sockets_;
206 228
207 SpdyTestUtil spdy_util_; 229 SpdyTestUtil spdy_util_;
208 SpdySessionDependencies session_deps_; 230 SpdySessionDependencies session_deps_;
209 std::unique_ptr<HttpNetworkSession> http_session_; 231 std::unique_ptr<HttpNetworkSession> http_session_;
210 base::WeakPtr<SpdySession> session_; 232 base::WeakPtr<SpdySession> session_;
233 TestServerPushDelegate test_push_delegate_;
211 SpdySessionPool* spdy_session_pool_; 234 SpdySessionPool* spdy_session_pool_;
212 const GURL test_url_; 235 const GURL test_url_;
213 const url::SchemeHostPort test_server_; 236 const url::SchemeHostPort test_server_;
214 SpdySessionKey key_; 237 SpdySessionKey key_;
215 SSLSocketDataProvider ssl_; 238 SSLSocketDataProvider ssl_;
216 BoundTestNetLog log_; 239 BoundTestNetLog log_;
217 }; 240 };
218 241
219 // Try to create a SPDY session that will fail during 242 // Try to create a SPDY session that will fail during
220 // initialization. Nothing should blow up. 243 // initialization. Nothing should blow up.
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 // Cancel the third stream and run the message loop. Verify that the second 1293 // Cancel the third stream and run the message loop. Verify that the second
1271 // stream creation now completes. 1294 // stream creation now completes.
1272 stream3->Cancel(); 1295 stream3->Cancel();
1273 base::RunLoop().RunUntilIdle(); 1296 base::RunLoop().RunUntilIdle();
1274 1297
1275 EXPECT_EQ(1u, session_->num_created_streams()); 1298 EXPECT_EQ(1u, session_->num_created_streams());
1276 EXPECT_EQ(0u, session_->pending_create_stream_queue_size(MEDIUM)); 1299 EXPECT_EQ(0u, session_->pending_create_stream_queue_size(MEDIUM));
1277 EXPECT_THAT(callback2.WaitForResult(), IsOk()); 1300 EXPECT_THAT(callback2.WaitForResult(), IsOk());
1278 } 1301 }
1279 1302
1303 TEST_F(SpdySessionTest, CancelPushAfterSessionGoesAway) {
1304 base::HistogramTester histogram_tester;
1305 session_deps_.host_resolver->set_synchronous_mode(true);
1306 session_deps_.time_func = TheNearFuture;
1307
1308 SpdySerializedFrame req(
1309 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true));
1310 SpdySerializedFrame rst(
1311 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
1312 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)};
1313
1314 SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush(
1315 nullptr, 0, 2, 1, "https://www.example.org/a.dat"));
1316 SpdySerializedFrame push_a_body(spdy_util_.ConstructSpdyDataFrame(2, false));
1317 // In ascii "0" < "a". We use it to verify that we properly handle std::map
1318 // iterators inside. See http://crbug.com/443490
1319 SpdySerializedFrame push_b(spdy_util_.ConstructSpdyPush(
1320 nullptr, 0, 4, 1, "https://www.example.org/0.dat"));
1321 MockRead reads[] = {
1322 CreateMockRead(push_a, 1), CreateMockRead(push_a_body, 2),
1323 MockRead(ASYNC, ERR_IO_PENDING, 3), CreateMockRead(push_b, 4),
1324 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1325 };
1326
1327 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1328 session_deps_.socket_factory->AddSocketDataProvider(&data);
1329
1330 AddSSLSocketData();
1331
1332 CreateNetworkSession();
1333 CreateSecureSpdySession();
1334 session_->set_push_delegate(&test_push_delegate_);
1335
1336 // Process the principal request, and the first push stream request & body.
1337 base::WeakPtr<SpdyStream> spdy_stream =
1338 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1339 test_url_, MEDIUM, NetLogWithSource());
1340 test::StreamDelegateDoNothing delegate(spdy_stream);
1341 spdy_stream->SetDelegate(&delegate);
1342
1343 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1344 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
1345
1346 base::RunLoop().RunUntilIdle();
1347
1348 // Verify that there is one unclaimed push stream.
1349 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1350 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(
1351 GURL("https://www.example.org/a.dat")));
1352
1353 // Unclaimed push body consumed bytes from the session window.
1354 EXPECT_EQ(kDefaultInitialWindowSize - kUploadDataSize,
1355 session_->session_recv_window_size_);
1356 EXPECT_EQ(0, session_->session_unacked_recv_window_bytes_);
1357
1358 // Shift time to expire the push stream. Read the second HEADERS,
1359 // and verify a RST_STREAM was written.
1360 g_time_delta = base::TimeDelta::FromSeconds(301);
1361 data.Resume();
1362 base::RunLoop().RunUntilIdle();
1363
1364 // Verify that the second pushed stream evicted the first pushed stream.
1365 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1366 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(
1367 GURL("https://www.example.org/0.dat")));
1368
1369 // Verify that the session window reclaimed the evicted stream body.
1370 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_);
1371 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_);
1372 EXPECT_TRUE(session_);
1373
1374 // Read and process EOF.
1375 data.Resume();
1376 base::RunLoop().RunUntilIdle();
1377
1378 // Cancel the first push after session goes away. Verify the test doesn't
1379 // crash.
1380 EXPECT_FALSE(session_);
1381 EXPECT_TRUE(
1382 test_push_delegate_.CancelPush(GURL("https://www.example.org/a.dat")));
1383
1384 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1);
1385 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes",
1386 6, 1);
1387 }
1388
1280 TEST_F(SpdySessionTest, CancelPushAfterExpired) { 1389 TEST_F(SpdySessionTest, CancelPushAfterExpired) {
1281 base::HistogramTester histogram_tester; 1390 base::HistogramTester histogram_tester;
1282 session_deps_.host_resolver->set_synchronous_mode(true); 1391 session_deps_.host_resolver->set_synchronous_mode(true);
1283 session_deps_.time_func = TheNearFuture; 1392 session_deps_.time_func = TheNearFuture;
1284 1393
1285 SpdySerializedFrame req( 1394 SpdySerializedFrame req(
1286 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true)); 1395 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true));
1287 SpdySerializedFrame rst( 1396 SpdySerializedFrame rst(
1288 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); 1397 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
1289 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)}; 1398 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)};
(...skipping 11 matching lines...) Expand all
1301 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF 1410 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1302 }; 1411 };
1303 1412
1304 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1413 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1305 session_deps_.socket_factory->AddSocketDataProvider(&data); 1414 session_deps_.socket_factory->AddSocketDataProvider(&data);
1306 1415
1307 AddSSLSocketData(); 1416 AddSSLSocketData();
1308 1417
1309 CreateNetworkSession(); 1418 CreateNetworkSession();
1310 CreateSecureSpdySession(); 1419 CreateSecureSpdySession();
1420 session_->set_push_delegate(&test_push_delegate_);
1311 1421
1312 // Process the principal request, and the first push stream request & body. 1422 // Process the principal request, and the first push stream request & body.
1313 base::WeakPtr<SpdyStream> spdy_stream = 1423 base::WeakPtr<SpdyStream> spdy_stream =
1314 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, 1424 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1315 test_url_, MEDIUM, NetLogWithSource()); 1425 test_url_, MEDIUM, NetLogWithSource());
1316 test::StreamDelegateDoNothing delegate(spdy_stream); 1426 test::StreamDelegateDoNothing delegate(spdy_stream);
1317 spdy_stream->SetDelegate(&delegate); 1427 spdy_stream->SetDelegate(&delegate);
1318 1428
1319 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); 1429 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1320 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); 1430 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
(...skipping 15 matching lines...) Expand all
1336 g_time_delta = base::TimeDelta::FromSeconds(301); 1446 g_time_delta = base::TimeDelta::FromSeconds(301);
1337 data.Resume(); 1447 data.Resume();
1338 base::RunLoop().RunUntilIdle(); 1448 base::RunLoop().RunUntilIdle();
1339 1449
1340 // Verify that the second pushed stream evicted the first pushed stream. 1450 // Verify that the second pushed stream evicted the first pushed stream.
1341 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); 1451 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1342 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url( 1452 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(
1343 GURL("https://www.example.org/0.dat"))); 1453 GURL("https://www.example.org/0.dat")));
1344 1454
1345 // Cancel the first push after its expiration. 1455 // Cancel the first push after its expiration.
1346 session_->CancelPush(GURL("https://www.example.org/a.dat")); 1456 EXPECT_TRUE(
1457 test_push_delegate_.CancelPush(GURL("https://www.example.org/a.dat")));
1347 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); 1458 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1348 EXPECT_TRUE(session_); 1459 EXPECT_TRUE(session_);
1349 1460
1350 // Verify that the session window reclaimed the evicted stream body. 1461 // Verify that the session window reclaimed the evicted stream body.
1351 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); 1462 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_);
1352 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); 1463 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_);
1353 EXPECT_TRUE(session_); 1464 EXPECT_TRUE(session_);
1354 1465
1355 // Read and process EOF. 1466 // Read and process EOF.
1356 data.Resume(); 1467 data.Resume();
1357 base::RunLoop().RunUntilIdle(); 1468 base::RunLoop().RunUntilIdle();
1358 EXPECT_FALSE(session_); 1469 EXPECT_FALSE(session_);
1470
1359 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); 1471 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1);
1360 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", 1472 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes",
1361 6, 1); 1473 6, 1);
1362 } 1474 }
1363 1475
1364 TEST_F(SpdySessionTest, CancelPushBeforeClaimed) { 1476 TEST_F(SpdySessionTest, CancelPushBeforeClaimed) {
1365 base::HistogramTester histogram_tester; 1477 base::HistogramTester histogram_tester;
1366 session_deps_.host_resolver->set_synchronous_mode(true); 1478 session_deps_.host_resolver->set_synchronous_mode(true);
1367 session_deps_.time_func = TheNearFuture; 1479 session_deps_.time_func = TheNearFuture;
1368 1480
(...skipping 16 matching lines...) Expand all
1385 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF 1497 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1386 }; 1498 };
1387 1499
1388 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1500 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1389 session_deps_.socket_factory->AddSocketDataProvider(&data); 1501 session_deps_.socket_factory->AddSocketDataProvider(&data);
1390 1502
1391 AddSSLSocketData(); 1503 AddSSLSocketData();
1392 1504
1393 CreateNetworkSession(); 1505 CreateNetworkSession();
1394 CreateSecureSpdySession(); 1506 CreateSecureSpdySession();
1507 session_->set_push_delegate(&test_push_delegate_);
1395 1508
1396 // Process the principal request, and the first push stream request & body. 1509 // Process the principal request, and the first push stream request & body.
1397 base::WeakPtr<SpdyStream> spdy_stream = 1510 base::WeakPtr<SpdyStream> spdy_stream =
1398 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, 1511 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1399 test_url_, MEDIUM, NetLogWithSource()); 1512 test_url_, MEDIUM, NetLogWithSource());
1400 test::StreamDelegateDoNothing delegate(spdy_stream); 1513 test::StreamDelegateDoNothing delegate(spdy_stream);
1401 spdy_stream->SetDelegate(&delegate); 1514 spdy_stream->SetDelegate(&delegate);
1402 1515
1403 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); 1516 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1404 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); 1517 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
(...skipping 20 matching lines...) Expand all
1425 GURL pushed_url("https://www.example.org/0.dat"); 1538 GURL pushed_url("https://www.example.org/0.dat");
1426 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); 1539 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1427 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); 1540 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(pushed_url));
1428 1541
1429 // Verify that the session window reclaimed the evicted stream body. 1542 // Verify that the session window reclaimed the evicted stream body.
1430 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); 1543 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_);
1431 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); 1544 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_);
1432 1545
1433 EXPECT_TRUE(session_); 1546 EXPECT_TRUE(session_);
1434 // Cancel the push before it's claimed. 1547 // Cancel the push before it's claimed.
1435 session_->CancelPush(pushed_url); 1548 EXPECT_TRUE(test_push_delegate_.CancelPush(pushed_url));
1436 EXPECT_EQ(0u, session_->num_unclaimed_pushed_streams()); 1549 EXPECT_EQ(0u, session_->num_unclaimed_pushed_streams());
1437 EXPECT_EQ(0u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); 1550 EXPECT_EQ(0u, session_->count_unclaimed_pushed_streams_for_url(pushed_url));
1438 1551
1439 // Read and process EOF. 1552 // Read and process EOF.
1440 data.Resume(); 1553 data.Resume();
1441 base::RunLoop().RunUntilIdle(); 1554 base::RunLoop().RunUntilIdle();
1442 EXPECT_FALSE(session_); 1555 EXPECT_FALSE(session_);
1443 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); 1556 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1);
1444 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", 1557 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes",
1445 6, 1); 1558 6, 1);
(...skipping 4372 matching lines...) Expand 10 before | Expand all | Expand 10 after
5818 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 5931 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
5819 "spdy_pooling.pem"); 5932 "spdy_pooling.pem");
5820 ssl_info.is_issued_by_known_root = true; 5933 ssl_info.is_issued_by_known_root = true;
5821 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 5934 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
5822 5935
5823 EXPECT_TRUE(SpdySession::CanPool( 5936 EXPECT_TRUE(SpdySession::CanPool(
5824 &tss, ssl_info, "www.example.org", "mail.example.org")); 5937 &tss, ssl_info, "www.example.org", "mail.example.org"));
5825 } 5938 }
5826 5939
5827 } // namespace net 5940 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/tools/quic/test_tools/push_promise_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698