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

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

Issue 2456713002: Server push cancellation: add methods in session layer to cancel push given the pushed url. Not in … (Closed)
Patch Set: address rch's comments 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') | no next file » | 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 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 // Cancel the third stream and run the message loop. Verify that the second 1270 // Cancel the third stream and run the message loop. Verify that the second
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, CancelPushAfterExpired) {
1281 base::HistogramTester histogram_tester;
1282 session_deps_.host_resolver->set_synchronous_mode(true);
1283 session_deps_.time_func = TheNearFuture;
1284
1285 SpdySerializedFrame req(
1286 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true));
1287 SpdySerializedFrame rst(
1288 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
1289 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)};
1290
1291 SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush(
1292 nullptr, 0, 2, 1, "https://www.example.org/a.dat"));
1293 SpdySerializedFrame push_a_body(spdy_util_.ConstructSpdyDataFrame(2, false));
1294 // In ascii "0" < "a". We use it to verify that we properly handle std::map
1295 // iterators inside. See http://crbug.com/443490
1296 SpdySerializedFrame push_b(spdy_util_.ConstructSpdyPush(
1297 nullptr, 0, 4, 1, "https://www.example.org/0.dat"));
1298 MockRead reads[] = {
1299 CreateMockRead(push_a, 1), CreateMockRead(push_a_body, 2),
1300 MockRead(ASYNC, ERR_IO_PENDING, 3), CreateMockRead(push_b, 4),
1301 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1302 };
1303
1304 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1305 session_deps_.socket_factory->AddSocketDataProvider(&data);
1306
1307 AddSSLSocketData();
1308
1309 CreateNetworkSession();
1310 CreateSecureSpdySession();
1311
1312 // Process the principal request, and the first push stream request & body.
1313 base::WeakPtr<SpdyStream> spdy_stream =
1314 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1315 test_url_, MEDIUM, NetLogWithSource());
1316 test::StreamDelegateDoNothing delegate(spdy_stream);
1317 spdy_stream->SetDelegate(&delegate);
1318
1319 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1320 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
1321
1322 base::RunLoop().RunUntilIdle();
1323
1324 // Verify that there is one unclaimed push stream.
1325 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1326 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(
1327 GURL("https://www.example.org/a.dat")));
1328
1329 // Unclaimed push body consumed bytes from the session window.
1330 EXPECT_EQ(kDefaultInitialWindowSize - kUploadDataSize,
1331 session_->session_recv_window_size_);
1332 EXPECT_EQ(0, session_->session_unacked_recv_window_bytes_);
1333
1334 // Shift time to expire the push stream. Read the second HEADERS,
1335 // and verify a RST_STREAM was written.
1336 g_time_delta = base::TimeDelta::FromSeconds(301);
1337 data.Resume();
1338 base::RunLoop().RunUntilIdle();
1339
1340 // Verify that the second pushed stream evicted the first pushed stream.
1341 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1342 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(
1343 GURL("https://www.example.org/0.dat")));
1344
1345 // Cancel the first push after its expiration.
1346 session_->CancelPush(GURL("https://www.example.org/a.dat"));
1347 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1348 EXPECT_TRUE(session_);
1349
1350 // Verify that the session window reclaimed the evicted stream body.
1351 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_);
1352 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_);
1353 EXPECT_TRUE(session_);
1354
1355 // Read and process EOF.
1356 data.Resume();
1357 base::RunLoop().RunUntilIdle();
1358 EXPECT_FALSE(session_);
1359 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1);
1360 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes",
1361 6, 1);
1362 }
1363
1364 TEST_F(SpdySessionTest, CancelPushBeforeClaimed) {
1365 base::HistogramTester histogram_tester;
1366 session_deps_.host_resolver->set_synchronous_mode(true);
1367 session_deps_.time_func = TheNearFuture;
1368
1369 SpdySerializedFrame req(
1370 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true));
1371 SpdySerializedFrame rst(
1372 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
1373 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)};
1374
1375 SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush(
1376 nullptr, 0, 2, 1, "https://www.example.org/a.dat"));
1377 SpdySerializedFrame push_a_body(spdy_util_.ConstructSpdyDataFrame(2, false));
1378 // In ascii "0" < "a". We use it to verify that we properly handle std::map
1379 // iterators inside. See http://crbug.com/443490
1380 SpdySerializedFrame push_b(spdy_util_.ConstructSpdyPush(
1381 nullptr, 0, 4, 1, "https://www.example.org/0.dat"));
1382 MockRead reads[] = {
1383 CreateMockRead(push_a, 1), CreateMockRead(push_a_body, 2),
1384 MockRead(ASYNC, ERR_IO_PENDING, 3), CreateMockRead(push_b, 4),
1385 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1386 };
1387
1388 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1389 session_deps_.socket_factory->AddSocketDataProvider(&data);
1390
1391 AddSSLSocketData();
1392
1393 CreateNetworkSession();
1394 CreateSecureSpdySession();
1395
1396 // Process the principal request, and the first push stream request & body.
1397 base::WeakPtr<SpdyStream> spdy_stream =
1398 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1399 test_url_, MEDIUM, NetLogWithSource());
1400 test::StreamDelegateDoNothing delegate(spdy_stream);
1401 spdy_stream->SetDelegate(&delegate);
1402
1403 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1404 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
1405
1406 base::RunLoop().RunUntilIdle();
1407
1408 // Verify that there is one unclaimed push stream.
1409 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1410 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(
1411 GURL("https://www.example.org/a.dat")));
1412
1413 // Unclaimed push body consumed bytes from the session window.
1414 EXPECT_EQ(kDefaultInitialWindowSize - kUploadDataSize,
1415 session_->session_recv_window_size_);
1416 EXPECT_EQ(0, session_->session_unacked_recv_window_bytes_);
1417
1418 // Shift time to expire the push stream. Read the second HEADERS,
1419 // and verify a RST_STREAM was written.
1420 g_time_delta = base::TimeDelta::FromSeconds(301);
1421 data.Resume();
1422 base::RunLoop().RunUntilIdle();
1423
1424 // Verify that the second pushed stream evicted the first pushed stream.
1425 GURL pushed_url("https://www.example.org/0.dat");
1426 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1427 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(pushed_url));
1428
1429 // Verify that the session window reclaimed the evicted stream body.
1430 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_);
1431 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_);
1432
1433 EXPECT_TRUE(session_);
1434 // Cancel the push before it's claimed.
1435 session_->CancelPush(pushed_url);
1436 EXPECT_EQ(0u, session_->num_unclaimed_pushed_streams());
1437 EXPECT_EQ(0u, session_->count_unclaimed_pushed_streams_for_url(pushed_url));
1438
1439 // Read and process EOF.
1440 data.Resume();
1441 base::RunLoop().RunUntilIdle();
1442 EXPECT_FALSE(session_);
1443 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1);
1444 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes",
1445 6, 1);
1446 }
1447
1280 TEST_F(SpdySessionTest, DeleteExpiredPushStreams) { 1448 TEST_F(SpdySessionTest, DeleteExpiredPushStreams) {
1281 base::HistogramTester histogram_tester; 1449 base::HistogramTester histogram_tester;
1282 session_deps_.host_resolver->set_synchronous_mode(true); 1450 session_deps_.host_resolver->set_synchronous_mode(true);
1283 session_deps_.time_func = TheNearFuture; 1451 session_deps_.time_func = TheNearFuture;
1284 1452
1285 SpdySerializedFrame req( 1453 SpdySerializedFrame req(
1286 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true)); 1454 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, MEDIUM, true));
1287 SpdySerializedFrame rst( 1455 SpdySerializedFrame rst(
1288 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); 1456 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
1289 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)}; 1457 MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 5)};
(...skipping 4360 matching lines...) Expand 10 before | Expand all | Expand 10 after
5650 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 5818 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
5651 "spdy_pooling.pem"); 5819 "spdy_pooling.pem");
5652 ssl_info.is_issued_by_known_root = true; 5820 ssl_info.is_issued_by_known_root = true;
5653 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 5821 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
5654 5822
5655 EXPECT_TRUE(SpdySession::CanPool( 5823 EXPECT_TRUE(SpdySession::CanPool(
5656 &tss, ssl_info, "www.example.org", "mail.example.org")); 5824 &tss, ssl_info, "www.example.org", "mail.example.org"));
5657 } 5825 }
5658 5826
5659 } // namespace net 5827 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698