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

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

Issue 16374004: Revert 204046 "Land Recent QUIC changes." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/net/quic/quic_session.cc ('k') | trunk/src/net/quic/reliable_quic_stream.cc » ('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/string_util.h" 8 #include "base/string_util.h"
9 #include "net/dns/mock_host_resolver.h" 9 #include "net/dns/mock_host_resolver.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 BoundNetLog net_log_; 122 BoundNetLog net_log_;
123 TestCompletionCallback callback_; 123 TestCompletionCallback callback_;
124 }; 124 };
125 125
126 TEST_F(QuicStreamFactoryTest, CreateIfSessionExists) { 126 TEST_F(QuicStreamFactoryTest, CreateIfSessionExists) {
127 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, 127 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_,
128 net_log_).get()); 128 net_log_).get());
129 } 129 }
130 130
131 TEST_F(QuicStreamFactoryTest, Create) { 131 TEST_F(QuicStreamFactoryTest, Create) {
132 scoped_ptr<QuicEncryptedPacket> rst3(ConstructRstPacket(1, 3));
133 scoped_ptr<QuicEncryptedPacket> rst5(ConstructRstPacket(2, 5));
134 scoped_ptr<QuicEncryptedPacket> rst7(ConstructRstPacket(3, 7));
135 MockWrite writes[] = {
136 MockWrite(SYNCHRONOUS, rst3->data(), rst3->length(), 0),
137 MockWrite(SYNCHRONOUS, rst5->data(), rst5->length(), 1),
138 MockWrite(SYNCHRONOUS, rst7->data(), rst7->length(), 2),
139 };
132 MockRead reads[] = { 140 MockRead reads[] = {
133 MockRead(ASYNC, OK, 0) // EOF 141 MockRead(ASYNC, OK, 3) // EOF
134 }; 142 };
135 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 143 DeterministicSocketData socket_data(reads, arraysize(reads),
144 writes, arraysize(writes));
136 socket_factory_.AddSocketDataProvider(&socket_data); 145 socket_factory_.AddSocketDataProvider(&socket_data);
137 socket_data.StopAfter(1); 146 socket_data.StopAfter(3);
138 147
139 QuicStreamRequest request(&factory_); 148 QuicStreamRequest request(&factory_);
140 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_, 149 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_,
141 callback_.callback())); 150 callback_.callback()));
142 151
143 EXPECT_EQ(OK, callback_.WaitForResult()); 152 EXPECT_EQ(OK, callback_.WaitForResult());
144 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 153 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
145 EXPECT_TRUE(stream.get()); 154 EXPECT_TRUE(stream.get());
146 155
147 // Will reset stream 3. 156 // Will reset stream 3.
148 stream = factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_); 157 stream = factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_);
149 EXPECT_TRUE(stream.get()); 158 EXPECT_TRUE(stream.get());
150 159
151 QuicStreamRequest request2(&factory_); 160 QuicStreamRequest request2(&factory_);
152 EXPECT_EQ(OK, request2.Request(host_port_proxy_pair_, net_log_, 161 EXPECT_EQ(OK, request2.Request(host_port_proxy_pair_, net_log_,
153 callback_.callback())); 162 callback_.callback()));
154 stream = request2.ReleaseStream(); // Will reset stream 5. 163 stream = request2.ReleaseStream(); // Will reset stream 5.
155 stream.reset(); // Will reset stream 7. 164 stream.reset(); // Will reset stream 7.
156 165
166 socket_data.RunFor(1);
167
157 EXPECT_TRUE(socket_data.at_read_eof()); 168 EXPECT_TRUE(socket_data.at_read_eof());
158 EXPECT_TRUE(socket_data.at_write_eof()); 169 EXPECT_TRUE(socket_data.at_write_eof());
159 } 170 }
160 171
161 TEST_F(QuicStreamFactoryTest, CreateError) { 172 TEST_F(QuicStreamFactoryTest, CreateError) {
162 DeterministicSocketData socket_data(NULL, 0, NULL, 0); 173 DeterministicSocketData socket_data(NULL, 0, NULL, 0);
163 socket_factory_.AddSocketDataProvider(&socket_data); 174 socket_factory_.AddSocketDataProvider(&socket_data);
164 175
165 host_resolver_.rules()->AddSimulatedFailure("www.google.com"); 176 host_resolver_.rules()->AddSimulatedFailure("www.google.com");
166 177
167 QuicStreamRequest request(&factory_); 178 QuicStreamRequest request(&factory_);
168 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_, 179 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_,
169 callback_.callback())); 180 callback_.callback()));
170 181
171 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); 182 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult());
172 183
173 EXPECT_TRUE(socket_data.at_read_eof()); 184 EXPECT_TRUE(socket_data.at_read_eof());
174 EXPECT_TRUE(socket_data.at_write_eof()); 185 EXPECT_TRUE(socket_data.at_write_eof());
175 } 186 }
176 187
177 TEST_F(QuicStreamFactoryTest, CancelCreate) { 188 TEST_F(QuicStreamFactoryTest, CancelCreate) {
189 scoped_ptr<QuicEncryptedPacket> rst3(ConstructRstPacket(1, 3));
190
191 MockWrite writes[] = {
192 MockWrite(SYNCHRONOUS, rst3->data(), rst3->length(), 0),
193 };
178 MockRead reads[] = { 194 MockRead reads[] = {
179 MockRead(ASYNC, OK, 0) // EOF 195 MockRead(ASYNC, OK, 1) // EOF
180 }; 196 };
181 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 197 DeterministicSocketData socket_data(reads, arraysize(reads),
198 writes, arraysize(writes));
182 socket_factory_.AddSocketDataProvider(&socket_data); 199 socket_factory_.AddSocketDataProvider(&socket_data);
183 { 200 {
184 QuicStreamRequest request(&factory_); 201 QuicStreamRequest request(&factory_);
185 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_, 202 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_,
186 callback_.callback())); 203 callback_.callback()));
187 } 204 }
188 205
189 socket_data.StopAfter(1); 206 socket_data.StopAfter(2);
190 base::RunLoop run_loop; 207 base::RunLoop run_loop;
191 run_loop.RunUntilIdle(); 208 run_loop.RunUntilIdle();
192 209
193 scoped_ptr<QuicHttpStream> stream( 210 scoped_ptr<QuicHttpStream> stream(
194 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_)); 211 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_));
195 EXPECT_TRUE(stream.get()); 212 EXPECT_TRUE(stream.get());
196 stream.reset(); 213 stream.reset();
197 214
215 socket_data.RunFor(1);
216
198 EXPECT_TRUE(socket_data.at_read_eof()); 217 EXPECT_TRUE(socket_data.at_read_eof());
199 EXPECT_TRUE(socket_data.at_write_eof()); 218 EXPECT_TRUE(socket_data.at_write_eof());
200 } 219 }
201 220
202 TEST_F(QuicStreamFactoryTest, CloseAllSessions) { 221 TEST_F(QuicStreamFactoryTest, CloseAllSessions) {
222 scoped_ptr<QuicEncryptedPacket> rst3(ConstructRstPacket(1, 3));
203 MockRead reads[] = { 223 MockRead reads[] = {
204 MockRead(ASYNC, 0, 0) // EOF 224 MockRead(ASYNC, 0, 0) // EOF
205 }; 225 };
206 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 226 DeterministicSocketData socket_data(reads, arraysize(reads),
227 NULL, 0);
207 socket_factory_.AddSocketDataProvider(&socket_data); 228 socket_factory_.AddSocketDataProvider(&socket_data);
208 socket_data.StopAfter(1); 229 socket_data.StopAfter(1);
209 230
231 MockWrite writes2[] = {
232 MockWrite(SYNCHRONOUS, rst3->data(), rst3->length(), 0),
233 };
210 MockRead reads2[] = { 234 MockRead reads2[] = {
211 MockRead(ASYNC, 0, 0) // EOF 235 MockRead(ASYNC, 0, 1) // EOF
212 }; 236 };
213 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); 237 DeterministicSocketData socket_data2(reads2, arraysize(reads2),
238 writes2, arraysize(writes2));
214 socket_factory_.AddSocketDataProvider(&socket_data2); 239 socket_factory_.AddSocketDataProvider(&socket_data2);
215 socket_data2.StopAfter(1); 240 socket_data2.StopAfter(1);
216 241
217 QuicStreamRequest request(&factory_); 242 QuicStreamRequest request(&factory_);
218 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_, 243 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_,
219 callback_.callback())); 244 callback_.callback()));
220 245
221 EXPECT_EQ(OK, callback_.WaitForResult()); 246 EXPECT_EQ(OK, callback_.WaitForResult());
222 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 247 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
223 248
224 // Close the session and verify that stream saw the error. 249 // Close the session and verify that stream saw the error.
225 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); 250 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED);
226 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, 251 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
227 stream->ReadResponseHeaders(callback_.callback())); 252 stream->ReadResponseHeaders(callback_.callback()));
228 253
229 // Now attempting to request a stream to the same origin should create 254 // Now attempting to request a stream to the same origin should create
230 // a new session. 255 // a new session.
231 256
232 QuicStreamRequest request2(&factory_); 257 QuicStreamRequest request2(&factory_);
233 EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, net_log_, 258 EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, net_log_,
234 callback_.callback())); 259 callback_.callback()));
235 260
236 EXPECT_EQ(OK, callback_.WaitForResult()); 261 EXPECT_EQ(OK, callback_.WaitForResult());
237 stream = request2.ReleaseStream(); 262 stream = request2.ReleaseStream();
238 stream.reset(); // Will reset stream 3. 263 stream.reset(); // Will reset stream 3.
239 264
265 socket_data2.RunFor(1);
266
240 EXPECT_TRUE(socket_data.at_read_eof()); 267 EXPECT_TRUE(socket_data.at_read_eof());
241 EXPECT_TRUE(socket_data.at_write_eof()); 268 EXPECT_TRUE(socket_data.at_write_eof());
242 EXPECT_TRUE(socket_data2.at_read_eof()); 269 EXPECT_TRUE(socket_data2.at_read_eof());
243 EXPECT_TRUE(socket_data2.at_write_eof()); 270 EXPECT_TRUE(socket_data2.at_write_eof());
244 } 271 }
245 272
246 TEST_F(QuicStreamFactoryTest, OnIPAddressChanged) { 273 TEST_F(QuicStreamFactoryTest, OnIPAddressChanged) {
274 scoped_ptr<QuicEncryptedPacket> rst3(ConstructRstPacket(1, 3));
247 MockRead reads[] = { 275 MockRead reads[] = {
248 MockRead(ASYNC, 0, 0) // EOF 276 MockRead(ASYNC, 0, 0) // EOF
249 }; 277 };
250 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); 278 DeterministicSocketData socket_data(reads, arraysize(reads),
279 NULL, 0);
251 socket_factory_.AddSocketDataProvider(&socket_data); 280 socket_factory_.AddSocketDataProvider(&socket_data);
252 socket_data.StopAfter(1); 281 socket_data.StopAfter(1);
253 282
283 MockWrite writes2[] = {
284 MockWrite(SYNCHRONOUS, rst3->data(), rst3->length(), 0),
285 };
254 MockRead reads2[] = { 286 MockRead reads2[] = {
255 MockRead(ASYNC, 0, 0) // EOF 287 MockRead(ASYNC, 0, 1) // EOF
256 }; 288 };
257 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); 289 DeterministicSocketData socket_data2(reads2, arraysize(reads2),
290 writes2, arraysize(writes2));
258 socket_factory_.AddSocketDataProvider(&socket_data2); 291 socket_factory_.AddSocketDataProvider(&socket_data2);
259 socket_data2.StopAfter(1); 292 socket_data2.StopAfter(1);
260 293
261 QuicStreamRequest request(&factory_); 294 QuicStreamRequest request(&factory_);
262 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_, 295 EXPECT_EQ(ERR_IO_PENDING, request.Request(host_port_proxy_pair_, net_log_,
263 callback_.callback())); 296 callback_.callback()));
264 297
265 EXPECT_EQ(OK, callback_.WaitForResult()); 298 EXPECT_EQ(OK, callback_.WaitForResult());
266 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 299 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
267 300
268 // Change the IP address and verify that stream saw the error. 301 // Change the IP address and verify that stream saw the error.
269 factory_.OnIPAddressChanged(); 302 factory_.OnIPAddressChanged();
270 EXPECT_EQ(ERR_NETWORK_CHANGED, 303 EXPECT_EQ(ERR_NETWORK_CHANGED,
271 stream->ReadResponseHeaders(callback_.callback())); 304 stream->ReadResponseHeaders(callback_.callback()));
272 305
273 // Now attempting to request a stream to the same origin should create 306 // Now attempting to request a stream to the same origin should create
274 // a new session. 307 // a new session.
275 308
276 QuicStreamRequest request2(&factory_); 309 QuicStreamRequest request2(&factory_);
277 EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, net_log_, 310 EXPECT_EQ(ERR_IO_PENDING, request2.Request(host_port_proxy_pair_, net_log_,
278 callback_.callback())); 311 callback_.callback()));
279 312
280 EXPECT_EQ(OK, callback_.WaitForResult()); 313 EXPECT_EQ(OK, callback_.WaitForResult());
281 stream = request2.ReleaseStream(); 314 stream = request2.ReleaseStream();
282 stream.reset(); // Will reset stream 3. 315 stream.reset(); // Will reset stream 3.
283 316
317 socket_data2.RunFor(1);
318
284 EXPECT_TRUE(socket_data.at_read_eof()); 319 EXPECT_TRUE(socket_data.at_read_eof());
285 EXPECT_TRUE(socket_data.at_write_eof()); 320 EXPECT_TRUE(socket_data.at_write_eof());
286 EXPECT_TRUE(socket_data2.at_read_eof()); 321 EXPECT_TRUE(socket_data2.at_read_eof());
287 EXPECT_TRUE(socket_data2.at_write_eof()); 322 EXPECT_TRUE(socket_data2.at_write_eof());
288 } 323 }
289 324
290 } // namespace test 325 } // namespace test
291 } // namespace net 326 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/quic/quic_session.cc ('k') | trunk/src/net/quic/reliable_quic_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698