OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 3678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3689 | 3689 |
3690 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1, | 3690 MakeTestRequestWithResourceType(filter_.get(), filter_->child_id(), 1, |
3691 GURL("http://example.com/blah"), | 3691 GURL("http://example.com/blah"), |
3692 RESOURCE_TYPE_STYLESHEET); | 3692 RESOURCE_TYPE_STYLESHEET); |
3693 | 3693 |
3694 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { | 3694 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { |
3695 } | 3695 } |
3696 base::RunLoop().RunUntilIdle(); | 3696 base::RunLoop().RunUntilIdle(); |
3697 } | 3697 } |
3698 | 3698 |
| 3699 namespace { |
| 3700 |
| 3701 void StoreSyncLoadResult(bool* called, |
| 3702 bool* was_null, |
| 3703 SyncLoadResult* result_out, |
| 3704 const SyncLoadResult* result) { |
| 3705 *called = true; |
| 3706 *was_null = !result; |
| 3707 |
| 3708 if (result) |
| 3709 *result_out = *result; |
| 3710 } |
| 3711 |
| 3712 } // namespace |
| 3713 |
| 3714 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { |
| 3715 ResourceRequest request = CreateResourceRequest( |
| 3716 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); |
| 3717 request.priority = net::MAXIMUM_PRIORITY; |
| 3718 |
| 3719 bool called = false; |
| 3720 bool was_null = false; |
| 3721 SyncLoadResult result; |
| 3722 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), |
| 3723 base::Bind(&StoreSyncLoadResult, |
| 3724 &called, &was_null, &result)); |
| 3725 base::RunLoop().RunUntilIdle(); |
| 3726 EXPECT_TRUE(called); |
| 3727 EXPECT_FALSE(was_null); |
| 3728 EXPECT_EQ(net::OK, result.error_code); |
| 3729 } |
| 3730 |
| 3731 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoError) { |
| 3732 ResourceRequest request = CreateResourceRequest( |
| 3733 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); |
| 3734 request.priority = net::MAXIMUM_PRIORITY; |
| 3735 |
| 3736 bool called = false; |
| 3737 bool was_null = false; |
| 3738 SyncLoadResult result; |
| 3739 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), |
| 3740 base::Bind(&StoreSyncLoadResult, |
| 3741 &called, &was_null, &result)); |
| 3742 base::RunLoop().RunUntilIdle(); |
| 3743 EXPECT_TRUE(called); |
| 3744 EXPECT_FALSE(was_null); |
| 3745 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); |
| 3746 } |
| 3747 |
| 3748 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { |
| 3749 ResourceRequest request = CreateResourceRequest( |
| 3750 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); |
| 3751 request.priority = net::MAXIMUM_PRIORITY; |
| 3752 |
| 3753 bool called = false; |
| 3754 bool was_null = false; |
| 3755 SyncLoadResult result; |
| 3756 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), |
| 3757 base::Bind(&StoreSyncLoadResult, |
| 3758 &called, &was_null, &result)); |
| 3759 host_.CancelRequestsForProcess(filter_->child_id()); |
| 3760 base::RunLoop().RunUntilIdle(); |
| 3761 EXPECT_TRUE(called); |
| 3762 EXPECT_TRUE(was_null); |
| 3763 } |
| 3764 |
3699 // A URLRequestTestJob that sets a test certificate on the |ssl_info| | 3765 // A URLRequestTestJob that sets a test certificate on the |ssl_info| |
3700 // field of the response. | 3766 // field of the response. |
3701 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { | 3767 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { |
3702 public: | 3768 public: |
3703 TestHTTPSURLRequestJob(net::URLRequest* request, | 3769 TestHTTPSURLRequestJob(net::URLRequest* request, |
3704 net::NetworkDelegate* network_delegate, | 3770 net::NetworkDelegate* network_delegate, |
3705 const std::string& response_headers, | 3771 const std::string& response_headers, |
3706 const std::string& response_data, | 3772 const std::string& response_data, |
3707 bool auto_advance) | 3773 bool auto_advance) |
3708 : net::URLRequestTestJob(request, | 3774 : net::URLRequestTestJob(request, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3779 return nullptr; | 3845 return nullptr; |
3780 } | 3846 } |
3781 | 3847 |
3782 INSTANTIATE_TEST_CASE_P( | 3848 INSTANTIATE_TEST_CASE_P( |
3783 ResourceDispatcherHostTests, | 3849 ResourceDispatcherHostTests, |
3784 ResourceDispatcherHostTest, | 3850 ResourceDispatcherHostTest, |
3785 testing::Values(TestConfig::kDefault, | 3851 testing::Values(TestConfig::kDefault, |
3786 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3852 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
3787 | 3853 |
3788 } // namespace content | 3854 } // namespace content |
OLD | NEW |