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

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: Fix test redness 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)))) {
94 // Some tests specify request.report_raw_headers, but the RDH checks the 95 // Some tests specify request.report_raw_headers, but the RDH checks the
(...skipping 18 matching lines...) Expand all
113 ~URLLoaderFactoryImplTest() override { 114 ~URLLoaderFactoryImplTest() override {
114 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(kChildId); 115 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(kChildId);
115 rdh_.SetDelegate(nullptr); 116 rdh_.SetDelegate(nullptr);
116 net::URLRequestFilter::GetInstance()->ClearHandlers(); 117 net::URLRequestFilter::GetInstance()->ClearHandlers();
117 118
118 resource_message_filter_->OnChannelClosing(); 119 resource_message_filter_->OnChannelClosing();
119 rdh_.CancelRequestsForProcess(resource_message_filter_->child_id()); 120 rdh_.CancelRequestsForProcess(resource_message_filter_->child_id());
120 base::RunLoop().RunUntilIdle(); 121 base::RunLoop().RunUntilIdle();
121 MojoAsyncResourceHandler::SetAllocationSizeForTesting( 122 MojoAsyncResourceHandler::SetAllocationSizeForTesting(
122 MojoAsyncResourceHandler::kDefaultAllocationSize); 123 MojoAsyncResourceHandler::kDefaultAllocationSize);
124 thread_bundle_.reset(nullptr);
123 } 125 }
124 126
125 void GetContexts(ResourceType resource_type, 127 void GetContexts(ResourceType resource_type,
126 ResourceContext** resource_context, 128 ResourceContext** resource_context,
127 net::URLRequestContext** request_context) { 129 net::URLRequestContext** request_context) {
128 *resource_context = browser_context_->GetResourceContext(); 130 *resource_context = browser_context_->GetResourceContext();
129 *request_context = 131 *request_context =
130 browser_context_->GetResourceContext()->GetRequestContext(); 132 browser_context_->GetResourceContext()->GetRequestContext();
131 } 133 }
132 134
133 TestBrowserThreadBundle thread_bundle_; 135 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_;
ananta 2017/03/29 19:41:04 This change was required to ensure that the thread
134 LoaderDelegateImpl loader_deleate_; 136 LoaderDelegateImpl loader_deleate_;
135 ResourceDispatcherHostImpl rdh_; 137 ResourceDispatcherHostImpl rdh_;
136 std::unique_ptr<TestBrowserContext> browser_context_; 138 std::unique_ptr<TestBrowserContext> browser_context_;
137 scoped_refptr<ResourceMessageFilter> resource_message_filter_; 139 scoped_refptr<ResourceMessageFilter> resource_message_filter_;
138 mojom::URLLoaderFactoryPtr factory_; 140 mojom::URLLoaderFactoryPtr factory_;
139 141
140 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest); 142 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest);
141 }; 143 };
142 144
143 TEST_P(URLLoaderFactoryImplTest, GetResponse) { 145 TEST_P(URLLoaderFactoryImplTest, GetResponse) {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 ASSERT_FALSE(rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId))); 551 ASSERT_FALSE(rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId)));
550 } 552 }
551 553
552 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest, 554 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest,
553 URLLoaderFactoryImplTest, 555 URLLoaderFactoryImplTest,
554 ::testing::Values(128, 32 * 1024)); 556 ::testing::Values(128, 32 * 1024));
555 557
556 } // namespace 558 } // namespace
557 559
558 } // namespace content 560 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/url_loader_factory_impl.cc ('k') | content/public/test/test_renderer_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698