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/plugins/plugin_info_message_filter.h" | 5 #include "chrome/browser/plugins/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 IsPluginEnabled(int render_process_id, | 30 virtual bool ShouldUsePlugin(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 | |
40 void set_plugin_enabled(const FilePath& plugin_path, bool enabled) { | 37 void set_plugin_enabled(const FilePath& plugin_path, bool enabled) { |
41 plugin_state_[plugin_path] = enabled; | 38 plugin_state_[plugin_path] = enabled; |
42 } | 39 } |
43 | 40 |
44 private: | 41 private: |
45 std::map<FilePath, bool> plugin_state_; | 42 std::map<FilePath, bool> plugin_state_; |
46 }; | 43 }; |
47 | 44 |
48 bool FakePluginServiceFilter::IsPluginEnabled(int render_process_id, | 45 bool FakePluginServiceFilter::ShouldUsePlugin(int render_process_id, |
49 int render_view_id, | 46 int render_view_id, |
50 const void* context, | 47 const void* context, |
51 const GURL& url, | 48 const GURL& url, |
52 const GURL& policy_url, | 49 const GURL& policy_url, |
53 webkit::WebPluginInfo* plugin) { | 50 webkit::WebPluginInfo* plugin) { |
54 std::map<FilePath, bool>::iterator it = plugin_state_.find(plugin->path); | 51 std::map<FilePath, bool>::iterator it = plugin_state_.find(plugin->path); |
55 if (it == plugin_state_.end()) { | 52 if (it == plugin_state_.end()) { |
56 ADD_FAILURE() << "No plug-in state for '" << plugin->path.value() << "'"; | 53 ADD_FAILURE() << "No plug-in state for '" << plugin->path.value() << "'"; |
57 return false; | 54 return false; |
58 } | 55 } |
59 return it->second; | 56 return it->second; |
60 } | 57 } |
61 | 58 |
62 bool FakePluginServiceFilter::CanLoadPlugin(int render_process_id, | |
63 const FilePath& path) { | |
64 return true; | |
65 } | |
66 | |
67 } // namespace | 59 } // namespace |
68 | 60 |
69 class PluginInfoMessageFilterTest : public ::testing::Test { | 61 class PluginInfoMessageFilterTest : public ::testing::Test { |
70 public: | 62 public: |
71 PluginInfoMessageFilterTest() : | 63 PluginInfoMessageFilterTest() : |
72 foo_plugin_path_(FILE_PATH_LITERAL("/path/to/foo")), | 64 foo_plugin_path_(FILE_PATH_LITERAL("/path/to/foo")), |
73 bar_plugin_path_(FILE_PATH_LITERAL("/path/to/bar")), | 65 bar_plugin_path_(FILE_PATH_LITERAL("/path/to/bar")), |
74 file_thread_(content::BrowserThread::FILE, &message_loop_) { | 66 file_thread_(content::BrowserThread::FILE, &message_loop_) { |
75 } | 67 } |
76 | 68 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 ChromeViewHostMsg_GetPluginInfo_Status status; | 156 ChromeViewHostMsg_GetPluginInfo_Status status; |
165 webkit::WebPluginInfo plugin; | 157 webkit::WebPluginInfo plugin; |
166 std::string actual_mime_type; | 158 std::string actual_mime_type; |
167 EXPECT_FALSE(context_.FindEnabledPlugin( | 159 EXPECT_FALSE(context_.FindEnabledPlugin( |
168 0, GURL(), GURL(), "baz/blurp", &status, &plugin, &actual_mime_type, | 160 0, GURL(), GURL(), "baz/blurp", &status, &plugin, &actual_mime_type, |
169 NULL)); | 161 NULL)); |
170 EXPECT_EQ(ChromeViewHostMsg_GetPluginInfo_Status::kNotFound, status.value); | 162 EXPECT_EQ(ChromeViewHostMsg_GetPluginInfo_Status::kNotFound, status.value); |
171 EXPECT_EQ(FILE_PATH_LITERAL(""), plugin.path.value()); | 163 EXPECT_EQ(FILE_PATH_LITERAL(""), plugin.path.value()); |
172 } | 164 } |
173 } | 165 } |
OLD | NEW |