| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/npapi/plugin_list.h" | 5 #include "webkit/plugins/npapi/plugin_list.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "webkit/plugins/npapi/mock_plugin_list.h" |
| 9 | 10 |
| 10 namespace webkit { | 11 namespace webkit { |
| 11 namespace npapi { | 12 namespace npapi { |
| 12 | 13 |
| 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 PluginListWithoutFileIO(const PluginGroupDefinition* group_definitions, | |
| 20 size_t num_group_definitions) : | |
| 21 PluginList(group_definitions, num_group_definitions) {} | |
| 22 virtual ~PluginListWithoutFileIO() {} | |
| 23 | |
| 24 void AddPluginToLoad(const WebPluginInfo& plugin) { | |
| 25 plugins_to_load_.push_back(plugin); | |
| 26 } | |
| 27 | |
| 28 void ClearPluginsToLoad() { | |
| 29 plugins_to_load_.clear(); | |
| 30 } | |
| 31 | |
| 32 void AddPluginGroupDefinition(const PluginGroupDefinition& definition) { | |
| 33 hardcoded_definitions_.push_back(definition); | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 std::vector<WebPluginInfo> plugins_to_load_; | |
| 38 std::vector<PluginGroupDefinition> hardcoded_definitions_; | |
| 39 | |
| 40 // PluginList methods: | |
| 41 virtual void LoadPluginsInternal( | |
| 42 ScopedVector<PluginGroup>* plugin_groups) OVERRIDE { | |
| 43 for (size_t i = 0; i < plugins_to_load_.size(); ++i) | |
| 44 AddToPluginGroups(plugins_to_load_[i], plugin_groups); | |
| 45 } | |
| 46 }; | |
| 47 | |
| 48 } // namespace plugin_test_internal | |
| 49 | |
| 50 namespace { | 14 namespace { |
| 51 | 15 |
| 52 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b, | 16 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b, |
| 53 bool care_about_enabled_status) { | 17 bool care_about_enabled_status) { |
| 54 return (a.name == b.name && | 18 return (a.name == b.name && |
| 55 a.path == b.path && | 19 a.path == b.path && |
| 56 a.version == b.version && | 20 a.version == b.version && |
| 57 a.desc == b.desc && | 21 a.desc == b.desc && |
| 58 (!care_about_enabled_status || a.enabled == b.enabled)); | 22 (!care_about_enabled_status || a.enabled == b.enabled)); |
| 59 } | 23 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 60 } |
| 97 | 61 |
| 98 virtual void SetUp() { | 62 virtual void SetUp() { |
| 99 bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; | 63 bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; |
| 100 plugin_list_.DisablePlugin(bar_plugin_.path); | 64 plugin_list_.DisablePlugin(bar_plugin_.path); |
| 101 plugin_list_.AddPluginToLoad(foo_plugin_); | 65 plugin_list_.AddPluginToLoad(foo_plugin_); |
| 102 plugin_list_.AddPluginToLoad(bar_plugin_); | 66 plugin_list_.AddPluginToLoad(bar_plugin_); |
| 103 } | 67 } |
| 104 | 68 |
| 105 protected: | 69 protected: |
| 106 plugin_test_internal::PluginListWithoutFileIO plugin_list_; | 70 MockPluginList plugin_list_; |
| 107 WebPluginInfo foo_plugin_; | 71 WebPluginInfo foo_plugin_; |
| 108 WebPluginInfo bar_plugin_; | 72 WebPluginInfo bar_plugin_; |
| 109 }; | 73 }; |
| 110 | 74 |
| 111 TEST_F(PluginListTest, GetPlugins) { | 75 TEST_F(PluginListTest, GetPlugins) { |
| 112 std::vector<WebPluginInfo> plugins; | 76 std::vector<WebPluginInfo> plugins; |
| 113 plugin_list_.GetPlugins(false, &plugins); | 77 plugin_list_.GetPlugins(false, &plugins); |
| 114 EXPECT_EQ(2u, plugins.size()); | 78 EXPECT_EQ(2u, plugins.size()); |
| 115 EXPECT_TRUE(Contains(plugins, foo_plugin_, true)); | 79 EXPECT_TRUE(Contains(plugins, foo_plugin_, true)); |
| 116 EXPECT_TRUE(Contains(plugins, bar_plugin_, true)); | 80 EXPECT_TRUE(Contains(plugins, bar_plugin_, true)); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 EXPECT_TRUE(plugin_list_.EnableGroup(false, ASCIIToUTF16(kFooGroupName))); | 232 EXPECT_TRUE(plugin_list_.EnableGroup(false, ASCIIToUTF16(kFooGroupName))); |
| 269 | 233 |
| 270 std::vector<WebPluginInfo> plugins; | 234 std::vector<WebPluginInfo> plugins; |
| 271 plugin_list_.GetPlugins(true, &plugins); | 235 plugin_list_.GetPlugins(true, &plugins); |
| 272 ASSERT_EQ(2u, plugins.size()); | 236 ASSERT_EQ(2u, plugins.size()); |
| 273 ASSERT_EQ(WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED, plugins[0].enabled); | 237 ASSERT_EQ(WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED, plugins[0].enabled); |
| 274 } | 238 } |
| 275 | 239 |
| 276 } // namespace npapi | 240 } // namespace npapi |
| 277 } // namespace webkit | 241 } // namespace webkit |
| OLD | NEW |