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

Side by Side Diff: net/url_request/url_request_job_unittest.cc

Issue 2837543002: Test network annotation tags added to unittests in net/url_request. (Closed)
Patch Set: Created 3 years, 8 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
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/url_request/url_request_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "net/base/request_priority.h" 10 #include "net/base/request_priority.h"
11 #include "net/http/http_transaction_test_util.h" 11 #include "net/http/http_transaction_test_util.h"
12 #include "net/test/cert_test_util.h" 12 #include "net/test/cert_test_util.h"
13 #include "net/test/gtest_util.h" 13 #include "net/test/gtest_util.h"
14 #include "net/test/test_data_directory.h" 14 #include "net/test/test_data_directory.h"
15 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
15 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_test_util.h" 17 #include "net/url_request/url_request_test_util.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using net::test::IsError; 21 using net::test::IsError;
21 using net::test::IsOk; 22 using net::test::IsOk;
22 23
23 namespace net { 24 namespace net {
24 25
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 }; 172 };
172 173
173 } // namespace 174 } // namespace
174 175
175 TEST(URLRequestJob, TransactionNoFilter) { 176 TEST(URLRequestJob, TransactionNoFilter) {
176 MockNetworkLayer network_layer; 177 MockNetworkLayer network_layer;
177 TestURLRequestContext context; 178 TestURLRequestContext context;
178 context.set_http_transaction_factory(&network_layer); 179 context.set_http_transaction_factory(&network_layer);
179 180
180 TestDelegate d; 181 TestDelegate d;
181 std::unique_ptr<URLRequest> req(context.CreateRequest( 182 std::unique_ptr<URLRequest> req(
182 GURL(kNoFilter_Transaction.url), DEFAULT_PRIORITY, &d)); 183 context.CreateRequest(GURL(kNoFilter_Transaction.url), DEFAULT_PRIORITY,
184 &d, TRAFFIC_ANNOTATION_FOR_TESTS));
183 AddMockTransaction(&kNoFilter_Transaction); 185 AddMockTransaction(&kNoFilter_Transaction);
184 186
185 req->set_method("GET"); 187 req->set_method("GET");
186 req->Start(); 188 req->Start();
187 189
188 base::RunLoop().Run(); 190 base::RunLoop().Run();
189 191
190 EXPECT_FALSE(d.request_failed()); 192 EXPECT_FALSE(d.request_failed());
191 EXPECT_EQ(200, req->GetResponseCode()); 193 EXPECT_EQ(200, req->GetResponseCode());
192 EXPECT_EQ("hello", d.data_received()); 194 EXPECT_EQ("hello", d.data_received());
193 EXPECT_TRUE(network_layer.done_reading_called()); 195 EXPECT_TRUE(network_layer.done_reading_called());
194 196
195 RemoveMockTransaction(&kNoFilter_Transaction); 197 RemoveMockTransaction(&kNoFilter_Transaction);
196 } 198 }
197 199
198 TEST(URLRequestJob, TransactionNotifiedWhenDone) { 200 TEST(URLRequestJob, TransactionNotifiedWhenDone) {
199 MockNetworkLayer network_layer; 201 MockNetworkLayer network_layer;
200 TestURLRequestContext context; 202 TestURLRequestContext context;
201 context.set_http_transaction_factory(&network_layer); 203 context.set_http_transaction_factory(&network_layer);
202 204
203 TestDelegate d; 205 TestDelegate d;
204 std::unique_ptr<URLRequest> req( 206 std::unique_ptr<URLRequest> req(
205 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 207 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d,
208 TRAFFIC_ANNOTATION_FOR_TESTS));
206 AddMockTransaction(&kGZip_Transaction); 209 AddMockTransaction(&kGZip_Transaction);
207 210
208 req->set_method("GET"); 211 req->set_method("GET");
209 req->Start(); 212 req->Start();
210 213
211 base::RunLoop().Run(); 214 base::RunLoop().Run();
212 215
213 EXPECT_TRUE(d.response_completed()); 216 EXPECT_TRUE(d.response_completed());
214 EXPECT_EQ(OK, d.request_status()); 217 EXPECT_EQ(OK, d.request_status());
215 EXPECT_EQ(200, req->GetResponseCode()); 218 EXPECT_EQ(200, req->GetResponseCode());
216 EXPECT_EQ("", d.data_received()); 219 EXPECT_EQ("", d.data_received());
217 EXPECT_TRUE(network_layer.done_reading_called()); 220 EXPECT_TRUE(network_layer.done_reading_called());
218 221
219 RemoveMockTransaction(&kGZip_Transaction); 222 RemoveMockTransaction(&kGZip_Transaction);
220 } 223 }
221 224
222 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { 225 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) {
223 MockNetworkLayer network_layer; 226 MockNetworkLayer network_layer;
224 TestURLRequestContext context; 227 TestURLRequestContext context;
225 context.set_http_transaction_factory(&network_layer); 228 context.set_http_transaction_factory(&network_layer);
226 229
227 TestDelegate d; 230 TestDelegate d;
228 std::unique_ptr<URLRequest> req( 231 std::unique_ptr<URLRequest> req(
229 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 232 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d,
233 TRAFFIC_ANNOTATION_FOR_TESTS));
230 MockTransaction transaction(kGZip_Transaction); 234 MockTransaction transaction(kGZip_Transaction);
231 transaction.test_mode = TEST_MODE_SYNC_ALL; 235 transaction.test_mode = TEST_MODE_SYNC_ALL;
232 AddMockTransaction(&transaction); 236 AddMockTransaction(&transaction);
233 237
234 req->set_method("GET"); 238 req->set_method("GET");
235 req->Start(); 239 req->Start();
236 240
237 base::RunLoop().Run(); 241 base::RunLoop().Run();
238 242
239 EXPECT_TRUE(d.response_completed()); 243 EXPECT_TRUE(d.response_completed());
240 EXPECT_EQ(OK, d.request_status()); 244 EXPECT_EQ(OK, d.request_status());
241 EXPECT_EQ(200, req->GetResponseCode()); 245 EXPECT_EQ(200, req->GetResponseCode());
242 EXPECT_EQ("", d.data_received()); 246 EXPECT_EQ("", d.data_received());
243 EXPECT_TRUE(network_layer.done_reading_called()); 247 EXPECT_TRUE(network_layer.done_reading_called());
244 248
245 RemoveMockTransaction(&transaction); 249 RemoveMockTransaction(&transaction);
246 } 250 }
247 251
248 // Tests processing a large gzip header one byte at a time. 252 // Tests processing a large gzip header one byte at a time.
249 TEST(URLRequestJob, SyncSlowTransaction) { 253 TEST(URLRequestJob, SyncSlowTransaction) {
250 MockNetworkLayer network_layer; 254 MockNetworkLayer network_layer;
251 TestURLRequestContext context; 255 TestURLRequestContext context;
252 context.set_http_transaction_factory(&network_layer); 256 context.set_http_transaction_factory(&network_layer);
253 257
254 TestDelegate d; 258 TestDelegate d;
255 std::unique_ptr<URLRequest> req( 259 std::unique_ptr<URLRequest> req(
256 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 260 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d,
261 TRAFFIC_ANNOTATION_FOR_TESTS));
257 MockTransaction transaction(kGZip_Transaction); 262 MockTransaction transaction(kGZip_Transaction);
258 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ; 263 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ;
259 transaction.handler = &BigGZipServer; 264 transaction.handler = &BigGZipServer;
260 AddMockTransaction(&transaction); 265 AddMockTransaction(&transaction);
261 266
262 req->set_method("GET"); 267 req->set_method("GET");
263 req->Start(); 268 req->Start();
264 269
265 base::RunLoop().Run(); 270 base::RunLoop().Run();
266 271
267 EXPECT_TRUE(d.response_completed()); 272 EXPECT_TRUE(d.response_completed());
268 EXPECT_EQ(OK, d.request_status()); 273 EXPECT_EQ(OK, d.request_status());
269 EXPECT_EQ(200, req->GetResponseCode()); 274 EXPECT_EQ(200, req->GetResponseCode());
270 EXPECT_EQ("", d.data_received()); 275 EXPECT_EQ("", d.data_received());
271 EXPECT_TRUE(network_layer.done_reading_called()); 276 EXPECT_TRUE(network_layer.done_reading_called());
272 277
273 RemoveMockTransaction(&transaction); 278 RemoveMockTransaction(&transaction);
274 } 279 }
275 280
276 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { 281 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) {
277 MockNetworkLayer network_layer; 282 MockNetworkLayer network_layer;
278 TestURLRequestContext context; 283 TestURLRequestContext context;
279 context.set_http_transaction_factory(&network_layer); 284 context.set_http_transaction_factory(&network_layer);
280 285
281 TestDelegate d; 286 TestDelegate d;
282 std::unique_ptr<URLRequest> req(context.CreateRequest( 287 std::unique_ptr<URLRequest> req(
283 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d)); 288 context.CreateRequest(GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY,
289 &d, TRAFFIC_ANNOTATION_FOR_TESTS));
284 AddMockTransaction(&kRedirect_Transaction); 290 AddMockTransaction(&kRedirect_Transaction);
285 291
286 req->set_method("GET"); 292 req->set_method("GET");
287 req->Start(); 293 req->Start();
288 294
289 base::RunLoop().Run(); 295 base::RunLoop().Run();
290 296
291 EXPECT_TRUE(network_layer.done_reading_called()); 297 EXPECT_TRUE(network_layer.done_reading_called());
292 298
293 RemoveMockTransaction(&kRedirect_Transaction); 299 RemoveMockTransaction(&kRedirect_Transaction);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 MakeMockReferrerPolicyTransaction(test.original_url, 467 MakeMockReferrerPolicyTransaction(test.original_url,
462 request_headers.c_str(), 468 request_headers.c_str(),
463 test.response_headers, &transaction); 469 test.response_headers, &transaction);
464 470
465 MockNetworkLayer network_layer; 471 MockNetworkLayer network_layer;
466 TestURLRequestContext context; 472 TestURLRequestContext context;
467 context.set_http_transaction_factory(&network_layer); 473 context.set_http_transaction_factory(&network_layer);
468 474
469 TestDelegate d; 475 TestDelegate d;
470 std::unique_ptr<URLRequest> req( 476 std::unique_ptr<URLRequest> req(
471 context.CreateRequest(GURL(transaction.url), DEFAULT_PRIORITY, &d)); 477 context.CreateRequest(GURL(transaction.url), DEFAULT_PRIORITY, &d,
478 TRAFFIC_ANNOTATION_FOR_TESTS));
472 AddMockTransaction(&transaction); 479 AddMockTransaction(&transaction);
473 480
474 req->set_referrer_policy(test.original_referrer_policy); 481 req->set_referrer_policy(test.original_referrer_policy);
475 req->SetReferrer(test.original_referrer); 482 req->SetReferrer(test.original_referrer);
476 483
477 req->set_method("GET"); 484 req->set_method("GET");
478 req->Start(); 485 req->Start();
479 486
480 base::RunLoop().Run(); 487 base::RunLoop().Run();
481 488
(...skipping 11 matching lines...) Expand all
493 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) { 500 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) {
494 MockNetworkLayer network_layer; 501 MockNetworkLayer network_layer;
495 TestNetworkDelegate network_delegate; 502 TestNetworkDelegate network_delegate;
496 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo")); 503 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo"));
497 TestURLRequestContext context; 504 TestURLRequestContext context;
498 context.set_http_transaction_factory(&network_layer); 505 context.set_http_transaction_factory(&network_layer);
499 context.set_network_delegate(&network_delegate); 506 context.set_network_delegate(&network_delegate);
500 507
501 TestDelegate d; 508 TestDelegate d;
502 std::unique_ptr<URLRequest> req( 509 std::unique_ptr<URLRequest> req(
503 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 510 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d,
511 TRAFFIC_ANNOTATION_FOR_TESTS));
504 AddMockTransaction(&kGZip_Transaction); 512 AddMockTransaction(&kGZip_Transaction);
505 513
506 req->set_method("GET"); 514 req->set_method("GET");
507 req->Start(); 515 req->Start();
508 516
509 base::RunLoop().Run(); 517 base::RunLoop().Run();
510 518
511 EXPECT_TRUE(network_layer.stop_caching_called()); 519 EXPECT_TRUE(network_layer.stop_caching_called());
512 520
513 RemoveMockTransaction(&kGZip_Transaction); 521 RemoveMockTransaction(&kGZip_Transaction);
514 } 522 }
515 523
516 // Makes sure that ReadRawDataComplete correctly updates request status before 524 // Makes sure that ReadRawDataComplete correctly updates request status before
517 // calling ReadFilteredData. 525 // calling ReadFilteredData.
518 // Regression test for crbug.com/553300. 526 // Regression test for crbug.com/553300.
519 TEST(URLRequestJob, EmptyBodySkipFilter) { 527 TEST(URLRequestJob, EmptyBodySkipFilter) {
520 MockNetworkLayer network_layer; 528 MockNetworkLayer network_layer;
521 TestURLRequestContext context; 529 TestURLRequestContext context;
522 context.set_http_transaction_factory(&network_layer); 530 context.set_http_transaction_factory(&network_layer);
523 531
524 TestDelegate d; 532 TestDelegate d;
525 std::unique_ptr<URLRequest> req(context.CreateRequest( 533 std::unique_ptr<URLRequest> req(context.CreateRequest(
526 GURL(kEmptyBodyGzip_Transaction.url), DEFAULT_PRIORITY, &d)); 534 GURL(kEmptyBodyGzip_Transaction.url), DEFAULT_PRIORITY, &d,
535 TRAFFIC_ANNOTATION_FOR_TESTS));
527 AddMockTransaction(&kEmptyBodyGzip_Transaction); 536 AddMockTransaction(&kEmptyBodyGzip_Transaction);
528 537
529 req->set_method("GET"); 538 req->set_method("GET");
530 req->Start(); 539 req->Start();
531 540
532 base::RunLoop().Run(); 541 base::RunLoop().Run();
533 542
534 EXPECT_FALSE(d.request_failed()); 543 EXPECT_FALSE(d.request_failed());
535 EXPECT_EQ(200, req->GetResponseCode()); 544 EXPECT_EQ(200, req->GetResponseCode());
536 EXPECT_TRUE(d.data_received().empty()); 545 EXPECT_TRUE(d.data_received().empty());
537 EXPECT_TRUE(network_layer.done_reading_called()); 546 EXPECT_TRUE(network_layer.done_reading_called());
538 547
539 RemoveMockTransaction(&kEmptyBodyGzip_Transaction); 548 RemoveMockTransaction(&kEmptyBodyGzip_Transaction);
540 } 549 }
541 550
542 // Regression test for crbug.com/575213. 551 // Regression test for crbug.com/575213.
543 TEST(URLRequestJob, InvalidContentGZipTransaction) { 552 TEST(URLRequestJob, InvalidContentGZipTransaction) {
544 MockNetworkLayer network_layer; 553 MockNetworkLayer network_layer;
545 TestURLRequestContext context; 554 TestURLRequestContext context;
546 context.set_http_transaction_factory(&network_layer); 555 context.set_http_transaction_factory(&network_layer);
547 556
548 TestDelegate d; 557 TestDelegate d;
549 std::unique_ptr<URLRequest> req(context.CreateRequest( 558 std::unique_ptr<URLRequest> req(context.CreateRequest(
550 GURL(kInvalidContentGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 559 GURL(kInvalidContentGZip_Transaction.url), DEFAULT_PRIORITY, &d,
560 TRAFFIC_ANNOTATION_FOR_TESTS));
551 AddMockTransaction(&kInvalidContentGZip_Transaction); 561 AddMockTransaction(&kInvalidContentGZip_Transaction);
552 562
553 req->set_method("GET"); 563 req->set_method("GET");
554 req->Start(); 564 req->Start();
555 565
556 base::RunLoop().Run(); 566 base::RunLoop().Run();
557 567
558 // Request failed indicates the request failed before headers were received, 568 // Request failed indicates the request failed before headers were received,
559 // so should be false. 569 // so should be false.
560 EXPECT_FALSE(d.request_failed()); 570 EXPECT_FALSE(d.request_failed());
561 EXPECT_EQ(200, req->GetResponseCode()); 571 EXPECT_EQ(200, req->GetResponseCode());
562 EXPECT_FALSE(req->status().is_success()); 572 EXPECT_FALSE(req->status().is_success());
563 EXPECT_EQ(ERR_CONTENT_DECODING_FAILED, d.request_status()); 573 EXPECT_EQ(ERR_CONTENT_DECODING_FAILED, d.request_status());
564 EXPECT_TRUE(d.data_received().empty()); 574 EXPECT_TRUE(d.data_received().empty());
565 EXPECT_FALSE(network_layer.done_reading_called()); 575 EXPECT_FALSE(network_layer.done_reading_called());
566 576
567 RemoveMockTransaction(&kInvalidContentGZip_Transaction); 577 RemoveMockTransaction(&kInvalidContentGZip_Transaction);
568 } 578 }
569 579
570 // Regression test for crbug.com/553300. 580 // Regression test for crbug.com/553300.
571 TEST(URLRequestJob, SlowFilterRead) { 581 TEST(URLRequestJob, SlowFilterRead) {
572 MockNetworkLayer network_layer; 582 MockNetworkLayer network_layer;
573 TestURLRequestContext context; 583 TestURLRequestContext context;
574 context.set_http_transaction_factory(&network_layer); 584 context.set_http_transaction_factory(&network_layer);
575 585
576 TestDelegate d; 586 TestDelegate d;
577 std::unique_ptr<URLRequest> req(context.CreateRequest( 587 std::unique_ptr<URLRequest> req(
578 GURL(kGzip_Slow_Transaction.url), DEFAULT_PRIORITY, &d)); 588 context.CreateRequest(GURL(kGzip_Slow_Transaction.url), DEFAULT_PRIORITY,
589 &d, TRAFFIC_ANNOTATION_FOR_TESTS));
579 AddMockTransaction(&kGzip_Slow_Transaction); 590 AddMockTransaction(&kGzip_Slow_Transaction);
580 591
581 req->set_method("GET"); 592 req->set_method("GET");
582 req->Start(); 593 req->Start();
583 594
584 base::RunLoop().Run(); 595 base::RunLoop().Run();
585 596
586 EXPECT_FALSE(d.request_failed()); 597 EXPECT_FALSE(d.request_failed());
587 EXPECT_EQ(200, req->GetResponseCode()); 598 EXPECT_EQ(200, req->GetResponseCode());
588 EXPECT_EQ("hello\n", d.data_received()); 599 EXPECT_EQ("hello\n", d.data_received());
589 EXPECT_TRUE(network_layer.done_reading_called()); 600 EXPECT_TRUE(network_layer.done_reading_called());
590 601
591 RemoveMockTransaction(&kGzip_Slow_Transaction); 602 RemoveMockTransaction(&kGzip_Slow_Transaction);
592 } 603 }
593 604
594 TEST(URLRequestJob, SlowBrotliRead) { 605 TEST(URLRequestJob, SlowBrotliRead) {
595 MockNetworkLayer network_layer; 606 MockNetworkLayer network_layer;
596 TestURLRequestContext context; 607 TestURLRequestContext context;
597 context.set_http_transaction_factory(&network_layer); 608 context.set_http_transaction_factory(&network_layer);
598 609
599 TestDelegate d; 610 TestDelegate d;
600 std::unique_ptr<URLRequest> req(context.CreateRequest( 611 std::unique_ptr<URLRequest> req(context.CreateRequest(
601 GURL(kBrotli_Slow_Transaction.url), DEFAULT_PRIORITY, &d)); 612 GURL(kBrotli_Slow_Transaction.url), DEFAULT_PRIORITY, &d,
613 TRAFFIC_ANNOTATION_FOR_TESTS));
602 AddMockTransaction(&kBrotli_Slow_Transaction); 614 AddMockTransaction(&kBrotli_Slow_Transaction);
603 615
604 req->set_method("GET"); 616 req->set_method("GET");
605 req->Start(); 617 req->Start();
606 618
607 base::RunLoop().RunUntilIdle(); 619 base::RunLoop().RunUntilIdle();
608 620
609 EXPECT_FALSE(d.request_failed()); 621 EXPECT_FALSE(d.request_failed());
610 EXPECT_EQ(200, req->GetResponseCode()); 622 EXPECT_EQ(200, req->GetResponseCode());
611 EXPECT_EQ(kHelloData, d.data_received()); 623 EXPECT_EQ(kHelloData, d.data_received());
612 EXPECT_TRUE(network_layer.done_reading_called()); 624 EXPECT_TRUE(network_layer.done_reading_called());
613 625
614 RemoveMockTransaction(&kBrotli_Slow_Transaction); 626 RemoveMockTransaction(&kBrotli_Slow_Transaction);
615 } 627 }
616 628
617 } // namespace net 629 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job_factory_impl_unittest.cc ('k') | net/url_request/url_request_quic_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698