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

Side by Side Diff: net/quic/chromium/quic_network_transaction_unittest.cc

Issue 2789093003: Mark QUIC broken when the network blackholes after the handshake (Closed)
Patch Set: Created 3 years, 8 months 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 <memory> 5 #include <memory>
6 #include <ostream> 6 #include <ostream>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 23 matching lines...) Expand all
34 #include "net/log/test_net_log.h" 34 #include "net/log/test_net_log.h"
35 #include "net/log/test_net_log_entry.h" 35 #include "net/log/test_net_log_entry.h"
36 #include "net/log/test_net_log_util.h" 36 #include "net/log/test_net_log_util.h"
37 #include "net/proxy/proxy_config_service_fixed.h" 37 #include "net/proxy/proxy_config_service_fixed.h"
38 #include "net/proxy/proxy_resolver.h" 38 #include "net/proxy/proxy_resolver.h"
39 #include "net/proxy/proxy_service.h" 39 #include "net/proxy/proxy_service.h"
40 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" 40 #include "net/quic/chromium/crypto/proof_verifier_chromium.h"
41 #include "net/quic/chromium/mock_crypto_client_stream_factory.h" 41 #include "net/quic/chromium/mock_crypto_client_stream_factory.h"
42 #include "net/quic/chromium/mock_network_change_notifier.h" 42 #include "net/quic/chromium/mock_network_change_notifier.h"
43 #include "net/quic/chromium/mock_quic_data.h" 43 #include "net/quic/chromium/mock_quic_data.h"
44 #include "net/quic/chromium/quic_chromium_alarm_factory.h"
44 #include "net/quic/chromium/quic_http_utils.h" 45 #include "net/quic/chromium/quic_http_utils.h"
46 #include "net/quic/chromium/quic_stream_factory_peer.h"
45 #include "net/quic/chromium/quic_test_packet_maker.h" 47 #include "net/quic/chromium/quic_test_packet_maker.h"
46 #include "net/quic/core/crypto/quic_decrypter.h" 48 #include "net/quic/core/crypto/quic_decrypter.h"
47 #include "net/quic/core/crypto/quic_encrypter.h" 49 #include "net/quic/core/crypto/quic_encrypter.h"
48 #include "net/quic/core/quic_framer.h" 50 #include "net/quic/core/quic_framer.h"
49 #include "net/quic/platform/api/quic_string_piece.h" 51 #include "net/quic/platform/api/quic_string_piece.h"
50 #include "net/quic/test_tools/crypto_test_utils.h" 52 #include "net/quic/test_tools/crypto_test_utils.h"
51 #include "net/quic/test_tools/mock_clock.h" 53 #include "net/quic/test_tools/mock_clock.h"
52 #include "net/quic/test_tools/mock_random.h" 54 #include "net/quic/test_tools/mock_random.h"
53 #include "net/quic/test_tools/quic_test_utils.h" 55 #include "net/quic/test_tools/quic_test_utils.h"
56 #include "net/quic/test_tools/test_task_runner.h"
54 #include "net/socket/client_socket_factory.h" 57 #include "net/socket/client_socket_factory.h"
55 #include "net/socket/mock_client_socket_pool_manager.h" 58 #include "net/socket/mock_client_socket_pool_manager.h"
56 #include "net/socket/next_proto.h" 59 #include "net/socket/next_proto.h"
57 #include "net/socket/socket_performance_watcher.h" 60 #include "net/socket/socket_performance_watcher.h"
58 #include "net/socket/socket_performance_watcher_factory.h" 61 #include "net/socket/socket_performance_watcher_factory.h"
59 #include "net/socket/socket_test_util.h" 62 #include "net/socket/socket_test_util.h"
60 #include "net/spdy/spdy_frame_builder.h" 63 #include "net/spdy/spdy_frame_builder.h"
61 #include "net/spdy/spdy_framer.h" 64 #include "net/spdy/spdy_framer.h"
62 #include "net/ssl/ssl_config_service_defaults.h" 65 #include "net/ssl/ssl_config_service_defaults.h"
63 #include "net/test/cert_test_util.h" 66 #include "net/test/cert_test_util.h"
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 EXPECT_THAT(callback.WaitForResult(), IsOk()); 1350 EXPECT_THAT(callback.WaitForResult(), IsOk());
1348 1351
1349 // Check whether this transaction is correctly marked as received a go-away 1352 // Check whether this transaction is correctly marked as received a go-away
1350 // because of migrating port. 1353 // because of migrating port.
1351 NetErrorDetails details; 1354 NetErrorDetails details;
1352 EXPECT_FALSE(details.quic_port_migration_detected); 1355 EXPECT_FALSE(details.quic_port_migration_detected);
1353 trans.PopulateNetErrorDetails(&details); 1356 trans.PopulateNetErrorDetails(&details);
1354 EXPECT_TRUE(details.quic_port_migration_detected); 1357 EXPECT_TRUE(details.quic_port_migration_detected);
1355 } 1358 }
1356 1359
1360 // Verify that if a QUIC connection times out, the QuicHttpStream will
1361 // return QUIC_PROTOCOL_ERROR.
1362 TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmed) {
1363 params_.quic_idle_connection_timeout_seconds = 5;
1364
1365 // The request will initially go out over QUIC.
1366 MockQuicData quic_data;
1367 QuicStreamOffset header_stream_offset = 0;
1368 SpdyPriority priority =
1369 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
1370
1371 std::string request_data;
1372 quic_data.AddWrite(client_maker_.MakeRequestHeadersPacketAndSaveData(
1373 1, kClientDataStreamId1, true, true, priority,
1374 GetRequestHeaders("GET", "https", "/"), nullptr, &header_stream_offset,
1375 &request_data));
1376
1377 std::string settings_data;
1378 QuicStreamOffset settings_offset = header_stream_offset;
1379 quic_data.AddWrite(client_maker_.MakeSettingsPacketAndSaveData(
1380 2, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, true,
1381 &header_stream_offset, &settings_data));
1382 // TLP 1
1383 quic_data.AddWrite(client_maker_.MakeDataPacket(3, kHeadersStreamId, true,
1384 false, 0, request_data));
1385 // TLP 2
1386 quic_data.AddWrite(client_maker_.MakeDataPacket(
1387 4, kHeadersStreamId, true, false, settings_offset, settings_data));
1388 // RTO 1
1389 quic_data.AddWrite(client_maker_.MakeDataPacket(5, kHeadersStreamId, true,
1390 false, 0, request_data));
1391 quic_data.AddWrite(client_maker_.MakeDataPacket(
1392 6, kHeadersStreamId, true, false, settings_offset, settings_data));
1393 // RTO 2
1394 quic_data.AddWrite(client_maker_.MakeDataPacket(7, kHeadersStreamId, true,
1395 false, 0, request_data));
1396 quic_data.AddWrite(client_maker_.MakeDataPacket(
1397 8, kHeadersStreamId, true, false, settings_offset, settings_data));
1398 // RTO 3
1399 quic_data.AddWrite(client_maker_.MakeDataPacket(9, kHeadersStreamId, true,
1400 false, 0, request_data));
1401 quic_data.AddWrite(client_maker_.MakeDataPacket(
1402 10, kHeadersStreamId, true, false, settings_offset, settings_data));
1403
1404 quic_data.AddRead(ASYNC, ERR_IO_PENDING);
1405 quic_data.AddRead(ASYNC, OK);
1406 quic_data.AddSocketDataToFactory(&socket_factory_);
1407
1408 // In order for a new QUIC session to be established via alternate-protocol
1409 // without racing an HTTP connection, we need the host resolution to happen
1410 // synchronously. Of course, even though QUIC *could* perform a 0-RTT
1411 // connection to the the server, in this test we require confirmation
1412 // before encrypting so the HTTP job will still start.
1413 host_resolver_.set_synchronous_mode(true);
1414 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1",
1415 "");
1416 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443));
1417 AddressList address;
1418 std::unique_ptr<HostResolver::Request> request;
1419 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(),
1420 &request, net_log_.bound());
1421
1422 CreateSession();
1423 // Use a TestTaskRunner to avoid waiting in real time for timeouts.
1424 scoped_refptr<TestTaskRunner> quic_task_runner_(new TestTaskRunner(clock_));
1425 QuicStreamFactoryPeer::SetAlarmFactory(
1426 session_->quic_stream_factory(),
1427 base::MakeUnique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
1428 clock_));
1429
1430 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1431
1432 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
1433 TestCompletionCallback callback;
1434 int rv = trans.Start(&request_, callback.callback(), net_log_.bound());
1435 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1436
1437 // Pump the message loop to get the request started.
1438 base::RunLoop().RunUntilIdle();
1439 // Explicitly confirm the handshake.
1440 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1441 QuicSession::HANDSHAKE_CONFIRMED);
1442
1443 // Run the QUIC session to completion.
1444 quic_task_runner_->RunUntilIdle();
1445
1446 ASSERT_TRUE(quic_data.AllWriteDataConsumed());
1447 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_QUIC_PROTOCOL_ERROR));
1448 }
1449
1450 // Verify that if a QUIC connection RTOs, the QuicHttpStream will
1451 // return QUIC_PROTOCOL_ERROR.
1452 TEST_P(QuicNetworkTransactionTest, TooManyRtosAfterHandshakeConfirmed) {
1453 params_.quic_connection_options.push_back(k5RTO);
1454
1455 // The request will initially go out over QUIC.
1456 MockQuicData quic_data;
1457 QuicStreamOffset header_stream_offset = 0;
1458 SpdyPriority priority =
1459 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
1460
1461 std::string request_data;
1462 quic_data.AddWrite(client_maker_.MakeRequestHeadersPacketAndSaveData(
1463 1, kClientDataStreamId1, true, true, priority,
1464 GetRequestHeaders("GET", "https", "/"), nullptr, &header_stream_offset,
1465 &request_data));
1466
1467 std::string settings_data;
1468 QuicStreamOffset settings_offset = header_stream_offset;
1469 quic_data.AddWrite(client_maker_.MakeSettingsPacketAndSaveData(
1470 2, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, true,
1471 &header_stream_offset, &settings_data));
1472 // TLP 1
1473 quic_data.AddWrite(client_maker_.MakeDataPacket(3, kHeadersStreamId, true,
1474 false, 0, request_data));
1475 // TLP 2
1476 quic_data.AddWrite(client_maker_.MakeDataPacket(
1477 4, kHeadersStreamId, true, false, settings_offset, settings_data));
1478 // RTO 1
1479 quic_data.AddWrite(client_maker_.MakeDataPacket(5, kHeadersStreamId, true,
1480 false, 0, request_data));
1481 quic_data.AddWrite(client_maker_.MakeDataPacket(
1482 6, kHeadersStreamId, true, false, settings_offset, settings_data));
1483 // RTO 2
1484 quic_data.AddWrite(client_maker_.MakeDataPacket(7, kHeadersStreamId, true,
1485 false, 0, request_data));
1486 quic_data.AddWrite(client_maker_.MakeDataPacket(
1487 8, kHeadersStreamId, true, false, settings_offset, settings_data));
1488 // RTO 3
1489 quic_data.AddWrite(client_maker_.MakeDataPacket(9, kHeadersStreamId, true,
1490 false, 0, request_data));
1491 quic_data.AddWrite(client_maker_.MakeDataPacket(
1492 10, kHeadersStreamId, true, false, settings_offset, settings_data));
1493 // RTO 4
1494 quic_data.AddWrite(client_maker_.MakeDataPacket(11, kHeadersStreamId, true,
1495 false, 0, request_data));
1496 quic_data.AddWrite(client_maker_.MakeDataPacket(
1497 12, kHeadersStreamId, true, false, settings_offset, settings_data));
1498 // RTO 5
1499 quic_data.AddWrite(client_maker_.MakeAckAndConnectionClosePacket(
1500 13, true, QuicTime::Delta::Infinite(), 0, 1, QUIC_TOO_MANY_RTOS,
1501 "5 consecutive retransmission timeouts"));
1502
1503 quic_data.AddRead(ASYNC, OK);
1504 quic_data.AddSocketDataToFactory(&socket_factory_);
1505
1506 // In order for a new QUIC session to be established via alternate-protocol
1507 // without racing an HTTP connection, we need the host resolution to happen
1508 // synchronously. Of course, even though QUIC *could* perform a 0-RTT
1509 // connection to the the server, in this test we require confirmation
1510 // before encrypting so the HTTP job will still start.
1511 host_resolver_.set_synchronous_mode(true);
1512 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1",
1513 "");
1514 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443));
1515 AddressList address;
1516 std::unique_ptr<HostResolver::Request> request;
1517 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(),
1518 &request, net_log_.bound());
1519
1520 CreateSession();
1521 // Use a TestTaskRunner to avoid waiting in real time for timeouts.
1522 scoped_refptr<TestTaskRunner> quic_task_runner_(new TestTaskRunner(clock_));
1523 QuicStreamFactoryPeer::SetAlarmFactory(
1524 session_->quic_stream_factory(),
1525 base::MakeUnique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
1526 clock_));
1527
1528 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1529
1530 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
1531 TestCompletionCallback callback;
1532 int rv = trans.Start(&request_, callback.callback(), net_log_.bound());
1533 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1534
1535 // Pump the message loop to get the request started.
1536 base::RunLoop().RunUntilIdle();
1537 // Explicitly confirm the handshake.
1538 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1539 QuicSession::HANDSHAKE_CONFIRMED);
1540
1541 // Run the QUIC session to completion.
1542 quic_task_runner_->RunUntilIdle();
1543
1544 ASSERT_TRUE(quic_data.AllWriteDataConsumed());
1545 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_QUIC_PROTOCOL_ERROR));
1546 }
1547
1548 // Verify that with mark_quic_broken_when_network_suspected enabled, if a QUIC
1549 // connection times out, then QUIC will be marked as broken and the request
1550 // retried over TCP.
1551 TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken) {
1552 params_.mark_quic_broken_when_network_suspected = true;
1553 params_.quic_idle_connection_timeout_seconds = 5;
1554
1555 // The request will initially go out over QUIC.
1556 MockQuicData quic_data;
1557 QuicStreamOffset header_stream_offset = 0;
1558 SpdyPriority priority =
1559 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
1560
1561 std::string request_data;
1562 quic_data.AddWrite(client_maker_.MakeRequestHeadersPacketAndSaveData(
1563 1, kClientDataStreamId1, true, true, priority,
1564 GetRequestHeaders("GET", "https", "/"), nullptr, &header_stream_offset,
1565 &request_data));
1566
1567 std::string settings_data;
1568 QuicStreamOffset settings_offset = header_stream_offset;
1569 quic_data.AddWrite(client_maker_.MakeSettingsPacketAndSaveData(
1570 2, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, true,
1571 &header_stream_offset, &settings_data));
1572 // TLP 1
1573 quic_data.AddWrite(client_maker_.MakeDataPacket(3, kHeadersStreamId, true,
1574 false, 0, request_data));
1575 // TLP 2
1576 quic_data.AddWrite(client_maker_.MakeDataPacket(
1577 4, kHeadersStreamId, true, false, settings_offset, settings_data));
1578 // RTO 1
1579 quic_data.AddWrite(client_maker_.MakeDataPacket(5, kHeadersStreamId, true,
1580 false, 0, request_data));
1581 quic_data.AddWrite(client_maker_.MakeDataPacket(
1582 6, kHeadersStreamId, true, false, settings_offset, settings_data));
1583 // RTO 2
1584 quic_data.AddWrite(client_maker_.MakeDataPacket(7, kHeadersStreamId, true,
1585 false, 0, request_data));
1586 quic_data.AddWrite(client_maker_.MakeDataPacket(
1587 8, kHeadersStreamId, true, false, settings_offset, settings_data));
1588 // RTO 3
1589 quic_data.AddWrite(client_maker_.MakeDataPacket(9, kHeadersStreamId, true,
1590 false, 0, request_data));
1591 quic_data.AddWrite(client_maker_.MakeDataPacket(
1592 10, kHeadersStreamId, true, false, settings_offset, settings_data));
1593
1594 quic_data.AddRead(ASYNC, ERR_IO_PENDING);
1595 quic_data.AddRead(ASYNC, OK);
1596 quic_data.AddSocketDataToFactory(&socket_factory_);
1597
1598 // After that fails, it will be resent via HTTP.
1599 MockWrite http_writes[] = {
1600 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"),
1601 MockWrite(SYNCHRONOUS, 1, "Host: mail.example.org\r\n"),
1602 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n")};
1603
1604 MockRead http_reads[] = {
1605 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"),
1606 MockRead(SYNCHRONOUS, 4, kQuicAlternativeServiceHeader),
1607 MockRead(SYNCHRONOUS, 5, "hello world"), MockRead(SYNCHRONOUS, OK, 6)};
1608 SequencedSocketData http_data(http_reads, arraysize(http_reads), http_writes,
1609 arraysize(http_writes));
1610 socket_factory_.AddSocketDataProvider(&http_data);
1611 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
1612
1613 // In order for a new QUIC session to be established via alternate-protocol
1614 // without racing an HTTP connection, we need the host resolution to happen
1615 // synchronously. Of course, even though QUIC *could* perform a 0-RTT
1616 // connection to the the server, in this test we require confirmation
1617 // before encrypting so the HTTP job will still start.
1618 host_resolver_.set_synchronous_mode(true);
1619 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1",
1620 "");
1621 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443));
1622 AddressList address;
1623 std::unique_ptr<HostResolver::Request> request;
1624 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(),
1625 &request, net_log_.bound());
1626
1627 CreateSession();
1628 // Use a TestTaskRunner to avoid waiting in real time for timeouts.
1629 scoped_refptr<TestTaskRunner> quic_task_runner_(new TestTaskRunner(clock_));
1630 QuicStreamFactoryPeer::SetAlarmFactory(
1631 session_->quic_stream_factory(),
1632 base::MakeUnique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
1633 clock_));
1634
1635 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1636
1637 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
1638 TestCompletionCallback callback;
1639 int rv = trans.Start(&request_, callback.callback(), net_log_.bound());
1640 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1641
1642 // Pump the message loop to get the request started.
1643 base::RunLoop().RunUntilIdle();
1644 // Explicitly confirm the handshake.
1645 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1646 QuicSession::HANDSHAKE_CONFIRMED);
1647
1648 // Run the QUIC session to completion.
1649 quic_task_runner_->RunUntilIdle();
1650 ASSERT_TRUE(quic_data.AllWriteDataConsumed());
1651
1652 // Let the transaction proceed which will result in QUIC being marked
1653 // as broken and the request falling back to TCP.
1654 EXPECT_THAT(callback.WaitForResult(), IsOk());
1655
1656 ExpectBrokenAlternateProtocolMapping();
1657 ASSERT_TRUE(quic_data.AllWriteDataConsumed());
1658 ASSERT_FALSE(http_data.AllReadDataConsumed());
1659
1660 // Read the response body over TCP.
1661 CheckResponseData(&trans, "hello world");
1662 ASSERT_TRUE(http_data.AllWriteDataConsumed());
1663 ASSERT_TRUE(http_data.AllReadDataConsumed());
1664 }
1665
1666 // Verify that with mark_quic_broken_when_network_suspected enabled, if a QUIC
1667 // connection RTOs, then QUIC will be marked as broken and the request retried
1668 // over TCP.
1669 TEST_P(QuicNetworkTransactionTest,
1670 TooManyRtosAfterHandshakeConfirmedThenBroken) {
1671 params_.mark_quic_broken_when_network_suspected = true;
1672 params_.quic_connection_options.push_back(k5RTO);
1673
1674 // The request will initially go out over QUIC.
1675 MockQuicData quic_data;
1676 QuicStreamOffset header_stream_offset = 0;
1677 SpdyPriority priority =
1678 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
1679
1680 std::string request_data;
1681 quic_data.AddWrite(client_maker_.MakeRequestHeadersPacketAndSaveData(
1682 1, kClientDataStreamId1, true, true, priority,
1683 GetRequestHeaders("GET", "https", "/"), nullptr, &header_stream_offset,
1684 &request_data));
1685
1686 std::string settings_data;
1687 QuicStreamOffset settings_offset = header_stream_offset;
1688 quic_data.AddWrite(client_maker_.MakeSettingsPacketAndSaveData(
1689 2, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize, true,
1690 &header_stream_offset, &settings_data));
1691 // TLP 1
1692 quic_data.AddWrite(client_maker_.MakeDataPacket(3, kHeadersStreamId, true,
1693 false, 0, request_data));
1694 // TLP 2
1695 quic_data.AddWrite(client_maker_.MakeDataPacket(
1696 4, kHeadersStreamId, true, false, settings_offset, settings_data));
1697 // RTO 1
1698 quic_data.AddWrite(client_maker_.MakeDataPacket(5, kHeadersStreamId, true,
1699 false, 0, request_data));
1700 quic_data.AddWrite(client_maker_.MakeDataPacket(
1701 6, kHeadersStreamId, true, false, settings_offset, settings_data));
1702 // RTO 2
1703 quic_data.AddWrite(client_maker_.MakeDataPacket(7, kHeadersStreamId, true,
1704 false, 0, request_data));
1705 quic_data.AddWrite(client_maker_.MakeDataPacket(
1706 8, kHeadersStreamId, true, false, settings_offset, settings_data));
1707 // RTO 3
1708 quic_data.AddWrite(client_maker_.MakeDataPacket(9, kHeadersStreamId, true,
1709 false, 0, request_data));
1710 quic_data.AddWrite(client_maker_.MakeDataPacket(
1711 10, kHeadersStreamId, true, false, settings_offset, settings_data));
1712 // RTO 4
1713 quic_data.AddWrite(client_maker_.MakeDataPacket(11, kHeadersStreamId, true,
1714 false, 0, request_data));
1715 quic_data.AddWrite(client_maker_.MakeDataPacket(
1716 12, kHeadersStreamId, true, false, settings_offset, settings_data));
1717
1718 quic_data.AddWrite(client_maker_.MakeAckAndConnectionClosePacket(
1719 13, true, QuicTime::Delta::Infinite(), 0, 1, QUIC_TOO_MANY_RTOS,
1720 "5 consecutive retransmission timeouts"));
1721
1722 quic_data.AddRead(ASYNC, OK);
1723 quic_data.AddSocketDataToFactory(&socket_factory_);
1724
1725 // After that fails, it will be resent via HTTP.
1726 MockWrite http_writes[] = {
1727 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"),
1728 MockWrite(SYNCHRONOUS, 1, "Host: mail.example.org\r\n"),
1729 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n")};
1730
1731 MockRead http_reads[] = {
1732 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"),
1733 MockRead(SYNCHRONOUS, 4, kQuicAlternativeServiceHeader),
1734 MockRead(SYNCHRONOUS, 5, "hello world"), MockRead(SYNCHRONOUS, OK, 6)};
1735 SequencedSocketData http_data(http_reads, arraysize(http_reads), http_writes,
1736 arraysize(http_writes));
1737 socket_factory_.AddSocketDataProvider(&http_data);
1738 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
1739
1740 // In order for a new QUIC session to be established via alternate-protocol
1741 // without racing an HTTP connection, we need the host resolution to happen
1742 // synchronously. Of course, even though QUIC *could* perform a 0-RTT
1743 // connection to the the server, in this test we require confirmation
1744 // before encrypting so the HTTP job will still start.
1745 host_resolver_.set_synchronous_mode(true);
1746 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1",
1747 "");
1748 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443));
1749 AddressList address;
1750 std::unique_ptr<HostResolver::Request> request;
1751 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(),
1752 &request, net_log_.bound());
1753
1754 CreateSession();
1755 // Use a TestTaskRunner to avoid waiting in real time for timeouts.
1756 scoped_refptr<TestTaskRunner> quic_task_runner_(new TestTaskRunner(clock_));
1757 QuicStreamFactoryPeer::SetAlarmFactory(
1758 session_->quic_stream_factory(),
1759 base::MakeUnique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
1760 clock_));
1761
1762 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1763
1764 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
1765 TestCompletionCallback callback;
1766 int rv = trans.Start(&request_, callback.callback(), net_log_.bound());
1767 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1768
1769 // Pump the message loop to get the request started.
1770 base::RunLoop().RunUntilIdle();
1771 // Explicitly confirm the handshake.
1772 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1773 QuicSession::HANDSHAKE_CONFIRMED);
1774
1775 // Run the QUIC session to completion.
1776 quic_task_runner_->RunUntilIdle();
1777 ASSERT_TRUE(quic_data.AllWriteDataConsumed());
1778
1779 // Let the transaction proceed which will result in QUIC being marked
1780 // as broken and the request falling back to TCP.
1781 EXPECT_THAT(callback.WaitForResult(), IsOk());
1782
1783 ExpectBrokenAlternateProtocolMapping();
1784 ASSERT_TRUE(quic_data.AllWriteDataConsumed());
1785 ASSERT_FALSE(http_data.AllReadDataConsumed());
1786
1787 // Read the response body over TCP.
1788 CheckResponseData(&trans, "hello world");
1789 ASSERT_TRUE(http_data.AllWriteDataConsumed());
1790 ASSERT_TRUE(http_data.AllReadDataConsumed());
1791 }
1792
1357 TEST_P(QuicNetworkTransactionTest, 1793 TEST_P(QuicNetworkTransactionTest,
1358 DoNotUseAlternativeServiceQuicUnsupportedVersion) { 1794 DoNotUseAlternativeServiceQuicUnsupportedVersion) {
1359 std::string altsvc_header = base::StringPrintf( 1795 std::string altsvc_header = base::StringPrintf(
1360 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", version_ - 1); 1796 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", version_ - 1);
1361 MockRead http_reads[] = { 1797 MockRead http_reads[] = {
1362 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), 1798 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()),
1363 MockRead("hello world"), 1799 MockRead("hello world"),
1364 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 1800 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
1365 MockRead(ASYNC, OK)}; 1801 MockRead(ASYNC, OK)};
1366 1802
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3513 AddHangingSocketData(); 3949 AddHangingSocketData();
3514 3950
3515 SendRequestAndExpectQuicResponse(origin1_); 3951 SendRequestAndExpectQuicResponse(origin1_);
3516 SendRequestAndExpectQuicResponse(origin2_); 3952 SendRequestAndExpectQuicResponse(origin2_);
3517 3953
3518 EXPECT_TRUE(AllDataConsumed()); 3954 EXPECT_TRUE(AllDataConsumed());
3519 } 3955 }
3520 3956
3521 } // namespace test 3957 } // namespace test
3522 } // namespace net 3958 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698