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

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

Issue 2489793002: Use a proper URLLoaderAssociatedRequest in MojoAsyncResourceHandler tests (Closed)
Patch Set: fix Created 4 years, 1 month 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
« no previous file with comments | « no previous file | content/browser/loader/test_url_loader_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/mojo_async_resource_handler.h" 5 #include "content/browser/loader/mojo_async_resource_handler.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/resource_controller.h" 26 #include "content/public/browser/resource_controller.h"
27 #include "content/public/browser/resource_dispatcher_host_delegate.h" 27 #include "content/public/browser/resource_dispatcher_host_delegate.h"
28 #include "content/public/browser/resource_throttle.h" 28 #include "content/public/browser/resource_throttle.h"
29 #include "content/public/browser/stream_info.h" 29 #include "content/public/browser/stream_info.h"
30 #include "content/public/common/resource_response.h" 30 #include "content/public/common/resource_response.h"
31 #include "content/public/common/resource_type.h" 31 #include "content/public/common/resource_type.h"
32 #include "content/public/test/test_browser_context.h" 32 #include "content/public/test/test_browser_context.h"
33 #include "content/public/test/test_browser_thread_bundle.h" 33 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "mojo/public/c/system/data_pipe.h" 34 #include "mojo/public/c/system/data_pipe.h"
35 #include "mojo/public/c/system/types.h" 35 #include "mojo/public/c/system/types.h"
36 #include "mojo/public/cpp/bindings/strong_binding.h"
36 #include "mojo/public/cpp/system/data_pipe.h" 37 #include "mojo/public/cpp/system/data_pipe.h"
37 #include "net/base/auth.h" 38 #include "net/base/auth.h"
38 #include "net/base/net_errors.h" 39 #include "net/base/net_errors.h"
39 #include "net/http/http_response_headers.h" 40 #include "net/http/http_response_headers.h"
40 #include "net/http/http_response_info.h" 41 #include "net/http/http_response_info.h"
41 #include "net/http/http_status_code.h" 42 #include "net/http/http_status_code.h"
42 #include "net/http/http_util.h" 43 #include "net/http/http_util.h"
43 #include "net/ssl/client_cert_store.h" 44 #include "net/ssl/client_cert_store.h"
44 #include "net/test/url_request/url_request_failed_job.h" 45 #include "net/test/url_request/url_request_failed_job.h"
45 #include "net/url_request/url_request.h" 46 #include "net/url_request/url_request.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 261
261 bool is_begin_write_expectation_set_ = false; 262 bool is_begin_write_expectation_set_ = false;
262 bool is_end_write_expectation_set_ = false; 263 bool is_end_write_expectation_set_ = false;
263 MojoResult begin_write_expectation_ = MOJO_RESULT_UNKNOWN; 264 MojoResult begin_write_expectation_ = MOJO_RESULT_UNKNOWN;
264 MojoResult end_write_expectation_ = MOJO_RESULT_UNKNOWN; 265 MojoResult end_write_expectation_ = MOJO_RESULT_UNKNOWN;
265 266
266 DISALLOW_COPY_AND_ASSIGN( 267 DISALLOW_COPY_AND_ASSIGN(
267 MojoAsyncResourceHandlerWithCustomDataPipeOperations); 268 MojoAsyncResourceHandlerWithCustomDataPipeOperations);
268 }; 269 };
269 270
271 class TestURLLoaderFactory final : public mojom::URLLoaderFactory {
272 public:
273 explicit TestURLLoaderFactory(base::WeakPtr<TestURLLoaderFactory>* weak_ptr)
274 : weak_factory_(this) {
275 *weak_ptr = weak_factory_.GetWeakPtr();
276 }
277 ~TestURLLoaderFactory() override {}
278
279 void CreateLoaderAndStart(
280 mojom::URLLoaderAssociatedRequest request,
281 int32_t routing_id,
282 int32_t request_id,
283 const ResourceRequest& url_request,
284 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) override {
285 loader_request_ = std::move(request);
286 client_ptr_info_ = std::move(client_ptr_info);
287 }
288
289 mojom::URLLoaderAssociatedRequest LoaderRequest() {
yzshen1 2016/11/10 17:28:36 style nit: Please consider either naming it PassLo
yhirano 2016/11/11 03:13:37 Done.
290 return std::move(loader_request_);
291 }
292
293 mojom::URLLoaderClientAssociatedPtrInfo ClientPtrInfo() {
294 return std::move(client_ptr_info_);
295 }
296
297 void SyncLoad(int32_t routing_id,
298 int32_t request_id,
299 const ResourceRequest& url_request,
300 const SyncLoadCallback& callback) override {
301 NOTREACHED();
302 }
303
304 private:
305 mojom::URLLoaderAssociatedRequest loader_request_;
306 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info_;
307
308 base::WeakPtrFactory<TestURLLoaderFactory> weak_factory_;
yzshen1 2016/11/10 17:28:36 I think this is not needed. mojo::MakeStrongBindin
yhirano 2016/11/11 03:13:37 Done.
309
310 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory);
311 };
312
270 class MojoAsyncResourceHandlerTestBase { 313 class MojoAsyncResourceHandlerTestBase {
271 public: 314 public:
272 MojoAsyncResourceHandlerTestBase() 315 MojoAsyncResourceHandlerTestBase()
273 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 316 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
274 browser_context_(new TestBrowserContext()) { 317 browser_context_(new TestBrowserContext()) {
275 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024); 318 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024);
276 rdh_.SetDelegate(&rdh_delegate_); 319 rdh_.SetDelegate(&rdh_delegate_);
277 320
278 url_request_delegate_.reset(new net::TestDelegate()); 321 url_request_delegate_.reset(new net::TestDelegate());
279 net::URLRequestContext* request_context = 322 net::URLRequestContext* request_context =
280 browser_context_->GetResourceContext()->GetRequestContext(); 323 browser_context_->GetResourceContext()->GetRequestContext();
281 request_ = request_context->CreateRequest( 324 request_ = request_context->CreateRequest(
282 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_TIMED_OUT), 325 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_TIMED_OUT),
283 net::DEFAULT_PRIORITY, url_request_delegate_.get()); 326 net::DEFAULT_PRIORITY, url_request_delegate_.get());
284 ResourceRequestInfo::AllocateForTesting( 327 ResourceRequestInfo::AllocateForTesting(
285 request_.get(), // request 328 request_.get(), // request
286 RESOURCE_TYPE_XHR, // resource_type 329 RESOURCE_TYPE_XHR, // resource_type
287 browser_context_->GetResourceContext(), // context 330 browser_context_->GetResourceContext(), // context
288 2, // render_process_id 331 2, // render_process_id
289 0, // render_view_id 332 0, // render_view_id
290 0, // render_frame_id 333 0, // render_frame_id
291 true, // is_main_frame 334 true, // is_main_frame
292 false, // parent_is_main_frame 335 false, // parent_is_main_frame
293 false, // allow_download 336 false, // allow_download
294 true, // is_async 337 true, // is_async
295 false // is_using_lofi 338 false // is_using_lofi
296 ); 339 );
297 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info = 340
298 url_loader_client_.CreateLocalAssociatedPtrInfo(); 341 ResourceRequest request;
342 base::WeakPtr<TestURLLoaderFactory> weak_url_loader_factory_impl;
343 mojo::MakeStrongBinding(
344 base::MakeUnique<TestURLLoaderFactory>(&weak_url_loader_factory_impl),
345 mojo::GetProxy(&url_loader_factory_));
346
347 url_loader_factory_->CreateLoaderAndStart(
348 mojo::GetProxy(&url_loader_proxy_,
349 url_loader_factory_.associated_group()),
350 0, 0, request, url_loader_client_.CreateRemoteAssociatedPtrInfo(
351 url_loader_factory_.associated_group()));
352
353 url_loader_factory_.FlushForTesting();
354 DCHECK(weak_url_loader_factory_impl);
355
299 mojom::URLLoaderClientAssociatedPtr client_ptr; 356 mojom::URLLoaderClientAssociatedPtr client_ptr;
300 client_ptr.Bind(std::move(client_ptr_info)); 357 client_ptr.Bind(weak_url_loader_factory_impl->ClientPtrInfo());
301 handler_.reset(new MojoAsyncResourceHandlerWithCustomDataPipeOperations( 358 handler_.reset(new MojoAsyncResourceHandlerWithCustomDataPipeOperations(
302 request_.get(), &rdh_, nullptr, std::move(client_ptr))); 359 request_.get(), &rdh_, weak_url_loader_factory_impl->LoaderRequest(),
360 std::move(client_ptr)));
303 handler_->SetController(&resource_controller_); 361 handler_->SetController(&resource_controller_);
304 } 362 }
305 363
306 virtual ~MojoAsyncResourceHandlerTestBase() { 364 virtual ~MojoAsyncResourceHandlerTestBase() {
307 net::URLRequestFilter::GetInstance()->ClearHandlers(); 365 net::URLRequestFilter::GetInstance()->ClearHandlers();
308 MojoAsyncResourceHandler::SetAllocationSizeForTesting( 366 MojoAsyncResourceHandler::SetAllocationSizeForTesting(
309 MojoAsyncResourceHandler::kDefaultAllocationSize); 367 MojoAsyncResourceHandler::kDefaultAllocationSize);
310 base::RunLoop().RunUntilIdle(); 368 base::RunLoop().RunUntilIdle();
311 } 369 }
312 370
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 ADD_FAILURE() << "URLLoaderClient unexpectedly gets a response."; 402 ADD_FAILURE() << "URLLoaderClient unexpectedly gets a response.";
345 return false; 403 return false;
346 } 404 }
347 url_loader_client_.RunUntilResponseReceived(); 405 url_loader_client_.RunUntilResponseReceived();
348 return true; 406 return true;
349 } 407 }
350 408
351 TestBrowserThreadBundle thread_bundle_; 409 TestBrowserThreadBundle thread_bundle_;
352 TestResourceDispatcherHostDelegate rdh_delegate_; 410 TestResourceDispatcherHostDelegate rdh_delegate_;
353 ResourceDispatcherHostImpl rdh_; 411 ResourceDispatcherHostImpl rdh_;
412 mojom::URLLoaderFactoryPtr url_loader_factory_;
413 mojom::URLLoaderAssociatedPtr url_loader_proxy_;
354 TestURLLoaderClient url_loader_client_; 414 TestURLLoaderClient url_loader_client_;
355 TestResourceController resource_controller_; 415 TestResourceController resource_controller_;
356 std::unique_ptr<TestBrowserContext> browser_context_; 416 std::unique_ptr<TestBrowserContext> browser_context_;
357 std::unique_ptr<net::TestDelegate> url_request_delegate_; 417 std::unique_ptr<net::TestDelegate> url_request_delegate_;
358 std::unique_ptr<net::URLRequest> request_; 418 std::unique_ptr<net::URLRequest> request_;
359 std::unique_ptr<MojoAsyncResourceHandlerWithCustomDataPipeOperations> 419 std::unique_ptr<MojoAsyncResourceHandlerWithCustomDataPipeOperations>
360 handler_; 420 handler_;
361 421
362 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase); 422 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase);
363 }; 423 };
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 } 1199 }
1140 } 1200 }
1141 EXPECT_EQ("B", body); 1201 EXPECT_EQ("B", body);
1142 } 1202 }
1143 1203
1144 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 1204 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
1145 MojoAsyncResourceHandlerWithAllocationSizeTest, 1205 MojoAsyncResourceHandlerWithAllocationSizeTest,
1146 ::testing::Values(8, 32 * 2014)); 1206 ::testing::Values(8, 32 * 2014));
1147 } // namespace 1207 } // namespace
1148 } // namespace content 1208 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/test_url_loader_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698