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

Side by Side Diff: chrome/browser/enumerate_modules_model_unittest_win.cc

Issue 2037883004: [Win] Add reporting of total number of modules loaded in browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move vfunc impls to cc file. Created 4 years, 6 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
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/enumerate_modules_model_win.h" 11 #include "chrome/browser/enumerate_modules_model_win.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 typedef testing::Test EnumerateModulesTest; 14 typedef testing::Test EnumerateModulesTest;
15 15
16 // Set up some constants to use as default when creating the structs. 16 // Set up some constants to use as default when creating the structs.
17 static const ModuleEnumerator::ModuleType kType = 17 static const ModuleEnumerator::ModuleType kType =
18 ModuleEnumerator::LOADED_MODULE; 18 ModuleEnumerator::LOADED_MODULE;
19 19
20 static const ModuleEnumerator::ModuleStatus kStatus = 20 static const ModuleEnumerator::ModuleStatus kStatus =
21 ModuleEnumerator::NOT_MATCHED; 21 ModuleEnumerator::NOT_MATCHED;
22 22
23 static const ModuleEnumerator::RecommendedAction kAction = 23 static const ModuleEnumerator::RecommendedAction kAction =
24 ModuleEnumerator::NONE; 24 ModuleEnumerator::NONE;
25 25
26 static const ModuleEnumerator::OperatingSystem kOs = 26 static const ModuleEnumerator::OperatingSystem kOs =
grt (UTC plus 2) 2016/06/16 18:27:52 cool: clang points out that this is now unused (am
chrisha 2016/06/17 20:48:02 Acknowledged.
27 ModuleEnumerator::ALL; 27 ModuleEnumerator::ALL;
28 28
29 // This is a list of test cases to normalize. 29 // This is a list of test cases to normalize.
30 static const struct NormalizationEntryList { 30 static const struct NormalizationEntryList {
31 ModuleEnumerator::Module test_case; 31 ModuleEnumerator::Module test_case;
32 ModuleEnumerator::Module expected; 32 ModuleEnumerator::Module expected;
33 } kNormalizationTestCases[] = { 33 } kNormalizationTestCases[] = {
34 { 34 {
35 // Only path normalization needed. 35 // Only path normalization needed.
36 {kType, kStatus, L"c:\\foo\\bar.dll", L"", L"Prod", L"Desc", L"1.0", 36 {kType, kStatus, L"c:\\foo\\bar.dll", L"", L"Prod", L"Desc", L"1.0",
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Name, location, description and signature are compared by hashing. 94 // Name, location, description and signature are compared by hashing.
95 static const char kMatchName[] = "88e8c9e0"; // "bar.dll". 95 static const char kMatchName[] = "88e8c9e0"; // "bar.dll".
96 static const char kMatchLocation[] = "e6ca7b1c"; // "c:\\foo\\". 96 static const char kMatchLocation[] = "e6ca7b1c"; // "c:\\foo\\".
97 static const char kNoMatchLocation[] = "c:\\foobar\\"; 97 static const char kNoMatchLocation[] = "c:\\foobar\\";
98 static const char kMatchDesc[] = "5c4419a6"; // "Desc". 98 static const char kMatchDesc[] = "5c4419a6"; // "Desc".
99 static const char kVersionHigh[] = "2.0"; 99 static const char kVersionHigh[] = "2.0";
100 static const char kVersionLow[] = "0.5"; 100 static const char kVersionLow[] = "0.5";
101 static const char kMatchSignature[] = "7bfd87e1"; // "Sig". 101 static const char kMatchSignature[] = "7bfd87e1"; // "Sig".
102 static const char kEmpty[] = ""; 102 static const char kEmpty[] = "";
103 103
104 const struct MatchingEntryList {
105 ModuleEnumerator::ModuleStatus expected_result;
106 ModuleEnumerator::Module test_case;
107 ModuleEnumerator::BlacklistEntry blacklist;
108 } kMatchineEntryList[] = {
109 // Each BlacklistEntry is:
110 // Filename, location, desc_or_signer, version from, version to, help_tip.
111
112 { // Matches: Name (location doesn't match) => Not enough for a match.
113 ModuleEnumerator::NOT_MATCHED,
114 kStandardModule,
115 { kMatchName, kNoMatchLocation, kEmpty, kEmpty, kEmpty, kOs,
116 ModuleEnumerator::SEE_LINK }
117 }, { // Matches: Name (location not given) => Suspected match.
118 ModuleEnumerator::SUSPECTED_BAD,
119 kStandardModule,
120 { kMatchName, kEmpty, kEmpty, kEmpty, kEmpty, kOs,
121 ModuleEnumerator::SEE_LINK }
122 }, { // Matches: Name, not version (location not given) => Not a match.
123 ModuleEnumerator::NOT_MATCHED,
124 kStandardModule,
125 { kMatchName, kEmpty, kEmpty, kVersionHigh, kVersionHigh, kOs,
126 ModuleEnumerator::SEE_LINK }
127 }, { // Matches: Name, location => Suspected match.
128 ModuleEnumerator::SUSPECTED_BAD,
129 kStandardModule,
130 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, kOs,
131 ModuleEnumerator::SEE_LINK }
132 }, { // Matches: Name, location, (description not given) => Confirmed match.
133 ModuleEnumerator::CONFIRMED_BAD,
134 kStandardModuleNoDescription, // Note: No description.
135 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, kOs,
136 ModuleEnumerator::SEE_LINK }
137 }, { // Matches: Name, location, (signature not given) => Confirmed match.
138 ModuleEnumerator::CONFIRMED_BAD,
139 kStandardModuleNoSignature, // Note: No signature.
140 { kMatchName, kMatchLocation, kEmpty, kEmpty, kEmpty, kOs,
141 ModuleEnumerator::SEE_LINK }
142 }, { // Matches: Name, location (not version) => Not a match.
143 ModuleEnumerator::NOT_MATCHED,
144 kStandardModule,
145 { kMatchName, kMatchLocation, kEmpty, kVersionHigh, kVersionLow, kOs,
146 ModuleEnumerator::SEE_LINK }
147 }, { // Matches: Name, location, signature => Confirmed match.
148 ModuleEnumerator::CONFIRMED_BAD,
149 kStandardModule,
150 { kMatchName, kMatchLocation, kMatchSignature, kEmpty, kEmpty, kOs,
151 ModuleEnumerator::SEE_LINK }
152 }, { // Matches: Name, location, signature (not version) => No match.
153 ModuleEnumerator::NOT_MATCHED,
154 kStandardModule,
155 { kMatchName, kMatchLocation, kMatchSignature,
156 kVersionLow, kVersionLow, kOs, ModuleEnumerator::SEE_LINK }
157 }, { // Matches: Name, location, description => Confirmed match.
158 ModuleEnumerator::CONFIRMED_BAD,
159 kStandardModule,
160 { kMatchName, kMatchLocation, kMatchDesc, kEmpty, kEmpty, kOs,
161 ModuleEnumerator::SEE_LINK }
162 }, { // Matches: Name, location, description (not version) => No match.
163 ModuleEnumerator::NOT_MATCHED,
164 kStandardModule,
165 { kMatchName, kMatchLocation, kMatchDesc,
166 kVersionHigh, kVersionHigh, kOs, ModuleEnumerator::SEE_LINK }
167 }, { // Matches: Name, location, signature, version => Confirmed match.
168 ModuleEnumerator::CONFIRMED_BAD,
169 kStandardModule,
170 { kMatchName, kMatchLocation, kMatchSignature,
171 kVersionLow, kVersionHigh, kOs, ModuleEnumerator::SEE_LINK }
172 }, { // Matches: Name, location, signature, version (lower) => Confirmed.
173 ModuleEnumerator::CONFIRMED_BAD,
174 kStandardModule,
175 { kMatchName, kMatchLocation, kMatchSignature,
176 kVersionLow, kEmpty, kOs, ModuleEnumerator::SEE_LINK }
177 }, { // Matches: Name, location, signature, version (upper) => Confirmed.
178 ModuleEnumerator::CONFIRMED_BAD,
179 kStandardModule,
180 { kMatchName, kMatchLocation, kMatchSignature,
181 kEmpty, kVersionHigh, kOs, ModuleEnumerator::SEE_LINK }
182 }, { // Matches: Name, Location, Version lower is inclusive => Confirmed.
183 ModuleEnumerator::CONFIRMED_BAD,
184 kStandardModule,
185 { kMatchName, kMatchLocation, kMatchSignature,
186 "1.0", "2.0", kOs, ModuleEnumerator::SEE_LINK }
187 }, { // Matches: Name, Location, Version higher is exclusive => No match.
188 ModuleEnumerator::NOT_MATCHED,
189 kStandardModule,
190 { kMatchName, kMatchLocation, kEmpty,
191 "0.0", "1.0", kOs, ModuleEnumerator::SEE_LINK }
192 }, { // All empty fields doesn't produce a match.
193 ModuleEnumerator::NOT_MATCHED,
194 { kType, kStatus, L"", L"", L"", L"", L"", L"", ModuleEnumerator::NONE },
195 { "a.dll", "", "", "", "", kOs, ModuleEnumerator::SEE_LINK }
196 },
197 };
198
199 TEST_F(EnumerateModulesTest, MatchFunction) {
200 for (size_t i = 0; i < arraysize(kMatchineEntryList); ++i) {
201 ModuleEnumerator::Module test = kMatchineEntryList[i].test_case;
202 ModuleEnumerator::NormalizeModule(&test);
203 ModuleEnumerator::BlacklistEntry blacklist =
204 kMatchineEntryList[i].blacklist;
205
206 SCOPED_TRACE("Test case no " + base::IntToString(i) +
207 ": '" + base::UTF16ToASCII(test.name) + "'");
208 EXPECT_EQ(kMatchineEntryList[i].expected_result,
209 ModuleEnumerator::Match(test, blacklist));
210 }
211 }
212
213 const struct CollapsePathList { 104 const struct CollapsePathList {
214 base::string16 expected_result; 105 base::string16 expected_result;
215 base::string16 test_case; 106 base::string16 test_case;
216 } kCollapsePathList[] = { 107 } kCollapsePathList[] = {
217 // Negative testing (should not collapse this path). 108 // Negative testing (should not collapse this path).
218 { base::ASCIIToUTF16("c:\\a\\a.dll"), base::ASCIIToUTF16("c:\\a\\a.dll") }, 109 { base::ASCIIToUTF16("c:\\a\\a.dll"), base::ASCIIToUTF16("c:\\a\\a.dll") },
219 // These two are to test that we select the maximum collapsed path. 110 // These two are to test that we select the maximum collapsed path.
220 { base::ASCIIToUTF16("%foo%\\a.dll"), base::ASCIIToUTF16("c:\\foo\\a.dll") }, 111 { base::ASCIIToUTF16("%foo%\\a.dll"), base::ASCIIToUTF16("c:\\foo\\a.dll") },
221 { base::ASCIIToUTF16("%x%\\a.dll"), 112 { base::ASCIIToUTF16("%x%\\a.dll"),
222 base::ASCIIToUTF16("c:\\foo\\bar\\a.dll") }, 113 base::ASCIIToUTF16("c:\\foo\\bar\\a.dll") },
(...skipping 11 matching lines...) Expand all
234 ModuleEnumerator::Module module; 125 ModuleEnumerator::Module module;
235 module.location = kCollapsePathList[i].test_case; 126 module.location = kCollapsePathList[i].test_case;
236 module_enumerator->CollapsePath(&module); 127 module_enumerator->CollapsePath(&module);
237 128
238 SCOPED_TRACE("Test case no " + base::IntToString(i) + ": '" + 129 SCOPED_TRACE("Test case no " + base::IntToString(i) + ": '" +
239 base::UTF16ToASCII(kCollapsePathList[i].expected_result) + 130 base::UTF16ToASCII(kCollapsePathList[i].expected_result) +
240 "'"); 131 "'");
241 EXPECT_EQ(kCollapsePathList[i].expected_result, module.location); 132 EXPECT_EQ(kCollapsePathList[i].expected_result, module.location);
242 } 133 }
243 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698