| 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/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "content/browser/loader/intercepting_resource_handler.h" | 17 #include "content/browser/loader/intercepting_resource_handler.h" |
| 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 19 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 20 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 21 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| 22 #include "content/public/common/resource_response.h" | 22 #include "content/public/common/resource_response.h" |
| 23 #include "content/public/common/webplugininfo.h" | 23 #include "content/public/common/webplugininfo.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 26 #include "content/test/fake_plugin_service.h" | 26 #include "content/test/fake_plugin_service.h" |
| 27 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 #include "url/origin.h" |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 class TestResourceHandler : public ResourceHandler { | 36 class TestResourceHandler : public ResourceHandler { |
| 36 public: | 37 public: |
| 37 TestResourceHandler(bool response_started_succeeds, | 38 TestResourceHandler(bool response_started_succeeds, |
| 38 bool defer_on_response_started, | 39 bool defer_on_response_started, |
| 39 bool will_read_succeeds, | 40 bool will_read_succeeds, |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // If |is_plugin_stale| is true, GetPluginInfo will indicate the plugins are | 204 // If |is_plugin_stale| is true, GetPluginInfo will indicate the plugins are |
| 204 // stale until GetPlugins is called. | 205 // stale until GetPlugins is called. |
| 205 TestFakePluginService(bool plugin_available, bool is_plugin_stale) | 206 TestFakePluginService(bool plugin_available, bool is_plugin_stale) |
| 206 : plugin_available_(plugin_available), | 207 : plugin_available_(plugin_available), |
| 207 is_plugin_stale_(is_plugin_stale) {} | 208 is_plugin_stale_(is_plugin_stale) {} |
| 208 | 209 |
| 209 bool GetPluginInfo(int render_process_id, | 210 bool GetPluginInfo(int render_process_id, |
| 210 int render_frame_id, | 211 int render_frame_id, |
| 211 ResourceContext* context, | 212 ResourceContext* context, |
| 212 const GURL& url, | 213 const GURL& url, |
| 213 const GURL& page_url, | 214 const url::Origin& page_url, |
| 214 const std::string& mime_type, | 215 const std::string& mime_type, |
| 215 bool allow_wildcard, | 216 bool allow_wildcard, |
| 216 bool* is_stale, | 217 bool* is_stale, |
| 217 WebPluginInfo* info, | 218 WebPluginInfo* info, |
| 218 std::string* actual_mime_type) override { | 219 std::string* actual_mime_type) override { |
| 219 *is_stale = is_plugin_stale_; | 220 *is_stale = is_plugin_stale_; |
| 220 if (!is_plugin_stale_ || !plugin_available_) | 221 if (!is_plugin_stale_ || !plugin_available_) |
| 221 return false; | 222 return false; |
| 222 info->type = WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; | 223 info->type = WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; |
| 223 info->path = base::FilePath::FromUTF8Unsafe( | 224 info->path = base::FilePath::FromUTF8Unsafe( |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 // mime sniffing is disabled and the wrapped resource handler returns false | 1064 // mime sniffing is disabled and the wrapped resource handler returns false |
| 1064 // on OnResponseStarted. | 1065 // on OnResponseStarted. |
| 1065 EXPECT_FALSE( | 1066 EXPECT_FALSE( |
| 1066 mime_sniffing_handler->OnResponseStarted(response.get(), &defer)); | 1067 mime_sniffing_handler->OnResponseStarted(response.get(), &defer)); |
| 1067 | 1068 |
| 1068 // Process all messages to ensure proper test teardown. | 1069 // Process all messages to ensure proper test teardown. |
| 1069 content::RunAllPendingInMessageLoop(); | 1070 content::RunAllPendingInMessageLoop(); |
| 1070 } | 1071 } |
| 1071 | 1072 |
| 1072 } // namespace content | 1073 } // namespace content |
| OLD | NEW |