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 #include "webkit/plugins/npapi/mock_plugin_list.h" |
10 | 10 |
11 namespace webkit { | 11 namespace webkit { |
12 namespace npapi { | 12 namespace npapi { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b, | 16 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { |
17 bool care_about_enabled_status) { | |
18 return (a.name == b.name && | 17 return (a.name == b.name && |
19 a.path == b.path && | 18 a.path == b.path && |
20 a.version == b.version && | 19 a.version == b.version && |
21 a.desc == b.desc && | 20 a.desc == b.desc); |
22 (!care_about_enabled_status || a.enabled == b.enabled)); | |
23 } | 21 } |
24 | 22 |
25 bool Contains(const std::vector<WebPluginInfo>& list, | 23 bool Contains(const std::vector<WebPluginInfo>& list, |
26 const WebPluginInfo& plugin, | 24 const WebPluginInfo& plugin) { |
27 bool care_about_enabled_status) { | |
28 for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); | 25 for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); |
29 it != list.end(); ++it) { | 26 it != list.end(); ++it) { |
30 if (Equals(*it, plugin, care_about_enabled_status)) | 27 if (Equals(*it, plugin)) |
31 return true; | 28 return true; |
32 } | 29 } |
33 return false; | 30 return false; |
34 } | 31 } |
35 | 32 |
36 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); | 33 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); |
37 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); | 34 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); |
38 const char* kFooIdentifier = "foo"; | 35 const char* kFooIdentifier = "foo"; |
39 const char* kFooGroupName = "Foo"; | 36 const char* kFooGroupName = "Foo"; |
40 const char* kFooName = "Foo Plugin"; | 37 const char* kFooName = "Foo Plugin"; |
(...skipping 12 matching lines...) Expand all Loading... |
53 FilePath(kFooPath), | 50 FilePath(kFooPath), |
54 ASCIIToUTF16("1.2.3"), | 51 ASCIIToUTF16("1.2.3"), |
55 ASCIIToUTF16("foo")), | 52 ASCIIToUTF16("foo")), |
56 bar_plugin_(ASCIIToUTF16("Bar Plugin"), | 53 bar_plugin_(ASCIIToUTF16("Bar Plugin"), |
57 FilePath(kBarPath), | 54 FilePath(kBarPath), |
58 ASCIIToUTF16("2.3.4"), | 55 ASCIIToUTF16("2.3.4"), |
59 ASCIIToUTF16("bar")) { | 56 ASCIIToUTF16("bar")) { |
60 } | 57 } |
61 | 58 |
62 virtual void SetUp() { | 59 virtual void SetUp() { |
63 bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; | |
64 plugin_list_.DisablePlugin(bar_plugin_.path); | |
65 plugin_list_.AddPluginToLoad(foo_plugin_); | 60 plugin_list_.AddPluginToLoad(foo_plugin_); |
66 plugin_list_.AddPluginToLoad(bar_plugin_); | 61 plugin_list_.AddPluginToLoad(bar_plugin_); |
67 } | 62 } |
68 | 63 |
69 protected: | 64 protected: |
70 MockPluginList plugin_list_; | 65 MockPluginList plugin_list_; |
71 WebPluginInfo foo_plugin_; | 66 WebPluginInfo foo_plugin_; |
72 WebPluginInfo bar_plugin_; | 67 WebPluginInfo bar_plugin_; |
73 }; | 68 }; |
74 | 69 |
75 TEST_F(PluginListTest, GetPlugins) { | 70 TEST_F(PluginListTest, GetPlugins) { |
76 std::vector<WebPluginInfo> plugins; | 71 std::vector<WebPluginInfo> plugins; |
77 plugin_list_.GetPlugins(&plugins); | 72 plugin_list_.GetPlugins(&plugins); |
78 EXPECT_EQ(2u, plugins.size()); | 73 EXPECT_EQ(2u, plugins.size()); |
79 EXPECT_TRUE(Contains(plugins, foo_plugin_, true)); | 74 EXPECT_TRUE(Contains(plugins, foo_plugin_)); |
80 EXPECT_TRUE(Contains(plugins, bar_plugin_, true)); | 75 EXPECT_TRUE(Contains(plugins, bar_plugin_)); |
81 } | 76 } |
82 | 77 |
83 TEST_F(PluginListTest, GetPluginGroup) { | 78 TEST_F(PluginListTest, GetPluginGroup) { |
84 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_); | 79 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_); |
85 EXPECT_EQ(ASCIIToUTF16(kFooGroupName), foo_group->GetGroupName()); | 80 EXPECT_EQ(ASCIIToUTF16(kFooGroupName), foo_group->GetGroupName()); |
86 EXPECT_TRUE(foo_group->Enabled()); | |
87 // The second request should return a pointer to the same instance. | |
88 const PluginGroup* foo_group2 = plugin_list_.GetPluginGroup(foo_plugin_); | |
89 EXPECT_EQ(foo_group, foo_group2); | |
90 const PluginGroup* bar_group = plugin_list_.GetPluginGroup(bar_plugin_); | |
91 EXPECT_FALSE(bar_group->Enabled()); | |
92 } | 81 } |
93 | 82 |
94 TEST_F(PluginListTest, EmptyGroup) { | 83 TEST_F(PluginListTest, EmptyGroup) { |
95 std::vector<PluginGroup> groups; | 84 std::vector<PluginGroup> groups; |
96 plugin_list_.GetPluginGroups(false, &groups); | 85 plugin_list_.GetPluginGroups(false, &groups); |
97 for (size_t i = 0; i < groups.size(); ++i) | 86 for (size_t i = 0; i < groups.size(); ++i) |
98 EXPECT_GE(1U, groups[i].web_plugins_info().size()); | 87 EXPECT_GE(1U, groups[i].web_plugin_infos().size()); |
99 } | 88 } |
100 | 89 |
101 TEST_F(PluginListTest, BadPluginDescription) { | 90 TEST_F(PluginListTest, BadPluginDescription) { |
102 WebPluginInfo plugin_3043(ASCIIToUTF16(""), | 91 WebPluginInfo plugin_3043(ASCIIToUTF16(""), |
103 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), | 92 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), |
104 ASCIIToUTF16(""), | 93 ASCIIToUTF16(""), |
105 ASCIIToUTF16("")); | 94 ASCIIToUTF16("")); |
106 // Simulate loading of the plugins. | 95 // Simulate loading of the plugins. |
107 plugin_list_.ClearPluginsToLoad(); | 96 plugin_list_.ClearPluginsToLoad(); |
108 plugin_list_.AddPluginToLoad(plugin_3043); | 97 plugin_list_.AddPluginToLoad(plugin_3043); |
109 // Now we should have them in the state we specified above. | 98 // Now we should have them in the state we specified above. |
110 plugin_list_.RefreshPlugins(); | 99 plugin_list_.RefreshPlugins(); |
111 std::vector<WebPluginInfo> plugins; | 100 std::vector<WebPluginInfo> plugins; |
112 plugin_list_.GetPlugins(&plugins); | 101 plugin_list_.GetPlugins(&plugins); |
113 ASSERT_TRUE(Contains(plugins, plugin_3043, true)); | 102 ASSERT_TRUE(Contains(plugins, plugin_3043)); |
114 } | |
115 | |
116 TEST_F(PluginListTest, DisableAndEnableBeforeLoad) { | |
117 WebPluginInfo plugin_3043(ASCIIToUTF16("MyPlugin"), | |
118 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), | |
119 ASCIIToUTF16("3.0.43"), | |
120 ASCIIToUTF16("MyPlugin version 3.0.43")); | |
121 WebPluginInfo plugin_3045(ASCIIToUTF16("MyPlugin"), | |
122 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.45")), | |
123 ASCIIToUTF16("3.0.45"), | |
124 ASCIIToUTF16("MyPlugin version 3.0.45")); | |
125 // Disable the first one and disable and then enable the second one. | |
126 EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3043.path)); | |
127 EXPECT_TRUE(plugin_list_.DisablePlugin(plugin_3045.path)); | |
128 EXPECT_TRUE(plugin_list_.EnablePlugin(plugin_3045.path)); | |
129 // Simulate loading of the plugins. | |
130 plugin_list_.ClearPluginsToLoad(); | |
131 plugin_list_.AddPluginToLoad(plugin_3043); | |
132 plugin_list_.AddPluginToLoad(plugin_3045); | |
133 // Now we should have them in the state we specified above. | |
134 plugin_list_.RefreshPlugins(); | |
135 std::vector<WebPluginInfo> plugins; | |
136 plugin_list_.GetPlugins(&plugins); | |
137 plugin_3043.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; | |
138 ASSERT_TRUE(Contains(plugins, plugin_3043, true)); | |
139 ASSERT_TRUE(Contains(plugins, plugin_3045, true)); | |
140 } | 103 } |
141 | 104 |
142 TEST_F(PluginListTest, HardcodedGroups) { | 105 TEST_F(PluginListTest, HardcodedGroups) { |
143 std::vector<PluginGroup> groups; | 106 std::vector<PluginGroup> groups; |
144 plugin_list_.GetPluginGroups(true, &groups); | 107 plugin_list_.GetPluginGroups(true, &groups); |
145 ASSERT_EQ(2u, groups.size()); | 108 ASSERT_EQ(2u, groups.size()); |
146 EXPECT_TRUE(groups[0].Enabled()); | 109 EXPECT_EQ(1u, groups[0].web_plugin_infos().size()); |
147 EXPECT_EQ(1u, groups[0].web_plugins_info().size()); | |
148 EXPECT_TRUE(groups[0].ContainsPlugin(FilePath(kFooPath))); | 110 EXPECT_TRUE(groups[0].ContainsPlugin(FilePath(kFooPath))); |
149 EXPECT_EQ(kFooIdentifier, groups[0].identifier()); | 111 EXPECT_EQ(kFooIdentifier, groups[0].identifier()); |
150 EXPECT_FALSE(groups[1].Enabled()); | 112 EXPECT_EQ(1u, groups[1].web_plugin_infos().size()); |
151 EXPECT_EQ(1u, groups[1].web_plugins_info().size()); | |
152 EXPECT_TRUE(groups[1].ContainsPlugin(FilePath(kBarPath))); | 113 EXPECT_TRUE(groups[1].ContainsPlugin(FilePath(kBarPath))); |
153 EXPECT_EQ("bar.plugin", groups[1].identifier()); | 114 EXPECT_EQ("bar.plugin", groups[1].identifier()); |
154 } | 115 } |
155 | 116 |
156 TEST_F(PluginListTest, DisableBeforeLoad) { | |
157 // Test that a plugin group that was disabled before plugins are loaded stays | |
158 // disabled afterwards. | |
159 | |
160 EXPECT_TRUE(plugin_list_.EnableGroup(false, ASCIIToUTF16(kFooGroupName))); | |
161 | |
162 plugin_list_.RefreshPlugins(); | |
163 std::vector<WebPluginInfo> plugins; | |
164 plugin_list_.GetPlugins(&plugins); | |
165 ASSERT_EQ(2u, plugins.size()); | |
166 ASSERT_EQ(WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED, plugins[0].enabled); | |
167 } | |
168 | |
169 } // namespace npapi | 117 } // namespace npapi |
170 } // namespace webkit | 118 } // namespace webkit |
OLD | NEW |