OLD | NEW |
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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 271 |
272 // MainResource_Miss -------------------------------------------------- | 272 // MainResource_Miss -------------------------------------------------- |
273 | 273 |
274 void MainResource_Miss() { | 274 void MainResource_Miss() { |
275 PushNextTask( | 275 PushNextTask( |
276 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, | 276 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, |
277 base::Unretained(this))); | 277 base::Unretained(this))); |
278 | 278 |
279 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 279 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
280 net::DEFAULT_PRIORITY, &delegate_); | 280 net::DEFAULT_PRIORITY, &delegate_); |
281 handler_.reset(host_->CreateRequestHandler(request_.get(), | 281 handler_ = host_->CreateRequestHandler(request_.get(), |
282 RESOURCE_TYPE_MAIN_FRAME, | 282 RESOURCE_TYPE_MAIN_FRAME, false); |
283 false)); | |
284 EXPECT_TRUE(handler_.get()); | 283 EXPECT_TRUE(handler_.get()); |
285 | 284 |
286 job_.reset(handler_->MaybeLoadResource( | 285 job_.reset(handler_->MaybeLoadResource( |
287 request_.get(), request_->context()->network_delegate())); | 286 request_.get(), request_->context()->network_delegate())); |
288 EXPECT_TRUE(job_.get()); | 287 EXPECT_TRUE(job_.get()); |
289 EXPECT_TRUE(job_->is_waiting()); | 288 EXPECT_TRUE(job_->is_waiting()); |
290 | 289 |
291 // We have to wait for completion of storage->FindResponseForMainRequest. | 290 // We have to wait for completion of storage->FindResponseForMainRequest. |
292 ScheduleNextTask(); | 291 ScheduleNextTask(); |
293 } | 292 } |
(...skipping 25 matching lines...) Expand all Loading... |
319 | 318 |
320 // MainResource_Hit -------------------------------------------------- | 319 // MainResource_Hit -------------------------------------------------- |
321 | 320 |
322 void MainResource_Hit() { | 321 void MainResource_Hit() { |
323 PushNextTask( | 322 PushNextTask( |
324 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit, | 323 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit, |
325 base::Unretained(this))); | 324 base::Unretained(this))); |
326 | 325 |
327 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 326 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
328 net::DEFAULT_PRIORITY, &delegate_); | 327 net::DEFAULT_PRIORITY, &delegate_); |
329 handler_.reset(host_->CreateRequestHandler(request_.get(), | 328 handler_ = host_->CreateRequestHandler(request_.get(), |
330 RESOURCE_TYPE_MAIN_FRAME, | 329 RESOURCE_TYPE_MAIN_FRAME, false); |
331 false)); | |
332 EXPECT_TRUE(handler_.get()); | 330 EXPECT_TRUE(handler_.get()); |
333 | 331 |
334 mock_storage()->SimulateFindMainResource( | 332 mock_storage()->SimulateFindMainResource( |
335 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 333 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
336 GURL(), AppCacheEntry(), | 334 GURL(), AppCacheEntry(), |
337 1, 2, GURL("http://blah/manifest/")); | 335 1, 2, GURL("http://blah/manifest/")); |
338 | 336 |
339 job_.reset(handler_->MaybeLoadResource( | 337 job_.reset(handler_->MaybeLoadResource( |
340 request_.get(), request_->context()->network_delegate())); | 338 request_.get(), request_->context()->network_delegate())); |
341 EXPECT_TRUE(job_.get()); | 339 EXPECT_TRUE(job_.get()); |
(...skipping 27 matching lines...) Expand all Loading... |
369 | 367 |
370 // MainResource_Fallback -------------------------------------------------- | 368 // MainResource_Fallback -------------------------------------------------- |
371 | 369 |
372 void MainResource_Fallback() { | 370 void MainResource_Fallback() { |
373 PushNextTask( | 371 PushNextTask( |
374 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback, | 372 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback, |
375 base::Unretained(this))); | 373 base::Unretained(this))); |
376 | 374 |
377 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 375 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
378 net::DEFAULT_PRIORITY, &delegate_); | 376 net::DEFAULT_PRIORITY, &delegate_); |
379 handler_.reset(host_->CreateRequestHandler(request_.get(), | 377 handler_ = host_->CreateRequestHandler(request_.get(), |
380 RESOURCE_TYPE_MAIN_FRAME, | 378 RESOURCE_TYPE_MAIN_FRAME, false); |
381 false)); | |
382 EXPECT_TRUE(handler_.get()); | 379 EXPECT_TRUE(handler_.get()); |
383 | 380 |
384 mock_storage()->SimulateFindMainResource( | 381 mock_storage()->SimulateFindMainResource( |
385 AppCacheEntry(), | 382 AppCacheEntry(), |
386 GURL("http://blah/fallbackurl"), | 383 GURL("http://blah/fallbackurl"), |
387 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 384 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
388 1, 2, GURL("http://blah/manifest/")); | 385 1, 2, GURL("http://blah/manifest/")); |
389 | 386 |
390 job_.reset(handler_->MaybeLoadResource( | 387 job_.reset(handler_->MaybeLoadResource( |
391 request_.get(), request_->context()->network_delegate())); | 388 request_.get(), request_->context()->network_delegate())); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // MainResource_FallbackOverride -------------------------------------------- | 449 // MainResource_FallbackOverride -------------------------------------------- |
453 | 450 |
454 void MainResource_FallbackOverride() { | 451 void MainResource_FallbackOverride() { |
455 PushNextTask(base::Bind( | 452 PushNextTask(base::Bind( |
456 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride, | 453 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride, |
457 base::Unretained(this))); | 454 base::Unretained(this))); |
458 | 455 |
459 request_ = | 456 request_ = |
460 empty_context_->CreateRequest(GURL("http://blah/fallback-override"), | 457 empty_context_->CreateRequest(GURL("http://blah/fallback-override"), |
461 net::DEFAULT_PRIORITY, &delegate_); | 458 net::DEFAULT_PRIORITY, &delegate_); |
462 handler_.reset(host_->CreateRequestHandler(request_.get(), | 459 handler_ = host_->CreateRequestHandler(request_.get(), |
463 RESOURCE_TYPE_MAIN_FRAME, | 460 RESOURCE_TYPE_MAIN_FRAME, false); |
464 false)); | |
465 EXPECT_TRUE(handler_.get()); | 461 EXPECT_TRUE(handler_.get()); |
466 | 462 |
467 mock_storage()->SimulateFindMainResource( | 463 mock_storage()->SimulateFindMainResource( |
468 AppCacheEntry(), | 464 AppCacheEntry(), |
469 GURL("http://blah/fallbackurl"), | 465 GURL("http://blah/fallbackurl"), |
470 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 466 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
471 1, 2, GURL("http://blah/manifest/")); | 467 1, 2, GURL("http://blah/manifest/")); |
472 | 468 |
473 job_.reset(handler_->MaybeLoadResource( | 469 job_.reset(handler_->MaybeLoadResource( |
474 request_.get(), request_->context()->network_delegate())); | 470 request_.get(), request_->context()->network_delegate())); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 EXPECT_TRUE(manifest_url.is_empty()); | 513 EXPECT_TRUE(manifest_url.is_empty()); |
518 | 514 |
519 TestFinished(); | 515 TestFinished(); |
520 } | 516 } |
521 | 517 |
522 // SubResource_Miss_WithNoCacheSelected ---------------------------------- | 518 // SubResource_Miss_WithNoCacheSelected ---------------------------------- |
523 | 519 |
524 void SubResource_Miss_WithNoCacheSelected() { | 520 void SubResource_Miss_WithNoCacheSelected() { |
525 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 521 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
526 net::DEFAULT_PRIORITY, &delegate_); | 522 net::DEFAULT_PRIORITY, &delegate_); |
527 handler_.reset(host_->CreateRequestHandler(request_.get(), | 523 handler_ = host_->CreateRequestHandler(request_.get(), |
528 RESOURCE_TYPE_SUB_RESOURCE, | 524 RESOURCE_TYPE_SUB_RESOURCE, false); |
529 false)); | |
530 | 525 |
531 // We avoid creating handler when possible, sub-resource requests are not | 526 // We avoid creating handler when possible, sub-resource requests are not |
532 // subject to retrieval from an appcache when there's no associated cache. | 527 // subject to retrieval from an appcache when there's no associated cache. |
533 EXPECT_FALSE(handler_.get()); | 528 EXPECT_FALSE(handler_.get()); |
534 | 529 |
535 TestFinished(); | 530 TestFinished(); |
536 } | 531 } |
537 | 532 |
538 // SubResource_Miss_WithCacheSelected ---------------------------------- | 533 // SubResource_Miss_WithCacheSelected ---------------------------------- |
539 | 534 |
540 void SubResource_Miss_WithCacheSelected() { | 535 void SubResource_Miss_WithCacheSelected() { |
541 // A sub-resource load where the resource is not in an appcache, or | 536 // A sub-resource load where the resource is not in an appcache, or |
542 // in a network or fallback namespace, should result in a failed request. | 537 // in a network or fallback namespace, should result in a failed request. |
543 host_->AssociateCompleteCache(MakeNewCache()); | 538 host_->AssociateCompleteCache(MakeNewCache()); |
544 | 539 |
545 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 540 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
546 net::DEFAULT_PRIORITY, &delegate_); | 541 net::DEFAULT_PRIORITY, &delegate_); |
547 handler_.reset(host_->CreateRequestHandler(request_.get(), | 542 handler_ = host_->CreateRequestHandler(request_.get(), |
548 RESOURCE_TYPE_SUB_RESOURCE, | 543 RESOURCE_TYPE_SUB_RESOURCE, false); |
549 false)); | |
550 EXPECT_TRUE(handler_.get()); | 544 EXPECT_TRUE(handler_.get()); |
551 | 545 |
552 job_.reset(handler_->MaybeLoadResource( | 546 job_.reset(handler_->MaybeLoadResource( |
553 request_.get(), request_->context()->network_delegate())); | 547 request_.get(), request_->context()->network_delegate())); |
554 EXPECT_TRUE(job_.get()); | 548 EXPECT_TRUE(job_.get()); |
555 EXPECT_TRUE(job_->is_delivering_error_response()); | 549 EXPECT_TRUE(job_->is_delivering_error_response()); |
556 | 550 |
557 std::unique_ptr<AppCacheURLRequestJob> fallback_job( | 551 std::unique_ptr<AppCacheURLRequestJob> fallback_job( |
558 handler_->MaybeLoadFallbackForRedirect( | 552 handler_->MaybeLoadFallbackForRedirect( |
559 request_.get(), request_->context()->network_delegate(), | 553 request_.get(), request_->context()->network_delegate(), |
560 GURL("http://blah/redirect"))); | 554 GURL("http://blah/redirect"))); |
561 EXPECT_FALSE(fallback_job); | 555 EXPECT_FALSE(fallback_job); |
562 fallback_job.reset(handler_->MaybeLoadFallbackForResponse( | 556 fallback_job.reset(handler_->MaybeLoadFallbackForResponse( |
563 request_.get(), request_->context()->network_delegate())); | 557 request_.get(), request_->context()->network_delegate())); |
564 EXPECT_FALSE(fallback_job); | 558 EXPECT_FALSE(fallback_job); |
565 | 559 |
566 TestFinished(); | 560 TestFinished(); |
567 } | 561 } |
568 | 562 |
569 // SubResource_Miss_WithWaitForCacheSelection ----------------------------- | 563 // SubResource_Miss_WithWaitForCacheSelection ----------------------------- |
570 | 564 |
571 void SubResource_Miss_WithWaitForCacheSelection() { | 565 void SubResource_Miss_WithWaitForCacheSelection() { |
572 // Precondition, the host is waiting on cache selection. | 566 // Precondition, the host is waiting on cache selection. |
573 scoped_refptr<AppCache> cache(MakeNewCache()); | 567 scoped_refptr<AppCache> cache(MakeNewCache()); |
574 host_->pending_selected_cache_id_ = cache->cache_id(); | 568 host_->pending_selected_cache_id_ = cache->cache_id(); |
575 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url()); | 569 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url()); |
576 | 570 |
577 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 571 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
578 net::DEFAULT_PRIORITY, &delegate_); | 572 net::DEFAULT_PRIORITY, &delegate_); |
579 handler_.reset(host_->CreateRequestHandler(request_.get(), | 573 handler_ = host_->CreateRequestHandler(request_.get(), |
580 RESOURCE_TYPE_SUB_RESOURCE, | 574 RESOURCE_TYPE_SUB_RESOURCE, false); |
581 false)); | |
582 EXPECT_TRUE(handler_.get()); | 575 EXPECT_TRUE(handler_.get()); |
583 job_.reset(handler_->MaybeLoadResource( | 576 job_.reset(handler_->MaybeLoadResource( |
584 request_.get(), request_->context()->network_delegate())); | 577 request_.get(), request_->context()->network_delegate())); |
585 EXPECT_TRUE(job_.get()); | 578 EXPECT_TRUE(job_.get()); |
586 EXPECT_TRUE(job_->is_waiting()); | 579 EXPECT_TRUE(job_->is_waiting()); |
587 | 580 |
588 host_->FinishCacheSelection(cache.get(), NULL); | 581 host_->FinishCacheSelection(cache.get(), NULL); |
589 EXPECT_FALSE(job_->is_waiting()); | 582 EXPECT_FALSE(job_->is_waiting()); |
590 EXPECT_TRUE(job_->is_delivering_error_response()); | 583 EXPECT_TRUE(job_->is_delivering_error_response()); |
591 | 584 |
(...skipping 12 matching lines...) Expand all Loading... |
604 // SubResource_Hit ----------------------------- | 597 // SubResource_Hit ----------------------------- |
605 | 598 |
606 void SubResource_Hit() { | 599 void SubResource_Hit() { |
607 host_->AssociateCompleteCache(MakeNewCache()); | 600 host_->AssociateCompleteCache(MakeNewCache()); |
608 | 601 |
609 mock_storage()->SimulateFindSubResource( | 602 mock_storage()->SimulateFindSubResource( |
610 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 603 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
611 | 604 |
612 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 605 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
613 net::DEFAULT_PRIORITY, &delegate_); | 606 net::DEFAULT_PRIORITY, &delegate_); |
614 handler_.reset(host_->CreateRequestHandler(request_.get(), | 607 handler_ = host_->CreateRequestHandler(request_.get(), |
615 RESOURCE_TYPE_SUB_RESOURCE, | 608 RESOURCE_TYPE_SUB_RESOURCE, false); |
616 false)); | |
617 EXPECT_TRUE(handler_.get()); | 609 EXPECT_TRUE(handler_.get()); |
618 job_.reset(handler_->MaybeLoadResource( | 610 job_.reset(handler_->MaybeLoadResource( |
619 request_.get(), request_->context()->network_delegate())); | 611 request_.get(), request_->context()->network_delegate())); |
620 EXPECT_TRUE(job_.get()); | 612 EXPECT_TRUE(job_.get()); |
621 EXPECT_TRUE(job_->is_delivering_appcache_response()); | 613 EXPECT_TRUE(job_->is_delivering_appcache_response()); |
622 | 614 |
623 std::unique_ptr<AppCacheURLRequestJob> fallback_job( | 615 std::unique_ptr<AppCacheURLRequestJob> fallback_job( |
624 handler_->MaybeLoadFallbackForRedirect( | 616 handler_->MaybeLoadFallbackForRedirect( |
625 request_.get(), request_->context()->network_delegate(), | 617 request_.get(), request_->context()->network_delegate(), |
626 GURL("http://blah/redirect"))); | 618 GURL("http://blah/redirect"))); |
(...skipping 10 matching lines...) Expand all Loading... |
637 void SubResource_RedirectFallback() { | 629 void SubResource_RedirectFallback() { |
638 // Redirects to resources in the a different origin are subject to | 630 // Redirects to resources in the a different origin are subject to |
639 // fallback namespaces. | 631 // fallback namespaces. |
640 host_->AssociateCompleteCache(MakeNewCache()); | 632 host_->AssociateCompleteCache(MakeNewCache()); |
641 | 633 |
642 mock_storage()->SimulateFindSubResource( | 634 mock_storage()->SimulateFindSubResource( |
643 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); | 635 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); |
644 | 636 |
645 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 637 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
646 net::DEFAULT_PRIORITY, &delegate_); | 638 net::DEFAULT_PRIORITY, &delegate_); |
647 handler_.reset(host_->CreateRequestHandler(request_.get(), | 639 handler_ = host_->CreateRequestHandler(request_.get(), |
648 RESOURCE_TYPE_SUB_RESOURCE, | 640 RESOURCE_TYPE_SUB_RESOURCE, false); |
649 false)); | |
650 EXPECT_TRUE(handler_.get()); | 641 EXPECT_TRUE(handler_.get()); |
651 job_.reset(handler_->MaybeLoadResource( | 642 job_.reset(handler_->MaybeLoadResource( |
652 request_.get(), request_->context()->network_delegate())); | 643 request_.get(), request_->context()->network_delegate())); |
653 EXPECT_FALSE(job_.get()); | 644 EXPECT_FALSE(job_.get()); |
654 | 645 |
655 job_.reset(handler_->MaybeLoadFallbackForRedirect( | 646 job_.reset(handler_->MaybeLoadFallbackForRedirect( |
656 request_.get(), request_->context()->network_delegate(), | 647 request_.get(), request_->context()->network_delegate(), |
657 GURL("http://not_blah/redirect"))); | 648 GURL("http://not_blah/redirect"))); |
658 EXPECT_TRUE(job_.get()); | 649 EXPECT_TRUE(job_.get()); |
659 EXPECT_TRUE(job_->is_delivering_appcache_response()); | 650 EXPECT_TRUE(job_->is_delivering_appcache_response()); |
(...skipping 11 matching lines...) Expand all Loading... |
671 void SubResource_NoRedirectFallback() { | 662 void SubResource_NoRedirectFallback() { |
672 // Redirects to resources in the same-origin are not subject to | 663 // Redirects to resources in the same-origin are not subject to |
673 // fallback namespaces. | 664 // fallback namespaces. |
674 host_->AssociateCompleteCache(MakeNewCache()); | 665 host_->AssociateCompleteCache(MakeNewCache()); |
675 | 666 |
676 mock_storage()->SimulateFindSubResource( | 667 mock_storage()->SimulateFindSubResource( |
677 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); | 668 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); |
678 | 669 |
679 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 670 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
680 net::DEFAULT_PRIORITY, &delegate_); | 671 net::DEFAULT_PRIORITY, &delegate_); |
681 handler_.reset(host_->CreateRequestHandler(request_.get(), | 672 handler_ = host_->CreateRequestHandler(request_.get(), |
682 RESOURCE_TYPE_SUB_RESOURCE, | 673 RESOURCE_TYPE_SUB_RESOURCE, false); |
683 false)); | |
684 EXPECT_TRUE(handler_.get()); | 674 EXPECT_TRUE(handler_.get()); |
685 job_.reset(handler_->MaybeLoadResource( | 675 job_.reset(handler_->MaybeLoadResource( |
686 request_.get(), request_->context()->network_delegate())); | 676 request_.get(), request_->context()->network_delegate())); |
687 EXPECT_FALSE(job_.get()); | 677 EXPECT_FALSE(job_.get()); |
688 | 678 |
689 std::unique_ptr<AppCacheURLRequestJob> fallback_job( | 679 std::unique_ptr<AppCacheURLRequestJob> fallback_job( |
690 handler_->MaybeLoadFallbackForRedirect( | 680 handler_->MaybeLoadFallbackForRedirect( |
691 request_.get(), request_->context()->network_delegate(), | 681 request_.get(), request_->context()->network_delegate(), |
692 GURL("http://blah/redirect"))); | 682 GURL("http://blah/redirect"))); |
693 EXPECT_FALSE(fallback_job); | 683 EXPECT_FALSE(fallback_job); |
(...skipping 12 matching lines...) Expand all Loading... |
706 // A sub-resource load where the resource is in a network namespace, | 696 // A sub-resource load where the resource is in a network namespace, |
707 // should result in the system using a 'real' job to do the network | 697 // should result in the system using a 'real' job to do the network |
708 // retrieval. | 698 // retrieval. |
709 host_->AssociateCompleteCache(MakeNewCache()); | 699 host_->AssociateCompleteCache(MakeNewCache()); |
710 | 700 |
711 mock_storage()->SimulateFindSubResource( | 701 mock_storage()->SimulateFindSubResource( |
712 AppCacheEntry(), AppCacheEntry(), true); | 702 AppCacheEntry(), AppCacheEntry(), true); |
713 | 703 |
714 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 704 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
715 net::DEFAULT_PRIORITY, &delegate_); | 705 net::DEFAULT_PRIORITY, &delegate_); |
716 handler_.reset(host_->CreateRequestHandler(request_.get(), | 706 handler_ = host_->CreateRequestHandler(request_.get(), |
717 RESOURCE_TYPE_SUB_RESOURCE, | 707 RESOURCE_TYPE_SUB_RESOURCE, false); |
718 false)); | |
719 EXPECT_TRUE(handler_.get()); | 708 EXPECT_TRUE(handler_.get()); |
720 job_.reset(handler_->MaybeLoadResource( | 709 job_.reset(handler_->MaybeLoadResource( |
721 request_.get(), request_->context()->network_delegate())); | 710 request_.get(), request_->context()->network_delegate())); |
722 EXPECT_FALSE(job_.get()); | 711 EXPECT_FALSE(job_.get()); |
723 | 712 |
724 std::unique_ptr<AppCacheURLRequestJob> fallback_job( | 713 std::unique_ptr<AppCacheURLRequestJob> fallback_job( |
725 handler_->MaybeLoadFallbackForRedirect( | 714 handler_->MaybeLoadFallbackForRedirect( |
726 request_.get(), request_->context()->network_delegate(), | 715 request_.get(), request_->context()->network_delegate(), |
727 GURL("http://blah/redirect"))); | 716 GURL("http://blah/redirect"))); |
728 EXPECT_FALSE(fallback_job); | 717 EXPECT_FALSE(fallback_job); |
729 fallback_job.reset(handler_->MaybeLoadFallbackForResponse( | 718 fallback_job.reset(handler_->MaybeLoadFallbackForResponse( |
730 request_.get(), request_->context()->network_delegate())); | 719 request_.get(), request_->context()->network_delegate())); |
731 EXPECT_FALSE(fallback_job); | 720 EXPECT_FALSE(fallback_job); |
732 | 721 |
733 TestFinished(); | 722 TestFinished(); |
734 } | 723 } |
735 | 724 |
736 // DestroyedHost ----------------------------- | 725 // DestroyedHost ----------------------------- |
737 | 726 |
738 void DestroyedHost() { | 727 void DestroyedHost() { |
739 host_->AssociateCompleteCache(MakeNewCache()); | 728 host_->AssociateCompleteCache(MakeNewCache()); |
740 | 729 |
741 mock_storage()->SimulateFindSubResource( | 730 mock_storage()->SimulateFindSubResource( |
742 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 731 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
743 | 732 |
744 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 733 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
745 net::DEFAULT_PRIORITY, &delegate_); | 734 net::DEFAULT_PRIORITY, &delegate_); |
746 handler_.reset(host_->CreateRequestHandler(request_.get(), | 735 handler_ = host_->CreateRequestHandler(request_.get(), |
747 RESOURCE_TYPE_SUB_RESOURCE, | 736 RESOURCE_TYPE_SUB_RESOURCE, false); |
748 false)); | |
749 EXPECT_TRUE(handler_.get()); | 737 EXPECT_TRUE(handler_.get()); |
750 | 738 |
751 backend_impl_->UnregisterHost(1); | 739 backend_impl_->UnregisterHost(1); |
752 host_ = NULL; | 740 host_ = NULL; |
753 | 741 |
754 EXPECT_FALSE(handler_->MaybeLoadResource( | 742 EXPECT_FALSE(handler_->MaybeLoadResource( |
755 request_.get(), request_->context()->network_delegate())); | 743 request_.get(), request_->context()->network_delegate())); |
756 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( | 744 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( |
757 request_.get(), | 745 request_.get(), |
758 request_->context()->network_delegate(), | 746 request_->context()->network_delegate(), |
759 GURL("http://blah/redirect"))); | 747 GURL("http://blah/redirect"))); |
760 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( | 748 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( |
761 request_.get(), request_->context()->network_delegate())); | 749 request_.get(), request_->context()->network_delegate())); |
762 | 750 |
763 TestFinished(); | 751 TestFinished(); |
764 } | 752 } |
765 | 753 |
766 // DestroyedHostWithWaitingJob ----------------------------- | 754 // DestroyedHostWithWaitingJob ----------------------------- |
767 | 755 |
768 void DestroyedHostWithWaitingJob() { | 756 void DestroyedHostWithWaitingJob() { |
769 // Precondition, the host is waiting on cache selection. | 757 // Precondition, the host is waiting on cache selection. |
770 host_->pending_selected_cache_id_ = 1; | 758 host_->pending_selected_cache_id_ = 1; |
771 | 759 |
772 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 760 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
773 net::DEFAULT_PRIORITY, &delegate_); | 761 net::DEFAULT_PRIORITY, &delegate_); |
774 handler_.reset(host_->CreateRequestHandler(request_.get(), | 762 handler_ = host_->CreateRequestHandler(request_.get(), |
775 RESOURCE_TYPE_SUB_RESOURCE, | 763 RESOURCE_TYPE_SUB_RESOURCE, false); |
776 false)); | |
777 EXPECT_TRUE(handler_.get()); | 764 EXPECT_TRUE(handler_.get()); |
778 | 765 |
779 job_.reset(handler_->MaybeLoadResource( | 766 job_.reset(handler_->MaybeLoadResource( |
780 request_.get(), request_->context()->network_delegate())); | 767 request_.get(), request_->context()->network_delegate())); |
781 EXPECT_TRUE(job_.get()); | 768 EXPECT_TRUE(job_.get()); |
782 EXPECT_TRUE(job_->is_waiting()); | 769 EXPECT_TRUE(job_->is_waiting()); |
783 | 770 |
784 backend_impl_->UnregisterHost(1); | 771 backend_impl_->UnregisterHost(1); |
785 host_ = NULL; | 772 host_ = NULL; |
786 EXPECT_TRUE(job_->has_been_killed()); | 773 EXPECT_TRUE(job_->has_been_killed()); |
(...skipping 13 matching lines...) Expand all Loading... |
800 // DestroyedService ----------------------------- | 787 // DestroyedService ----------------------------- |
801 | 788 |
802 void DestroyedService() { | 789 void DestroyedService() { |
803 host_->AssociateCompleteCache(MakeNewCache()); | 790 host_->AssociateCompleteCache(MakeNewCache()); |
804 | 791 |
805 mock_storage()->SimulateFindSubResource( | 792 mock_storage()->SimulateFindSubResource( |
806 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 793 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
807 | 794 |
808 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 795 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
809 net::DEFAULT_PRIORITY, &delegate_); | 796 net::DEFAULT_PRIORITY, &delegate_); |
810 handler_.reset(host_->CreateRequestHandler(request_.get(), | 797 handler_ = host_->CreateRequestHandler(request_.get(), |
811 RESOURCE_TYPE_SUB_RESOURCE, | 798 RESOURCE_TYPE_SUB_RESOURCE, false); |
812 false)); | |
813 EXPECT_TRUE(handler_.get()); | 799 EXPECT_TRUE(handler_.get()); |
814 job_.reset(handler_->MaybeLoadResource( | 800 job_.reset(handler_->MaybeLoadResource( |
815 request_.get(), request_->context()->network_delegate())); | 801 request_.get(), request_->context()->network_delegate())); |
816 EXPECT_TRUE(job_.get()); | 802 EXPECT_TRUE(job_.get()); |
817 | 803 |
818 backend_impl_.reset(); | 804 backend_impl_.reset(); |
819 mock_frontend_.reset(); | 805 mock_frontend_.reset(); |
820 mock_service_.reset(); | 806 mock_service_.reset(); |
821 mock_policy_.reset(); | 807 mock_policy_.reset(); |
822 host_ = NULL; | 808 host_ = NULL; |
823 | 809 |
824 EXPECT_TRUE(job_->has_been_killed()); | 810 EXPECT_TRUE(job_->has_been_killed()); |
825 EXPECT_FALSE(handler_->MaybeLoadResource( | 811 EXPECT_FALSE(handler_->MaybeLoadResource( |
826 request_.get(), request_->context()->network_delegate())); | 812 request_.get(), request_->context()->network_delegate())); |
827 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( | 813 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( |
828 request_.get(), | 814 request_.get(), |
829 request_->context()->network_delegate(), | 815 request_->context()->network_delegate(), |
830 GURL("http://blah/redirect"))); | 816 GURL("http://blah/redirect"))); |
831 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( | 817 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( |
832 request_.get(), request_->context()->network_delegate())); | 818 request_.get(), request_->context()->network_delegate())); |
833 | 819 |
834 TestFinished(); | 820 TestFinished(); |
835 } | 821 } |
836 | 822 |
837 void DestroyedServiceWithCrossSiteNav() { | 823 void DestroyedServiceWithCrossSiteNav() { |
838 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 824 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
839 net::DEFAULT_PRIORITY, &delegate_); | 825 net::DEFAULT_PRIORITY, &delegate_); |
840 handler_.reset(host_->CreateRequestHandler(request_.get(), | 826 handler_ = host_->CreateRequestHandler(request_.get(), |
841 RESOURCE_TYPE_MAIN_FRAME, | 827 RESOURCE_TYPE_MAIN_FRAME, false); |
842 false)); | |
843 EXPECT_TRUE(handler_.get()); | 828 EXPECT_TRUE(handler_.get()); |
844 handler_->PrepareForCrossSiteTransfer(backend_impl_->process_id()); | 829 handler_->PrepareForCrossSiteTransfer(backend_impl_->process_id()); |
845 EXPECT_TRUE(handler_->host_for_cross_site_transfer_.get()); | 830 EXPECT_TRUE(handler_->host_for_cross_site_transfer_.get()); |
846 | 831 |
847 backend_impl_.reset(); | 832 backend_impl_.reset(); |
848 mock_frontend_.reset(); | 833 mock_frontend_.reset(); |
849 mock_service_.reset(); | 834 mock_service_.reset(); |
850 mock_policy_.reset(); | 835 mock_policy_.reset(); |
851 host_ = NULL; | 836 host_ = NULL; |
852 | 837 |
(...skipping 11 matching lines...) Expand all Loading... |
864 } | 849 } |
865 | 850 |
866 // UnsupportedScheme ----------------------------- | 851 // UnsupportedScheme ----------------------------- |
867 | 852 |
868 void UnsupportedScheme() { | 853 void UnsupportedScheme() { |
869 // Precondition, the host is waiting on cache selection. | 854 // Precondition, the host is waiting on cache selection. |
870 host_->pending_selected_cache_id_ = 1; | 855 host_->pending_selected_cache_id_ = 1; |
871 | 856 |
872 request_ = empty_context_->CreateRequest(GURL("ftp://blah/"), | 857 request_ = empty_context_->CreateRequest(GURL("ftp://blah/"), |
873 net::DEFAULT_PRIORITY, &delegate_); | 858 net::DEFAULT_PRIORITY, &delegate_); |
874 handler_.reset(host_->CreateRequestHandler(request_.get(), | 859 handler_ = host_->CreateRequestHandler(request_.get(), |
875 RESOURCE_TYPE_SUB_RESOURCE, | 860 RESOURCE_TYPE_SUB_RESOURCE, false); |
876 false)); | |
877 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) | 861 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) |
878 | 862 |
879 EXPECT_FALSE(handler_->MaybeLoadResource( | 863 EXPECT_FALSE(handler_->MaybeLoadResource( |
880 request_.get(), request_->context()->network_delegate())); | 864 request_.get(), request_->context()->network_delegate())); |
881 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( | 865 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( |
882 request_.get(), | 866 request_.get(), |
883 request_->context()->network_delegate(), | 867 request_->context()->network_delegate(), |
884 GURL("ftp://blah/redirect"))); | 868 GURL("ftp://blah/redirect"))); |
885 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( | 869 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( |
886 request_.get(), request_->context()->network_delegate())); | 870 request_.get(), request_->context()->network_delegate())); |
887 | 871 |
888 TestFinished(); | 872 TestFinished(); |
889 } | 873 } |
890 | 874 |
891 // CanceledRequest ----------------------------- | 875 // CanceledRequest ----------------------------- |
892 | 876 |
893 void CanceledRequest() { | 877 void CanceledRequest() { |
894 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 878 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
895 net::DEFAULT_PRIORITY, &delegate_); | 879 net::DEFAULT_PRIORITY, &delegate_); |
896 handler_.reset(host_->CreateRequestHandler(request_.get(), | 880 handler_ = host_->CreateRequestHandler(request_.get(), |
897 RESOURCE_TYPE_MAIN_FRAME, | 881 RESOURCE_TYPE_MAIN_FRAME, false); |
898 false)); | |
899 EXPECT_TRUE(handler_.get()); | 882 EXPECT_TRUE(handler_.get()); |
900 | 883 |
901 job_.reset(handler_->MaybeLoadResource( | 884 job_.reset(handler_->MaybeLoadResource( |
902 request_.get(), request_->context()->network_delegate())); | 885 request_.get(), request_->context()->network_delegate())); |
903 EXPECT_TRUE(job_.get()); | 886 EXPECT_TRUE(job_.get()); |
904 EXPECT_TRUE(job_->is_waiting()); | 887 EXPECT_TRUE(job_->is_waiting()); |
905 EXPECT_FALSE(job_->has_been_started()); | 888 EXPECT_FALSE(job_->has_been_started()); |
906 | 889 |
907 base::WeakPtr<AppCacheURLRequestJob> weak_job = job_->GetWeakPtr(); | 890 base::WeakPtr<AppCacheURLRequestJob> weak_job = job_->GetWeakPtr(); |
908 | 891 |
(...skipping 27 matching lines...) Expand all Loading... |
936 net::DEFAULT_PRIORITY, &delegate_); | 919 net::DEFAULT_PRIORITY, &delegate_); |
937 | 920 |
938 const int kParentHostId = host_->host_id(); | 921 const int kParentHostId = host_->host_id(); |
939 const int kWorkerHostId = 2; | 922 const int kWorkerHostId = 2; |
940 const int kAbandonedWorkerHostId = 3; | 923 const int kAbandonedWorkerHostId = 3; |
941 const int kNonExsitingHostId = 700; | 924 const int kNonExsitingHostId = 700; |
942 | 925 |
943 backend_impl_->RegisterHost(kWorkerHostId); | 926 backend_impl_->RegisterHost(kWorkerHostId); |
944 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); | 927 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); |
945 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); | 928 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); |
946 handler_.reset(worker_host->CreateRequestHandler( | 929 handler_ = worker_host->CreateRequestHandler( |
947 request_.get(), RESOURCE_TYPE_SHARED_WORKER, false)); | 930 request_.get(), RESOURCE_TYPE_SHARED_WORKER, false); |
948 EXPECT_TRUE(handler_.get()); | 931 EXPECT_TRUE(handler_.get()); |
949 // Verify that the handler is associated with the parent host. | 932 // Verify that the handler is associated with the parent host. |
950 EXPECT_EQ(host_, handler_->host_); | 933 EXPECT_EQ(host_, handler_->host_); |
951 | 934 |
952 // Create a new worker host, but associate it with a parent host that | 935 // Create a new worker host, but associate it with a parent host that |
953 // does not exists to simulate the host having been torn down. | 936 // does not exists to simulate the host having been torn down. |
954 backend_impl_->UnregisterHost(kWorkerHostId); | 937 backend_impl_->UnregisterHost(kWorkerHostId); |
955 backend_impl_->RegisterHost(kAbandonedWorkerHostId); | 938 backend_impl_->RegisterHost(kAbandonedWorkerHostId); |
956 worker_host = backend_impl_->GetHost(kAbandonedWorkerHostId); | 939 worker_host = backend_impl_->GetHost(kAbandonedWorkerHostId); |
957 EXPECT_EQ(NULL, backend_impl_->GetHost(kNonExsitingHostId)); | 940 EXPECT_EQ(NULL, backend_impl_->GetHost(kNonExsitingHostId)); |
958 worker_host->SelectCacheForWorker(kNonExsitingHostId, kMockProcessId); | 941 worker_host->SelectCacheForWorker(kNonExsitingHostId, kMockProcessId); |
959 handler_.reset(worker_host->CreateRequestHandler( | 942 handler_ = worker_host->CreateRequestHandler( |
960 request_.get(), RESOURCE_TYPE_SHARED_WORKER, false)); | 943 request_.get(), RESOURCE_TYPE_SHARED_WORKER, false); |
961 EXPECT_FALSE(handler_.get()); | 944 EXPECT_FALSE(handler_.get()); |
962 | 945 |
963 TestFinished(); | 946 TestFinished(); |
964 } | 947 } |
965 | 948 |
966 // MainResource_Blocked -------------------------------------------------- | 949 // MainResource_Blocked -------------------------------------------------- |
967 | 950 |
968 void MainResource_Blocked() { | 951 void MainResource_Blocked() { |
969 PushNextTask( | 952 PushNextTask( |
970 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked, | 953 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked, |
971 base::Unretained(this))); | 954 base::Unretained(this))); |
972 | 955 |
973 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 956 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
974 net::DEFAULT_PRIORITY, &delegate_); | 957 net::DEFAULT_PRIORITY, &delegate_); |
975 handler_.reset(host_->CreateRequestHandler(request_.get(), | 958 handler_ = host_->CreateRequestHandler(request_.get(), |
976 RESOURCE_TYPE_MAIN_FRAME, | 959 RESOURCE_TYPE_MAIN_FRAME, false); |
977 false)); | |
978 EXPECT_TRUE(handler_.get()); | 960 EXPECT_TRUE(handler_.get()); |
979 | 961 |
980 mock_policy_->can_load_return_value_ = false; | 962 mock_policy_->can_load_return_value_ = false; |
981 mock_storage()->SimulateFindMainResource( | 963 mock_storage()->SimulateFindMainResource( |
982 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 964 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
983 GURL(), AppCacheEntry(), | 965 GURL(), AppCacheEntry(), |
984 1, 2, GURL("http://blah/manifest/")); | 966 1, 2, GURL("http://blah/manifest/")); |
985 | 967 |
986 job_.reset(handler_->MaybeLoadResource( | 968 job_.reset(handler_->MaybeLoadResource( |
987 request_.get(), request_->context()->network_delegate())); | 969 request_.get(), request_->context()->network_delegate())); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 | 1104 |
1123 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1105 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
1124 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1106 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
1125 } | 1107 } |
1126 | 1108 |
1127 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1109 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
1128 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1110 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
1129 } | 1111 } |
1130 | 1112 |
1131 } // namespace content | 1113 } // namespace content |
OLD | NEW |