| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mime_sniffing_resource_handler.h" | 5 #include "content/browser/loader/mime_sniffing_resource_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "content/browser/loader/intercepting_resource_handler.h" | 18 #include "content/browser/loader/intercepting_resource_handler.h" |
| 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 19 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 19 #include "content/public/browser/resource_controller.h" | 20 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 21 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 21 #include "content/public/browser/resource_request_info.h" | 22 #include "content/public/browser/resource_request_info.h" |
| 22 #include "content/public/common/resource_response.h" | 23 #include "content/public/common/resource_response.h" |
| 23 #include "content/public/common/webplugininfo.h" | 24 #include "content/public/common/webplugininfo.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 allow_download, // allow_download | 374 allow_download, // allow_download |
| 374 true, // is_async | 375 true, // is_async |
| 375 false); // is_using_lofi | 376 false); // is_using_lofi |
| 376 | 377 |
| 377 TestResourceDispatcherHost host(stream_has_handler_); | 378 TestResourceDispatcherHost host(stream_has_handler_); |
| 378 TestResourceDispatcherHostDelegate host_delegate(must_download); | 379 TestResourceDispatcherHostDelegate host_delegate(must_download); |
| 379 host.SetDelegate(&host_delegate); | 380 host.SetDelegate(&host_delegate); |
| 380 | 381 |
| 381 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); | 382 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); |
| 382 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( | 383 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( |
| 383 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), | 384 new InterceptingResourceHandler(base::MakeUnique<TestResourceHandler>( |
| 385 true, // response_started_succeeds |
| 386 false, // defer_response_started |
| 387 true, // will_read_succeeds, |
| 388 true, // read_completed_succeeds, |
| 389 false), // defer_read_completed |
| 384 nullptr)); | 390 nullptr)); |
| 385 std::unique_ptr<ResourceHandler> mime_handler(new MimeSniffingResourceHandler( | 391 std::unique_ptr<ResourceHandler> mime_handler(new MimeSniffingResourceHandler( |
| 386 std::unique_ptr<ResourceHandler>( | 392 std::unique_ptr<ResourceHandler>( |
| 387 new TestResourceHandler(false, false, false, false, false)), | 393 new TestResourceHandler(false, false, false, false, false)), |
| 388 &host, &plugin_service, intercepting_handler.get(), request.get(), | 394 &host, &plugin_service, intercepting_handler.get(), request.get(), |
| 389 REQUEST_CONTEXT_TYPE_UNSPECIFIED)); | 395 REQUEST_CONTEXT_TYPE_UNSPECIFIED)); |
| 390 | 396 |
| 391 TestResourceController resource_controller; | 397 TestResourceController resource_controller; |
| 392 mime_handler->SetController(&resource_controller); | 398 mime_handler->SetController(&resource_controller); |
| 393 | 399 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 false, // allow_download | 431 false, // allow_download |
| 426 true, // is_async | 432 true, // is_async |
| 427 false); // is_using_lofi | 433 false); // is_using_lofi |
| 428 | 434 |
| 429 TestResourceDispatcherHost host(false); | 435 TestResourceDispatcherHost host(false); |
| 430 TestResourceDispatcherHostDelegate host_delegate(false); | 436 TestResourceDispatcherHostDelegate host_delegate(false); |
| 431 host.SetDelegate(&host_delegate); | 437 host.SetDelegate(&host_delegate); |
| 432 | 438 |
| 433 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); | 439 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); |
| 434 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( | 440 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( |
| 435 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), | 441 new InterceptingResourceHandler(base::MakeUnique<TestResourceHandler>( |
| 442 true, // response_started_succeeds |
| 443 false, // defer_on_response_started |
| 444 true, // will_read_succeeds |
| 445 true, // read_completed_succeeds |
| 446 false), // defer_on_read_completed |
| 436 nullptr)); | 447 nullptr)); |
| 437 std::unique_ptr<TestResourceHandler> scoped_test_handler = | 448 std::unique_ptr<TestResourceHandler> scoped_test_handler = |
| 438 std::unique_ptr<TestResourceHandler>(new TestResourceHandler( | 449 std::unique_ptr<TestResourceHandler>(new TestResourceHandler( |
| 439 response_started, defer_response_started, will_read, read_completed, | 450 response_started, defer_response_started, will_read, read_completed, |
| 440 defer_read_completed)); | 451 defer_read_completed)); |
| 441 TestResourceHandler* test_handler = scoped_test_handler.get(); | 452 TestResourceHandler* test_handler = scoped_test_handler.get(); |
| 442 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler( | 453 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler( |
| 443 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, | 454 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, |
| 444 &plugin_service, | 455 &plugin_service, |
| 445 intercepting_handler.get(), request.get(), | 456 intercepting_handler.get(), request.get(), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 false, // allow_download | 597 false, // allow_download |
| 587 true, // is_async | 598 true, // is_async |
| 588 false); // is_using_lofi | 599 false); // is_using_lofi |
| 589 | 600 |
| 590 TestResourceDispatcherHost host(false); | 601 TestResourceDispatcherHost host(false); |
| 591 TestResourceDispatcherHostDelegate host_delegate(false); | 602 TestResourceDispatcherHostDelegate host_delegate(false); |
| 592 host.SetDelegate(&host_delegate); | 603 host.SetDelegate(&host_delegate); |
| 593 | 604 |
| 594 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); | 605 TestFakePluginService plugin_service(plugin_available_, plugin_stale_); |
| 595 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( | 606 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( |
| 596 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), | 607 new InterceptingResourceHandler(base::MakeUnique<TestResourceHandler>( |
| 608 true, // response_started_succeeds |
| 609 false, // defer_response_started |
| 610 true, // will_read_succeeds, |
| 611 true, // read_completed_succeeds, |
| 612 false), // defer_read_completed |
| 597 nullptr)); | 613 nullptr)); |
| 598 | 614 |
| 599 std::unique_ptr<TestResourceHandler> scoped_test_handler = | 615 std::unique_ptr<TestResourceHandler> scoped_test_handler = |
| 600 std::unique_ptr<TestResourceHandler>(new TestResourceHandler( | 616 std::unique_ptr<TestResourceHandler>(new TestResourceHandler( |
| 601 response_started, defer_response_started, will_read, read_completed, | 617 response_started, defer_response_started, will_read, read_completed, |
| 602 defer_read_completed)); | 618 defer_read_completed)); |
| 603 TestResourceHandler* test_handler = scoped_test_handler.get(); | 619 TestResourceHandler* test_handler = scoped_test_handler.get(); |
| 604 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler( | 620 std::unique_ptr<MimeSniffingResourceHandler> mime_sniffing_handler( |
| 605 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, | 621 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, |
| 606 &plugin_service, | 622 &plugin_service, |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 true, // allow_download | 996 true, // allow_download |
| 981 true, // is_async | 997 true, // is_async |
| 982 false); // is_using_lofi | 998 false); // is_using_lofi |
| 983 | 999 |
| 984 TestResourceDispatcherHost host(false); | 1000 TestResourceDispatcherHost host(false); |
| 985 TestResourceDispatcherHostDelegate host_delegate(false); | 1001 TestResourceDispatcherHostDelegate host_delegate(false); |
| 986 host.SetDelegate(&host_delegate); | 1002 host.SetDelegate(&host_delegate); |
| 987 | 1003 |
| 988 TestFakePluginService plugin_service(false, false); | 1004 TestFakePluginService plugin_service(false, false); |
| 989 std::unique_ptr<ResourceHandler> intercepting_handler( | 1005 std::unique_ptr<ResourceHandler> intercepting_handler( |
| 990 new InterceptingResourceHandler(std::unique_ptr<ResourceHandler>(), | 1006 new InterceptingResourceHandler(base::MakeUnique<TestResourceHandler>( |
| 1007 true, // response_started_succeeds |
| 1008 false, // defer_response_started |
| 1009 true, // will_read_succeeds, |
| 1010 true, // read_completed_succeeds, |
| 1011 false), // defer_read_completed |
| 991 nullptr)); | 1012 nullptr)); |
| 992 std::unique_ptr<ResourceHandler> mime_handler(new MimeSniffingResourceHandler( | 1013 std::unique_ptr<ResourceHandler> mime_handler(new MimeSniffingResourceHandler( |
| 993 std::unique_ptr<ResourceHandler>( | 1014 std::unique_ptr<ResourceHandler>( |
| 994 new TestResourceHandler(true, false, true, true, false)), | 1015 new TestResourceHandler(true, false, true, true, false)), |
| 995 &host, &plugin_service, | 1016 &host, &plugin_service, |
| 996 static_cast<InterceptingResourceHandler*>(intercepting_handler.get()), | 1017 static_cast<InterceptingResourceHandler*>(intercepting_handler.get()), |
| 997 request.get(), REQUEST_CONTEXT_TYPE_UNSPECIFIED)); | 1018 request.get(), REQUEST_CONTEXT_TYPE_UNSPECIFIED)); |
| 998 | 1019 |
| 999 TestResourceController resource_controller; | 1020 TestResourceController resource_controller; |
| 1000 mime_handler->SetController(&resource_controller); | 1021 mime_handler->SetController(&resource_controller); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1028 true, // is_main_frame | 1049 true, // is_main_frame |
| 1029 false, // parent_is_main_frame | 1050 false, // parent_is_main_frame |
| 1030 false, // allow_download | 1051 false, // allow_download |
| 1031 true, // is_async | 1052 true, // is_async |
| 1032 false); // is_using_lofi | 1053 false); // is_using_lofi |
| 1033 | 1054 |
| 1034 TestResourceDispatcherHost host(false); | 1055 TestResourceDispatcherHost host(false); |
| 1035 | 1056 |
| 1036 TestFakePluginService plugin_service(false, false); | 1057 TestFakePluginService plugin_service(false, false); |
| 1037 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( | 1058 std::unique_ptr<InterceptingResourceHandler> intercepting_handler( |
| 1038 new InterceptingResourceHandler(nullptr, nullptr)); | 1059 new InterceptingResourceHandler(base::MakeUnique<TestResourceHandler>( |
| 1060 true, // response_started_succeeds |
| 1061 false, // defer_response_started |
| 1062 true, // will_read_succeeds, |
| 1063 true, // read_completed_succeeds, |
| 1064 false), // defer_read_completed |
| 1065 nullptr)); |
| 1039 | 1066 |
| 1040 std::unique_ptr<TestResourceHandler> scoped_test_handler( | 1067 std::unique_ptr<TestResourceHandler> scoped_test_handler( |
| 1041 new TestResourceHandler(false, // response_started | 1068 new TestResourceHandler(false, // response_started |
| 1042 false, // defer_response_started | 1069 false, // defer_response_started |
| 1043 true, // will_read, | 1070 true, // will_read, |
| 1044 true, // read_completed, | 1071 true, // read_completed, |
| 1045 false)); // defer_read_completed | 1072 false)); // defer_read_completed |
| 1046 std::unique_ptr<ResourceHandler> mime_sniffing_handler( | 1073 std::unique_ptr<ResourceHandler> mime_sniffing_handler( |
| 1047 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, | 1074 new MimeSniffingResourceHandler(std::move(scoped_test_handler), &host, |
| 1048 &plugin_service, | 1075 &plugin_service, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1063 // mime sniffing is disabled and the wrapped resource handler returns false | 1090 // mime sniffing is disabled and the wrapped resource handler returns false |
| 1064 // on OnResponseStarted. | 1091 // on OnResponseStarted. |
| 1065 EXPECT_FALSE( | 1092 EXPECT_FALSE( |
| 1066 mime_sniffing_handler->OnResponseStarted(response.get(), &defer)); | 1093 mime_sniffing_handler->OnResponseStarted(response.get(), &defer)); |
| 1067 | 1094 |
| 1068 // Process all messages to ensure proper test teardown. | 1095 // Process all messages to ensure proper test teardown. |
| 1069 content::RunAllPendingInMessageLoop(); | 1096 content::RunAllPendingInMessageLoop(); |
| 1070 } | 1097 } |
| 1071 | 1098 |
| 1072 } // namespace content | 1099 } // namespace content |
| OLD | NEW |