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

Side by Side Diff: webkit/plugins/npapi/plugin_list_unittest.cc

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Bernhard comments. Pending bonus expected ;) Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/npapi/plugin_list.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace webkit {
11 namespace npapi {
12
13 namespace plugin_test_internal {
14
15 // A PluginList for tests that avoids file system IO. There is also no reason
16 // to use |lock_| (but it doesn't hurt either).
17 class PluginListWithoutFileIO : public PluginList {
18 public:
19 void CreatePluginGroup(const PluginGroupDefinition& definition) {
20 PluginGroup* group = PluginGroup::FromPluginGroupDefinition(definition);
21 plugin_groups_.push_back(group);
22 }
23
24 // NPAPI::PluginList methods:
25
26 virtual void LoadPlugins(bool refresh) {
27 if (plugins_loaded_ && !refresh)
28 return;
29
30 for (size_t i = 0; i < plugins_to_load_.size(); ++i)
31 AddToPluginGroups(plugins_to_load_[i], &plugin_groups_);
32
33 for (size_t i = 0; i < plugins_to_disable_.size(); ++i)
34 DisablePlugin(plugins_to_disable_[i]);
Bernhard Bauer 2011/01/24 12:20:17 Uh, why is this in here (and not in the real Plugi
pastarmovj 2011/01/24 13:02:10 Partially yes. I extracted the functionality from
35
36 for (size_t i = 0; i < groups_to_disable_.size(); ++i)
37 EnableGroup(false, groups_to_disable_[i]);
38
39 plugins_loaded_ = true;
40 }
41
42 std::vector<WebPluginInfo> plugins_to_load_;
43 };
44
45 } // namespace plugin_test_internal
46
47 namespace {
48
49 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b,
50 bool care_about_enabled_status) {
51 return (a.name == b.name &&
52 a.path == b.path &&
53 a.version == b.version &&
54 a.desc == b.desc &&
55 (!care_about_enabled_status || a.enabled == b.enabled));
56 }
57
58 bool Contains(const std::vector<WebPluginInfo>& list,
59 const WebPluginInfo& plugin,
60 bool care_about_enabled_status) {
61 for (std::vector<WebPluginInfo>::const_iterator it = list.begin();
62 it != list.end(); ++it) {
63 if (Equals(*it, plugin, care_about_enabled_status))
64 return true;
65 }
66 return false;
67 }
68
69 } // namespace
70
71 class PluginListTest : public testing::Test {
72 public:
73 PluginListTest()
74 : foo_plugin_(ASCIIToUTF16("Foo Plugin"),
75 FilePath(FILE_PATH_LITERAL("/plugins/foo.plugin")),
76 ASCIIToUTF16("1.2.3"),
77 ASCIIToUTF16("foo")),
78 bar_plugin_(ASCIIToUTF16("Bar Plugin"),
79 FilePath(FILE_PATH_LITERAL("/plugins/bar.plugin")),
80 ASCIIToUTF16("2.3.4"),
81 ASCIIToUTF16("bar")) {
82 }
83
84 virtual void SetUp() {
85 bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED;
86 plugin_list_.DisablePlugin(bar_plugin_.path);
87 plugin_list_.plugins_to_load_.push_back(foo_plugin_);
88 plugin_list_.plugins_to_load_.push_back(bar_plugin_);
89 plugin_list_.LoadPlugins(true);
90 }
91
92 protected:
93 plugin_test_internal::PluginListWithoutFileIO plugin_list_;
94 WebPluginInfo foo_plugin_;
95 WebPluginInfo bar_plugin_;
96 };
97
98 TEST_F(PluginListTest, GetPlugins) {
99 std::vector<WebPluginInfo> plugins;
100 plugin_list_.GetPlugins(false, &plugins);
101 EXPECT_EQ(2u, plugins.size());
102 EXPECT_TRUE(Contains(plugins, foo_plugin_, true));
103 EXPECT_TRUE(Contains(plugins, bar_plugin_, true));
104 }
105
106 TEST_F(PluginListTest, GetEnabledPlugins) {
107 std::vector<WebPluginInfo> plugins;
108 plugin_list_.GetEnabledPlugins(false, &plugins);
109 EXPECT_EQ(1u, plugins.size());
110 EXPECT_TRUE(Contains(plugins, foo_plugin_, true));
111 }
112
113 TEST_F(PluginListTest, GetPluginGroup) {
114 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
115 EXPECT_EQ(foo_group->GetGroupName(), foo_plugin_.name);
116 EXPECT_TRUE(foo_group->Enabled());
117 // The second request should return a pointer to the same instance.
118 const PluginGroup* foo_group2 = plugin_list_.GetPluginGroup(foo_plugin_);
119 EXPECT_EQ(foo_group, foo_group2);
120 const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
121 EXPECT_FALSE(bar_group->Enabled());
122 }
123
124 TEST_F(PluginListTest, EnableDisablePlugin) {
125 // Disable "foo" plugin.
126 plugin_list_.DisablePlugin(foo_plugin_.path);
127 std::vector<WebPluginInfo> plugins;
128 plugin_list_.GetEnabledPlugins(false, &plugins);
129 EXPECT_FALSE(Contains(plugins, foo_plugin_, false));
130 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
131 EXPECT_FALSE(foo_group->Enabled());
132 // Enable "bar" plugin.
133 plugin_list_.EnablePlugin(bar_plugin_.path);
134 plugin_list_.GetEnabledPlugins(false, &plugins);
135 EXPECT_TRUE(Contains(plugins, bar_plugin_, false));
136 const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
137 EXPECT_TRUE(bar_group->Enabled());
138 }
139
140 TEST_F(PluginListTest, EnableGroup) {
141 // Disable "foo" plugin group.
142 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
143 EXPECT_TRUE(foo_group->Enabled());
144 EXPECT_TRUE(plugin_list_.EnableGroup(false, foo_group->GetGroupName()));
145 EXPECT_FALSE(foo_group->Enabled());
146 std::vector<WebPluginInfo> plugins;
147 plugin_list_.GetEnabledPlugins(false, &plugins);
148 EXPECT_EQ(0u, plugins.size());
149 EXPECT_FALSE(Contains(plugins, foo_plugin_, false));
150 // Enable "bar" plugin group.
151 const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
152 EXPECT_FALSE(bar_group->Enabled());
153 plugin_list_.EnableGroup(true, bar_group->GetGroupName());
154 EXPECT_TRUE(bar_group->Enabled());
155 plugin_list_.GetEnabledPlugins(false, &plugins);
156 EXPECT_TRUE(Contains(plugins, bar_plugin_, false));
157 }
158
159 TEST_F(PluginListTest, EmptyGroup) {
160 std::vector<PluginGroup> groups;
161 plugin_list_.GetPluginGroups(false, &groups);
162 for (size_t i = 0; i < groups.size(); ++i) {
163 EXPECT_GE(1U, groups[i].web_plugins_info().size());
164 }
165 }
166
167 TEST_F(PluginListTest, DisableOutdated) {
168 VersionRangeDefinition version_range[] = {
169 { "0", "4", "3.0.44" },
170 { "4", "5", "" }
171 };
172 PluginGroupDefinition plugin_def = {
173 "myplugin-34", "MyPlugin 3/4", "MyPlugin", version_range,
174 arraysize(version_range), "http://latest" };
175 WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"),
176 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
177 ASCIIToUTF16("3.0.43"),
178 ASCIIToUTF16("MyPlugin version 3.0.43"));
179 WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"),
180 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")),
181 ASCIIToUTF16("3.0.45"),
182 ASCIIToUTF16("MyPlugin version 3.0.45"));
183 plugin_list_.plugins_to_load_.clear();
184 plugin_list_.plugins_to_load_.push_back(plugin_3043);
185 plugin_list_.plugins_to_load_.push_back(plugin_3045);
186 plugin_list_.CreatePluginGroup(plugin_def);
187 plugin_list_.LoadPlugins(true);
188 const PluginGroup* group_3043 = plugin_list_.GetPluginGroup(plugin_3043);
189 const PluginGroup* group_3045 = plugin_list_.GetPluginGroup(plugin_3045);
190 EXPECT_EQ(group_3043, group_3045);
191 EXPECT_EQ(plugin_3043.desc, group_3043->description());
192 EXPECT_TRUE(group_3043->IsVulnerable());
193 const_cast<PluginGroup*>(group_3043)->DisableOutdatedPlugins();
194 EXPECT_EQ(plugin_3045.desc, group_3043->description());
195 EXPECT_FALSE(group_3043->IsVulnerable());
196 }
197
198 TEST_F(PluginListTest, DisableAndEnableBeforeLoad) {
199 WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"),
200 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
201 ASCIIToUTF16("3.0.43"),
202 ASCIIToUTF16("MyPlugin version 3.0.43"));
203 WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"),
204 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")),
205 ASCIIToUTF16("3.0.45"),
206 ASCIIToUTF16("MyPlugin version 3.0.45"));
207 // Disable the first one and disable and then enable the second one.
208 EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3043.path));
209 EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3045.path));
210 EXPECT_TRUE(plugin_list_.EnablePlugin(plugin_3045.path));
211 // Simulate loading of the plugins.
212 plugin_list_.plugins_to_load_.clear();
213 plugin_list_.plugins_to_load_.push_back(plugin_3043);
214 plugin_list_.plugins_to_load_.push_back(plugin_3045);
215 plugin_list_.LoadPlugins(true);
216 // Now we should have them in the state we specified above.
217 std::vector<WebPluginInfo> plugins;
218 plugin_list_.GetPlugins(false, &plugins);
219 plugin_3043.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED;
220 ASSERT_TRUE(Contains(plugins, plugin_3043, true));
221 ASSERT_TRUE(Contains(plugins, plugin_3045, true));
222 }
223
224 } // namespace npapi
225 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698