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

Side by Side Diff: webkit/glue/plugins/plugin_group_unittest.cc

Issue 5621006: Merge PluginGroups for Adobe Reader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/glue/plugins/plugin_group.h" 5 #include "webkit/glue/plugins/plugin_group.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/glue/plugins/webplugininfo.h" 16 #include "webkit/glue/plugins/webplugininfo.h"
17 #include "webkit/glue/plugins/plugin_list.h" 17 #include "webkit/glue/plugins/plugin_list.h"
18 18
19 namespace plugin_test_internal {
20
21 static const VersionRangeDefinition kPluginVersionRange[] = {
22 { "", "", "3.0.44" }
23 };
24 static const VersionRangeDefinition kPlugin3VersionRange[] = {
25 { "0", "4", "3.0.44" }
26 };
27 static const VersionRangeDefinition kPlugin4VersionRange[] = {
28 { "4", "5", "4.0.44" }
29 };
30 static const VersionRangeDefinition kPlugin34VersionRange[] = {
31 { "0", "4", "3.0.44" },
32 { "4", "5", "4.0.44" }
33 };
34
19 static const PluginGroupDefinition kPluginDef = { 35 static const PluginGroupDefinition kPluginDef = {
20 "myplugin", "MyPlugin", "MyPlugin", "", "", "3.0.44", "http://latest/" }; 36 "myplugin", "MyPlugin", "MyPlugin", kPluginVersionRange, 1,
37 "http://latest/" };
21 static const PluginGroupDefinition kPluginDef3 = { 38 static const PluginGroupDefinition kPluginDef3 = {
22 "myplugin-3", "MyPlugin 3", "MyPlugin", "0", "4", "3.0.44", 39 "myplugin-3", "MyPlugin 3", "MyPlugin", kPlugin3VersionRange, 1,
23 "http://latest" }; 40 "http://latest" };
24 static const PluginGroupDefinition kPluginDef4 = { 41 static const PluginGroupDefinition kPluginDef4 = {
25 "myplugin-4", "MyPlugin 4", "MyPlugin", "4", "5", "4.0.44", 42 "myplugin-4", "MyPlugin 4", "MyPlugin", kPlugin4VersionRange, 1,
43 "http://latest" };
44 static const PluginGroupDefinition kPluginDef34 = {
45 "myplugin-34", "MyPlugin 3/4", "MyPlugin", kPlugin34VersionRange, 2,
26 "http://latest" }; 46 "http://latest" };
27 static const PluginGroupDefinition kPluginDefNotVulnerable = { 47 static const PluginGroupDefinition kPluginDefNotVulnerable = {
28 "myplugin-latest", "MyPlugin", "MyPlugin", "", "", "", "http://latest" }; 48 "myplugin-latest", "MyPlugin", "MyPlugin", NULL, 0, "http://latest" };
29 49
30 // name, path, version, desc, mime_types, enabled. 50 // name, path, version, desc, mime_types, enabled.
31 static WebPluginInfo kPlugin2043 = WebPluginInfo( 51 static WebPluginInfo kPlugin2043 = WebPluginInfo(
32 ASCIIToUTF16("MyPlugin"), ASCIIToUTF16("2.0.43"), 52 ASCIIToUTF16("MyPlugin"), ASCIIToUTF16("2.0.43"),
33 ASCIIToUTF16("MyPlugin version 2.0.43")); 53 ASCIIToUTF16("MyPlugin version 2.0.43"));
34 static WebPluginInfo kPlugin3043 = WebPluginInfo( 54 static WebPluginInfo kPlugin3043 = WebPluginInfo(
35 ASCIIToUTF16("MyPlugin"), ASCIIToUTF16("3.0.43"), 55 ASCIIToUTF16("MyPlugin"), ASCIIToUTF16("3.0.43"),
36 ASCIIToUTF16("MyPlugin version 3.0.43")); 56 ASCIIToUTF16("MyPlugin version 3.0.43"));
37 static WebPluginInfo kPlugin3044 = WebPluginInfo( 57 static WebPluginInfo kPlugin3044 = WebPluginInfo(
38 ASCIIToUTF16("MyPlugin"), ASCIIToUTF16("3.0.44"), 58 ASCIIToUTF16("MyPlugin"), ASCIIToUTF16("3.0.44"),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( 91 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(
72 kPluginDef3)); 92 kPluginDef3));
73 EXPECT_TRUE(group->Match(kPlugin2043)); 93 EXPECT_TRUE(group->Match(kPlugin2043));
74 EXPECT_TRUE(group->Match(kPlugin3043)); 94 EXPECT_TRUE(group->Match(kPlugin3043));
75 EXPECT_FALSE(group->Match(kPlugin4043)); 95 EXPECT_FALSE(group->Match(kPlugin4043));
76 96
77 group.reset(PluginGroupTest::CreatePluginGroup(kPluginDef4)); 97 group.reset(PluginGroupTest::CreatePluginGroup(kPluginDef4));
78 EXPECT_FALSE(group->Match(kPlugin2043)); 98 EXPECT_FALSE(group->Match(kPlugin2043));
79 EXPECT_FALSE(group->Match(kPlugin3043)); 99 EXPECT_FALSE(group->Match(kPlugin3043));
80 EXPECT_TRUE(group->Match(kPlugin4043)); 100 EXPECT_TRUE(group->Match(kPlugin4043));
101
102 group.reset(PluginGroupTest::CreatePluginGroup(kPluginDef34));
103 EXPECT_TRUE(group->Match(kPlugin2043));
104 EXPECT_TRUE(group->Match(kPlugin3043));
105 EXPECT_TRUE(group->Match(kPlugin4043));
81 } 106 }
82 107
83 TEST(PluginGroupTest, PluginGroupDescription) { 108 TEST(PluginGroupTest, PluginGroupDescription) {
84 string16 desc3043(ASCIIToUTF16("MyPlugin version 3.0.43")); 109 string16 desc3043(ASCIIToUTF16("MyPlugin version 3.0.43"));
85 string16 desc3045(ASCIIToUTF16("MyPlugin version 3.0.45")); 110 string16 desc3045(ASCIIToUTF16("MyPlugin version 3.0.45"));
86 WebPluginInfo plugin3043(kPlugin3043);
87 WebPluginInfo plugin3045(kPlugin3045);
88 111
89 { 112 PluginGroupDefinition plugindefs[] = { kPluginDef3, kPluginDef34 };
90 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( 113 for (size_t i = 0; i < 2; ++i) {
91 kPluginDef3)); 114 WebPluginInfo plugin3043(kPlugin3043);
92 EXPECT_TRUE(group->Match(plugin3043)); 115 WebPluginInfo plugin3045(kPlugin3045);
93 group->AddPlugin(plugin3043, 0); 116 {
94 EXPECT_EQ(desc3043, group->description()); 117 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(
95 EXPECT_TRUE(group->IsVulnerable()); 118 plugindefs[i]));
96 EXPECT_TRUE(group->Match(plugin3045)); 119 EXPECT_TRUE(group->Match(plugin3043));
97 group->AddPlugin(plugin3045, 1); 120 group->AddPlugin(plugin3043, 0);
98 EXPECT_EQ(desc3043, group->description()); 121 EXPECT_EQ(desc3043, group->description());
99 EXPECT_TRUE(group->IsVulnerable()); 122 EXPECT_TRUE(group->IsVulnerable());
100 } 123 EXPECT_TRUE(group->Match(plugin3045));
124 group->AddPlugin(plugin3045, 1);
125 EXPECT_EQ(desc3043, group->description());
126 EXPECT_TRUE(group->IsVulnerable());
127 }
101 128
102 { 129 {
103 // Disable the first plugin. 130 // Disable the first plugin.
104 plugin3043.enabled = false; 131 plugin3043.enabled = false;
105 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( 132 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(
106 kPluginDef3)); 133 plugindefs[i]));
107 EXPECT_TRUE(group->Match(plugin3043)); 134 EXPECT_TRUE(group->Match(plugin3043));
108 group->AddPlugin(plugin3043, 0); 135 group->AddPlugin(plugin3043, 0);
109 EXPECT_EQ(desc3043, group->description()); 136 EXPECT_EQ(desc3043, group->description());
110 EXPECT_TRUE(group->IsVulnerable()); 137 EXPECT_TRUE(group->IsVulnerable());
111 EXPECT_TRUE(group->Match(plugin3045)); 138 EXPECT_FALSE(group->Enabled());
112 group->AddPlugin(plugin3045, 1); 139 EXPECT_TRUE(group->Match(plugin3045));
113 EXPECT_EQ(desc3045, group->description()); 140 group->AddPlugin(plugin3045, 1);
114 EXPECT_FALSE(group->IsVulnerable()); 141 EXPECT_EQ(desc3045, group->description());
115 } 142 EXPECT_FALSE(group->IsVulnerable());
143 }
116 144
117 { 145 {
118 // Disable the second plugin. 146 // Disable the second plugin.
119 plugin3045.enabled = false; 147 plugin3045.enabled = false;
120 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( 148 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(
121 kPluginDef3)); 149 plugindefs[i]));
122 EXPECT_TRUE(group->Match(plugin3043)); 150 EXPECT_TRUE(group->Match(plugin3043));
123 group->AddPlugin(plugin3043, 1); 151 group->AddPlugin(plugin3043, 1);
124 EXPECT_EQ(desc3043, group->description()); 152 EXPECT_EQ(desc3043, group->description());
125 EXPECT_TRUE(group->IsVulnerable()); 153 EXPECT_TRUE(group->IsVulnerable());
126 EXPECT_TRUE(group->Match(plugin3045)); 154 EXPECT_TRUE(group->Match(plugin3045));
127 group->AddPlugin(plugin3045, 0); 155 group->AddPlugin(plugin3045, 0);
128 EXPECT_EQ(desc3043, group->description()); 156 EXPECT_EQ(desc3043, group->description());
129 EXPECT_TRUE(group->IsVulnerable()); 157 EXPECT_TRUE(group->IsVulnerable());
158 }
130 } 159 }
131 } 160 }
132 161
133 TEST(PluginGroupTest, PluginGroupDefinition) { 162 TEST(PluginGroupTest, PluginGroupDefinition) {
134 const PluginGroupDefinition* definitions = 163 const PluginGroupDefinition* definitions =
135 NPAPI::PluginList::GetPluginGroupDefinitions(); 164 NPAPI::PluginList::GetPluginGroupDefinitions();
136 for (size_t i = 0; 165 for (size_t i = 0;
137 i < NPAPI::PluginList::GetPluginGroupDefinitionsSize(); 166 i < NPAPI::PluginList::GetPluginGroupDefinitionsSize();
138 ++i) { 167 ++i) {
139 scoped_ptr<PluginGroup> def_group( 168 scoped_ptr<PluginGroup> def_group(
140 PluginGroupTest::CreatePluginGroup(definitions[i])); 169 PluginGroupTest::CreatePluginGroup(definitions[i]));
141 ASSERT_TRUE(def_group.get() != NULL); 170 ASSERT_TRUE(def_group.get() != NULL);
142 EXPECT_FALSE(def_group->Match(kPlugin2043)); 171 EXPECT_FALSE(def_group->Match(kPlugin2043));
143 } 172 }
144 } 173 }
145 174
146 TEST(PluginGroupTest, DisableOutdated) { 175 TEST(PluginGroupTest, DisableOutdated) {
147 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( 176 PluginGroupDefinition plugindefs[] = { kPluginDef3, kPluginDef34 };
148 kPluginDef3)); 177 for (size_t i = 0; i < 2; ++i) {
149 group->AddPlugin(kPlugin3043, 0); 178 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(
150 group->AddPlugin(kPlugin3045, 1); 179 plugindefs[i]));
151 EXPECT_EQ(ASCIIToUTF16("MyPlugin version 3.0.43"), group->description()); 180 group->AddPlugin(kPlugin3043, 0);
152 EXPECT_TRUE(group->IsVulnerable()); 181 group->AddPlugin(kPlugin3045, 1);
182 EXPECT_EQ(ASCIIToUTF16("MyPlugin version 3.0.43"), group->description());
183 EXPECT_TRUE(group->IsVulnerable());
153 184
154 group->DisableOutdatedPlugins(); 185 group->DisableOutdatedPlugins();
155 EXPECT_EQ(ASCIIToUTF16("MyPlugin version 3.0.45"), group->description()); 186 EXPECT_EQ(ASCIIToUTF16("MyPlugin version 3.0.45"), group->description());
156 EXPECT_FALSE(group->IsVulnerable()); 187 EXPECT_FALSE(group->IsVulnerable());
188 }
157 } 189 }
158 190
159 TEST(PluginGroupTest, VersionExtraction) { 191 TEST(PluginGroupTest, VersionExtraction) {
160 // Some real-world plugin versions (spaces, commata, parentheses, 'r', oh my) 192 // Some real-world plugin versions (spaces, commata, parentheses, 'r', oh my)
161 const char* versions[][2] = { 193 const char* versions[][2] = {
162 { "7.6.6 (1671)", "7.6.6.1671" }, // Quicktime 194 { "7.6.6 (1671)", "7.6.6.1671" }, // Quicktime
163 { "2, 0, 0, 254", "2.0.0.254" }, // DivX 195 { "2, 0, 0, 254", "2.0.0.254" }, // DivX
164 { "3, 0, 0, 0", "3.0.0.0" }, // Picasa 196 { "3, 0, 0, 0", "3.0.0.0" }, // Picasa
165 { "1, 0, 0, 1", "1.0.0.1" }, // Earth 197 { "1, 0, 0, 1", "1.0.0.1" }, // Earth
166 { "10,0,45,2", "10.0.45.2" }, // Flash 198 { "10,0,45,2", "10.0.45.2" }, // Flash
(...skipping 18 matching lines...) Expand all
185 disabled_plugins.insert(ASCIIToUTF16("Disable this!")); 217 disabled_plugins.insert(ASCIIToUTF16("Disable this!"));
186 disabled_plugins.insert(ASCIIToUTF16("*Google*")); 218 disabled_plugins.insert(ASCIIToUTF16("*Google*"));
187 PluginGroup::SetPolicyDisabledPluginPatterns(disabled_plugins); 219 PluginGroup::SetPolicyDisabledPluginPatterns(disabled_plugins);
188 220
189 EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(ASCIIToUTF16("42"))); 221 EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(ASCIIToUTF16("42")));
190 EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy( 222 EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy(
191 ASCIIToUTF16("Disable this!"))); 223 ASCIIToUTF16("Disable this!")));
192 EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy( 224 EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy(
193 ASCIIToUTF16("Google Earth"))); 225 ASCIIToUTF16("Google Earth")));
194 } 226 }
227
228 } // namespace plugin_test_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698