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

Unified 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: Whitespace fixes only. Trybot happiness still applies. 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/npapi/plugin_list_unittest.cc
diff --git a/webkit/plugins/npapi/plugin_list_unittest.cc b/webkit/plugins/npapi/plugin_list_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3e0fb47a702f5d0ed29c90a0f64fb64c85f219aa
--- /dev/null
+++ b/webkit/plugins/npapi/plugin_list_unittest.cc
@@ -0,0 +1,211 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/plugins/npapi/plugin_list.h"
+
+#include "base/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace webkit {
+namespace npapi {
+
+namespace plugin_test_internal {
+
+// A PluginList for tests that avoids file system IO. There is also no reason
+// to use |lock_| (but it doesn't hurt either).
+class PluginListWithoutFileIO : public PluginList {
+ public:
+ std::vector<WebPluginInfo> plugins_to_load_;
+
+ private:
+ // NPAPI::PluginList methods:
+ virtual void LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) {
+ for (size_t i = 0; i < plugins_to_load_.size(); ++i)
+ AddToPluginGroups(plugins_to_load_[i], plugin_groups);
+
+ return;
+ }
+};
+
+} // namespace plugin_test_internal
+
+namespace {
+
+bool Equals(const WebPluginInfo& a, const WebPluginInfo& b,
+ bool care_about_enabled_status) {
+ return (a.name == b.name &&
+ a.path == b.path &&
+ a.version == b.version &&
+ a.desc == b.desc &&
+ (!care_about_enabled_status || a.enabled == b.enabled));
+}
+
+bool Contains(const std::vector<WebPluginInfo>& list,
+ const WebPluginInfo& plugin,
+ bool care_about_enabled_status) {
+ for (std::vector<WebPluginInfo>::const_iterator it = list.begin();
+ it != list.end(); ++it) {
+ if (Equals(*it, plugin, care_about_enabled_status))
+ return true;
+ }
+ return false;
+}
+
+} // namespace
+
+class PluginListTest : public testing::Test {
+ public:
+ PluginListTest()
+ : foo_plugin_(ASCIIToUTF16("Foo Plugin"),
+ FilePath(FILE_PATH_LITERAL("/plugins/foo.plugin")),
+ ASCIIToUTF16("1.2.3"),
+ ASCIIToUTF16("foo")),
+ bar_plugin_(ASCIIToUTF16("Bar Plugin"),
+ FilePath(FILE_PATH_LITERAL("/plugins/bar.plugin")),
+ ASCIIToUTF16("2.3.4"),
+ ASCIIToUTF16("bar")) {
+ }
+
+ virtual void SetUp() {
+ bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED;
+ plugin_list_.DisablePlugin(bar_plugin_.path);
+ plugin_list_.plugins_to_load_.push_back(foo_plugin_);
+ plugin_list_.plugins_to_load_.push_back(bar_plugin_);
+ plugin_list_.LoadPlugins(true);
+ }
+
+ protected:
+ plugin_test_internal::PluginListWithoutFileIO plugin_list_;
+ WebPluginInfo foo_plugin_;
+ WebPluginInfo bar_plugin_;
+};
+
+TEST_F(PluginListTest, GetPlugins) {
+ std::vector<WebPluginInfo> plugins;
+ plugin_list_.GetPlugins(false, &plugins);
+ EXPECT_EQ(2u, plugins.size());
+ EXPECT_TRUE(Contains(plugins, foo_plugin_, true));
+ EXPECT_TRUE(Contains(plugins, bar_plugin_, true));
+}
+
+TEST_F(PluginListTest, GetEnabledPlugins) {
+ std::vector<WebPluginInfo> plugins;
+ plugin_list_.GetEnabledPlugins(false, &plugins);
+ EXPECT_EQ(1u, plugins.size());
+ EXPECT_TRUE(Contains(plugins, foo_plugin_, true));
+}
+
+TEST_F(PluginListTest, GetPluginGroup) {
+ const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
+ EXPECT_EQ(foo_group->GetGroupName(), foo_plugin_.name);
+ EXPECT_TRUE(foo_group->Enabled());
+ // The second request should return a pointer to the same instance.
+ const PluginGroup* foo_group2 = plugin_list_.GetPluginGroup(foo_plugin_);
+ EXPECT_EQ(foo_group, foo_group2);
+ const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
+ EXPECT_FALSE(bar_group->Enabled());
+}
+
+TEST_F(PluginListTest, EnableDisablePlugin) {
+ // Disable "foo" plugin.
+ plugin_list_.DisablePlugin(foo_plugin_.path);
+ std::vector<WebPluginInfo> plugins;
+ plugin_list_.GetEnabledPlugins(false, &plugins);
+ EXPECT_FALSE(Contains(plugins, foo_plugin_, false));
+ const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
+ EXPECT_FALSE(foo_group->Enabled());
+ // Enable "bar" plugin.
+ plugin_list_.EnablePlugin(bar_plugin_.path);
+ plugin_list_.GetEnabledPlugins(false, &plugins);
+ EXPECT_TRUE(Contains(plugins, bar_plugin_, false));
+ const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
+ EXPECT_TRUE(bar_group->Enabled());
+}
+
+TEST_F(PluginListTest, EnableGroup) {
+ // Disable "foo" plugin group.
+ const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
+ EXPECT_TRUE(foo_group->Enabled());
+ EXPECT_TRUE(plugin_list_.EnableGroup(false, foo_group->GetGroupName()));
+ EXPECT_FALSE(foo_group->Enabled());
+ std::vector<WebPluginInfo> plugins;
+ plugin_list_.GetEnabledPlugins(false, &plugins);
+ EXPECT_EQ(0u, plugins.size());
+ EXPECT_FALSE(Contains(plugins, foo_plugin_, false));
+ // Enable "bar" plugin group.
+ const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_);
+ EXPECT_FALSE(bar_group->Enabled());
+ plugin_list_.EnableGroup(true, bar_group->GetGroupName());
+ EXPECT_TRUE(bar_group->Enabled());
+ plugin_list_.GetEnabledPlugins(false, &plugins);
+ EXPECT_TRUE(Contains(plugins, bar_plugin_, false));
+}
+
+TEST_F(PluginListTest, EmptyGroup) {
+ std::vector<PluginGroup> groups;
+ plugin_list_.GetPluginGroups(false, &groups);
+ for (size_t i = 0; i < groups.size(); ++i) {
+ EXPECT_GE(1U, groups[i].web_plugins_info().size());
+ }
+}
+
+TEST_F(PluginListTest, DisableOutdated) {
+ VersionRangeDefinition version_range[] = {
+ { "0", "4", "3.0.44" },
+ { "4", "5", "" }
+ };
+ WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"),
+ FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
+ ASCIIToUTF16("3.0.43"),
+ ASCIIToUTF16("MyPlugin version 3.0.43"));
+ WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"),
+ FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")),
+ ASCIIToUTF16("3.0.45"),
+ ASCIIToUTF16("MyPlugin version 3.0.45"));
+ plugin_list_.plugins_to_load_.clear();
+ plugin_list_.plugins_to_load_.push_back(plugin_3043);
+ plugin_list_.plugins_to_load_.push_back(plugin_3045);
+ // Enfore the load to run.
+ std::vector<WebPluginInfo> plugins;
+ plugin_list_.GetPlugins(true, &plugins);
+ PluginGroup* group_3043 =
+ const_cast<PluginGroup*>(plugin_list_.GetPluginGroup(plugin_3043));
+ const PluginGroup* group_3045 = plugin_list_.GetPluginGroup(plugin_3045);
+ EXPECT_EQ(group_3043, group_3045);
+ group_3043->version_ranges_.push_back(VersionRange(version_range[0]));
+ group_3043->version_ranges_.push_back(VersionRange(version_range[1]));
+ EXPECT_EQ(plugin_3043.desc, group_3043->description());
+ EXPECT_TRUE(group_3043->IsVulnerable());
+ group_3043->DisableOutdatedPlugins();
+ EXPECT_EQ(plugin_3045.desc, group_3043->description());
+ EXPECT_FALSE(group_3043->IsVulnerable());
+}
+
+TEST_F(PluginListTest, DisableAndEnableBeforeLoad) {
+ WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"),
+ FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
+ ASCIIToUTF16("3.0.43"),
+ ASCIIToUTF16("MyPlugin version 3.0.43"));
+ WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"),
+ FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")),
+ ASCIIToUTF16("3.0.45"),
+ ASCIIToUTF16("MyPlugin version 3.0.45"));
+ // Disable the first one and disable and then enable the second one.
+ EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3043.path));
+ EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3045.path));
+ EXPECT_TRUE(plugin_list_.EnablePlugin(plugin_3045.path));
+ // Simulate loading of the plugins.
+ plugin_list_.plugins_to_load_.clear();
+ plugin_list_.plugins_to_load_.push_back(plugin_3043);
+ plugin_list_.plugins_to_load_.push_back(plugin_3045);
+ // Now we should have them in the state we specified above.
+ std::vector<WebPluginInfo> plugins;
+ plugin_list_.GetPlugins(true, &plugins);
+ plugin_3043.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED;
+ ASSERT_TRUE(Contains(plugins, plugin_3043, true));
+ ASSERT_TRUE(Contains(plugins, plugin_3045, true));
+}
+
+} // namespace npapi
+} // namespace webkit
« 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