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

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

Issue 7901015: Revert 101269 - Store plug-in enabled/disabled state in PluginPrefs instead of WebPluginInfo, to ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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')
Property Changes:
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/src/webkit/plugins/npapi/plugin_list_unittest.cc:r3734-4217,4606-5108,5177-5263
OLDNEW
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) {
17 return (a.name == b.name && 18 return (a.name == b.name &&
18 a.path == b.path && 19 a.path == b.path &&
19 a.version == b.version && 20 a.version == b.version &&
20 a.desc == b.desc); 21 a.desc == b.desc &&
22 (!care_about_enabled_status || a.enabled == b.enabled));
21 } 23 }
22 24
23 bool Contains(const std::vector<WebPluginInfo>& list, 25 bool Contains(const std::vector<WebPluginInfo>& list,
24 const WebPluginInfo& plugin) { 26 const WebPluginInfo& plugin,
27 bool care_about_enabled_status) {
25 for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); 28 for (std::vector<WebPluginInfo>::const_iterator it = list.begin();
26 it != list.end(); ++it) { 29 it != list.end(); ++it) {
27 if (Equals(*it, plugin)) 30 if (Equals(*it, plugin, care_about_enabled_status))
28 return true; 31 return true;
29 } 32 }
30 return false; 33 return false;
31 } 34 }
32 35
33 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); 36 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin");
34 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); 37 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin");
35 const char* kFooIdentifier = "foo"; 38 const char* kFooIdentifier = "foo";
36 const char* kFooGroupName = "Foo"; 39 const char* kFooGroupName = "Foo";
37 const char* kFooName = "Foo Plugin"; 40 const char* kFooName = "Foo Plugin";
(...skipping 12 matching lines...) Expand all
50 FilePath(kFooPath), 53 FilePath(kFooPath),
51 ASCIIToUTF16("1.2.3"), 54 ASCIIToUTF16("1.2.3"),
52 ASCIIToUTF16("foo")), 55 ASCIIToUTF16("foo")),
53 bar_plugin_(ASCIIToUTF16("Bar Plugin"), 56 bar_plugin_(ASCIIToUTF16("Bar Plugin"),
54 FilePath(kBarPath), 57 FilePath(kBarPath),
55 ASCIIToUTF16("2.3.4"), 58 ASCIIToUTF16("2.3.4"),
56 ASCIIToUTF16("bar")) { 59 ASCIIToUTF16("bar")) {
57 } 60 }
58 61
59 virtual void SetUp() { 62 virtual void SetUp() {
63 bar_plugin_.enabled = WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED;
64 plugin_list_.DisablePlugin(bar_plugin_.path);
60 plugin_list_.AddPluginToLoad(foo_plugin_); 65 plugin_list_.AddPluginToLoad(foo_plugin_);
61 plugin_list_.AddPluginToLoad(bar_plugin_); 66 plugin_list_.AddPluginToLoad(bar_plugin_);
62 } 67 }
63 68
64 protected: 69 protected:
65 MockPluginList plugin_list_; 70 MockPluginList plugin_list_;
66 WebPluginInfo foo_plugin_; 71 WebPluginInfo foo_plugin_;
67 WebPluginInfo bar_plugin_; 72 WebPluginInfo bar_plugin_;
68 }; 73 };
69 74
70 TEST_F(PluginListTest, GetPlugins) { 75 TEST_F(PluginListTest, GetPlugins) {
71 std::vector<WebPluginInfo> plugins; 76 std::vector<WebPluginInfo> plugins;
72 plugin_list_.GetPlugins(&plugins); 77 plugin_list_.GetPlugins(&plugins);
73 EXPECT_EQ(2u, plugins.size()); 78 EXPECT_EQ(2u, plugins.size());
74 EXPECT_TRUE(Contains(plugins, foo_plugin_)); 79 EXPECT_TRUE(Contains(plugins, foo_plugin_, true));
75 EXPECT_TRUE(Contains(plugins, bar_plugin_)); 80 EXPECT_TRUE(Contains(plugins, bar_plugin_, true));
76 } 81 }
77 82
78 TEST_F(PluginListTest, GetPluginGroup) { 83 TEST_F(PluginListTest, GetPluginGroup) {
79 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_); 84 const PluginGroup* foo_group = plugin_list_.GetPluginGroup(foo_plugin_);
80 EXPECT_EQ(ASCIIToUTF16(kFooGroupName), foo_group->GetGroupName()); 85 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());
81 } 92 }
82 93
83 TEST_F(PluginListTest, EmptyGroup) { 94 TEST_F(PluginListTest, EmptyGroup) {
84 std::vector<PluginGroup> groups; 95 std::vector<PluginGroup> groups;
85 plugin_list_.GetPluginGroups(false, &groups); 96 plugin_list_.GetPluginGroups(false, &groups);
86 for (size_t i = 0; i < groups.size(); ++i) 97 for (size_t i = 0; i < groups.size(); ++i)
87 EXPECT_GE(1U, groups[i].web_plugin_infos().size()); 98 EXPECT_GE(1U, groups[i].web_plugins_info().size());
88 } 99 }
89 100
90 TEST_F(PluginListTest, BadPluginDescription) { 101 TEST_F(PluginListTest, BadPluginDescription) {
91 WebPluginInfo plugin_3043(ASCIIToUTF16(""), 102 WebPluginInfo plugin_3043(ASCIIToUTF16(""),
92 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), 103 FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
93 ASCIIToUTF16(""), 104 ASCIIToUTF16(""),
94 ASCIIToUTF16("")); 105 ASCIIToUTF16(""));
95 // Simulate loading of the plugins. 106 // Simulate loading of the plugins.
96 plugin_list_.ClearPluginsToLoad(); 107 plugin_list_.ClearPluginsToLoad();
97 plugin_list_.AddPluginToLoad(plugin_3043); 108 plugin_list_.AddPluginToLoad(plugin_3043);
98 // Now we should have them in the state we specified above. 109 // Now we should have them in the state we specified above.
99 plugin_list_.RefreshPlugins(); 110 plugin_list_.RefreshPlugins();
100 std::vector<WebPluginInfo> plugins; 111 std::vector<WebPluginInfo> plugins;
101 plugin_list_.GetPlugins(&plugins); 112 plugin_list_.GetPlugins(&plugins);
102 ASSERT_TRUE(Contains(plugins, plugin_3043)); 113 ASSERT_TRUE(Contains(plugins, plugin_3043, true));
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));
103 } 140 }
104 141
105 TEST_F(PluginListTest, HardcodedGroups) { 142 TEST_F(PluginListTest, HardcodedGroups) {
106 std::vector<PluginGroup> groups; 143 std::vector<PluginGroup> groups;
107 plugin_list_.GetPluginGroups(true, &groups); 144 plugin_list_.GetPluginGroups(true, &groups);
108 ASSERT_EQ(2u, groups.size()); 145 ASSERT_EQ(2u, groups.size());
109 EXPECT_EQ(1u, groups[0].web_plugin_infos().size()); 146 EXPECT_TRUE(groups[0].Enabled());
147 EXPECT_EQ(1u, groups[0].web_plugins_info().size());
110 EXPECT_TRUE(groups[0].ContainsPlugin(FilePath(kFooPath))); 148 EXPECT_TRUE(groups[0].ContainsPlugin(FilePath(kFooPath)));
111 EXPECT_EQ(kFooIdentifier, groups[0].identifier()); 149 EXPECT_EQ(kFooIdentifier, groups[0].identifier());
112 EXPECT_EQ(1u, groups[1].web_plugin_infos().size()); 150 EXPECT_FALSE(groups[1].Enabled());
151 EXPECT_EQ(1u, groups[1].web_plugins_info().size());
113 EXPECT_TRUE(groups[1].ContainsPlugin(FilePath(kBarPath))); 152 EXPECT_TRUE(groups[1].ContainsPlugin(FilePath(kBarPath)));
114 EXPECT_EQ("bar.plugin", groups[1].identifier()); 153 EXPECT_EQ("bar.plugin", groups[1].identifier());
115 } 154 }
116 155
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
117 } // namespace npapi 169 } // namespace npapi
118 } // namespace webkit 170 } // 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