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 <algorithm> | 5 #include <algorithm> |
6 #include <memory> | 6 #include <memory> |
7 #include <ostream> | 7 #include <ostream> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 | 1445 |
1446 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 1446 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
1447 | 1447 |
1448 AddHangingNonAlternateProtocolSocketData(); | 1448 AddHangingNonAlternateProtocolSocketData(); |
1449 CreateSession(); | 1449 CreateSession(); |
1450 | 1450 |
1451 SendRequestAndExpectHttpResponse("hello world"); | 1451 SendRequestAndExpectHttpResponse("hello world"); |
1452 SendRequestAndExpectQuicResponse("hello!"); | 1452 SendRequestAndExpectQuicResponse("hello!"); |
1453 } | 1453 } |
1454 | 1454 |
| 1455 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceWithVersionForQuic1) { |
| 1456 // Both server advertises and client supports two QUIC versions. |
| 1457 // Only |version_| is advertised and supported. |
| 1458 // The QuicStreamFactoy will pick up |version_|, which is verified as the |
| 1459 // PacketMakers are using |version_|. |
| 1460 |
| 1461 // Add support for another QUIC version besides |version_| on the client side. |
| 1462 // Also find a different version advertised by the server. |
| 1463 QuicVersion advertised_version_2 = QUIC_VERSION_UNSUPPORTED; |
| 1464 for (const QuicVersion& version : AllSupportedVersions()) { |
| 1465 if (version == version_) |
| 1466 continue; |
| 1467 if (supported_versions_.size() != 2) { |
| 1468 supported_versions_.push_back(version); |
| 1469 continue; |
| 1470 } |
| 1471 advertised_version_2 = version; |
| 1472 break; |
| 1473 } |
| 1474 DCHECK_NE(advertised_version_2, QUIC_VERSION_UNSUPPORTED); |
| 1475 |
| 1476 std::string QuicAltSvcWithVersionHeader = |
| 1477 base::StringPrintf("Alt-Svc: quic=\":443\";v=\"%d,%d\"\r\n\r\n", |
| 1478 advertised_version_2, version_); |
| 1479 |
| 1480 MockRead http_reads[] = { |
| 1481 MockRead("HTTP/1.1 200 OK\r\n"), |
| 1482 MockRead(QuicAltSvcWithVersionHeader.c_str()), MockRead("hello world"), |
| 1483 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1484 MockRead(ASYNC, OK)}; |
| 1485 |
| 1486 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 1487 0); |
| 1488 socket_factory_.AddSocketDataProvider(&http_data); |
| 1489 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); |
| 1490 |
| 1491 MockQuicData mock_quic_data; |
| 1492 QuicStreamOffset header_stream_offset = 0; |
| 1493 mock_quic_data.AddWrite( |
| 1494 ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 1495 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( |
| 1496 2, GetNthClientInitiatedStreamId(0), true, true, |
| 1497 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); |
| 1498 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( |
| 1499 1, GetNthClientInitiatedStreamId(0), false, false, |
| 1500 GetResponseHeaders("200 OK"))); |
| 1501 mock_quic_data.AddRead(ConstructServerDataPacket( |
| 1502 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!")); |
| 1503 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1)); |
| 1504 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 1505 mock_quic_data.AddRead(ASYNC, 0); // EOF |
| 1506 |
| 1507 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1508 |
| 1509 AddHangingNonAlternateProtocolSocketData(); |
| 1510 CreateSession(supported_versions_); |
| 1511 |
| 1512 SendRequestAndExpectHttpResponse("hello world"); |
| 1513 SendRequestAndExpectQuicResponse("hello!"); |
| 1514 } |
| 1515 |
| 1516 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceWithVersionForQuic2) { |
| 1517 // Client and server mutually support more than one QUIC_VERSION. |
| 1518 // The QuicStreamFactoy will pick the preferred QUIC_VERSION: |version_|, |
| 1519 // which is verified as the PacketMakers are using |version_|. |
| 1520 |
| 1521 QuicVersion common_version_2 = QUIC_VERSION_UNSUPPORTED; |
| 1522 for (const QuicVersion& version : AllSupportedVersions()) { |
| 1523 if (version == version_) |
| 1524 continue; |
| 1525 common_version_2 = version; |
| 1526 break; |
| 1527 } |
| 1528 DCHECK_NE(common_version_2, QUIC_VERSION_UNSUPPORTED); |
| 1529 |
| 1530 supported_versions_.push_back( |
| 1531 common_version_2); // Supported but unpreferred. |
| 1532 |
| 1533 std::string QuicAltSvcWithVersionHeader = base::StringPrintf( |
| 1534 "Alt-Svc: quic=\":443\";v=\"%d,%d\"\r\n\r\n", common_version_2, version_); |
| 1535 |
| 1536 MockRead http_reads[] = { |
| 1537 MockRead("HTTP/1.1 200 OK\r\n"), |
| 1538 MockRead(QuicAltSvcWithVersionHeader.c_str()), MockRead("hello world"), |
| 1539 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1540 MockRead(ASYNC, OK)}; |
| 1541 |
| 1542 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 1543 0); |
| 1544 socket_factory_.AddSocketDataProvider(&http_data); |
| 1545 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); |
| 1546 |
| 1547 MockQuicData mock_quic_data; |
| 1548 QuicStreamOffset header_stream_offset = 0; |
| 1549 mock_quic_data.AddWrite( |
| 1550 ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 1551 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( |
| 1552 2, GetNthClientInitiatedStreamId(0), true, true, |
| 1553 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); |
| 1554 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( |
| 1555 1, GetNthClientInitiatedStreamId(0), false, false, |
| 1556 GetResponseHeaders("200 OK"))); |
| 1557 mock_quic_data.AddRead(ConstructServerDataPacket( |
| 1558 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!")); |
| 1559 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1)); |
| 1560 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 1561 mock_quic_data.AddRead(ASYNC, 0); // EOF |
| 1562 |
| 1563 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1564 |
| 1565 AddHangingNonAlternateProtocolSocketData(); |
| 1566 CreateSession(supported_versions_); |
| 1567 |
| 1568 SendRequestAndExpectHttpResponse("hello world"); |
| 1569 SendRequestAndExpectQuicResponse("hello!"); |
| 1570 } |
| 1571 |
1455 TEST_P(QuicNetworkTransactionTest, | 1572 TEST_P(QuicNetworkTransactionTest, |
1456 UseAlternativeServiceWithProbabilityForQuic) { | 1573 UseAlternativeServiceWithProbabilityForQuic) { |
1457 MockRead http_reads[] = { | 1574 MockRead http_reads[] = { |
1458 MockRead("HTTP/1.1 200 OK\r\n"), | 1575 MockRead("HTTP/1.1 200 OK\r\n"), |
1459 MockRead(kQuicAlternativeServiceWithProbabilityHeader), | 1576 MockRead(kQuicAlternativeServiceWithProbabilityHeader), |
1460 MockRead("hello world"), | 1577 MockRead("hello world"), |
1461 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 1578 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
1462 MockRead(ASYNC, OK)}; | 1579 MockRead(ASYNC, OK)}; |
1463 | 1580 |
1464 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, | 1581 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
(...skipping 3819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5284 | 5401 |
5285 request_.url = GURL("https://mail.example.org/pushed.jpg"); | 5402 request_.url = GURL("https://mail.example.org/pushed.jpg"); |
5286 ChunkedUploadDataStream upload_data(0); | 5403 ChunkedUploadDataStream upload_data(0); |
5287 upload_data.AppendData("1", 1, true); | 5404 upload_data.AppendData("1", 1, true); |
5288 request_.upload_data_stream = &upload_data; | 5405 request_.upload_data_stream = &upload_data; |
5289 SendRequestAndExpectQuicResponse("and hello!"); | 5406 SendRequestAndExpectQuicResponse("and hello!"); |
5290 } | 5407 } |
5291 | 5408 |
5292 } // namespace test | 5409 } // namespace test |
5293 } // namespace net | 5410 } // namespace net |
OLD | NEW |