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/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 #include <vector> | 10 #include <vector> |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); | 214 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); |
215 }; | 215 }; |
216 | 216 |
217 class MojoAsyncResourceHandlerWithStubOperations | 217 class MojoAsyncResourceHandlerWithStubOperations |
218 : public MojoAsyncResourceHandler { | 218 : public MojoAsyncResourceHandler { |
219 public: | 219 public: |
220 MojoAsyncResourceHandlerWithStubOperations( | 220 MojoAsyncResourceHandlerWithStubOperations( |
221 net::URLRequest* request, | 221 net::URLRequest* request, |
222 ResourceDispatcherHostImpl* rdh, | 222 ResourceDispatcherHostImpl* rdh, |
223 mojom::URLLoaderAssociatedRequest mojo_request, | 223 mojom::URLLoaderAssociatedRequest mojo_request, |
224 mojom::URLLoaderClientAssociatedPtr url_loader_client) | 224 mojom::URLLoaderClientPtr url_loader_client) |
225 : MojoAsyncResourceHandler(request, | 225 : MojoAsyncResourceHandler(request, |
226 rdh, | 226 rdh, |
227 std::move(mojo_request), | 227 std::move(mojo_request), |
228 std::move(url_loader_client), | 228 std::move(url_loader_client), |
229 RESOURCE_TYPE_MAIN_FRAME), | 229 RESOURCE_TYPE_MAIN_FRAME), |
230 task_runner_(new base::TestSimpleTaskRunner) {} | 230 task_runner_(new base::TestSimpleTaskRunner) {} |
231 ~MojoAsyncResourceHandlerWithStubOperations() override {} | 231 ~MojoAsyncResourceHandlerWithStubOperations() override {} |
232 | 232 |
233 void ResetBeginWriteExpectation() { is_begin_write_expectation_set_ = false; } | 233 void ResetBeginWriteExpectation() { is_begin_write_expectation_set_ = false; } |
234 | 234 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 296 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
297 | 297 |
298 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerWithStubOperations); | 298 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerWithStubOperations); |
299 }; | 299 }; |
300 | 300 |
301 class TestURLLoaderFactory final : public mojom::URLLoaderFactory { | 301 class TestURLLoaderFactory final : public mojom::URLLoaderFactory { |
302 public: | 302 public: |
303 TestURLLoaderFactory() {} | 303 TestURLLoaderFactory() {} |
304 ~TestURLLoaderFactory() override {} | 304 ~TestURLLoaderFactory() override {} |
305 | 305 |
306 void CreateLoaderAndStart( | 306 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, |
307 mojom::URLLoaderAssociatedRequest request, | 307 int32_t routing_id, |
308 int32_t routing_id, | 308 int32_t request_id, |
309 int32_t request_id, | 309 const ResourceRequest& url_request, |
310 const ResourceRequest& url_request, | 310 mojom::URLLoaderClientPtr client_ptr) override { |
311 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) override { | |
312 loader_request_ = std::move(request); | 311 loader_request_ = std::move(request); |
313 client_ptr_info_ = std::move(client_ptr_info); | 312 client_ptr_ = std::move(client_ptr); |
314 } | 313 } |
315 | 314 |
316 mojom::URLLoaderAssociatedRequest PassLoaderRequest() { | 315 mojom::URLLoaderAssociatedRequest PassLoaderRequest() { |
317 return std::move(loader_request_); | 316 return std::move(loader_request_); |
318 } | 317 } |
319 | 318 |
320 mojom::URLLoaderClientAssociatedPtrInfo PassClientPtrInfo() { | 319 mojom::URLLoaderClientPtr PassClientPtr() { return std::move(client_ptr_); } |
321 return std::move(client_ptr_info_); | |
322 } | |
323 | 320 |
324 void SyncLoad(int32_t routing_id, | 321 void SyncLoad(int32_t routing_id, |
325 int32_t request_id, | 322 int32_t request_id, |
326 const ResourceRequest& url_request, | 323 const ResourceRequest& url_request, |
327 const SyncLoadCallback& callback) override { | 324 const SyncLoadCallback& callback) override { |
328 NOTREACHED(); | 325 NOTREACHED(); |
329 } | 326 } |
330 | 327 |
331 private: | 328 private: |
332 mojom::URLLoaderAssociatedRequest loader_request_; | 329 mojom::URLLoaderAssociatedRequest loader_request_; |
333 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info_; | 330 mojom::URLLoaderClientPtr client_ptr_; |
334 | 331 |
335 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory); | 332 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory); |
336 }; | 333 }; |
337 | 334 |
338 class MojoAsyncResourceHandlerTestBase { | 335 class MojoAsyncResourceHandlerTestBase { |
339 public: | 336 public: |
340 explicit MojoAsyncResourceHandlerTestBase( | 337 explicit MojoAsyncResourceHandlerTestBase( |
341 std::unique_ptr<net::UploadDataStream> upload_stream) | 338 std::unique_ptr<net::UploadDataStream> upload_stream) |
342 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 339 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
343 browser_context_(new TestBrowserContext()) { | 340 browser_context_(new TestBrowserContext()) { |
(...skipping 21 matching lines...) Expand all Loading... |
365 PREVIEWS_OFF // previews_state | 362 PREVIEWS_OFF // previews_state |
366 ); | 363 ); |
367 | 364 |
368 ResourceRequest request; | 365 ResourceRequest request; |
369 base::WeakPtr<mojo::StrongBinding<mojom::URLLoaderFactory>> weak_binding = | 366 base::WeakPtr<mojo::StrongBinding<mojom::URLLoaderFactory>> weak_binding = |
370 mojo::MakeStrongBinding(base::MakeUnique<TestURLLoaderFactory>(), | 367 mojo::MakeStrongBinding(base::MakeUnique<TestURLLoaderFactory>(), |
371 mojo::MakeRequest(&url_loader_factory_)); | 368 mojo::MakeRequest(&url_loader_factory_)); |
372 | 369 |
373 url_loader_factory_->CreateLoaderAndStart( | 370 url_loader_factory_->CreateLoaderAndStart( |
374 mojo::MakeRequest(&url_loader_proxy_), kRouteId, kRequestId, request, | 371 mojo::MakeRequest(&url_loader_proxy_), kRouteId, kRequestId, request, |
375 url_loader_client_.CreateRemoteAssociatedPtrInfo()); | 372 url_loader_client_.CreateInterfacePtr()); |
376 | 373 |
377 url_loader_factory_.FlushForTesting(); | 374 url_loader_factory_.FlushForTesting(); |
378 DCHECK(weak_binding); | 375 DCHECK(weak_binding); |
379 TestURLLoaderFactory* factory_impl = | 376 TestURLLoaderFactory* factory_impl = |
380 static_cast<TestURLLoaderFactory*>(weak_binding->impl()); | 377 static_cast<TestURLLoaderFactory*>(weak_binding->impl()); |
381 | 378 |
382 mojom::URLLoaderClientAssociatedPtr client_ptr; | |
383 client_ptr.Bind(factory_impl->PassClientPtrInfo()); | |
384 handler_.reset(new MojoAsyncResourceHandlerWithStubOperations( | 379 handler_.reset(new MojoAsyncResourceHandlerWithStubOperations( |
385 request_.get(), &rdh_, factory_impl->PassLoaderRequest(), | 380 request_.get(), &rdh_, factory_impl->PassLoaderRequest(), |
386 std::move(client_ptr))); | 381 factory_impl->PassClientPtr())); |
387 mock_loader_.reset(new MockResourceLoader(handler_.get())); | 382 mock_loader_.reset(new MockResourceLoader(handler_.get())); |
388 } | 383 } |
389 | 384 |
390 virtual ~MojoAsyncResourceHandlerTestBase() { | 385 virtual ~MojoAsyncResourceHandlerTestBase() { |
391 MojoAsyncResourceHandler::SetAllocationSizeForTesting( | 386 MojoAsyncResourceHandler::SetAllocationSizeForTesting( |
392 MojoAsyncResourceHandler::kDefaultAllocationSize); | 387 MojoAsyncResourceHandler::kDefaultAllocationSize); |
393 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
394 } | 389 } |
395 | 390 |
396 // Returns false if something bad happens. | 391 // Returns false if something bad happens. |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 } | 1275 } |
1281 } | 1276 } |
1282 EXPECT_EQ("B", body); | 1277 EXPECT_EQ("B", body); |
1283 } | 1278 } |
1284 | 1279 |
1285 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1280 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
1286 MojoAsyncResourceHandlerWithAllocationSizeTest, | 1281 MojoAsyncResourceHandlerWithAllocationSizeTest, |
1287 ::testing::Values(8, 32 * 2014)); | 1282 ::testing::Values(8, 32 * 2014)); |
1288 } // namespace | 1283 } // namespace |
1289 } // namespace content | 1284 } // namespace content |
OLD | NEW |