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

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

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

Powered by Google App Engine
This is Rietveld 408576698