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

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: Made *_to_disable_ sets and extracted some functionality from LoadPlugins for better testability. 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
« no previous file with comments | « webkit/plugins/npapi/plugin_list_posix.cc ('k') | webkit/plugins/npapi/plugin_list_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 UpdatePluginsEnabledFlags(&plugin_groups_);
Bernhard Bauer 2011/01/24 13:12:21 What I meant was actually extracting the part that
pastarmovj 2011/01/24 14:47:45 Done.
34
35 plugins_loaded_ = true;
36 }
37
38 std::vector<WebPluginInfo> plugins_to_load_;
39 };
40
41 } // namespace plugin_test_internal
42
43 namespace {
44
45 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b,
46 bool care_about_enabled_status) {
47 return (a.name == b.name &&
48 a.path == b.path &&
49 a.version == b.version &&
50 a.desc == b.desc &&
51 (!care_about_enabled_status || a.enabled == b.enabled));
52 }
53
54 bool Contains(const std::vector<WebPluginInfo>& list,
55 const WebPluginInfo& plugin,
56 bool care_about_enabled_status) {
57 for (std::vector<WebPluginInfo>::const_iterator it = list.begin();
58 it != list.end(); ++it) {
59 if (Equals(*it, plugin, care_about_enabled_status))
60 return true;
61 }
62 return false;
63 }
64
65 } // namespace
66
67 class PluginListTest : public testing::Test {
68 public:
69 PluginListTest()
70 : foo_plugin_(ASCIIToUTF16("Foo Plugin"),
71 FilePath(FILE_PATH_LITERAL("/plugins/foo.plugin")),
72 ASCIIToUTF16("1.2.3"),
73 ASCIIToUTF16("foo")),
74 bar_plugin_(ASCIIToUTF16("Bar Plugin"),
75 FilePath(FILE_PATH_LITERAL("/plugins/bar.plugin")),
76 ASCIIToUTF16("2.3.4"),
77 ASCIIToUTF16("bar")) {
78 }
79
80 virtual void SetUp() {
81 bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED;
82 plugin_list_.DisablePlugin(bar_plugin_.path);
83 plugin_list_.plugins_to_load_.push_back(foo_plugin_);
84 plugin_list_.plugins_to_load_.push_back(bar_plugin_);
85 plugin_list_.LoadPlugins(true);
86 }
87
88 protected:
89 plugin_test_internal::PluginListWithoutFileIO plugin_list_;
90 WebPluginInfo foo_plugin_;
91 WebPluginInfo bar_plugin_;
92 };
93
94 TEST_F(PluginListTest, GetPlugins) {
95 std::vector<WebPluginInfo> plugins;
96 plugin_list_.GetPlugins(false, &plugins);
97 EXPECT_EQ(2u, plugins.size());
98 EXPECT_TRUE(Contains(plugins, foo_plugin_, true));
99 EXPECT_TRUE(Contains(plugins, bar_plugin_, true));
100 }
101
102 TEST_F(PluginListTest, GetEnabledPlugins) {
103 std::vector<WebPluginInfo> plugins;
104 plugin_list_.GetEnabledPlugins(false, &plugins);
105 EXPECT_EQ(1u, plugins.size());
106 EXPECT_TRUE(Contains(plugins, foo_plugin_, true));
107 }
108
109 TEST_F(PluginListTest, GetPluginGroup) {
110 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
111 EXPECT_EQ(foo_group->GetGroupName(), foo_plugin_.name);
112 EXPECT_TRUE(foo_group->Enabled());
113 // The second request should return a pointer to the same instance.
114 const PluginGroup* foo_group2 = plugin_list_.GetPluginGroup(foo_plugin_);
115 EXPECT_EQ(foo_group, foo_group2);
116 const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
117 EXPECT_FALSE(bar_group->Enabled());
118 }
119
120 TEST_F(PluginListTest, EnableDisablePlugin) {
121 // Disable "foo" plugin.
122 plugin_list_.DisablePlugin(foo_plugin_.path);
123 std::vector<WebPluginInfo> plugins;
124 plugin_list_.GetEnabledPlugins(false, &plugins);
125 EXPECT_FALSE(Contains(plugins, foo_plugin_, false));
126 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
127 EXPECT_FALSE(foo_group->Enabled());
128 // Enable "bar" plugin.
129 plugin_list_.EnablePlugin(bar_plugin_.path);
130 plugin_list_.GetEnabledPlugins(false, &plugins);
131 EXPECT_TRUE(Contains(plugins, bar_plugin_, false));
132 const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
133 EXPECT_TRUE(bar_group->Enabled());
134 }
135
136 TEST_F(PluginListTest, EnableGroup) {
137 // Disable "foo" plugin group.
138 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
139 EXPECT_TRUE(foo_group->Enabled());
140 EXPECT_TRUE(plugin_list_.EnableGroup(false, foo_group->GetGroupName()));
141 EXPECT_FALSE(foo_group->Enabled());
142 std::vector<WebPluginInfo> plugins;
143 plugin_list_.GetEnabledPlugins(false, &plugins);
144 EXPECT_EQ(0u, plugins.size());
145 EXPECT_FALSE(Contains(plugins, foo_plugin_, false));
146 // Enable "bar" plugin group.
147 const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
148 EXPECT_FALSE(bar_group->Enabled());
149 plugin_list_.EnableGroup(true, bar_group->GetGroupName());
150 EXPECT_TRUE(bar_group->Enabled());
151 plugin_list_.GetEnabledPlugins(false, &plugins);
152 EXPECT_TRUE(Contains(plugins, bar_plugin_, false));
153 }
154
155 TEST_F(PluginListTest, EmptyGroup) {
156 std::vector<PluginGroup> groups;
157 plugin_list_.GetPluginGroups(false, &groups);
158 for (size_t i = 0; i < groups.size(); ++i) {
159 EXPECT_GE(1U, groups[i].web_plugins_info().size());
160 }
161 }
162
163 TEST_F(PluginListTest, DisableOutdated) {
164 VersionRangeDefinition version_range[] = {
165 { "0", "4", "3.0.44" },
166 { "4", "5", "" }
167 };
168 PluginGroupDefinition plugin_def = {
169 "myplugin-34", "MyPlugin 3/4", "MyPlugin", version_range,
170 arraysize(version_range), "http://latest" };
171 WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"),
172 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
173 ASCIIToUTF16("3.0.43"),
174 ASCIIToUTF16("MyPlugin version 3.0.43"));
175 WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"),
176 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")),
177 ASCIIToUTF16("3.0.45"),
178 ASCIIToUTF16("MyPlugin version 3.0.45"));
179 plugin_list_.plugins_to_load_.clear();
180 plugin_list_.plugins_to_load_.push_back(plugin_3043);
181 plugin_list_.plugins_to_load_.push_back(plugin_3045);
182 plugin_list_.CreatePluginGroup(plugin_def);
183 plugin_list_.LoadPlugins(true);
184 const PluginGroup* group_3043 = plugin_list_.GetPluginGroup(plugin_3043);
185 const PluginGroup* group_3045 = plugin_list_.GetPluginGroup(plugin_3045);
186 EXPECT_EQ(group_3043, group_3045);
187 EXPECT_EQ(plugin_3043.desc, group_3043->description());
188 EXPECT_TRUE(group_3043->IsVulnerable());
189 const_cast<PluginGroup*>(group_3043)->DisableOutdatedPlugins();
190 EXPECT_EQ(plugin_3045.desc, group_3043->description());
191 EXPECT_FALSE(group_3043->IsVulnerable());
192 }
193
194 TEST_F(PluginListTest, DisableAndEnableBeforeLoad) {
195 WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"),
196 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
197 ASCIIToUTF16("3.0.43"),
198 ASCIIToUTF16("MyPlugin version 3.0.43"));
199 WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"),
200 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")),
201 ASCIIToUTF16("3.0.45"),
202 ASCIIToUTF16("MyPlugin version 3.0.45"));
203 // Disable the first one and disable and then enable the second one.
204 EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3043.path));
205 EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3045.path));
206 EXPECT_TRUE(plugin_list_.EnablePlugin(plugin_3045.path));
207 // Simulate loading of the plugins.
208 plugin_list_.plugins_to_load_.clear();
209 plugin_list_.plugins_to_load_.push_back(plugin_3043);
210 plugin_list_.plugins_to_load_.push_back(plugin_3045);
211 plugin_list_.LoadPlugins(true);
212 // Now we should have them in the state we specified above.
213 std::vector<WebPluginInfo> plugins;
214 plugin_list_.GetPlugins(false, &plugins);
215 plugin_3043.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED;
216 ASSERT_TRUE(Contains(plugins, plugin_3043, true));
217 ASSERT_TRUE(Contains(plugins, plugin_3045, true));
218 }
219
220 } // namespace npapi
221 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_list_posix.cc ('k') | webkit/plugins/npapi/plugin_list_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698