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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/enumerate_modules_model_win.h" | 8 #include "chrome/browser/enumerate_modules_model_win.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 typedef testing::Test EnumerateModulesTest; | 11 typedef testing::Test EnumerateModulesTest; |
12 | 12 |
13 // Set up some constants to use as default when creating the structs. | 13 // Set up some constants to use as default when creating the structs. |
14 static const ModuleEnumerator::ModuleType kType = | 14 static const ModuleEnumerator::ModuleType kType = |
15 ModuleEnumerator::LOADED_MODULE; | 15 ModuleEnumerator::LOADED_MODULE; |
16 | 16 |
17 static const ModuleEnumerator::ModuleStatus kStatus = | 17 static const ModuleEnumerator::ModuleStatus kStatus = |
18 ModuleEnumerator::NOT_MATCHED; | 18 ModuleEnumerator::NOT_MATCHED; |
19 | 19 |
20 static const ModuleEnumerator::RecommendedAction kAction = | 20 static const ModuleEnumerator::RecommendedAction kAction = |
21 ModuleEnumerator::NONE; | 21 ModuleEnumerator::NONE; |
22 | 22 |
| 23 static const ModuleEnumerator::OperatingSystem kOs = |
| 24 ModuleEnumerator::ALL; |
| 25 |
23 // This is a list of test cases to normalize. | 26 // This is a list of test cases to normalize. |
24 static const struct NormalizationEntryList { | 27 static const struct NormalizationEntryList { |
25 ModuleEnumerator::Module test_case; | 28 ModuleEnumerator::Module test_case; |
26 ModuleEnumerator::Module expected; | 29 ModuleEnumerator::Module expected; |
27 } kNormalizationTestCases[] = { | 30 } kNormalizationTestCases[] = { |
28 { | 31 { |
29 // Only path normalization needed. | 32 // Only path normalization needed. |
30 {kType, kStatus, L"c:\\foo\\bar.dll", L"", L"Prod", L"Desc", L"1.0", | 33 {kType, kStatus, L"c:\\foo\\bar.dll", L"", L"Prod", L"Desc", L"1.0", |
31 L"Sig", kAction}, | 34 L"Sig", kAction}, |
32 {kType, kStatus, L"c:\\foo\\", L"bar.dll", L"Prod", L"Desc", L"1.0", | 35 {kType, kStatus, L"c:\\foo\\", L"bar.dll", L"Prod", L"Desc", L"1.0", |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 ModuleEnumerator::ModuleStatus expected_result; | 105 ModuleEnumerator::ModuleStatus expected_result; |
103 ModuleEnumerator::Module test_case; | 106 ModuleEnumerator::Module test_case; |
104 ModuleEnumerator::BlacklistEntry blacklist; | 107 ModuleEnumerator::BlacklistEntry blacklist; |
105 } kMatchineEntryList[] = { | 108 } kMatchineEntryList[] = { |
106 // Each BlacklistEntry is: | 109 // Each BlacklistEntry is: |
107 // Filename, location, desc_or_signer, version from, version to, help_tip. | 110 // Filename, location, desc_or_signer, version from, version to, help_tip. |
108 | 111 |
109 { // Matches: Name (location doesn't match) => Not enough for a match. | 112 { // Matches: Name (location doesn't match) => Not enough for a match. |
110 ModuleEnumerator::NOT_MATCHED, | 113 ModuleEnumerator::NOT_MATCHED, |
111 kStandardModule, | 114 kStandardModule, |
112 { kMatchName, kNoMatchLocation, kEmpty, kEmpty, kEmpty, | 115 { kMatchName, kNoMatchLocation, kEmpty, kEmpty, kEmpty, kOs, |
113 ModuleEnumerator::SEE_LINK } | 116 ModuleEnumerator::SEE_LINK } |
114 }, { // Matches: Name (location not given) => Suspected match. | 117 }, { // Matches: Name (location not given) => Suspected match. |
115 ModuleEnumerator::SUSPECTED_BAD, | 118 ModuleEnumerator::SUSPECTED_BAD, |
116 kStandardModule, | 119 kStandardModule, |
117 { kMatchName, kEmpty, kEmpty, kEmpty, kEmpty, | 120 { kMatchName, kEmpty, kEmpty, kEmpty, kEmpty, kOs, |
118 ModuleEnumerator::SEE_LINK } | 121 ModuleEnumerator::SEE_LINK } |
119 }, { // Matches: Name, not version (location not given) => Not a match. | 122 }, { // Matches: Name, not version (location not given) => Not a match. |
120 ModuleEnumerator::NOT_MATCHED, | 123 ModuleEnumerator::NOT_MATCHED, |
121 kStandardModule, | 124 kStandardModule, |
122 { kMatchName, kEmpty, kEmpty, kVersionHigh, kVersionHigh, | 125 { kMatchName, kEmpty, kEmpty, kVersionHigh, kVersionHigh, kOs, |
123 ModuleEnumerator::SEE_LINK } | 126 ModuleEnumerator::SEE_LINK } |
124 }, { // Matches: Name, location => Suspected match. | 127 }, { // Matches: Name, location => Suspected match. |
125 ModuleEnumerator::SUSPECTED_BAD, | 128 ModuleEnumerator::SUSPECTED_BAD, |
126 kStandardModule, | 129 kStandardModule, |
127 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, | 130 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, kOs, |
128 ModuleEnumerator::SEE_LINK } | 131 ModuleEnumerator::SEE_LINK } |
129 }, { // Matches: Name, location, (description not given) => Confirmed match. | 132 }, { // Matches: Name, location, (description not given) => Confirmed match. |
130 ModuleEnumerator::CONFIRMED_BAD, | 133 ModuleEnumerator::CONFIRMED_BAD, |
131 kStandardModuleNoDescription, // Note: No description. | 134 kStandardModuleNoDescription, // Note: No description. |
132 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, | 135 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, kOs, |
133 ModuleEnumerator::SEE_LINK } | 136 ModuleEnumerator::SEE_LINK } |
134 }, { // Matches: Name, location, (signature not given) => Confirmed match. | 137 }, { // Matches: Name, location, (signature not given) => Confirmed match. |
135 ModuleEnumerator::CONFIRMED_BAD, | 138 ModuleEnumerator::CONFIRMED_BAD, |
136 kStandardModuleNoSignature, // Note: No signature. | 139 kStandardModuleNoSignature, // Note: No signature. |
137 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, | 140 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, kOs, |
138 ModuleEnumerator::SEE_LINK } | 141 ModuleEnumerator::SEE_LINK } |
139 }, { // Matches: Name, location (not version) => Not a match. | 142 }, { // Matches: Name, location (not version) => Not a match. |
140 ModuleEnumerator::NOT_MATCHED, | 143 ModuleEnumerator::NOT_MATCHED, |
141 kStandardModule, | 144 kStandardModule, |
142 { kMatchName, kMatchLocation, kEmpty, kVersionHigh, kVersionLow, | 145 { kMatchName, kMatchLocation, kEmpty, kVersionHigh, kVersionLow, kOs, |
143 ModuleEnumerator::SEE_LINK } | 146 ModuleEnumerator::SEE_LINK } |
144 }, { // Matches: Name, location, signature => Confirmed match. | 147 }, { // Matches: Name, location, signature => Confirmed match. |
145 ModuleEnumerator::CONFIRMED_BAD, | 148 ModuleEnumerator::CONFIRMED_BAD, |
146 kStandardModule, | 149 kStandardModule, |
147 { kMatchName, kMatchLocation, kMatchSignature, kEmpty, kEmpty, | 150 { kMatchName, kMatchLocation, kMatchSignature, kEmpty, kEmpty, kOs, |
148 ModuleEnumerator::SEE_LINK } | 151 ModuleEnumerator::SEE_LINK } |
149 }, { // Matches: Name, location, signature (not version) => No match. | 152 }, { // Matches: Name, location, signature (not version) => No match. |
150 ModuleEnumerator::NOT_MATCHED, | 153 ModuleEnumerator::NOT_MATCHED, |
151 kStandardModule, | 154 kStandardModule, |
152 { kMatchName, kMatchLocation, kMatchSignature, | 155 { kMatchName, kMatchLocation, kMatchSignature, |
153 kVersionLow, kVersionLow, ModuleEnumerator::SEE_LINK } | 156 kVersionLow, kVersionLow, kOs, ModuleEnumerator::SEE_LINK } |
154 }, { // Matches: Name, location, description => Confirmed match. | 157 }, { // Matches: Name, location, description => Confirmed match. |
155 ModuleEnumerator::CONFIRMED_BAD, | 158 ModuleEnumerator::CONFIRMED_BAD, |
156 kStandardModule, | 159 kStandardModule, |
157 { kMatchName, kMatchLocation, kMatchDesc, kEmpty, kEmpty, | 160 { kMatchName, kMatchLocation, kMatchDesc, kEmpty, kEmpty, kOs, |
158 ModuleEnumerator::SEE_LINK } | 161 ModuleEnumerator::SEE_LINK } |
159 }, { // Matches: Name, location, description (not version) => No match. | 162 }, { // Matches: Name, location, description (not version) => No match. |
160 ModuleEnumerator::NOT_MATCHED, | 163 ModuleEnumerator::NOT_MATCHED, |
161 kStandardModule, | 164 kStandardModule, |
162 { kMatchName, kMatchLocation, kMatchDesc, | 165 { kMatchName, kMatchLocation, kMatchDesc, |
163 kVersionHigh, kVersionHigh, ModuleEnumerator::SEE_LINK } | 166 kVersionHigh, kVersionHigh, kOs, ModuleEnumerator::SEE_LINK } |
164 }, { // Matches: Name, location, signature, version => Confirmed match. | 167 }, { // Matches: Name, location, signature, version => Confirmed match. |
165 ModuleEnumerator::CONFIRMED_BAD, | 168 ModuleEnumerator::CONFIRMED_BAD, |
166 kStandardModule, | 169 kStandardModule, |
167 { kMatchName, kMatchLocation, kMatchSignature, | 170 { kMatchName, kMatchLocation, kMatchSignature, |
168 kVersionLow, kVersionHigh, ModuleEnumerator::SEE_LINK } | 171 kVersionLow, kVersionHigh, kOs, ModuleEnumerator::SEE_LINK } |
169 }, { // Matches: Name, location, signature, version (lower) => Confirmed. | 172 }, { // Matches: Name, location, signature, version (lower) => Confirmed. |
170 ModuleEnumerator::CONFIRMED_BAD, | 173 ModuleEnumerator::CONFIRMED_BAD, |
171 kStandardModule, | 174 kStandardModule, |
172 { kMatchName, kMatchLocation, kMatchSignature, | 175 { kMatchName, kMatchLocation, kMatchSignature, |
173 kVersionLow, kEmpty, ModuleEnumerator::SEE_LINK } | 176 kVersionLow, kEmpty, kOs, ModuleEnumerator::SEE_LINK } |
174 }, { // Matches: Name, location, signature, version (upper) => Confirmed. | 177 }, { // Matches: Name, location, signature, version (upper) => Confirmed. |
175 ModuleEnumerator::CONFIRMED_BAD, | 178 ModuleEnumerator::CONFIRMED_BAD, |
176 kStandardModule, | 179 kStandardModule, |
177 { kMatchName, kMatchLocation, kMatchSignature, | 180 { kMatchName, kMatchLocation, kMatchSignature, |
178 kEmpty, kVersionHigh, ModuleEnumerator::SEE_LINK } | 181 kEmpty, kVersionHigh, kOs, ModuleEnumerator::SEE_LINK } |
179 }, { // Matches: Name, Location, Version lower is inclusive => Confirmed. | 182 }, { // Matches: Name, Location, Version lower is inclusive => Confirmed. |
180 ModuleEnumerator::CONFIRMED_BAD, | 183 ModuleEnumerator::CONFIRMED_BAD, |
181 kStandardModule, | 184 kStandardModule, |
182 { kMatchName, kMatchLocation, kMatchSignature, | 185 { kMatchName, kMatchLocation, kMatchSignature, |
183 "1.0", "2.0", ModuleEnumerator::SEE_LINK } | 186 "1.0", "2.0", kOs, ModuleEnumerator::SEE_LINK } |
184 }, { // Matches: Name, Location, Version higher is exclusive => No match. | 187 }, { // Matches: Name, Location, Version higher is exclusive => No match. |
185 ModuleEnumerator::NOT_MATCHED, | 188 ModuleEnumerator::NOT_MATCHED, |
186 kStandardModule, | 189 kStandardModule, |
187 { kMatchName, kMatchLocation, kEmpty, | 190 { kMatchName, kMatchLocation, kEmpty, |
188 "0.0", "1.0", ModuleEnumerator::SEE_LINK } | 191 "0.0", "1.0", kOs, ModuleEnumerator::SEE_LINK } |
189 }, { // All empty fields doesn't produce a match. | 192 }, { // All empty fields doesn't produce a match. |
190 ModuleEnumerator::NOT_MATCHED, | 193 ModuleEnumerator::NOT_MATCHED, |
191 { kType, kStatus, L"", L"", L"", L"", L""}, | 194 { kType, kStatus, L"", L"", L"", L"", L""}, |
192 { "a.dll", "", "", "", "", ModuleEnumerator::SEE_LINK } | 195 { "a.dll", "", "", "", "", kOs, ModuleEnumerator::SEE_LINK } |
193 }, | 196 }, |
194 }; | 197 }; |
195 | 198 |
196 TEST_F(EnumerateModulesTest, MatchFunction) { | 199 TEST_F(EnumerateModulesTest, MatchFunction) { |
197 for (size_t i = 0; i < arraysize(kMatchineEntryList); ++i) { | 200 for (size_t i = 0; i < arraysize(kMatchineEntryList); ++i) { |
198 ModuleEnumerator::Module test = kMatchineEntryList[i].test_case; | 201 ModuleEnumerator::Module test = kMatchineEntryList[i].test_case; |
199 ModuleEnumerator::NormalizeModule(&test); | 202 ModuleEnumerator::NormalizeModule(&test); |
200 ModuleEnumerator::BlacklistEntry blacklist = | 203 ModuleEnumerator::BlacklistEntry blacklist = |
201 kMatchineEntryList[i].blacklist; | 204 kMatchineEntryList[i].blacklist; |
202 | 205 |
(...skipping 27 matching lines...) Expand all Loading... |
230 ModuleEnumerator::Module module; | 233 ModuleEnumerator::Module module; |
231 module.location = kCollapsePathList[i].test_case; | 234 module.location = kCollapsePathList[i].test_case; |
232 module_enumerator->CollapsePath(&module); | 235 module_enumerator->CollapsePath(&module); |
233 | 236 |
234 SCOPED_TRACE("Test case no " + base::IntToString(i) + | 237 SCOPED_TRACE("Test case no " + base::IntToString(i) + |
235 ": '" + UTF16ToASCII(kCollapsePathList[i].expected_result) + | 238 ": '" + UTF16ToASCII(kCollapsePathList[i].expected_result) + |
236 "'"); | 239 "'"); |
237 EXPECT_EQ(kCollapsePathList[i].expected_result, module.location); | 240 EXPECT_EQ(kCollapsePathList[i].expected_result, module.location); |
238 } | 241 } |
239 } | 242 } |
OLD | NEW |