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

Unified Diff: net/quic/chromium/quic_network_transaction_unittest.cc

Issue 2958133002: Change QuicStreamRequest::Request() to take a preferred QuicVersion so that (Closed)
Patch Set: Add QuicNetworkTransactionTest: select correct Quic Version Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: net/quic/chromium/quic_network_transaction_unittest.cc
diff --git a/net/quic/chromium/quic_network_transaction_unittest.cc b/net/quic/chromium/quic_network_transaction_unittest.cc
index 95487579367f68827d2eea6f48a74d2d89fd0773..87d165b285a320e17fbb88a76824ad7670a41379 100644
--- a/net/quic/chromium/quic_network_transaction_unittest.cc
+++ b/net/quic/chromium/quic_network_transaction_unittest.cc
@@ -1359,6 +1359,114 @@ TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceForQuic) {
SendRequestAndExpectQuicResponse("hello!");
}
+TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceWithVersionForQuic1) {
+ // Server advertises support {QUIC_VERSION_40/QUIC_VERSION_39, version_}
+ // Client supports {QUIC_VERSION_38/QUIC_VERSION_37, version_}
+ // The QuicStreamFactoy will pick the single overlapped |version_|, which is
+ // verified as the PacketMakers are using |version_|.
+ QuicVersion advertised_version_2 = QUIC_VERSION_40;
+ if (version_ == QUIC_VERSION_40)
+ advertised_version_2 = QUIC_VERSION_39;
+ std::string QuicAltSvcWithVersionHeader =
+ base::StringPrintf("Alt-Svc: quic=\":443\";v=\"%d,%d\"\r\n\r\n",
+ advertised_version_2, version_);
+
+ QuicVersionVector supported_versions;
+ QuicVersion supported_version_2 = QUIC_VERSION_38;
+ if (version_ == QUIC_VERSION_38)
+ supported_version_2 = QUIC_VERSION_37;
+ supported_versions.push_back(
+ supported_version_2); // 0th entry, preferred QUIC version.
+ supported_versions.push_back(version_);
+
+ MockRead http_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"),
+ MockRead(QuicAltSvcWithVersionHeader.c_str()), MockRead("hello world"),
+ MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
+ MockRead(ASYNC, OK)};
+
+ StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
+ 0);
+ socket_factory_.AddSocketDataProvider(&http_data);
+ socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
+
+ MockQuicData mock_quic_data;
+ QuicStreamOffset header_stream_offset = 0;
+ mock_quic_data.AddWrite(
+ ConstructInitialSettingsPacket(1, &header_stream_offset));
+ mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
+ 2, GetNthClientInitiatedStreamId(0), true, true,
+ GetRequestHeaders("GET", "https", "/"), &header_stream_offset));
+ mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
+ 1, GetNthClientInitiatedStreamId(0), false, false,
+ GetResponseHeaders("200 OK")));
+ mock_quic_data.AddRead(ConstructServerDataPacket(
+ 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!"));
+ mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1));
+ mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
+ mock_quic_data.AddRead(ASYNC, 0); // EOF
+
+ mock_quic_data.AddSocketDataToFactory(&socket_factory_);
+
+ AddHangingNonAlternateProtocolSocketData();
+ CreateSession(supported_versions);
+
+ SendRequestAndExpectHttpResponse("hello world");
+ SendRequestAndExpectQuicResponse("hello!");
+}
+
+TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceWithVersionForQuic2) {
+ // Server advertises support {QUIC_VERSION_40/QUIC_VERSION_39, version_}
+ // Client supports {version_, QUIC_VERSION_40/QUIC_VERSION_39}
+ // 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.
+ // The QuicStreamFactoy will pick the preferred QUIC_VERSION: |version_|,
+ // which is verified as the PacketMakers are using |version_|.
+ QuicVersion common_version_2 = QUIC_VERSION_40;
+ if (version_ == QUIC_VERSION_40)
+ common_version_2 = QUIC_VERSION_39;
+ std::string QuicAltSvcWithVersionHeader = base::StringPrintf(
+ "Alt-Svc: quic=\":443\";v=\"%d,%d\"\r\n\r\n", common_version_2, version_);
+
+ QuicVersionVector supported_versions;
+ supported_versions.push_back(version_); // 0th entry, preferred QUIC version.
+ supported_versions.push_back(common_version_2);
+
+ MockRead http_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"),
+ MockRead(QuicAltSvcWithVersionHeader.c_str()), MockRead("hello world"),
+ MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
+ MockRead(ASYNC, OK)};
+
+ StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
+ 0);
+ socket_factory_.AddSocketDataProvider(&http_data);
+ socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
+
+ MockQuicData mock_quic_data;
+ QuicStreamOffset header_stream_offset = 0;
+ mock_quic_data.AddWrite(
+ ConstructInitialSettingsPacket(1, &header_stream_offset));
+ mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
+ 2, GetNthClientInitiatedStreamId(0), true, true,
+ GetRequestHeaders("GET", "https", "/"), &header_stream_offset));
+ mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
+ 1, GetNthClientInitiatedStreamId(0), false, false,
+ GetResponseHeaders("200 OK")));
+ mock_quic_data.AddRead(ConstructServerDataPacket(
+ 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!"));
+ mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1));
+ mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
+ mock_quic_data.AddRead(ASYNC, 0); // EOF
+
+ mock_quic_data.AddSocketDataToFactory(&socket_factory_);
+
+ AddHangingNonAlternateProtocolSocketData();
+ CreateSession(supported_versions);
+
+ SendRequestAndExpectHttpResponse("hello world");
+ SendRequestAndExpectQuicResponse("hello!");
+}
+
TEST_P(QuicNetworkTransactionTest,
UseAlternativeServiceWithProbabilityForQuic) {
MockRead http_reads[] = {

Powered by Google App Engine
This is Rietveld 408576698