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

Side by Side Diff: net/quic/quic_stream_factory_test.cc

Issue 1502453003: QUIC - Disable Preconnect when QUIC can be spoken to a server with 0RTT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test name Created 5 years 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/quic/quic_stream_factory.cc ('k') | net/quic/test_tools/quic_stream_factory_peer.h » ('j') | 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/quic/quic_stream_factory.h" 5 #include "net/quic/quic_stream_factory.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "net/base/test_data_directory.h" 10 #include "net/base/test_data_directory.h"
(...skipping 10 matching lines...) Expand all
21 #include "net/quic/crypto/properties_based_quic_server_info.h" 21 #include "net/quic/crypto/properties_based_quic_server_info.h"
22 #include "net/quic/crypto/quic_crypto_client_config.h" 22 #include "net/quic/crypto/quic_crypto_client_config.h"
23 #include "net/quic/crypto/quic_decrypter.h" 23 #include "net/quic/crypto/quic_decrypter.h"
24 #include "net/quic/crypto/quic_encrypter.h" 24 #include "net/quic/crypto/quic_encrypter.h"
25 #include "net/quic/crypto/quic_server_info.h" 25 #include "net/quic/crypto/quic_server_info.h"
26 #include "net/quic/quic_http_stream.h" 26 #include "net/quic/quic_http_stream.h"
27 #include "net/quic/quic_server_id.h" 27 #include "net/quic/quic_server_id.h"
28 #include "net/quic/test_tools/mock_clock.h" 28 #include "net/quic/test_tools/mock_clock.h"
29 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" 29 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
30 #include "net/quic/test_tools/mock_random.h" 30 #include "net/quic/test_tools/mock_random.h"
31 #include "net/quic/test_tools/quic_stream_factory_peer.h"
31 #include "net/quic/test_tools/quic_test_packet_maker.h" 32 #include "net/quic/test_tools/quic_test_packet_maker.h"
32 #include "net/quic/test_tools/quic_test_utils.h" 33 #include "net/quic/test_tools/quic_test_utils.h"
33 #include "net/quic/test_tools/test_task_runner.h" 34 #include "net/quic/test_tools/test_task_runner.h"
34 #include "net/socket/socket_test_util.h" 35 #include "net/socket/socket_test_util.h"
35 #include "net/spdy/spdy_session_test_util.h" 36 #include "net/spdy/spdy_session_test_util.h"
36 #include "net/spdy/spdy_test_utils.h" 37 #include "net/spdy/spdy_test_utils.h"
37 #include "net/ssl/channel_id_service.h" 38 #include "net/ssl/channel_id_service.h"
38 #include "net/ssl/default_channel_id_store.h" 39 #include "net/ssl/default_channel_id_store.h"
39 #include "net/test/cert_test_util.h" 40 #include "net/test/cert_test_util.h"
40 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 QuicVersionVector all_supported_versions = QuicSupportedVersions(); 74 QuicVersionVector all_supported_versions = QuicSupportedVersions();
74 for (const QuicVersion version : all_supported_versions) { 75 for (const QuicVersion version : all_supported_versions) {
75 params.push_back(TestParams(version, false)); 76 params.push_back(TestParams(version, false));
76 params.push_back(TestParams(version, true)); 77 params.push_back(TestParams(version, true));
77 } 78 }
78 return params; 79 return params;
79 } 80 }
80 81
81 } // namespace anonymous 82 } // namespace anonymous
82 83
83 class QuicStreamFactoryPeer {
84 public:
85 static const QuicConfig* GetConfig(QuicStreamFactory* factory) {
86 return &factory->config_;
87 }
88
89 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) {
90 return &factory->crypto_config_;
91 }
92
93 static bool HasActiveSession(QuicStreamFactory* factory,
94 const HostPortPair& host_port_pair) {
95 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED);
96 return factory->HasActiveSession(server_id);
97 }
98
99 static QuicChromiumClientSession* GetActiveSession(
100 QuicStreamFactory* factory,
101 const HostPortPair& host_port_pair) {
102 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED);
103 DCHECK(factory->HasActiveSession(server_id));
104 return factory->active_sessions_[server_id];
105 }
106
107 static scoped_ptr<QuicHttpStream> CreateFromSession(
108 QuicStreamFactory* factory,
109 QuicChromiumClientSession* session) {
110 return factory->CreateFromSession(session);
111 }
112
113 static bool IsLiveSession(QuicStreamFactory* factory,
114 QuicChromiumClientSession* session) {
115 for (QuicStreamFactory::SessionIdMap::iterator it =
116 factory->all_sessions_.begin();
117 it != factory->all_sessions_.end(); ++it) {
118 if (it->first == session)
119 return true;
120 }
121 return false;
122 }
123
124 static void SetTaskRunner(QuicStreamFactory* factory,
125 base::TaskRunner* task_runner) {
126 factory->task_runner_ = task_runner;
127 }
128
129 static int GetNumberOfLossyConnections(QuicStreamFactory* factory,
130 uint16 port) {
131 return factory->number_of_lossy_connections_[port];
132 }
133
134 static bool IsQuicDisabled(QuicStreamFactory* factory, uint16 port) {
135 return factory->IsQuicDisabled(port);
136 }
137
138 static bool GetDelayTcpRace(QuicStreamFactory* factory) {
139 return factory->delay_tcp_race_;
140 }
141
142 static void SetDelayTcpRace(QuicStreamFactory* factory, bool delay_tcp_race) {
143 factory->delay_tcp_race_ = delay_tcp_race;
144 }
145
146 static void SetYieldAfterPackets(QuicStreamFactory* factory,
147 int yield_after_packets) {
148 factory->yield_after_packets_ = yield_after_packets;
149 }
150
151 static void SetYieldAfterDuration(QuicStreamFactory* factory,
152 QuicTime::Delta yield_after_duration) {
153 factory->yield_after_duration_ = yield_after_duration;
154 }
155
156 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory,
157 const QuicServerId& server_id) {
158 return (factory->active_jobs_[server_id]).size();
159 }
160
161 static int GetNumTimeoutsWithOpenStreams(QuicStreamFactory* factory) {
162 return factory->num_timeouts_with_open_streams_;
163 }
164
165 static int GetNumPublicResetsPostHandshake(QuicStreamFactory* factory) {
166 return factory->num_public_resets_post_handshake_;
167 }
168
169 static void MaybeInitialize(QuicStreamFactory* factory) {
170 factory->MaybeInitialize();
171 }
172
173 static bool HasInitializedData(QuicStreamFactory* factory) {
174 return factory->has_initialized_data_;
175 }
176
177 static bool SupportsQuicAtStartUp(QuicStreamFactory* factory,
178 HostPortPair host_port_pair) {
179 return ContainsKey(factory->quic_supported_servers_at_startup_,
180 host_port_pair);
181 }
182
183 static bool CryptoConfigCacheIsEmpty(QuicStreamFactory* factory,
184 QuicServerId& quic_server_id) {
185 return factory->CryptoConfigCacheIsEmpty(quic_server_id);
186 }
187 };
188
189 class MockQuicServerInfo : public QuicServerInfo { 84 class MockQuicServerInfo : public QuicServerInfo {
190 public: 85 public:
191 MockQuicServerInfo(const QuicServerId& server_id) 86 MockQuicServerInfo(const QuicServerId& server_id)
192 : QuicServerInfo(server_id) {} 87 : QuicServerInfo(server_id) {}
193 ~MockQuicServerInfo() override {} 88 ~MockQuicServerInfo() override {}
194 89
195 void Start() override {} 90 void Start() override {}
196 91
197 int WaitForDataReady(const CompletionCallback& callback) override { 92 int WaitForDataReady(const CompletionCallback& callback) override {
198 return ERR_IO_PENDING; 93 return ERR_IO_PENDING;
(...skipping 2530 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 crypto_config->LookupOrCreate(quic_server_id); 2624 crypto_config->LookupOrCreate(quic_server_id);
2730 EXPECT_FALSE(cached->server_config().empty()); 2625 EXPECT_FALSE(cached->server_config().empty());
2731 EXPECT_TRUE(cached->GetServerConfig()); 2626 EXPECT_TRUE(cached->GetServerConfig());
2732 EXPECT_EQ(server_config, cached->server_config()); 2627 EXPECT_EQ(server_config, cached->server_config());
2733 EXPECT_EQ(source_address_token, cached->source_address_token()); 2628 EXPECT_EQ(source_address_token, cached->source_address_token());
2734 EXPECT_EQ(signature, cached->signature()); 2629 EXPECT_EQ(signature, cached->signature());
2735 ASSERT_EQ(1U, cached->certs().size()); 2630 ASSERT_EQ(1U, cached->certs().size());
2736 EXPECT_EQ(test_cert, cached->certs()[0]); 2631 EXPECT_EQ(test_cert, cached->certs()[0]);
2737 } 2632 }
2738 2633
2634 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) {
2635 Initialize();
2636
2637 factory_->set_require_confirmation(true);
2638 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED);
2639 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id));
2640
2641 factory_->set_require_confirmation(false);
2642 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id));
2643
2644 // Load server config and verify QUIC will do 0RTT.
2645 QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id);
2646 EXPECT_TRUE(factory_->ZeroRTTEnabledFor(quic_server_id));
2647 }
2648
2739 TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { 2649 TEST_P(QuicStreamFactoryTest, YieldAfterPackets) {
2740 Initialize(); 2650 Initialize();
2741 QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); 2651 QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0);
2742 2652
2743 scoped_ptr<QuicEncryptedPacket> close_packet( 2653 scoped_ptr<QuicEncryptedPacket> close_packet(
2744 ConstructConnectionClosePacket(0)); 2654 ConstructConnectionClosePacket(0));
2745 vector<MockRead> reads; 2655 vector<MockRead> reads;
2746 reads.push_back( 2656 reads.push_back(
2747 MockRead(SYNCHRONOUS, close_packet->data(), close_packet->length(), 0)); 2657 MockRead(SYNCHRONOUS, close_packet->data(), close_packet->length(), 0));
2748 reads.push_back(MockRead(ASYNC, OK, 1)); 2658 reads.push_back(MockRead(ASYNC, OK, 1));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 EXPECT_EQ(1u, observer.executed_count()); 2732 EXPECT_EQ(1u, observer.executed_count());
2823 2733
2824 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 2734 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2825 EXPECT_TRUE(stream.get()); 2735 EXPECT_TRUE(stream.get());
2826 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 2736 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2827 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 2737 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2828 } 2738 }
2829 2739
2830 } // namespace test 2740 } // namespace test
2831 } // namespace net 2741 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_stream_factory.cc ('k') | net/quic/test_tools/quic_stream_factory_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698