| 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 16 matching lines...) Expand all Loading... |
| 27 #include "content/browser/appcache/appcache.h" | 27 #include "content/browser/appcache/appcache.h" |
| 28 #include "content/browser/appcache/appcache_backend_impl.h" | 28 #include "content/browser/appcache/appcache_backend_impl.h" |
| 29 #include "content/browser/appcache/appcache_url_request.h" | 29 #include "content/browser/appcache/appcache_url_request.h" |
| 30 #include "content/browser/appcache/appcache_url_request_job.h" | 30 #include "content/browser/appcache/appcache_url_request_job.h" |
| 31 #include "content/browser/appcache/mock_appcache_policy.h" | 31 #include "content/browser/appcache/mock_appcache_policy.h" |
| 32 #include "content/browser/appcache/mock_appcache_service.h" | 32 #include "content/browser/appcache/mock_appcache_service.h" |
| 33 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
| 34 #include "net/base/request_priority.h" | 34 #include "net/base/request_priority.h" |
| 35 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
| 36 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
| 37 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 37 #include "net/url_request/url_request.h" | 38 #include "net/url_request/url_request.h" |
| 38 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
| 39 #include "net/url_request/url_request_error_job.h" | 40 #include "net/url_request/url_request_error_job.h" |
| 40 #include "net/url_request/url_request_job_factory.h" | 41 #include "net/url_request/url_request_job_factory.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 43 |
| 43 namespace content { | 44 namespace content { |
| 44 | 45 |
| 45 static const int kMockProcessId = 1; | 46 static const int kMockProcessId = 1; |
| 46 | 47 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 266 } |
| 266 | 267 |
| 267 // MainResource_Miss -------------------------------------------------- | 268 // MainResource_Miss -------------------------------------------------- |
| 268 | 269 |
| 269 void MainResource_Miss() { | 270 void MainResource_Miss() { |
| 270 PushNextTask( | 271 PushNextTask( |
| 271 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, | 272 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, |
| 272 base::Unretained(this))); | 273 base::Unretained(this))); |
| 273 | 274 |
| 274 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 275 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 275 net::DEFAULT_PRIORITY, &delegate_); | 276 net::DEFAULT_PRIORITY, &delegate_, |
| 277 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 276 handler_ = | 278 handler_ = |
| 277 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 279 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 278 RESOURCE_TYPE_MAIN_FRAME, false); | 280 RESOURCE_TYPE_MAIN_FRAME, false); |
| 279 EXPECT_TRUE(handler_.get()); | 281 EXPECT_TRUE(handler_.get()); |
| 280 | 282 |
| 281 job_.reset(static_cast<AppCacheURLRequestJob*>( | 283 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 282 handler_->MaybeLoadResource(request_->context()->network_delegate()) | 284 handler_->MaybeLoadResource(request_->context()->network_delegate()) |
| 283 ->AsURLRequestJob())); | 285 ->AsURLRequestJob())); |
| 284 EXPECT_TRUE(job_.get()); | 286 EXPECT_TRUE(job_.get()); |
| 285 EXPECT_TRUE(job_->IsWaiting()); | 287 EXPECT_TRUE(job_->IsWaiting()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 316 } | 318 } |
| 317 | 319 |
| 318 // MainResource_Hit -------------------------------------------------- | 320 // MainResource_Hit -------------------------------------------------- |
| 319 | 321 |
| 320 void MainResource_Hit() { | 322 void MainResource_Hit() { |
| 321 PushNextTask( | 323 PushNextTask( |
| 322 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit, | 324 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit, |
| 323 base::Unretained(this))); | 325 base::Unretained(this))); |
| 324 | 326 |
| 325 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 327 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 326 net::DEFAULT_PRIORITY, &delegate_); | 328 net::DEFAULT_PRIORITY, &delegate_, |
| 329 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 327 handler_ = | 330 handler_ = |
| 328 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 331 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 329 RESOURCE_TYPE_MAIN_FRAME, false); | 332 RESOURCE_TYPE_MAIN_FRAME, false); |
| 330 EXPECT_TRUE(handler_.get()); | 333 EXPECT_TRUE(handler_.get()); |
| 331 | 334 |
| 332 mock_storage()->SimulateFindMainResource( | 335 mock_storage()->SimulateFindMainResource( |
| 333 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 336 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
| 334 GURL(), AppCacheEntry(), | 337 GURL(), AppCacheEntry(), |
| 335 1, 2, GURL("http://blah/manifest/")); | 338 1, 2, GURL("http://blah/manifest/")); |
| 336 | 339 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 367 } | 370 } |
| 368 | 371 |
| 369 // MainResource_Fallback -------------------------------------------------- | 372 // MainResource_Fallback -------------------------------------------------- |
| 370 | 373 |
| 371 void MainResource_Fallback() { | 374 void MainResource_Fallback() { |
| 372 PushNextTask( | 375 PushNextTask( |
| 373 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback, | 376 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback, |
| 374 base::Unretained(this))); | 377 base::Unretained(this))); |
| 375 | 378 |
| 376 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 379 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 377 net::DEFAULT_PRIORITY, &delegate_); | 380 net::DEFAULT_PRIORITY, &delegate_, |
| 381 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 378 handler_ = | 382 handler_ = |
| 379 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 383 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 380 RESOURCE_TYPE_MAIN_FRAME, false); | 384 RESOURCE_TYPE_MAIN_FRAME, false); |
| 381 EXPECT_TRUE(handler_.get()); | 385 EXPECT_TRUE(handler_.get()); |
| 382 | 386 |
| 383 mock_storage()->SimulateFindMainResource( | 387 mock_storage()->SimulateFindMainResource( |
| 384 AppCacheEntry(), | 388 AppCacheEntry(), |
| 385 GURL("http://blah/fallbackurl"), | 389 GURL("http://blah/fallbackurl"), |
| 386 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 390 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
| 387 1, 2, GURL("http://blah/manifest/")); | 391 1, 2, GURL("http://blah/manifest/")); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 TestFinished(); | 458 TestFinished(); |
| 455 } | 459 } |
| 456 | 460 |
| 457 // MainResource_FallbackOverride -------------------------------------------- | 461 // MainResource_FallbackOverride -------------------------------------------- |
| 458 | 462 |
| 459 void MainResource_FallbackOverride() { | 463 void MainResource_FallbackOverride() { |
| 460 PushNextTask(base::Bind( | 464 PushNextTask(base::Bind( |
| 461 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride, | 465 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride, |
| 462 base::Unretained(this))); | 466 base::Unretained(this))); |
| 463 | 467 |
| 464 request_ = | 468 request_ = empty_context_->CreateRequest( |
| 465 empty_context_->CreateRequest(GURL("http://blah/fallback-override"), | 469 GURL("http://blah/fallback-override"), net::DEFAULT_PRIORITY, |
| 466 net::DEFAULT_PRIORITY, &delegate_); | 470 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 467 handler_ = | 471 handler_ = |
| 468 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 472 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 469 RESOURCE_TYPE_MAIN_FRAME, false); | 473 RESOURCE_TYPE_MAIN_FRAME, false); |
| 470 EXPECT_TRUE(handler_.get()); | 474 EXPECT_TRUE(handler_.get()); |
| 471 | 475 |
| 472 mock_storage()->SimulateFindMainResource( | 476 mock_storage()->SimulateFindMainResource( |
| 473 AppCacheEntry(), | 477 AppCacheEntry(), |
| 474 GURL("http://blah/fallbackurl"), | 478 GURL("http://blah/fallbackurl"), |
| 475 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 479 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
| 476 1, 2, GURL("http://blah/manifest/")); | 480 1, 2, GURL("http://blah/manifest/")); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 EXPECT_EQ(kAppCacheNoCacheId, cache_id); | 526 EXPECT_EQ(kAppCacheNoCacheId, cache_id); |
| 523 EXPECT_TRUE(manifest_url.is_empty()); | 527 EXPECT_TRUE(manifest_url.is_empty()); |
| 524 | 528 |
| 525 TestFinished(); | 529 TestFinished(); |
| 526 } | 530 } |
| 527 | 531 |
| 528 // SubResource_Miss_WithNoCacheSelected ---------------------------------- | 532 // SubResource_Miss_WithNoCacheSelected ---------------------------------- |
| 529 | 533 |
| 530 void SubResource_Miss_WithNoCacheSelected() { | 534 void SubResource_Miss_WithNoCacheSelected() { |
| 531 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 535 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 532 net::DEFAULT_PRIORITY, &delegate_); | 536 net::DEFAULT_PRIORITY, &delegate_, |
| 537 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 533 handler_ = | 538 handler_ = |
| 534 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 539 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 535 RESOURCE_TYPE_SUB_RESOURCE, false); | 540 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 536 | 541 |
| 537 // We avoid creating handler when possible, sub-resource requests are not | 542 // We avoid creating handler when possible, sub-resource requests are not |
| 538 // subject to retrieval from an appcache when there's no associated cache. | 543 // subject to retrieval from an appcache when there's no associated cache. |
| 539 EXPECT_FALSE(handler_.get()); | 544 EXPECT_FALSE(handler_.get()); |
| 540 | 545 |
| 541 TestFinished(); | 546 TestFinished(); |
| 542 } | 547 } |
| 543 | 548 |
| 544 // SubResource_Miss_WithCacheSelected ---------------------------------- | 549 // SubResource_Miss_WithCacheSelected ---------------------------------- |
| 545 | 550 |
| 546 void SubResource_Miss_WithCacheSelected() { | 551 void SubResource_Miss_WithCacheSelected() { |
| 547 // A sub-resource load where the resource is not in an appcache, or | 552 // A sub-resource load where the resource is not in an appcache, or |
| 548 // in a network or fallback namespace, should result in a failed request. | 553 // in a network or fallback namespace, should result in a failed request. |
| 549 host_->AssociateCompleteCache(MakeNewCache()); | 554 host_->AssociateCompleteCache(MakeNewCache()); |
| 550 | 555 |
| 551 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 556 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 552 net::DEFAULT_PRIORITY, &delegate_); | 557 net::DEFAULT_PRIORITY, &delegate_, |
| 558 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 553 handler_ = | 559 handler_ = |
| 554 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 560 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 555 RESOURCE_TYPE_SUB_RESOURCE, false); | 561 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 556 EXPECT_TRUE(handler_.get()); | 562 EXPECT_TRUE(handler_.get()); |
| 557 | 563 |
| 558 job_.reset(static_cast<AppCacheURLRequestJob*>( | 564 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 559 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 565 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 560 EXPECT_TRUE(job_.get()); | 566 EXPECT_TRUE(job_.get()); |
| 561 EXPECT_TRUE(job_->IsDeliveringErrorResponse()); | 567 EXPECT_TRUE(job_->IsDeliveringErrorResponse()); |
| 562 | 568 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 576 | 582 |
| 577 // SubResource_Miss_WithWaitForCacheSelection ----------------------------- | 583 // SubResource_Miss_WithWaitForCacheSelection ----------------------------- |
| 578 | 584 |
| 579 void SubResource_Miss_WithWaitForCacheSelection() { | 585 void SubResource_Miss_WithWaitForCacheSelection() { |
| 580 // Precondition, the host is waiting on cache selection. | 586 // Precondition, the host is waiting on cache selection. |
| 581 scoped_refptr<AppCache> cache(MakeNewCache()); | 587 scoped_refptr<AppCache> cache(MakeNewCache()); |
| 582 host_->pending_selected_cache_id_ = cache->cache_id(); | 588 host_->pending_selected_cache_id_ = cache->cache_id(); |
| 583 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url()); | 589 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url()); |
| 584 | 590 |
| 585 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 591 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 586 net::DEFAULT_PRIORITY, &delegate_); | 592 net::DEFAULT_PRIORITY, &delegate_, |
| 593 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 587 handler_ = | 594 handler_ = |
| 588 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 595 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 589 RESOURCE_TYPE_SUB_RESOURCE, false); | 596 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 590 EXPECT_TRUE(handler_.get()); | 597 EXPECT_TRUE(handler_.get()); |
| 591 job_.reset(static_cast<AppCacheURLRequestJob*>( | 598 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 592 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 599 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 593 EXPECT_TRUE(job_.get()); | 600 EXPECT_TRUE(job_.get()); |
| 594 EXPECT_TRUE(job_->IsWaiting()); | 601 EXPECT_TRUE(job_->IsWaiting()); |
| 595 | 602 |
| 596 host_->FinishCacheSelection(cache.get(), NULL); | 603 host_->FinishCacheSelection(cache.get(), NULL); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 613 | 620 |
| 614 // SubResource_Hit ----------------------------- | 621 // SubResource_Hit ----------------------------- |
| 615 | 622 |
| 616 void SubResource_Hit() { | 623 void SubResource_Hit() { |
| 617 host_->AssociateCompleteCache(MakeNewCache()); | 624 host_->AssociateCompleteCache(MakeNewCache()); |
| 618 | 625 |
| 619 mock_storage()->SimulateFindSubResource( | 626 mock_storage()->SimulateFindSubResource( |
| 620 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 627 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
| 621 | 628 |
| 622 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 629 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 623 net::DEFAULT_PRIORITY, &delegate_); | 630 net::DEFAULT_PRIORITY, &delegate_, |
| 631 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 624 handler_ = | 632 handler_ = |
| 625 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 633 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 626 RESOURCE_TYPE_SUB_RESOURCE, false); | 634 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 627 EXPECT_TRUE(handler_.get()); | 635 EXPECT_TRUE(handler_.get()); |
| 628 job_.reset(static_cast<AppCacheURLRequestJob*>( | 636 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 629 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 637 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 630 EXPECT_TRUE(job_.get()); | 638 EXPECT_TRUE(job_.get()); |
| 631 EXPECT_TRUE(job_->IsDeliveringAppCacheResponse()); | 639 EXPECT_TRUE(job_->IsDeliveringAppCacheResponse()); |
| 632 | 640 |
| 633 std::unique_ptr<AppCacheURLRequestJob> fallback_job( | 641 std::unique_ptr<AppCacheURLRequestJob> fallback_job( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 648 | 656 |
| 649 void SubResource_RedirectFallback() { | 657 void SubResource_RedirectFallback() { |
| 650 // Redirects to resources in the a different origin are subject to | 658 // Redirects to resources in the a different origin are subject to |
| 651 // fallback namespaces. | 659 // fallback namespaces. |
| 652 host_->AssociateCompleteCache(MakeNewCache()); | 660 host_->AssociateCompleteCache(MakeNewCache()); |
| 653 | 661 |
| 654 mock_storage()->SimulateFindSubResource( | 662 mock_storage()->SimulateFindSubResource( |
| 655 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); | 663 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); |
| 656 | 664 |
| 657 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 665 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 658 net::DEFAULT_PRIORITY, &delegate_); | 666 net::DEFAULT_PRIORITY, &delegate_, |
| 667 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 659 handler_ = | 668 handler_ = |
| 660 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 669 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 661 RESOURCE_TYPE_SUB_RESOURCE, false); | 670 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 662 EXPECT_TRUE(handler_.get()); | 671 EXPECT_TRUE(handler_.get()); |
| 663 job_.reset(static_cast<AppCacheURLRequestJob*>( | 672 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 664 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 673 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 665 EXPECT_FALSE(job_.get()); | 674 EXPECT_FALSE(job_.get()); |
| 666 | 675 |
| 667 job_.reset(static_cast<AppCacheURLRequestJob*>( | 676 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 668 handler_->MaybeLoadFallbackForRedirect( | 677 handler_->MaybeLoadFallbackForRedirect( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 684 | 693 |
| 685 void SubResource_NoRedirectFallback() { | 694 void SubResource_NoRedirectFallback() { |
| 686 // Redirects to resources in the same-origin are not subject to | 695 // Redirects to resources in the same-origin are not subject to |
| 687 // fallback namespaces. | 696 // fallback namespaces. |
| 688 host_->AssociateCompleteCache(MakeNewCache()); | 697 host_->AssociateCompleteCache(MakeNewCache()); |
| 689 | 698 |
| 690 mock_storage()->SimulateFindSubResource( | 699 mock_storage()->SimulateFindSubResource( |
| 691 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); | 700 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); |
| 692 | 701 |
| 693 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 702 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 694 net::DEFAULT_PRIORITY, &delegate_); | 703 net::DEFAULT_PRIORITY, &delegate_, |
| 704 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 695 handler_ = | 705 handler_ = |
| 696 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 706 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 697 RESOURCE_TYPE_SUB_RESOURCE, false); | 707 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 698 EXPECT_TRUE(handler_.get()); | 708 EXPECT_TRUE(handler_.get()); |
| 699 job_.reset(static_cast<AppCacheURLRequestJob*>( | 709 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 700 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 710 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 701 EXPECT_FALSE(job_.get()); | 711 EXPECT_FALSE(job_.get()); |
| 702 | 712 |
| 703 std::unique_ptr<AppCacheURLRequestJob> fallback_job( | 713 std::unique_ptr<AppCacheURLRequestJob> fallback_job( |
| 704 static_cast<AppCacheURLRequestJob*>( | 714 static_cast<AppCacheURLRequestJob*>( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 721 void SubResource_Network() { | 731 void SubResource_Network() { |
| 722 // A sub-resource load where the resource is in a network namespace, | 732 // A sub-resource load where the resource is in a network namespace, |
| 723 // should result in the system using a 'real' job to do the network | 733 // should result in the system using a 'real' job to do the network |
| 724 // retrieval. | 734 // retrieval. |
| 725 host_->AssociateCompleteCache(MakeNewCache()); | 735 host_->AssociateCompleteCache(MakeNewCache()); |
| 726 | 736 |
| 727 mock_storage()->SimulateFindSubResource( | 737 mock_storage()->SimulateFindSubResource( |
| 728 AppCacheEntry(), AppCacheEntry(), true); | 738 AppCacheEntry(), AppCacheEntry(), true); |
| 729 | 739 |
| 730 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 740 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 731 net::DEFAULT_PRIORITY, &delegate_); | 741 net::DEFAULT_PRIORITY, &delegate_, |
| 742 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 732 handler_ = | 743 handler_ = |
| 733 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 744 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 734 RESOURCE_TYPE_SUB_RESOURCE, false); | 745 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 735 EXPECT_TRUE(handler_.get()); | 746 EXPECT_TRUE(handler_.get()); |
| 736 job_.reset(static_cast<AppCacheURLRequestJob*>( | 747 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 737 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 748 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 738 EXPECT_FALSE(job_.get()); | 749 EXPECT_FALSE(job_.get()); |
| 739 | 750 |
| 740 std::unique_ptr<AppCacheURLRequestJob> fallback_job( | 751 std::unique_ptr<AppCacheURLRequestJob> fallback_job( |
| 741 static_cast<AppCacheURLRequestJob*>( | 752 static_cast<AppCacheURLRequestJob*>( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 753 | 764 |
| 754 // DestroyedHost ----------------------------- | 765 // DestroyedHost ----------------------------- |
| 755 | 766 |
| 756 void DestroyedHost() { | 767 void DestroyedHost() { |
| 757 host_->AssociateCompleteCache(MakeNewCache()); | 768 host_->AssociateCompleteCache(MakeNewCache()); |
| 758 | 769 |
| 759 mock_storage()->SimulateFindSubResource( | 770 mock_storage()->SimulateFindSubResource( |
| 760 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 771 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
| 761 | 772 |
| 762 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 773 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 763 net::DEFAULT_PRIORITY, &delegate_); | 774 net::DEFAULT_PRIORITY, &delegate_, |
| 775 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 764 handler_ = | 776 handler_ = |
| 765 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 777 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 766 RESOURCE_TYPE_SUB_RESOURCE, false); | 778 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 767 EXPECT_TRUE(handler_.get()); | 779 EXPECT_TRUE(handler_.get()); |
| 768 | 780 |
| 769 backend_impl_->UnregisterHost(1); | 781 backend_impl_->UnregisterHost(1); |
| 770 host_ = NULL; | 782 host_ = NULL; |
| 771 | 783 |
| 772 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( | 784 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( |
| 773 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 785 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 774 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( | 786 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( |
| 775 handler_->MaybeLoadFallbackForRedirect( | 787 handler_->MaybeLoadFallbackForRedirect( |
| 776 request_->context()->network_delegate(), | 788 request_->context()->network_delegate(), |
| 777 GURL("http://blah/redirect")))); | 789 GURL("http://blah/redirect")))); |
| 778 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( | 790 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( |
| 779 handler_->MaybeLoadFallbackForResponse( | 791 handler_->MaybeLoadFallbackForResponse( |
| 780 request_->context()->network_delegate()))); | 792 request_->context()->network_delegate()))); |
| 781 | 793 |
| 782 TestFinished(); | 794 TestFinished(); |
| 783 } | 795 } |
| 784 | 796 |
| 785 // DestroyedHostWithWaitingJob ----------------------------- | 797 // DestroyedHostWithWaitingJob ----------------------------- |
| 786 | 798 |
| 787 void DestroyedHostWithWaitingJob() { | 799 void DestroyedHostWithWaitingJob() { |
| 788 // Precondition, the host is waiting on cache selection. | 800 // Precondition, the host is waiting on cache selection. |
| 789 host_->pending_selected_cache_id_ = 1; | 801 host_->pending_selected_cache_id_ = 1; |
| 790 | 802 |
| 791 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 803 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 792 net::DEFAULT_PRIORITY, &delegate_); | 804 net::DEFAULT_PRIORITY, &delegate_, |
| 805 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 793 handler_ = | 806 handler_ = |
| 794 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 807 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 795 RESOURCE_TYPE_SUB_RESOURCE, false); | 808 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 796 EXPECT_TRUE(handler_.get()); | 809 EXPECT_TRUE(handler_.get()); |
| 797 | 810 |
| 798 job_.reset(static_cast<AppCacheURLRequestJob*>( | 811 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 799 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 812 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 800 EXPECT_TRUE(job_.get()); | 813 EXPECT_TRUE(job_.get()); |
| 801 EXPECT_TRUE(job_->IsWaiting()); | 814 EXPECT_TRUE(job_->IsWaiting()); |
| 802 | 815 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 819 | 832 |
| 820 // DestroyedService ----------------------------- | 833 // DestroyedService ----------------------------- |
| 821 | 834 |
| 822 void DestroyedService() { | 835 void DestroyedService() { |
| 823 host_->AssociateCompleteCache(MakeNewCache()); | 836 host_->AssociateCompleteCache(MakeNewCache()); |
| 824 | 837 |
| 825 mock_storage()->SimulateFindSubResource( | 838 mock_storage()->SimulateFindSubResource( |
| 826 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 839 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
| 827 | 840 |
| 828 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 841 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 829 net::DEFAULT_PRIORITY, &delegate_); | 842 net::DEFAULT_PRIORITY, &delegate_, |
| 843 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 830 handler_ = | 844 handler_ = |
| 831 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 845 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 832 RESOURCE_TYPE_SUB_RESOURCE, false); | 846 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 833 EXPECT_TRUE(handler_.get()); | 847 EXPECT_TRUE(handler_.get()); |
| 834 job_.reset(static_cast<AppCacheURLRequestJob*>( | 848 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 835 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 849 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 836 EXPECT_TRUE(job_.get()); | 850 EXPECT_TRUE(job_.get()); |
| 837 | 851 |
| 838 backend_impl_.reset(); | 852 backend_impl_.reset(); |
| 839 mock_frontend_.reset(); | 853 mock_frontend_.reset(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 850 GURL("http://blah/redirect")))); | 864 GURL("http://blah/redirect")))); |
| 851 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( | 865 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( |
| 852 handler_->MaybeLoadFallbackForResponse( | 866 handler_->MaybeLoadFallbackForResponse( |
| 853 request_->context()->network_delegate()))); | 867 request_->context()->network_delegate()))); |
| 854 | 868 |
| 855 TestFinished(); | 869 TestFinished(); |
| 856 } | 870 } |
| 857 | 871 |
| 858 void DestroyedServiceWithCrossSiteNav() { | 872 void DestroyedServiceWithCrossSiteNav() { |
| 859 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 873 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 860 net::DEFAULT_PRIORITY, &delegate_); | 874 net::DEFAULT_PRIORITY, &delegate_, |
| 875 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 861 handler_ = | 876 handler_ = |
| 862 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 877 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 863 RESOURCE_TYPE_MAIN_FRAME, false); | 878 RESOURCE_TYPE_MAIN_FRAME, false); |
| 864 EXPECT_TRUE(handler_.get()); | 879 EXPECT_TRUE(handler_.get()); |
| 865 handler_->PrepareForCrossSiteTransfer(backend_impl_->process_id()); | 880 handler_->PrepareForCrossSiteTransfer(backend_impl_->process_id()); |
| 866 EXPECT_TRUE(handler_->host_for_cross_site_transfer_.get()); | 881 EXPECT_TRUE(handler_->host_for_cross_site_transfer_.get()); |
| 867 | 882 |
| 868 backend_impl_.reset(); | 883 backend_impl_.reset(); |
| 869 mock_frontend_.reset(); | 884 mock_frontend_.reset(); |
| 870 mock_service_.reset(); | 885 mock_service_.reset(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 885 TestFinished(); | 900 TestFinished(); |
| 886 } | 901 } |
| 887 | 902 |
| 888 // UnsupportedScheme ----------------------------- | 903 // UnsupportedScheme ----------------------------- |
| 889 | 904 |
| 890 void UnsupportedScheme() { | 905 void UnsupportedScheme() { |
| 891 // Precondition, the host is waiting on cache selection. | 906 // Precondition, the host is waiting on cache selection. |
| 892 host_->pending_selected_cache_id_ = 1; | 907 host_->pending_selected_cache_id_ = 1; |
| 893 | 908 |
| 894 request_ = empty_context_->CreateRequest(GURL("ftp://blah/"), | 909 request_ = empty_context_->CreateRequest(GURL("ftp://blah/"), |
| 895 net::DEFAULT_PRIORITY, &delegate_); | 910 net::DEFAULT_PRIORITY, &delegate_, |
| 911 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 896 handler_ = | 912 handler_ = |
| 897 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 913 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 898 RESOURCE_TYPE_SUB_RESOURCE, false); | 914 RESOURCE_TYPE_SUB_RESOURCE, false); |
| 899 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) | 915 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) |
| 900 | 916 |
| 901 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( | 917 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( |
| 902 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 918 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 903 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( | 919 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( |
| 904 handler_->MaybeLoadFallbackForRedirect( | 920 handler_->MaybeLoadFallbackForRedirect( |
| 905 request_->context()->network_delegate(), | 921 request_->context()->network_delegate(), |
| 906 GURL("ftp://blah/redirect")))); | 922 GURL("ftp://blah/redirect")))); |
| 907 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( | 923 EXPECT_FALSE(static_cast<AppCacheURLRequestJob*>( |
| 908 handler_->MaybeLoadFallbackForResponse( | 924 handler_->MaybeLoadFallbackForResponse( |
| 909 request_->context()->network_delegate()))); | 925 request_->context()->network_delegate()))); |
| 910 | 926 |
| 911 TestFinished(); | 927 TestFinished(); |
| 912 } | 928 } |
| 913 | 929 |
| 914 // CanceledRequest ----------------------------- | 930 // CanceledRequest ----------------------------- |
| 915 | 931 |
| 916 void CanceledRequest() { | 932 void CanceledRequest() { |
| 917 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 933 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 918 net::DEFAULT_PRIORITY, &delegate_); | 934 net::DEFAULT_PRIORITY, &delegate_, |
| 935 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 919 handler_ = | 936 handler_ = |
| 920 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 937 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 921 RESOURCE_TYPE_MAIN_FRAME, false); | 938 RESOURCE_TYPE_MAIN_FRAME, false); |
| 922 EXPECT_TRUE(handler_.get()); | 939 EXPECT_TRUE(handler_.get()); |
| 923 | 940 |
| 924 job_.reset(static_cast<AppCacheURLRequestJob*>( | 941 job_.reset(static_cast<AppCacheURLRequestJob*>( |
| 925 handler_->MaybeLoadResource(request_->context()->network_delegate()))); | 942 handler_->MaybeLoadResource(request_->context()->network_delegate()))); |
| 926 EXPECT_TRUE(job_.get()); | 943 EXPECT_TRUE(job_.get()); |
| 927 EXPECT_TRUE(job_->IsWaiting()); | 944 EXPECT_TRUE(job_->IsWaiting()); |
| 928 EXPECT_FALSE(job_->IsStarted()); | 945 EXPECT_FALSE(job_->IsStarted()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 950 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( | 967 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( |
| 951 RESOURCE_TYPE_MAIN_FRAME)); | 968 RESOURCE_TYPE_MAIN_FRAME)); |
| 952 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( | 969 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( |
| 953 RESOURCE_TYPE_SUB_FRAME)); | 970 RESOURCE_TYPE_SUB_FRAME)); |
| 954 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( | 971 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( |
| 955 RESOURCE_TYPE_SHARED_WORKER)); | 972 RESOURCE_TYPE_SHARED_WORKER)); |
| 956 EXPECT_FALSE(AppCacheRequestHandler::IsMainResourceType( | 973 EXPECT_FALSE(AppCacheRequestHandler::IsMainResourceType( |
| 957 RESOURCE_TYPE_WORKER)); | 974 RESOURCE_TYPE_WORKER)); |
| 958 | 975 |
| 959 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 976 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 960 net::DEFAULT_PRIORITY, &delegate_); | 977 net::DEFAULT_PRIORITY, &delegate_, |
| 978 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 961 | 979 |
| 962 const int kParentHostId = host_->host_id(); | 980 const int kParentHostId = host_->host_id(); |
| 963 const int kWorkerHostId = 2; | 981 const int kWorkerHostId = 2; |
| 964 const int kAbandonedWorkerHostId = 3; | 982 const int kAbandonedWorkerHostId = 3; |
| 965 const int kNonExsitingHostId = 700; | 983 const int kNonExsitingHostId = 700; |
| 966 | 984 |
| 967 backend_impl_->RegisterHost(kWorkerHostId); | 985 backend_impl_->RegisterHost(kWorkerHostId); |
| 968 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); | 986 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); |
| 969 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); | 987 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); |
| 970 handler_ = worker_host->CreateRequestHandler( | 988 handler_ = worker_host->CreateRequestHandler( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 990 } | 1008 } |
| 991 | 1009 |
| 992 // MainResource_Blocked -------------------------------------------------- | 1010 // MainResource_Blocked -------------------------------------------------- |
| 993 | 1011 |
| 994 void MainResource_Blocked() { | 1012 void MainResource_Blocked() { |
| 995 PushNextTask( | 1013 PushNextTask( |
| 996 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked, | 1014 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked, |
| 997 base::Unretained(this))); | 1015 base::Unretained(this))); |
| 998 | 1016 |
| 999 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 1017 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 1000 net::DEFAULT_PRIORITY, &delegate_); | 1018 net::DEFAULT_PRIORITY, &delegate_, |
| 1019 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1001 handler_ = | 1020 handler_ = |
| 1002 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), | 1021 host_->CreateRequestHandler(AppCacheURLRequest::Create(request_.get()), |
| 1003 RESOURCE_TYPE_MAIN_FRAME, false); | 1022 RESOURCE_TYPE_MAIN_FRAME, false); |
| 1004 EXPECT_TRUE(handler_.get()); | 1023 EXPECT_TRUE(handler_.get()); |
| 1005 | 1024 |
| 1006 mock_policy_->can_load_return_value_ = false; | 1025 mock_policy_->can_load_return_value_ = false; |
| 1007 mock_storage()->SimulateFindMainResource( | 1026 mock_storage()->SimulateFindMainResource( |
| 1008 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 1027 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
| 1009 GURL(), AppCacheEntry(), | 1028 GURL(), AppCacheEntry(), |
| 1010 1, 2, GURL("http://blah/manifest/")); | 1029 1, 2, GURL("http://blah/manifest/")); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 | 1167 |
| 1149 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1168 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
| 1150 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1169 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
| 1151 } | 1170 } |
| 1152 | 1171 |
| 1153 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1172 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
| 1154 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1173 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
| 1155 } | 1174 } |
| 1156 | 1175 |
| 1157 } // namespace content | 1176 } // namespace content |
| OLD | NEW |