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