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

Side by Side Diff: content/browser/appcache/appcache_request_handler_unittest.cc

Issue 2799133005: Network traffic annotation added to appcache_update_job. (Closed)
Patch Set: Comments addressed. Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/appcache/appcache_request_handler.h" 5 #include "content/browser/appcache/appcache_request_handler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <stack> 9 #include <stack>
10 #include <string> 10 #include <string>
(...skipping 14 matching lines...) Expand all
25 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
26 #include "content/browser/appcache/appcache.h" 26 #include "content/browser/appcache/appcache.h"
27 #include "content/browser/appcache/appcache_backend_impl.h" 27 #include "content/browser/appcache/appcache_backend_impl.h"
28 #include "content/browser/appcache/appcache_url_request_job.h" 28 #include "content/browser/appcache/appcache_url_request_job.h"
29 #include "content/browser/appcache/mock_appcache_policy.h" 29 #include "content/browser/appcache/mock_appcache_policy.h"
30 #include "content/browser/appcache/mock_appcache_service.h" 30 #include "content/browser/appcache/mock_appcache_service.h"
31 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
32 #include "net/base/request_priority.h" 32 #include "net/base/request_priority.h"
33 #include "net/http/http_response_headers.h" 33 #include "net/http/http_response_headers.h"
34 #include "net/http/http_util.h" 34 #include "net/http/http_util.h"
35 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
35 #include "net/url_request/url_request.h" 36 #include "net/url_request/url_request.h"
36 #include "net/url_request/url_request_context.h" 37 #include "net/url_request/url_request_context.h"
37 #include "net/url_request/url_request_error_job.h" 38 #include "net/url_request/url_request_error_job.h"
38 #include "net/url_request/url_request_job_factory.h" 39 #include "net/url_request/url_request_job_factory.h"
39 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
40 41
41 namespace content { 42 namespace content {
42 43
43 static const int kMockProcessId = 1; 44 static const int kMockProcessId = 1;
44 45
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 264 }
264 265
265 // MainResource_Miss -------------------------------------------------- 266 // MainResource_Miss --------------------------------------------------
266 267
267 void MainResource_Miss() { 268 void MainResource_Miss() {
268 PushNextTask( 269 PushNextTask(
269 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, 270 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss,
270 base::Unretained(this))); 271 base::Unretained(this)));
271 272
272 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 273 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
273 net::DEFAULT_PRIORITY, &delegate_); 274 net::DEFAULT_PRIORITY, &delegate_,
275 TRAFFIC_ANNOTATION_FOR_TESTS);
274 handler_ = host_->CreateRequestHandler(request_.get(), 276 handler_ = host_->CreateRequestHandler(request_.get(),
275 RESOURCE_TYPE_MAIN_FRAME, false); 277 RESOURCE_TYPE_MAIN_FRAME, false);
276 EXPECT_TRUE(handler_.get()); 278 EXPECT_TRUE(handler_.get());
277 279
278 job_.reset(handler_->MaybeLoadResource( 280 job_.reset(handler_->MaybeLoadResource(
279 request_.get(), request_->context()->network_delegate())); 281 request_.get(), request_->context()->network_delegate()));
280 EXPECT_TRUE(job_.get()); 282 EXPECT_TRUE(job_.get());
281 EXPECT_TRUE(job_->is_waiting()); 283 EXPECT_TRUE(job_->is_waiting());
282 284
283 // We have to wait for completion of storage->FindResponseForMainRequest. 285 // We have to wait for completion of storage->FindResponseForMainRequest.
(...skipping 26 matching lines...) Expand all
310 } 312 }
311 313
312 // MainResource_Hit -------------------------------------------------- 314 // MainResource_Hit --------------------------------------------------
313 315
314 void MainResource_Hit() { 316 void MainResource_Hit() {
315 PushNextTask( 317 PushNextTask(
316 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit, 318 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit,
317 base::Unretained(this))); 319 base::Unretained(this)));
318 320
319 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 321 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
320 net::DEFAULT_PRIORITY, &delegate_); 322 net::DEFAULT_PRIORITY, &delegate_,
323 TRAFFIC_ANNOTATION_FOR_TESTS);
321 handler_ = host_->CreateRequestHandler(request_.get(), 324 handler_ = host_->CreateRequestHandler(request_.get(),
322 RESOURCE_TYPE_MAIN_FRAME, false); 325 RESOURCE_TYPE_MAIN_FRAME, false);
323 EXPECT_TRUE(handler_.get()); 326 EXPECT_TRUE(handler_.get());
324 327
325 mock_storage()->SimulateFindMainResource( 328 mock_storage()->SimulateFindMainResource(
326 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 329 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
327 GURL(), AppCacheEntry(), 330 GURL(), AppCacheEntry(),
328 1, 2, GURL("http://blah/manifest/")); 331 1, 2, GURL("http://blah/manifest/"));
329 332
330 job_.reset(handler_->MaybeLoadResource( 333 job_.reset(handler_->MaybeLoadResource(
(...skipping 28 matching lines...) Expand all
359 } 362 }
360 363
361 // MainResource_Fallback -------------------------------------------------- 364 // MainResource_Fallback --------------------------------------------------
362 365
363 void MainResource_Fallback() { 366 void MainResource_Fallback() {
364 PushNextTask( 367 PushNextTask(
365 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback, 368 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback,
366 base::Unretained(this))); 369 base::Unretained(this)));
367 370
368 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 371 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
369 net::DEFAULT_PRIORITY, &delegate_); 372 net::DEFAULT_PRIORITY, &delegate_,
373 TRAFFIC_ANNOTATION_FOR_TESTS);
370 handler_ = host_->CreateRequestHandler(request_.get(), 374 handler_ = host_->CreateRequestHandler(request_.get(),
371 RESOURCE_TYPE_MAIN_FRAME, false); 375 RESOURCE_TYPE_MAIN_FRAME, false);
372 EXPECT_TRUE(handler_.get()); 376 EXPECT_TRUE(handler_.get());
373 377
374 mock_storage()->SimulateFindMainResource( 378 mock_storage()->SimulateFindMainResource(
375 AppCacheEntry(), 379 AppCacheEntry(),
376 GURL("http://blah/fallbackurl"), 380 GURL("http://blah/fallbackurl"),
377 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 381 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
378 1, 2, GURL("http://blah/manifest/")); 382 1, 2, GURL("http://blah/manifest/"));
379 383
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 TestFinished(); 448 TestFinished();
445 } 449 }
446 450
447 // MainResource_FallbackOverride -------------------------------------------- 451 // MainResource_FallbackOverride --------------------------------------------
448 452
449 void MainResource_FallbackOverride() { 453 void MainResource_FallbackOverride() {
450 PushNextTask(base::Bind( 454 PushNextTask(base::Bind(
451 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride, 455 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride,
452 base::Unretained(this))); 456 base::Unretained(this)));
453 457
454 request_ = 458 request_ = empty_context_->CreateRequest(
455 empty_context_->CreateRequest(GURL("http://blah/fallback-override"), 459 GURL("http://blah/fallback-override"), net::DEFAULT_PRIORITY,
456 net::DEFAULT_PRIORITY, &delegate_); 460 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
457 handler_ = host_->CreateRequestHandler(request_.get(), 461 handler_ = host_->CreateRequestHandler(request_.get(),
458 RESOURCE_TYPE_MAIN_FRAME, false); 462 RESOURCE_TYPE_MAIN_FRAME, false);
459 EXPECT_TRUE(handler_.get()); 463 EXPECT_TRUE(handler_.get());
460 464
461 mock_storage()->SimulateFindMainResource( 465 mock_storage()->SimulateFindMainResource(
462 AppCacheEntry(), 466 AppCacheEntry(),
463 GURL("http://blah/fallbackurl"), 467 GURL("http://blah/fallbackurl"),
464 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 468 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
465 1, 2, GURL("http://blah/manifest/")); 469 1, 2, GURL("http://blah/manifest/"));
466 470
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 EXPECT_EQ(kAppCacheNoCacheId, cache_id); 514 EXPECT_EQ(kAppCacheNoCacheId, cache_id);
511 EXPECT_TRUE(manifest_url.is_empty()); 515 EXPECT_TRUE(manifest_url.is_empty());
512 516
513 TestFinished(); 517 TestFinished();
514 } 518 }
515 519
516 // SubResource_Miss_WithNoCacheSelected ---------------------------------- 520 // SubResource_Miss_WithNoCacheSelected ----------------------------------
517 521
518 void SubResource_Miss_WithNoCacheSelected() { 522 void SubResource_Miss_WithNoCacheSelected() {
519 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 523 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
520 net::DEFAULT_PRIORITY, &delegate_); 524 net::DEFAULT_PRIORITY, &delegate_,
525 TRAFFIC_ANNOTATION_FOR_TESTS);
521 handler_ = host_->CreateRequestHandler(request_.get(), 526 handler_ = host_->CreateRequestHandler(request_.get(),
522 RESOURCE_TYPE_SUB_RESOURCE, false); 527 RESOURCE_TYPE_SUB_RESOURCE, false);
523 528
524 // We avoid creating handler when possible, sub-resource requests are not 529 // We avoid creating handler when possible, sub-resource requests are not
525 // subject to retrieval from an appcache when there's no associated cache. 530 // subject to retrieval from an appcache when there's no associated cache.
526 EXPECT_FALSE(handler_.get()); 531 EXPECT_FALSE(handler_.get());
527 532
528 TestFinished(); 533 TestFinished();
529 } 534 }
530 535
531 // SubResource_Miss_WithCacheSelected ---------------------------------- 536 // SubResource_Miss_WithCacheSelected ----------------------------------
532 537
533 void SubResource_Miss_WithCacheSelected() { 538 void SubResource_Miss_WithCacheSelected() {
534 // A sub-resource load where the resource is not in an appcache, or 539 // A sub-resource load where the resource is not in an appcache, or
535 // in a network or fallback namespace, should result in a failed request. 540 // in a network or fallback namespace, should result in a failed request.
536 host_->AssociateCompleteCache(MakeNewCache()); 541 host_->AssociateCompleteCache(MakeNewCache());
537 542
538 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 543 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
539 net::DEFAULT_PRIORITY, &delegate_); 544 net::DEFAULT_PRIORITY, &delegate_,
545 TRAFFIC_ANNOTATION_FOR_TESTS);
540 handler_ = host_->CreateRequestHandler(request_.get(), 546 handler_ = host_->CreateRequestHandler(request_.get(),
541 RESOURCE_TYPE_SUB_RESOURCE, false); 547 RESOURCE_TYPE_SUB_RESOURCE, false);
542 EXPECT_TRUE(handler_.get()); 548 EXPECT_TRUE(handler_.get());
543 549
544 job_.reset(handler_->MaybeLoadResource( 550 job_.reset(handler_->MaybeLoadResource(
545 request_.get(), request_->context()->network_delegate())); 551 request_.get(), request_->context()->network_delegate()));
546 EXPECT_TRUE(job_.get()); 552 EXPECT_TRUE(job_.get());
547 EXPECT_TRUE(job_->is_delivering_error_response()); 553 EXPECT_TRUE(job_->is_delivering_error_response());
548 554
549 std::unique_ptr<AppCacheURLRequestJob> fallback_job( 555 std::unique_ptr<AppCacheURLRequestJob> fallback_job(
(...skipping 10 matching lines...) Expand all
560 566
561 // SubResource_Miss_WithWaitForCacheSelection ----------------------------- 567 // SubResource_Miss_WithWaitForCacheSelection -----------------------------
562 568
563 void SubResource_Miss_WithWaitForCacheSelection() { 569 void SubResource_Miss_WithWaitForCacheSelection() {
564 // Precondition, the host is waiting on cache selection. 570 // Precondition, the host is waiting on cache selection.
565 scoped_refptr<AppCache> cache(MakeNewCache()); 571 scoped_refptr<AppCache> cache(MakeNewCache());
566 host_->pending_selected_cache_id_ = cache->cache_id(); 572 host_->pending_selected_cache_id_ = cache->cache_id();
567 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url()); 573 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url());
568 574
569 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 575 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
570 net::DEFAULT_PRIORITY, &delegate_); 576 net::DEFAULT_PRIORITY, &delegate_,
577 TRAFFIC_ANNOTATION_FOR_TESTS);
571 handler_ = host_->CreateRequestHandler(request_.get(), 578 handler_ = host_->CreateRequestHandler(request_.get(),
572 RESOURCE_TYPE_SUB_RESOURCE, false); 579 RESOURCE_TYPE_SUB_RESOURCE, false);
573 EXPECT_TRUE(handler_.get()); 580 EXPECT_TRUE(handler_.get());
574 job_.reset(handler_->MaybeLoadResource( 581 job_.reset(handler_->MaybeLoadResource(
575 request_.get(), request_->context()->network_delegate())); 582 request_.get(), request_->context()->network_delegate()));
576 EXPECT_TRUE(job_.get()); 583 EXPECT_TRUE(job_.get());
577 EXPECT_TRUE(job_->is_waiting()); 584 EXPECT_TRUE(job_->is_waiting());
578 585
579 host_->FinishCacheSelection(cache.get(), NULL); 586 host_->FinishCacheSelection(cache.get(), NULL);
580 EXPECT_FALSE(job_->is_waiting()); 587 EXPECT_FALSE(job_->is_waiting());
(...skipping 13 matching lines...) Expand all
594 601
595 // SubResource_Hit ----------------------------- 602 // SubResource_Hit -----------------------------
596 603
597 void SubResource_Hit() { 604 void SubResource_Hit() {
598 host_->AssociateCompleteCache(MakeNewCache()); 605 host_->AssociateCompleteCache(MakeNewCache());
599 606
600 mock_storage()->SimulateFindSubResource( 607 mock_storage()->SimulateFindSubResource(
601 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); 608 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false);
602 609
603 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 610 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
604 net::DEFAULT_PRIORITY, &delegate_); 611 net::DEFAULT_PRIORITY, &delegate_,
612 TRAFFIC_ANNOTATION_FOR_TESTS);
605 handler_ = host_->CreateRequestHandler(request_.get(), 613 handler_ = host_->CreateRequestHandler(request_.get(),
606 RESOURCE_TYPE_SUB_RESOURCE, false); 614 RESOURCE_TYPE_SUB_RESOURCE, false);
607 EXPECT_TRUE(handler_.get()); 615 EXPECT_TRUE(handler_.get());
608 job_.reset(handler_->MaybeLoadResource( 616 job_.reset(handler_->MaybeLoadResource(
609 request_.get(), request_->context()->network_delegate())); 617 request_.get(), request_->context()->network_delegate()));
610 EXPECT_TRUE(job_.get()); 618 EXPECT_TRUE(job_.get());
611 EXPECT_TRUE(job_->is_delivering_appcache_response()); 619 EXPECT_TRUE(job_->is_delivering_appcache_response());
612 620
613 std::unique_ptr<AppCacheURLRequestJob> fallback_job( 621 std::unique_ptr<AppCacheURLRequestJob> fallback_job(
614 handler_->MaybeLoadFallbackForRedirect( 622 handler_->MaybeLoadFallbackForRedirect(
(...skipping 11 matching lines...) Expand all
626 634
627 void SubResource_RedirectFallback() { 635 void SubResource_RedirectFallback() {
628 // Redirects to resources in the a different origin are subject to 636 // Redirects to resources in the a different origin are subject to
629 // fallback namespaces. 637 // fallback namespaces.
630 host_->AssociateCompleteCache(MakeNewCache()); 638 host_->AssociateCompleteCache(MakeNewCache());
631 639
632 mock_storage()->SimulateFindSubResource( 640 mock_storage()->SimulateFindSubResource(
633 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); 641 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false);
634 642
635 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 643 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
636 net::DEFAULT_PRIORITY, &delegate_); 644 net::DEFAULT_PRIORITY, &delegate_,
645 TRAFFIC_ANNOTATION_FOR_TESTS);
637 handler_ = host_->CreateRequestHandler(request_.get(), 646 handler_ = host_->CreateRequestHandler(request_.get(),
638 RESOURCE_TYPE_SUB_RESOURCE, false); 647 RESOURCE_TYPE_SUB_RESOURCE, false);
639 EXPECT_TRUE(handler_.get()); 648 EXPECT_TRUE(handler_.get());
640 job_.reset(handler_->MaybeLoadResource( 649 job_.reset(handler_->MaybeLoadResource(
641 request_.get(), request_->context()->network_delegate())); 650 request_.get(), request_->context()->network_delegate()));
642 EXPECT_FALSE(job_.get()); 651 EXPECT_FALSE(job_.get());
643 652
644 job_.reset(handler_->MaybeLoadFallbackForRedirect( 653 job_.reset(handler_->MaybeLoadFallbackForRedirect(
645 request_.get(), request_->context()->network_delegate(), 654 request_.get(), request_->context()->network_delegate(),
646 GURL("http://not_blah/redirect"))); 655 GURL("http://not_blah/redirect")));
(...skipping 12 matching lines...) Expand all
659 668
660 void SubResource_NoRedirectFallback() { 669 void SubResource_NoRedirectFallback() {
661 // Redirects to resources in the same-origin are not subject to 670 // Redirects to resources in the same-origin are not subject to
662 // fallback namespaces. 671 // fallback namespaces.
663 host_->AssociateCompleteCache(MakeNewCache()); 672 host_->AssociateCompleteCache(MakeNewCache());
664 673
665 mock_storage()->SimulateFindSubResource( 674 mock_storage()->SimulateFindSubResource(
666 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); 675 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false);
667 676
668 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 677 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
669 net::DEFAULT_PRIORITY, &delegate_); 678 net::DEFAULT_PRIORITY, &delegate_,
679 TRAFFIC_ANNOTATION_FOR_TESTS);
670 handler_ = host_->CreateRequestHandler(request_.get(), 680 handler_ = host_->CreateRequestHandler(request_.get(),
671 RESOURCE_TYPE_SUB_RESOURCE, false); 681 RESOURCE_TYPE_SUB_RESOURCE, false);
672 EXPECT_TRUE(handler_.get()); 682 EXPECT_TRUE(handler_.get());
673 job_.reset(handler_->MaybeLoadResource( 683 job_.reset(handler_->MaybeLoadResource(
674 request_.get(), request_->context()->network_delegate())); 684 request_.get(), request_->context()->network_delegate()));
675 EXPECT_FALSE(job_.get()); 685 EXPECT_FALSE(job_.get());
676 686
677 std::unique_ptr<AppCacheURLRequestJob> fallback_job( 687 std::unique_ptr<AppCacheURLRequestJob> fallback_job(
678 handler_->MaybeLoadFallbackForRedirect( 688 handler_->MaybeLoadFallbackForRedirect(
679 request_.get(), request_->context()->network_delegate(), 689 request_.get(), request_->context()->network_delegate(),
(...skipping 13 matching lines...) Expand all
693 void SubResource_Network() { 703 void SubResource_Network() {
694 // A sub-resource load where the resource is in a network namespace, 704 // A sub-resource load where the resource is in a network namespace,
695 // should result in the system using a 'real' job to do the network 705 // should result in the system using a 'real' job to do the network
696 // retrieval. 706 // retrieval.
697 host_->AssociateCompleteCache(MakeNewCache()); 707 host_->AssociateCompleteCache(MakeNewCache());
698 708
699 mock_storage()->SimulateFindSubResource( 709 mock_storage()->SimulateFindSubResource(
700 AppCacheEntry(), AppCacheEntry(), true); 710 AppCacheEntry(), AppCacheEntry(), true);
701 711
702 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 712 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
703 net::DEFAULT_PRIORITY, &delegate_); 713 net::DEFAULT_PRIORITY, &delegate_,
714 TRAFFIC_ANNOTATION_FOR_TESTS);
704 handler_ = host_->CreateRequestHandler(request_.get(), 715 handler_ = host_->CreateRequestHandler(request_.get(),
705 RESOURCE_TYPE_SUB_RESOURCE, false); 716 RESOURCE_TYPE_SUB_RESOURCE, false);
706 EXPECT_TRUE(handler_.get()); 717 EXPECT_TRUE(handler_.get());
707 job_.reset(handler_->MaybeLoadResource( 718 job_.reset(handler_->MaybeLoadResource(
708 request_.get(), request_->context()->network_delegate())); 719 request_.get(), request_->context()->network_delegate()));
709 EXPECT_FALSE(job_.get()); 720 EXPECT_FALSE(job_.get());
710 721
711 std::unique_ptr<AppCacheURLRequestJob> fallback_job( 722 std::unique_ptr<AppCacheURLRequestJob> fallback_job(
712 handler_->MaybeLoadFallbackForRedirect( 723 handler_->MaybeLoadFallbackForRedirect(
713 request_.get(), request_->context()->network_delegate(), 724 request_.get(), request_->context()->network_delegate(),
714 GURL("http://blah/redirect"))); 725 GURL("http://blah/redirect")));
715 EXPECT_FALSE(fallback_job); 726 EXPECT_FALSE(fallback_job);
716 fallback_job.reset(handler_->MaybeLoadFallbackForResponse( 727 fallback_job.reset(handler_->MaybeLoadFallbackForResponse(
717 request_.get(), request_->context()->network_delegate())); 728 request_.get(), request_->context()->network_delegate()));
718 EXPECT_FALSE(fallback_job); 729 EXPECT_FALSE(fallback_job);
719 730
720 TestFinished(); 731 TestFinished();
721 } 732 }
722 733
723 // DestroyedHost ----------------------------- 734 // DestroyedHost -----------------------------
724 735
725 void DestroyedHost() { 736 void DestroyedHost() {
726 host_->AssociateCompleteCache(MakeNewCache()); 737 host_->AssociateCompleteCache(MakeNewCache());
727 738
728 mock_storage()->SimulateFindSubResource( 739 mock_storage()->SimulateFindSubResource(
729 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); 740 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false);
730 741
731 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 742 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
732 net::DEFAULT_PRIORITY, &delegate_); 743 net::DEFAULT_PRIORITY, &delegate_,
744 TRAFFIC_ANNOTATION_FOR_TESTS);
733 handler_ = host_->CreateRequestHandler(request_.get(), 745 handler_ = host_->CreateRequestHandler(request_.get(),
734 RESOURCE_TYPE_SUB_RESOURCE, false); 746 RESOURCE_TYPE_SUB_RESOURCE, false);
735 EXPECT_TRUE(handler_.get()); 747 EXPECT_TRUE(handler_.get());
736 748
737 backend_impl_->UnregisterHost(1); 749 backend_impl_->UnregisterHost(1);
738 host_ = NULL; 750 host_ = NULL;
739 751
740 EXPECT_FALSE(handler_->MaybeLoadResource( 752 EXPECT_FALSE(handler_->MaybeLoadResource(
741 request_.get(), request_->context()->network_delegate())); 753 request_.get(), request_->context()->network_delegate()));
742 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( 754 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect(
743 request_.get(), 755 request_.get(),
744 request_->context()->network_delegate(), 756 request_->context()->network_delegate(),
745 GURL("http://blah/redirect"))); 757 GURL("http://blah/redirect")));
746 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( 758 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse(
747 request_.get(), request_->context()->network_delegate())); 759 request_.get(), request_->context()->network_delegate()));
748 760
749 TestFinished(); 761 TestFinished();
750 } 762 }
751 763
752 // DestroyedHostWithWaitingJob ----------------------------- 764 // DestroyedHostWithWaitingJob -----------------------------
753 765
754 void DestroyedHostWithWaitingJob() { 766 void DestroyedHostWithWaitingJob() {
755 // Precondition, the host is waiting on cache selection. 767 // Precondition, the host is waiting on cache selection.
756 host_->pending_selected_cache_id_ = 1; 768 host_->pending_selected_cache_id_ = 1;
757 769
758 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 770 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
759 net::DEFAULT_PRIORITY, &delegate_); 771 net::DEFAULT_PRIORITY, &delegate_,
772 TRAFFIC_ANNOTATION_FOR_TESTS);
760 handler_ = host_->CreateRequestHandler(request_.get(), 773 handler_ = host_->CreateRequestHandler(request_.get(),
761 RESOURCE_TYPE_SUB_RESOURCE, false); 774 RESOURCE_TYPE_SUB_RESOURCE, false);
762 EXPECT_TRUE(handler_.get()); 775 EXPECT_TRUE(handler_.get());
763 776
764 job_.reset(handler_->MaybeLoadResource( 777 job_.reset(handler_->MaybeLoadResource(
765 request_.get(), request_->context()->network_delegate())); 778 request_.get(), request_->context()->network_delegate()));
766 EXPECT_TRUE(job_.get()); 779 EXPECT_TRUE(job_.get());
767 EXPECT_TRUE(job_->is_waiting()); 780 EXPECT_TRUE(job_->is_waiting());
768 781
769 backend_impl_->UnregisterHost(1); 782 backend_impl_->UnregisterHost(1);
(...skipping 14 matching lines...) Expand all
784 797
785 // DestroyedService ----------------------------- 798 // DestroyedService -----------------------------
786 799
787 void DestroyedService() { 800 void DestroyedService() {
788 host_->AssociateCompleteCache(MakeNewCache()); 801 host_->AssociateCompleteCache(MakeNewCache());
789 802
790 mock_storage()->SimulateFindSubResource( 803 mock_storage()->SimulateFindSubResource(
791 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); 804 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false);
792 805
793 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 806 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
794 net::DEFAULT_PRIORITY, &delegate_); 807 net::DEFAULT_PRIORITY, &delegate_,
808 TRAFFIC_ANNOTATION_FOR_TESTS);
795 handler_ = host_->CreateRequestHandler(request_.get(), 809 handler_ = host_->CreateRequestHandler(request_.get(),
796 RESOURCE_TYPE_SUB_RESOURCE, false); 810 RESOURCE_TYPE_SUB_RESOURCE, false);
797 EXPECT_TRUE(handler_.get()); 811 EXPECT_TRUE(handler_.get());
798 job_.reset(handler_->MaybeLoadResource( 812 job_.reset(handler_->MaybeLoadResource(
799 request_.get(), request_->context()->network_delegate())); 813 request_.get(), request_->context()->network_delegate()));
800 EXPECT_TRUE(job_.get()); 814 EXPECT_TRUE(job_.get());
801 815
802 backend_impl_.reset(); 816 backend_impl_.reset();
803 mock_frontend_.reset(); 817 mock_frontend_.reset();
804 mock_service_.reset(); 818 mock_service_.reset();
805 mock_policy_.reset(); 819 mock_policy_.reset();
806 host_ = NULL; 820 host_ = NULL;
807 821
808 EXPECT_TRUE(job_->has_been_killed()); 822 EXPECT_TRUE(job_->has_been_killed());
809 EXPECT_FALSE(handler_->MaybeLoadResource( 823 EXPECT_FALSE(handler_->MaybeLoadResource(
810 request_.get(), request_->context()->network_delegate())); 824 request_.get(), request_->context()->network_delegate()));
811 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( 825 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect(
812 request_.get(), 826 request_.get(),
813 request_->context()->network_delegate(), 827 request_->context()->network_delegate(),
814 GURL("http://blah/redirect"))); 828 GURL("http://blah/redirect")));
815 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( 829 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse(
816 request_.get(), request_->context()->network_delegate())); 830 request_.get(), request_->context()->network_delegate()));
817 831
818 TestFinished(); 832 TestFinished();
819 } 833 }
820 834
821 void DestroyedServiceWithCrossSiteNav() { 835 void DestroyedServiceWithCrossSiteNav() {
822 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 836 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
823 net::DEFAULT_PRIORITY, &delegate_); 837 net::DEFAULT_PRIORITY, &delegate_,
838 TRAFFIC_ANNOTATION_FOR_TESTS);
824 handler_ = host_->CreateRequestHandler(request_.get(), 839 handler_ = host_->CreateRequestHandler(request_.get(),
825 RESOURCE_TYPE_MAIN_FRAME, false); 840 RESOURCE_TYPE_MAIN_FRAME, false);
826 EXPECT_TRUE(handler_.get()); 841 EXPECT_TRUE(handler_.get());
827 handler_->PrepareForCrossSiteTransfer(backend_impl_->process_id()); 842 handler_->PrepareForCrossSiteTransfer(backend_impl_->process_id());
828 EXPECT_TRUE(handler_->host_for_cross_site_transfer_.get()); 843 EXPECT_TRUE(handler_->host_for_cross_site_transfer_.get());
829 844
830 backend_impl_.reset(); 845 backend_impl_.reset();
831 mock_frontend_.reset(); 846 mock_frontend_.reset();
832 mock_service_.reset(); 847 mock_service_.reset();
833 mock_policy_.reset(); 848 mock_policy_.reset();
(...skipping 12 matching lines...) Expand all
846 TestFinished(); 861 TestFinished();
847 } 862 }
848 863
849 // UnsupportedScheme ----------------------------- 864 // UnsupportedScheme -----------------------------
850 865
851 void UnsupportedScheme() { 866 void UnsupportedScheme() {
852 // Precondition, the host is waiting on cache selection. 867 // Precondition, the host is waiting on cache selection.
853 host_->pending_selected_cache_id_ = 1; 868 host_->pending_selected_cache_id_ = 1;
854 869
855 request_ = empty_context_->CreateRequest(GURL("ftp://blah/"), 870 request_ = empty_context_->CreateRequest(GURL("ftp://blah/"),
856 net::DEFAULT_PRIORITY, &delegate_); 871 net::DEFAULT_PRIORITY, &delegate_,
872 TRAFFIC_ANNOTATION_FOR_TESTS);
857 handler_ = host_->CreateRequestHandler(request_.get(), 873 handler_ = host_->CreateRequestHandler(request_.get(),
858 RESOURCE_TYPE_SUB_RESOURCE, false); 874 RESOURCE_TYPE_SUB_RESOURCE, false);
859 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) 875 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably)
860 876
861 EXPECT_FALSE(handler_->MaybeLoadResource( 877 EXPECT_FALSE(handler_->MaybeLoadResource(
862 request_.get(), request_->context()->network_delegate())); 878 request_.get(), request_->context()->network_delegate()));
863 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( 879 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect(
864 request_.get(), 880 request_.get(),
865 request_->context()->network_delegate(), 881 request_->context()->network_delegate(),
866 GURL("ftp://blah/redirect"))); 882 GURL("ftp://blah/redirect")));
867 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( 883 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse(
868 request_.get(), request_->context()->network_delegate())); 884 request_.get(), request_->context()->network_delegate()));
869 885
870 TestFinished(); 886 TestFinished();
871 } 887 }
872 888
873 // CanceledRequest ----------------------------- 889 // CanceledRequest -----------------------------
874 890
875 void CanceledRequest() { 891 void CanceledRequest() {
876 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 892 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
877 net::DEFAULT_PRIORITY, &delegate_); 893 net::DEFAULT_PRIORITY, &delegate_,
894 TRAFFIC_ANNOTATION_FOR_TESTS);
878 handler_ = host_->CreateRequestHandler(request_.get(), 895 handler_ = host_->CreateRequestHandler(request_.get(),
879 RESOURCE_TYPE_MAIN_FRAME, false); 896 RESOURCE_TYPE_MAIN_FRAME, false);
880 EXPECT_TRUE(handler_.get()); 897 EXPECT_TRUE(handler_.get());
881 898
882 job_.reset(handler_->MaybeLoadResource( 899 job_.reset(handler_->MaybeLoadResource(
883 request_.get(), request_->context()->network_delegate())); 900 request_.get(), request_->context()->network_delegate()));
884 EXPECT_TRUE(job_.get()); 901 EXPECT_TRUE(job_.get());
885 EXPECT_TRUE(job_->is_waiting()); 902 EXPECT_TRUE(job_->is_waiting());
886 EXPECT_FALSE(job_->has_been_started()); 903 EXPECT_FALSE(job_->has_been_started());
887 904
(...skipping 19 matching lines...) Expand all
907 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( 924 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType(
908 RESOURCE_TYPE_MAIN_FRAME)); 925 RESOURCE_TYPE_MAIN_FRAME));
909 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( 926 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType(
910 RESOURCE_TYPE_SUB_FRAME)); 927 RESOURCE_TYPE_SUB_FRAME));
911 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( 928 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType(
912 RESOURCE_TYPE_SHARED_WORKER)); 929 RESOURCE_TYPE_SHARED_WORKER));
913 EXPECT_FALSE(AppCacheRequestHandler::IsMainResourceType( 930 EXPECT_FALSE(AppCacheRequestHandler::IsMainResourceType(
914 RESOURCE_TYPE_WORKER)); 931 RESOURCE_TYPE_WORKER));
915 932
916 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 933 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
917 net::DEFAULT_PRIORITY, &delegate_); 934 net::DEFAULT_PRIORITY, &delegate_,
935 TRAFFIC_ANNOTATION_FOR_TESTS);
918 936
919 const int kParentHostId = host_->host_id(); 937 const int kParentHostId = host_->host_id();
920 const int kWorkerHostId = 2; 938 const int kWorkerHostId = 2;
921 const int kAbandonedWorkerHostId = 3; 939 const int kAbandonedWorkerHostId = 3;
922 const int kNonExsitingHostId = 700; 940 const int kNonExsitingHostId = 700;
923 941
924 backend_impl_->RegisterHost(kWorkerHostId); 942 backend_impl_->RegisterHost(kWorkerHostId);
925 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); 943 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId);
926 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); 944 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId);
927 handler_ = worker_host->CreateRequestHandler( 945 handler_ = worker_host->CreateRequestHandler(
(...skipping 17 matching lines...) Expand all
945 } 963 }
946 964
947 // MainResource_Blocked -------------------------------------------------- 965 // MainResource_Blocked --------------------------------------------------
948 966
949 void MainResource_Blocked() { 967 void MainResource_Blocked() {
950 PushNextTask( 968 PushNextTask(
951 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked, 969 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked,
952 base::Unretained(this))); 970 base::Unretained(this)));
953 971
954 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 972 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
955 net::DEFAULT_PRIORITY, &delegate_); 973 net::DEFAULT_PRIORITY, &delegate_,
974 TRAFFIC_ANNOTATION_FOR_TESTS);
956 handler_ = host_->CreateRequestHandler(request_.get(), 975 handler_ = host_->CreateRequestHandler(request_.get(),
957 RESOURCE_TYPE_MAIN_FRAME, false); 976 RESOURCE_TYPE_MAIN_FRAME, false);
958 EXPECT_TRUE(handler_.get()); 977 EXPECT_TRUE(handler_.get());
959 978
960 mock_policy_->can_load_return_value_ = false; 979 mock_policy_->can_load_return_value_ = false;
961 mock_storage()->SimulateFindMainResource( 980 mock_storage()->SimulateFindMainResource(
962 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 981 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
963 GURL(), AppCacheEntry(), 982 GURL(), AppCacheEntry(),
964 1, 2, GURL("http://blah/manifest/")); 983 1, 2, GURL("http://blah/manifest/"));
965 984
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1121
1103 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { 1122 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) {
1104 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); 1123 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest);
1105 } 1124 }
1106 1125
1107 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { 1126 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) {
1108 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); 1127 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked);
1109 } 1128 }
1110 1129
1111 } // namespace content 1130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698