| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/renderer_host/plugin_info_message_filter.h" | 5 #include "chrome/browser/renderer_host/plugin_info_message_filter.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 14 #include "content/public/browser/plugin_service.h" | 14 #include "content/public/browser/plugin_service.h" |
| 15 #include "content/public/browser/plugin_service_filter.h" | 15 #include "content/public/browser/plugin_service_filter.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "webkit/plugins/npapi/mock_plugin_list.h" | 19 #include "webkit/plugins/npapi/mock_plugin_list.h" |
| 20 | 20 |
| 21 using content::PluginService; | 21 using content::PluginService; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class FakePluginServiceFilter : public content::PluginServiceFilter { | 25 class FakePluginServiceFilter : public content::PluginServiceFilter { |
| 26 public: | 26 public: |
| 27 FakePluginServiceFilter() {} | 27 FakePluginServiceFilter() {} |
| 28 virtual ~FakePluginServiceFilter() {} | 28 virtual ~FakePluginServiceFilter() {} |
| 29 | 29 |
| 30 virtual bool ShouldUsePlugin(int render_process_id, | 30 virtual bool IsPluginEnabled(int render_process_id, |
| 31 int render_view_id, | 31 int render_view_id, |
| 32 const void* context, | 32 const void* context, |
| 33 const GURL& url, | 33 const GURL& url, |
| 34 const GURL& policy_url, | 34 const GURL& policy_url, |
| 35 webkit::WebPluginInfo* plugin) OVERRIDE; | 35 webkit::WebPluginInfo* plugin) OVERRIDE; |
| 36 | 36 |
| 37 virtual bool CanLoadPlugin(int render_process_id, |
| 38 const FilePath& path) OVERRIDE; |
| 39 |
| 37 void set_plugin_enabled(const FilePath& plugin_path, bool enabled) { | 40 void set_plugin_enabled(const FilePath& plugin_path, bool enabled) { |
| 38 plugin_state_[plugin_path] = enabled; | 41 plugin_state_[plugin_path] = enabled; |
| 39 } | 42 } |
| 40 | 43 |
| 41 private: | 44 private: |
| 42 std::map<FilePath, bool> plugin_state_; | 45 std::map<FilePath, bool> plugin_state_; |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 bool FakePluginServiceFilter::ShouldUsePlugin(int render_process_id, | 48 bool FakePluginServiceFilter::IsPluginEnabled(int render_process_id, |
| 46 int render_view_id, | 49 int render_view_id, |
| 47 const void* context, | 50 const void* context, |
| 48 const GURL& url, | 51 const GURL& url, |
| 49 const GURL& policy_url, | 52 const GURL& policy_url, |
| 50 webkit::WebPluginInfo* plugin) { | 53 webkit::WebPluginInfo* plugin) { |
| 51 std::map<FilePath, bool>::iterator it = plugin_state_.find(plugin->path); | 54 std::map<FilePath, bool>::iterator it = plugin_state_.find(plugin->path); |
| 52 if (it == plugin_state_.end()) { | 55 if (it == plugin_state_.end()) { |
| 53 ADD_FAILURE() << "No plug-in state for '" << plugin->path.value() << "'"; | 56 ADD_FAILURE() << "No plug-in state for '" << plugin->path.value() << "'"; |
| 54 return false; | 57 return false; |
| 55 } | 58 } |
| 56 return it->second; | 59 return it->second; |
| 57 } | 60 } |
| 58 | 61 |
| 62 bool FakePluginServiceFilter::CanLoadPlugin(int render_process_id, |
| 63 const FilePath& path) { |
| 64 return true; |
| 65 } |
| 66 |
| 59 } // namespace | 67 } // namespace |
| 60 | 68 |
| 61 class PluginInfoMessageFilterTest : public ::testing::Test { | 69 class PluginInfoMessageFilterTest : public ::testing::Test { |
| 62 public: | 70 public: |
| 63 PluginInfoMessageFilterTest() : | 71 PluginInfoMessageFilterTest() : |
| 64 foo_plugin_path_(FILE_PATH_LITERAL("/path/to/foo")), | 72 foo_plugin_path_(FILE_PATH_LITERAL("/path/to/foo")), |
| 65 bar_plugin_path_(FILE_PATH_LITERAL("/path/to/bar")), | 73 bar_plugin_path_(FILE_PATH_LITERAL("/path/to/bar")), |
| 66 file_thread_(content::BrowserThread::FILE, &message_loop_) { | 74 file_thread_(content::BrowserThread::FILE, &message_loop_) { |
| 67 } | 75 } |
| 68 | 76 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 ChromeViewHostMsg_GetPluginInfo_Status status; | 164 ChromeViewHostMsg_GetPluginInfo_Status status; |
| 157 webkit::WebPluginInfo plugin; | 165 webkit::WebPluginInfo plugin; |
| 158 std::string actual_mime_type; | 166 std::string actual_mime_type; |
| 159 EXPECT_FALSE(context_.FindEnabledPlugin( | 167 EXPECT_FALSE(context_.FindEnabledPlugin( |
| 160 0, GURL(), GURL(), "baz/blurp", &status, &plugin, &actual_mime_type, | 168 0, GURL(), GURL(), "baz/blurp", &status, &plugin, &actual_mime_type, |
| 161 NULL)); | 169 NULL)); |
| 162 EXPECT_EQ(ChromeViewHostMsg_GetPluginInfo_Status::kNotFound, status.value); | 170 EXPECT_EQ(ChromeViewHostMsg_GetPluginInfo_Status::kNotFound, status.value); |
| 163 EXPECT_EQ(FILE_PATH_LITERAL(""), plugin.path.value()); | 171 EXPECT_EQ(FILE_PATH_LITERAL(""), plugin.path.value()); |
| 164 } | 172 } |
| 165 } | 173 } |
| OLD | NEW |