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

Side by Side Diff: chrome/common/plugin_group_unittest.cc

Issue 2955005: Factor out PluginGroup into a separate class in common/. (Closed)
Patch Set: baseline updates Created 10 years, 5 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
« no previous file with comments | « chrome/common/plugin_group.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 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 "chrome/browser/plugin_updater.h" 5 #include "chrome/common/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/values.h"
12 #include "base/version.h" 13 #include "base/version.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/glue/plugins/webplugininfo.h" 15 #include "webkit/glue/plugins/webplugininfo.h"
15 16
16 static const PluginGroupDefinition kPluginDef = { 17 static const PluginGroupDefinition kPluginDef = {
17 "MyPlugin", "MyPlugin", "", "", "3.0.44", "http://latest/" }; 18 "MyPlugin", "MyPlugin", "", "", "3.0.44", "http://latest/" };
18 static const PluginGroupDefinition kPluginDef3 = { 19 static const PluginGroupDefinition kPluginDef3 = {
19 "MyPlugin 3", "MyPlugin", "0", "4", "3.0.44", "http://latest" }; 20 "MyPlugin 3", "MyPlugin", "0", "4", "3.0.44", "http://latest" };
20 static const PluginGroupDefinition kPluginDef4 = { 21 static const PluginGroupDefinition kPluginDef4 = {
21 "MyPlugin 4", "MyPlugin", "4", "5", "4.0.44", "http://latest" }; 22 "MyPlugin 4", "MyPlugin", "4", "5", "4.0.44", "http://latest" };
(...skipping 10 matching lines...) Expand all
32 static WebPluginInfo kPlugin3044 = { 33 static WebPluginInfo kPlugin3044 = {
33 ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("3.0.44"), string16(), 34 ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("3.0.44"), string16(),
34 std::vector<WebPluginMimeType>(), true }; 35 std::vector<WebPluginMimeType>(), true };
35 static WebPluginInfo kPlugin3045 = { 36 static WebPluginInfo kPlugin3045 = {
36 ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("3.0.45"), string16(), 37 ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("3.0.45"), string16(),
37 std::vector<WebPluginMimeType>(), true }; 38 std::vector<WebPluginMimeType>(), true };
38 static WebPluginInfo kPlugin4043 = { 39 static WebPluginInfo kPlugin4043 = {
39 ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("4.0.43"), string16(), 40 ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("4.0.43"), string16(),
40 std::vector<WebPluginMimeType>(), true }; 41 std::vector<WebPluginMimeType>(), true };
41 42
42 class PluginUpdaterTest : public testing::Test { 43 class PluginGroupTest : public testing::Test {
43 }; 44 };
44 45
45 TEST(PluginUpdaterTest, PluginGroupMatch) { 46 TEST(PluginGroupTest, PluginGroupMatch) {
46 scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition( 47 scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
47 kPluginDef3)); 48 kPluginDef3));
48 EXPECT_TRUE(group->Match(kPlugin3045)); 49 EXPECT_TRUE(group->Match(kPlugin3045));
49 group->AddPlugin(kPlugin3045, 0); 50 group->AddPlugin(kPlugin3045, 0);
50 EXPECT_FALSE(group->IsVulnerable()); 51 EXPECT_FALSE(group->IsVulnerable());
51 } 52 }
52 53
53 TEST(PluginUpdaterTest, PluginGroupMatchMultipleFiles) { 54 TEST(PluginGroupTest, PluginGroupMatchMultipleFiles) {
54 scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition( 55 scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
55 kPluginDef3)); 56 kPluginDef3));
56 EXPECT_TRUE(group->Match(kPlugin3043)); 57 EXPECT_TRUE(group->Match(kPlugin3043));
57 group->AddPlugin(kPlugin3043, 0); 58 group->AddPlugin(kPlugin3043, 0);
58 EXPECT_TRUE(group->IsVulnerable()); 59 EXPECT_TRUE(group->IsVulnerable());
59 60
60 EXPECT_TRUE(group->Match(kPlugin3045)); 61 EXPECT_TRUE(group->Match(kPlugin3045));
61 group->AddPlugin(kPlugin3045, 1); 62 group->AddPlugin(kPlugin3045, 1);
62 EXPECT_FALSE(group->IsVulnerable()); 63 EXPECT_FALSE(group->IsVulnerable());
63 } 64 }
64 65
65 TEST(PluginUpdaterTest, PluginGroupMatchCorrectVersion) { 66 TEST(PluginGroupTest, PluginGroupMatchCorrectVersion) {
66 scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition( 67 scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
67 kPluginDef3)); 68 kPluginDef3));
68 EXPECT_TRUE(group->Match(kPlugin2043)); 69 EXPECT_TRUE(group->Match(kPlugin2043));
69 EXPECT_TRUE(group->Match(kPlugin3043)); 70 EXPECT_TRUE(group->Match(kPlugin3043));
70 EXPECT_FALSE(group->Match(kPlugin4043)); 71 EXPECT_FALSE(group->Match(kPlugin4043));
71 72
72 group.reset(PluginGroup::FromPluginGroupDefinition(kPluginDef4)); 73 group.reset(PluginGroup::FromPluginGroupDefinition(kPluginDef4));
73 EXPECT_FALSE(group->Match(kPlugin2043)); 74 EXPECT_FALSE(group->Match(kPlugin2043));
74 EXPECT_FALSE(group->Match(kPlugin3043)); 75 EXPECT_FALSE(group->Match(kPlugin3043));
75 EXPECT_TRUE(group->Match(kPlugin4043)); 76 EXPECT_TRUE(group->Match(kPlugin4043));
76 } 77 }
77 78
78 TEST(PluginUpdaterTest, PluginGroupDefinition) { 79 TEST(PluginGroupTest, PluginGroupDefinition) {
79 const PluginGroupDefinition* definitions = 80 const PluginGroupDefinition* definitions =
80 PluginUpdater::GetPluginGroupDefinitions(); 81 PluginGroup::GetPluginGroupDefinitions();
81 for (size_t i = 0; i < PluginUpdater::GetPluginGroupDefinitionsSize(); ++i) { 82 for (size_t i = 0; i < PluginGroup::GetPluginGroupDefinitionsSize(); ++i) {
82 scoped_ptr<PluginGroup> def_group( 83 scoped_ptr<PluginGroup> def_group(
83 PluginGroup::FromPluginGroupDefinition(definitions[i])); 84 PluginGroup::FromPluginGroupDefinition(definitions[i]));
84 ASSERT_TRUE(def_group.get() != NULL); 85 ASSERT_TRUE(def_group.get() != NULL);
85 EXPECT_FALSE(def_group->Match(kPlugin2043)); 86 EXPECT_FALSE(def_group->Match(kPlugin2043));
86 } 87 }
87 } 88 }
88 89
89 TEST(PluginUpdaterTest, VersionExtraction) { 90 TEST(PluginGroupTest, VersionExtraction) {
90 // Some real-world plugin versions (spaces, commata, parentheses, 'r', oh my) 91 // Some real-world plugin versions (spaces, commata, parentheses, 'r', oh my)
91 const char* versions[][2] = { 92 const char* versions[][2] = {
92 { "7.6.6 (1671)", "7.6.6.1671" }, // Quicktime 93 { "7.6.6 (1671)", "7.6.6.1671" }, // Quicktime
93 { "2, 0, 0, 254", "2.0.0.254" }, // DivX 94 { "2, 0, 0, 254", "2.0.0.254" }, // DivX
94 { "3, 0, 0, 0", "3.0.0.0" }, // Picasa 95 { "3, 0, 0, 0", "3.0.0.0" }, // Picasa
95 { "1, 0, 0, 1", "1.0.0.1" }, // Earth 96 { "1, 0, 0, 1", "1.0.0.1" }, // Earth
96 { "10,0,45,2", "10.0.45.2" }, // Flash 97 { "10,0,45,2", "10.0.45.2" }, // Flash
97 { "11.5.7r609", "11.5.7.609"} // Shockwave 98 { "11.5.7r609", "11.5.7.609"} // Shockwave
98 }; 99 };
99 100
100 for (size_t i = 0; i < arraysize(versions); i++) { 101 for (size_t i = 0; i < arraysize(versions); i++) {
101 const WebPluginInfo plugin = { 102 const WebPluginInfo plugin = {
102 ASCIIToUTF16("Blah Plugin"), FilePath(), ASCIIToUTF16(versions[i][0]), 103 ASCIIToUTF16("Blah Plugin"), FilePath(), ASCIIToUTF16(versions[i][0]),
103 string16(),std::vector<WebPluginMimeType>(), true }; 104 string16(),std::vector<WebPluginMimeType>(), true };
104 scoped_ptr<PluginGroup> group(PluginGroup::FromWebPluginInfo(plugin)); 105 scoped_ptr<PluginGroup> group(PluginGroup::FromWebPluginInfo(plugin));
105 EXPECT_TRUE(group->Match(plugin)); 106 EXPECT_TRUE(group->Match(plugin));
106 group->AddPlugin(plugin, 0); 107 group->AddPlugin(plugin, 0);
107 scoped_ptr<DictionaryValue> data(group->GetData()); 108 scoped_ptr<DictionaryValue> data(group->GetDataForUI());
108 std::string version; 109 std::string version;
109 data->GetString(L"version", &version); 110 data->GetString(L"version", &version);
110 EXPECT_EQ(versions[i][1], version); 111 EXPECT_EQ(versions[i][1], version);
111 } 112 }
112 } 113 }
OLDNEW
« no previous file with comments | « chrome/common/plugin_group.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698