| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/loader/url_loader_factory_impl.h" | 5 #include "content/browser/loader/url_loader_factory_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(RejectingResourceDispatcherHostDelegate); | 75 DISALLOW_COPY_AND_ASSIGN(RejectingResourceDispatcherHostDelegate); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // The test parameter is the number of bytes allocated for the buffer in the | 78 // The test parameter is the number of bytes allocated for the buffer in the |
| 79 // data pipe, for testing the case where the allocated size is smaller than the | 79 // data pipe, for testing the case where the allocated size is smaller than the |
| 80 // size the mime sniffer *implicitly* requires. | 80 // size the mime sniffer *implicitly* requires. |
| 81 class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> { | 81 class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> { |
| 82 public: | 82 public: |
| 83 URLLoaderFactoryImplTest() | 83 URLLoaderFactoryImplTest() |
| 84 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 84 : thread_bundle_( |
| 85 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
| 85 browser_context_(new TestBrowserContext()), | 86 browser_context_(new TestBrowserContext()), |
| 86 resource_message_filter_(new ResourceMessageFilter( | 87 resource_message_filter_(new ResourceMessageFilter( |
| 87 kChildId, | 88 kChildId, |
| 88 nullptr, | 89 nullptr, |
| 89 nullptr, | 90 nullptr, |
| 90 nullptr, | 91 nullptr, |
| 91 nullptr, | 92 nullptr, |
| 92 base::Bind(&URLLoaderFactoryImplTest::GetContexts, | 93 base::Bind(&URLLoaderFactoryImplTest::GetContexts, |
| 93 base::Unretained(this)))) { | 94 base::Unretained(this)), |
| 95 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))) { |
| 94 // Some tests specify request.report_raw_headers, but the RDH checks the | 96 // Some tests specify request.report_raw_headers, but the RDH checks the |
| 95 // CanReadRawCookies permission before enabling it. | 97 // CanReadRawCookies permission before enabling it. |
| 96 ChildProcessSecurityPolicyImpl::GetInstance()->Add(kChildId); | 98 ChildProcessSecurityPolicyImpl::GetInstance()->Add(kChildId); |
| 97 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | 99 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( |
| 98 kChildId); | 100 kChildId); |
| 99 | 101 |
| 100 resource_message_filter_->InitializeForTest(); | 102 resource_message_filter_->InitializeForTest(); |
| 101 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam()); | 103 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam()); |
| 102 rdh_.SetLoaderDelegate(&loader_deleate_); | 104 rdh_.SetLoaderDelegate(&loader_deleate_); |
| 103 | 105 |
| 104 URLLoaderFactoryImpl::Create( | 106 URLLoaderFactoryImpl::Create( |
| 105 resource_message_filter_->requester_info_for_test(), | 107 resource_message_filter_->requester_info_for_test(), |
| 106 mojo::MakeRequest(&factory_)); | 108 mojo::MakeRequest(&factory_), |
| 109 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 107 | 110 |
| 108 // Calling this function creates a request context. | 111 // Calling this function creates a request context. |
| 109 browser_context_->GetResourceContext()->GetRequestContext(); | 112 browser_context_->GetResourceContext()->GetRequestContext(); |
| 110 base::RunLoop().RunUntilIdle(); | 113 base::RunLoop().RunUntilIdle(); |
| 111 } | 114 } |
| 112 | 115 |
| 113 ~URLLoaderFactoryImplTest() override { | 116 ~URLLoaderFactoryImplTest() override { |
| 114 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(kChildId); | 117 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(kChildId); |
| 115 rdh_.SetDelegate(nullptr); | 118 rdh_.SetDelegate(nullptr); |
| 116 net::URLRequestFilter::GetInstance()->ClearHandlers(); | 119 net::URLRequestFilter::GetInstance()->ClearHandlers(); |
| 117 | 120 |
| 118 resource_message_filter_->OnChannelClosing(); | 121 resource_message_filter_->OnChannelClosing(); |
| 119 rdh_.CancelRequestsForProcess(resource_message_filter_->child_id()); | 122 rdh_.CancelRequestsForProcess(resource_message_filter_->child_id()); |
| 120 base::RunLoop().RunUntilIdle(); | 123 base::RunLoop().RunUntilIdle(); |
| 121 MojoAsyncResourceHandler::SetAllocationSizeForTesting( | 124 MojoAsyncResourceHandler::SetAllocationSizeForTesting( |
| 122 MojoAsyncResourceHandler::kDefaultAllocationSize); | 125 MojoAsyncResourceHandler::kDefaultAllocationSize); |
| 126 thread_bundle_.reset(nullptr); |
| 123 } | 127 } |
| 124 | 128 |
| 125 void GetContexts(ResourceType resource_type, | 129 void GetContexts(ResourceType resource_type, |
| 126 ResourceContext** resource_context, | 130 ResourceContext** resource_context, |
| 127 net::URLRequestContext** request_context) { | 131 net::URLRequestContext** request_context) { |
| 128 *resource_context = browser_context_->GetResourceContext(); | 132 *resource_context = browser_context_->GetResourceContext(); |
| 129 *request_context = | 133 *request_context = |
| 130 browser_context_->GetResourceContext()->GetRequestContext(); | 134 browser_context_->GetResourceContext()->GetRequestContext(); |
| 131 } | 135 } |
| 132 | 136 |
| 133 TestBrowserThreadBundle thread_bundle_; | 137 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
| 134 LoaderDelegateImpl loader_deleate_; | 138 LoaderDelegateImpl loader_deleate_; |
| 135 ResourceDispatcherHostImpl rdh_; | 139 ResourceDispatcherHostImpl rdh_; |
| 136 std::unique_ptr<TestBrowserContext> browser_context_; | 140 std::unique_ptr<TestBrowserContext> browser_context_; |
| 137 scoped_refptr<ResourceMessageFilter> resource_message_filter_; | 141 scoped_refptr<ResourceMessageFilter> resource_message_filter_; |
| 138 mojom::URLLoaderFactoryPtr factory_; | 142 mojom::URLLoaderFactoryPtr factory_; |
| 139 | 143 |
| 140 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest); | 144 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest); |
| 141 }; | 145 }; |
| 142 | 146 |
| 143 TEST_P(URLLoaderFactoryImplTest, GetResponse) { | 147 TEST_P(URLLoaderFactoryImplTest, GetResponse) { |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 ASSERT_FALSE(rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId))); | 553 ASSERT_FALSE(rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId))); |
| 550 } | 554 } |
| 551 | 555 |
| 552 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest, | 556 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest, |
| 553 URLLoaderFactoryImplTest, | 557 URLLoaderFactoryImplTest, |
| 554 ::testing::Values(128, 32 * 1024)); | 558 ::testing::Values(128, 32 * 1024)); |
| 555 | 559 |
| 556 } // namespace | 560 } // namespace |
| 557 | 561 |
| 558 } // namespace content | 562 } // namespace content |
| OLD | NEW |