Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(862)

Side by Side Diff: content/browser/loader/url_loader_factory_impl_unittest.cc

Issue 2785523002: Reduce/remove usage of BrowserThread in content/browser/loader. (Closed)
Patch Set: Remove stray include Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::UI),
96 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))) {
94 // Some tests specify request.report_raw_headers, but the RDH checks the 97 // Some tests specify request.report_raw_headers, but the RDH checks the
95 // CanReadRawCookies permission before enabling it. 98 // CanReadRawCookies permission before enabling it.
96 ChildProcessSecurityPolicyImpl::GetInstance()->Add(kChildId); 99 ChildProcessSecurityPolicyImpl::GetInstance()->Add(kChildId);
97 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( 100 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies(
98 kChildId); 101 kChildId);
99 102
100 resource_message_filter_->InitializeForTest(); 103 resource_message_filter_->InitializeForTest();
101 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam()); 104 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam());
102 rdh_.SetLoaderDelegate(&loader_deleate_); 105 rdh_.SetLoaderDelegate(&loader_deleate_);
103 106
104 URLLoaderFactoryImpl::Create( 107 URLLoaderFactoryImpl::Create(
105 resource_message_filter_->requester_info_for_test(), 108 resource_message_filter_->requester_info_for_test(),
106 mojo::MakeRequest(&factory_)); 109 mojo::MakeRequest(&factory_),
110 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
107 111
108 // Calling this function creates a request context. 112 // Calling this function creates a request context.
109 browser_context_->GetResourceContext()->GetRequestContext(); 113 browser_context_->GetResourceContext()->GetRequestContext();
110 base::RunLoop().RunUntilIdle(); 114 base::RunLoop().RunUntilIdle();
111 } 115 }
112 116
113 ~URLLoaderFactoryImplTest() override { 117 ~URLLoaderFactoryImplTest() override {
114 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(kChildId); 118 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(kChildId);
115 rdh_.SetDelegate(nullptr); 119 rdh_.SetDelegate(nullptr);
116 net::URLRequestFilter::GetInstance()->ClearHandlers(); 120 net::URLRequestFilter::GetInstance()->ClearHandlers();
117 121
118 resource_message_filter_->OnChannelClosing(); 122 resource_message_filter_->OnChannelClosing();
119 rdh_.CancelRequestsForProcess(resource_message_filter_->child_id()); 123 rdh_.CancelRequestsForProcess(resource_message_filter_->child_id());
120 base::RunLoop().RunUntilIdle(); 124 base::RunLoop().RunUntilIdle();
121 MojoAsyncResourceHandler::SetAllocationSizeForTesting( 125 MojoAsyncResourceHandler::SetAllocationSizeForTesting(
122 MojoAsyncResourceHandler::kDefaultAllocationSize); 126 MojoAsyncResourceHandler::kDefaultAllocationSize);
127 thread_bundle_.reset(nullptr);
123 } 128 }
124 129
125 void GetContexts(ResourceType resource_type, 130 void GetContexts(ResourceType resource_type,
126 ResourceContext** resource_context, 131 ResourceContext** resource_context,
127 net::URLRequestContext** request_context) { 132 net::URLRequestContext** request_context) {
128 *resource_context = browser_context_->GetResourceContext(); 133 *resource_context = browser_context_->GetResourceContext();
129 *request_context = 134 *request_context =
130 browser_context_->GetResourceContext()->GetRequestContext(); 135 browser_context_->GetResourceContext()->GetRequestContext();
131 } 136 }
132 137
133 TestBrowserThreadBundle thread_bundle_; 138 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_;
134 LoaderDelegateImpl loader_deleate_; 139 LoaderDelegateImpl loader_deleate_;
135 ResourceDispatcherHostImpl rdh_; 140 ResourceDispatcherHostImpl rdh_;
136 std::unique_ptr<TestBrowserContext> browser_context_; 141 std::unique_ptr<TestBrowserContext> browser_context_;
137 scoped_refptr<ResourceMessageFilter> resource_message_filter_; 142 scoped_refptr<ResourceMessageFilter> resource_message_filter_;
138 mojom::URLLoaderFactoryPtr factory_; 143 mojom::URLLoaderFactoryPtr factory_;
139 144
140 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest); 145 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest);
141 }; 146 };
142 147
143 TEST_P(URLLoaderFactoryImplTest, GetResponse) { 148 TEST_P(URLLoaderFactoryImplTest, GetResponse) {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 ASSERT_FALSE(rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId))); 554 ASSERT_FALSE(rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId)));
550 } 555 }
551 556
552 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest, 557 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest,
553 URLLoaderFactoryImplTest, 558 URLLoaderFactoryImplTest,
554 ::testing::Values(128, 32 * 1024)); 559 ::testing::Values(128, 32 * 1024));
555 560
556 } // namespace 561 } // namespace
557 562
558 } // namespace content 563 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698