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