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 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1352 | 1352 |
1353 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 1353 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
1354 | 1354 |
1355 AddHangingNonAlternateProtocolSocketData(); | 1355 AddHangingNonAlternateProtocolSocketData(); |
1356 CreateSession(); | 1356 CreateSession(); |
1357 | 1357 |
1358 SendRequestAndExpectHttpResponse("hello world"); | 1358 SendRequestAndExpectHttpResponse("hello world"); |
1359 SendRequestAndExpectQuicResponse("hello!"); | 1359 SendRequestAndExpectQuicResponse("hello!"); |
1360 } | 1360 } |
1361 | 1361 |
1362 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceWithVersionForQuic1) { | |
1363 // Server advertises support {QUIC_VERSION_40/QUIC_VERSION_39, version_} | |
1364 // Client supports {QUIC_VERSION_38/QUIC_VERSION_37, version_} | |
1365 // The QuicStreamFactoy will pick the single overlapped |version_|, which is | |
1366 // verified as the PacketMakers are using |version_|. | |
1367 QuicVersion advertised_version_2 = QUIC_VERSION_40; | |
1368 if (version_ == QUIC_VERSION_40) | |
1369 advertised_version_2 = QUIC_VERSION_39; | |
1370 std::string QuicAltSvcWithVersionHeader = | |
1371 base::StringPrintf("Alt-Svc: quic=\":443\";v=\"%d,%d\"\r\n\r\n", | |
1372 advertised_version_2, version_); | |
1373 | |
1374 QuicVersionVector supported_versions; | |
1375 QuicVersion supported_version_2 = QUIC_VERSION_38; | |
1376 if (version_ == QUIC_VERSION_38) | |
1377 supported_version_2 = QUIC_VERSION_37; | |
1378 supported_versions.push_back( | |
1379 supported_version_2); // 0th entry, preferred QUIC version. | |
1380 supported_versions.push_back(version_); | |
1381 | |
1382 MockRead http_reads[] = { | |
1383 MockRead("HTTP/1.1 200 OK\r\n"), | |
1384 MockRead(QuicAltSvcWithVersionHeader.c_str()), MockRead("hello world"), | |
1385 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
1386 MockRead(ASYNC, OK)}; | |
1387 | |
1388 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, | |
1389 0); | |
1390 socket_factory_.AddSocketDataProvider(&http_data); | |
1391 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); | |
1392 | |
1393 MockQuicData mock_quic_data; | |
1394 QuicStreamOffset header_stream_offset = 0; | |
1395 mock_quic_data.AddWrite( | |
1396 ConstructInitialSettingsPacket(1, &header_stream_offset)); | |
1397 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | |
1398 2, GetNthClientInitiatedStreamId(0), true, true, | |
1399 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); | |
1400 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
1401 1, GetNthClientInitiatedStreamId(0), false, false, | |
1402 GetResponseHeaders("200 OK"))); | |
1403 mock_quic_data.AddRead(ConstructServerDataPacket( | |
1404 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!")); | |
1405 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1)); | |
1406 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | |
1407 mock_quic_data.AddRead(ASYNC, 0); // EOF | |
1408 | |
1409 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | |
1410 | |
1411 AddHangingNonAlternateProtocolSocketData(); | |
1412 CreateSession(supported_versions); | |
1413 | |
1414 SendRequestAndExpectHttpResponse("hello world"); | |
1415 SendRequestAndExpectQuicResponse("hello!"); | |
1416 } | |
1417 | |
1418 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceWithVersionForQuic2) { | |
1419 // Server advertises support {QUIC_VERSION_40/QUIC_VERSION_39, version_} | |
1420 // Client supports {version_, QUIC_VERSION_40/QUIC_VERSION_39} | |
1421 // Client and Server mutualy support more than one QUIC_VERSION. | |
Bence
2017/06/28 19:08:58
s/mutualy/mutually/
Zhongyi Shi
2017/07/05 23:08:59
Done.
| |
1422 // The QuicStreamFactoy will pick the preferred QUIC_VERSION: |version_|, | |
1423 // which is verified as the PacketMakers are using |version_|. | |
1424 QuicVersion common_version_2 = QUIC_VERSION_40; | |
1425 if (version_ == QUIC_VERSION_40) | |
1426 common_version_2 = QUIC_VERSION_39; | |
1427 std::string QuicAltSvcWithVersionHeader = base::StringPrintf( | |
1428 "Alt-Svc: quic=\":443\";v=\"%d,%d\"\r\n\r\n", common_version_2, version_); | |
1429 | |
1430 QuicVersionVector supported_versions; | |
1431 supported_versions.push_back(version_); // 0th entry, preferred QUIC version. | |
1432 supported_versions.push_back(common_version_2); | |
1433 | |
1434 MockRead http_reads[] = { | |
1435 MockRead("HTTP/1.1 200 OK\r\n"), | |
1436 MockRead(QuicAltSvcWithVersionHeader.c_str()), MockRead("hello world"), | |
1437 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
1438 MockRead(ASYNC, OK)}; | |
1439 | |
1440 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, | |
1441 0); | |
1442 socket_factory_.AddSocketDataProvider(&http_data); | |
1443 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); | |
1444 | |
1445 MockQuicData mock_quic_data; | |
1446 QuicStreamOffset header_stream_offset = 0; | |
1447 mock_quic_data.AddWrite( | |
1448 ConstructInitialSettingsPacket(1, &header_stream_offset)); | |
1449 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | |
1450 2, GetNthClientInitiatedStreamId(0), true, true, | |
1451 GetRequestHeaders("GET", "https", "/"), &header_stream_offset)); | |
1452 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
1453 1, GetNthClientInitiatedStreamId(0), false, false, | |
1454 GetResponseHeaders("200 OK"))); | |
1455 mock_quic_data.AddRead(ConstructServerDataPacket( | |
1456 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!")); | |
1457 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1)); | |
1458 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | |
1459 mock_quic_data.AddRead(ASYNC, 0); // EOF | |
1460 | |
1461 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | |
1462 | |
1463 AddHangingNonAlternateProtocolSocketData(); | |
1464 CreateSession(supported_versions); | |
1465 | |
1466 SendRequestAndExpectHttpResponse("hello world"); | |
1467 SendRequestAndExpectQuicResponse("hello!"); | |
1468 } | |
1469 | |
1362 TEST_P(QuicNetworkTransactionTest, | 1470 TEST_P(QuicNetworkTransactionTest, |
1363 UseAlternativeServiceWithProbabilityForQuic) { | 1471 UseAlternativeServiceWithProbabilityForQuic) { |
1364 MockRead http_reads[] = { | 1472 MockRead http_reads[] = { |
1365 MockRead("HTTP/1.1 200 OK\r\n"), | 1473 MockRead("HTTP/1.1 200 OK\r\n"), |
1366 MockRead(kQuicAlternativeServiceWithProbabilityHeader), | 1474 MockRead(kQuicAlternativeServiceWithProbabilityHeader), |
1367 MockRead("hello world"), | 1475 MockRead("hello world"), |
1368 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 1476 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
1369 MockRead(ASYNC, OK)}; | 1477 MockRead(ASYNC, OK)}; |
1370 | 1478 |
1371 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, | 1479 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
(...skipping 3820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5192 | 5300 |
5193 request_.url = GURL("https://mail.example.org/pushed.jpg"); | 5301 request_.url = GURL("https://mail.example.org/pushed.jpg"); |
5194 ChunkedUploadDataStream upload_data(0); | 5302 ChunkedUploadDataStream upload_data(0); |
5195 upload_data.AppendData("1", 1, true); | 5303 upload_data.AppendData("1", 1, true); |
5196 request_.upload_data_stream = &upload_data; | 5304 request_.upload_data_stream = &upload_data; |
5197 SendRequestAndExpectQuicResponse("and hello!"); | 5305 SendRequestAndExpectQuicResponse("and hello!"); |
5198 } | 5306 } |
5199 | 5307 |
5200 } // namespace test | 5308 } // namespace test |
5201 } // namespace net | 5309 } // namespace net |
OLD | NEW |