OLD | NEW |
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/plugins/npapi/plugin_group.h" | 5 #include "webkit/plugins/npapi/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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 static const PluginGroupDefinition kPluginDef4 = { | 42 static const PluginGroupDefinition kPluginDef4 = { |
43 "myplugin-4", "MyPlugin 4", "MyPlugin", kPlugin4VersionRange, | 43 "myplugin-4", "MyPlugin 4", "MyPlugin", kPlugin4VersionRange, |
44 arraysize(kPlugin4VersionRange), "http://latest" }; | 44 arraysize(kPlugin4VersionRange), "http://latest" }; |
45 static const PluginGroupDefinition kPluginDef34 = { | 45 static const PluginGroupDefinition kPluginDef34 = { |
46 "myplugin-34", "MyPlugin 3/4", "MyPlugin", kPlugin34VersionRange, | 46 "myplugin-34", "MyPlugin 3/4", "MyPlugin", kPlugin34VersionRange, |
47 arraysize(kPlugin34VersionRange), "http://latest" }; | 47 arraysize(kPlugin34VersionRange), "http://latest" }; |
48 static const PluginGroupDefinition kPluginDefNotVulnerable = { | 48 static const PluginGroupDefinition kPluginDefNotVulnerable = { |
49 "myplugin-latest", "MyPlugin", "MyPlugin", NULL, 0, "http://latest" }; | 49 "myplugin-latest", "MyPlugin", "MyPlugin", NULL, 0, "http://latest" }; |
50 | 50 |
51 // name, path, version, desc. | 51 // name, path, version, desc. |
| 52 static WebPluginInfo kPluginNoVersion = WebPluginInfo( |
| 53 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.2.0.43")), |
| 54 ASCIIToUTF16(""), ASCIIToUTF16("MyPlugin version 2.0.43")); |
52 static WebPluginInfo kPlugin2043 = WebPluginInfo( | 55 static WebPluginInfo kPlugin2043 = WebPluginInfo( |
53 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.2.0.43")), | 56 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.2.0.43")), |
54 ASCIIToUTF16("2.0.43"), ASCIIToUTF16("MyPlugin version 2.0.43")); | 57 ASCIIToUTF16("2.0.43"), ASCIIToUTF16("MyPlugin version 2.0.43")); |
55 static WebPluginInfo kPlugin3043 = WebPluginInfo( | 58 static WebPluginInfo kPlugin3043 = WebPluginInfo( |
56 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.3.0.43")), | 59 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.3.0.43")), |
57 ASCIIToUTF16("3.0.43"), ASCIIToUTF16("MyPlugin version 3.0.43")); | 60 ASCIIToUTF16("3.0.43"), ASCIIToUTF16("MyPlugin version 3.0.43")); |
58 static WebPluginInfo kPlugin3044 = WebPluginInfo( | 61 static WebPluginInfo kPlugin3044 = WebPluginInfo( |
59 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.3.0.44")), | 62 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.3.0.44")), |
60 ASCIIToUTF16("3.0.44"), ASCIIToUTF16("MyPlugin version 3.0.44")); | 63 ASCIIToUTF16("3.0.44"), ASCIIToUTF16("MyPlugin version 3.0.44")); |
61 static WebPluginInfo kPlugin3045 = WebPluginInfo( | 64 static WebPluginInfo kPlugin3045 = WebPluginInfo( |
62 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.3.0.45")), | 65 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.3.0.45")), |
63 ASCIIToUTF16("3.0.45"), ASCIIToUTF16("MyPlugin version 3.0.45")); | 66 ASCIIToUTF16("3.0.45"), ASCIIToUTF16("MyPlugin version 3.0.45")); |
| 67 static WebPluginInfo kPlugin3045r = WebPluginInfo( |
| 68 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.3.0.45")), |
| 69 ASCIIToUTF16("3.0r45"), ASCIIToUTF16("MyPlugin version 3.0r45")); |
64 static WebPluginInfo kPlugin4043 = WebPluginInfo( | 70 static WebPluginInfo kPlugin4043 = WebPluginInfo( |
65 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.4.0.43")), | 71 ASCIIToUTF16("MyPlugin"), FilePath(FILE_PATH_LITERAL("myplugin.so.4.0.43")), |
66 ASCIIToUTF16("4.0.43"), ASCIIToUTF16("MyPlugin version 4.0.43")); | 72 ASCIIToUTF16("4.0.43"), ASCIIToUTF16("MyPlugin version 4.0.43")); |
67 | 73 |
68 class PluginGroupTest : public testing::Test { | 74 class PluginGroupTest : public testing::Test { |
69 public: | 75 public: |
70 static PluginGroup* CreatePluginGroup( | 76 static PluginGroup* CreatePluginGroup( |
71 const PluginGroupDefinition& definition) { | 77 const PluginGroupDefinition& definition) { |
72 return PluginGroup::FromPluginGroupDefinition(definition); | 78 return PluginGroup::FromPluginGroupDefinition(definition); |
73 } | 79 } |
74 static PluginGroup* CreatePluginGroup(const WebPluginInfo& wpi) { | 80 static PluginGroup* CreatePluginGroup(const WebPluginInfo& wpi) { |
75 return PluginGroup::FromWebPluginInfo(wpi); | 81 return PluginGroup::FromWebPluginInfo(wpi); |
76 } | 82 } |
77 protected: | 83 protected: |
78 virtual void TearDown() { | 84 virtual void TearDown() { |
79 PluginGroup::SetPolicyDisabledPluginPatterns(std::set<string16>()); | 85 PluginGroup::SetPolicyDisabledPluginPatterns(std::set<string16>()); |
80 } | 86 } |
81 }; | 87 }; |
82 | 88 |
83 TEST(PluginGroupTest, PluginGroupMatch) { | 89 TEST(PluginGroupTest, PluginGroupMatch) { |
84 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( | 90 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( |
85 kPluginDef3)); | 91 kPluginDef3)); |
86 EXPECT_TRUE(group->Match(kPlugin3045)); | 92 EXPECT_TRUE(group->Match(kPlugin3045)); |
| 93 EXPECT_TRUE(group->Match(kPlugin3045r)); |
| 94 EXPECT_FALSE(group->Match(kPluginNoVersion)); |
87 group->AddPlugin(kPlugin3045, 0); | 95 group->AddPlugin(kPlugin3045, 0); |
88 EXPECT_FALSE(group->IsVulnerable()); | 96 EXPECT_FALSE(group->IsVulnerable()); |
| 97 |
| 98 group.reset(PluginGroupTest::CreatePluginGroup(kPluginDef)); |
| 99 EXPECT_FALSE(group->Match(kPluginNoVersion)); |
89 } | 100 } |
90 | 101 |
91 TEST(PluginGroupTest, PluginGroupMatchCorrectVersion) { | 102 TEST(PluginGroupTest, PluginGroupMatchCorrectVersion) { |
92 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( | 103 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup( |
93 kPluginDef3)); | 104 kPluginDef3)); |
94 EXPECT_TRUE(group->Match(kPlugin2043)); | 105 EXPECT_TRUE(group->Match(kPlugin2043)); |
95 EXPECT_TRUE(group->Match(kPlugin3043)); | 106 EXPECT_TRUE(group->Match(kPlugin3043)); |
96 EXPECT_FALSE(group->Match(kPlugin4043)); | 107 EXPECT_FALSE(group->Match(kPlugin4043)); |
97 | 108 |
98 group.reset(PluginGroupTest::CreatePluginGroup(kPluginDef4)); | 109 group.reset(PluginGroupTest::CreatePluginGroup(kPluginDef4)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 200 } |
190 | 201 |
191 TEST(PluginGroupTest, VersionExtraction) { | 202 TEST(PluginGroupTest, VersionExtraction) { |
192 // Some real-world plugin versions (spaces, commata, parentheses, 'r', oh my) | 203 // Some real-world plugin versions (spaces, commata, parentheses, 'r', oh my) |
193 const char* versions[][2] = { | 204 const char* versions[][2] = { |
194 { "7.6.6 (1671)", "7.6.6.1671" }, // Quicktime | 205 { "7.6.6 (1671)", "7.6.6.1671" }, // Quicktime |
195 { "2, 0, 0, 254", "2.0.0.254" }, // DivX | 206 { "2, 0, 0, 254", "2.0.0.254" }, // DivX |
196 { "3, 0, 0, 0", "3.0.0.0" }, // Picasa | 207 { "3, 0, 0, 0", "3.0.0.0" }, // Picasa |
197 { "1, 0, 0, 1", "1.0.0.1" }, // Earth | 208 { "1, 0, 0, 1", "1.0.0.1" }, // Earth |
198 { "10,0,45,2", "10.0.45.2" }, // Flash | 209 { "10,0,45,2", "10.0.45.2" }, // Flash |
199 { "11.5.7r609", "11.5.7.609"} // Shockwave | 210 { "11.5.7r609", "11.5.7.609"}, // Shockwave |
| 211 { "10.1 r102", "10.1.102"}, // Flash |
| 212 { "1.6.0_22", "1.6.0.22"}, // Java |
200 }; | 213 }; |
201 | 214 |
202 for (size_t i = 0; i < arraysize(versions); i++) { | 215 for (size_t i = 0; i < arraysize(versions); i++) { |
203 const WebPluginInfo plugin = WebPluginInfo( | 216 const WebPluginInfo plugin = WebPluginInfo( |
204 ASCIIToUTF16("Blah Plugin"), FilePath(FILE_PATH_LITERAL("blahfile")), | 217 ASCIIToUTF16("Blah Plugin"), FilePath(FILE_PATH_LITERAL("blahfile")), |
205 ASCIIToUTF16(versions[i][0]), string16()); | 218 ASCIIToUTF16(versions[i][0]), string16()); |
206 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(plugin)); | 219 scoped_ptr<PluginGroup> group(PluginGroupTest::CreatePluginGroup(plugin)); |
207 EXPECT_TRUE(group->Match(plugin)); | 220 EXPECT_TRUE(group->Match(plugin)); |
208 group->AddPlugin(plugin, 0); | 221 group->AddPlugin(plugin, 0); |
209 scoped_ptr<DictionaryValue> data(group->GetDataForUI()); | 222 scoped_ptr<DictionaryValue> data(group->GetDataForUI()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 WebPluginInfo silverlight_plugin(ASCIIToUTF16("Silverlight"), | 272 WebPluginInfo silverlight_plugin(ASCIIToUTF16("Silverlight"), |
260 FilePath(FILE_PATH_LITERAL("/silver.so")), | 273 FilePath(FILE_PATH_LITERAL("/silver.so")), |
261 ASCIIToUTF16("4.0.50917.0"), | 274 ASCIIToUTF16("4.0.50917.0"), |
262 ASCIIToUTF16("silverlight 4")); | 275 ASCIIToUTF16("silverlight 4")); |
263 group.reset(PluginGroupTest::CreatePluginGroup(silverlight_plugin_def)); | 276 group.reset(PluginGroupTest::CreatePluginGroup(silverlight_plugin_def)); |
264 group->AddPlugin(silverlight_plugin, 0); | 277 group->AddPlugin(silverlight_plugin, 0); |
265 EXPECT_FALSE(PluginGroup(*group).IsVulnerable()); | 278 EXPECT_FALSE(PluginGroup(*group).IsVulnerable()); |
266 } | 279 } |
267 } // namespace npapi | 280 } // namespace npapi |
268 } // namespace webkit | 281 } // namespace webkit |
OLD | NEW |