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

Unified Diff: chrome/browser/conflicts/module_info_util_win_unittest.cc

Issue 2720513005: Add InspectModule() that returns a populated ModuleInspectionResult struct (Closed)
Patch Set: Another Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/conflicts/module_info_util_win.cc ('k') | chrome/browser/conflicts/module_info_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/conflicts/module_info_util_win_unittest.cc
diff --git a/chrome/browser/conflicts/module_info_util_win_unittest.cc b/chrome/browser/conflicts/module_info_util_win_unittest.cc
index 4de2a22ce2c51a689e7e27be211abad76f483f52..bc3da2983949aeb20ede4c3030fdfdc35424a209 100644
--- a/chrome/browser/conflicts/module_info_util_win_unittest.cc
+++ b/chrome/browser/conflicts/module_info_util_win_unittest.cc
@@ -14,6 +14,46 @@
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+// Overrides |variables_name| to |value| for the lifetime of this class. Upon
+// destruction, the previous value is restored.
+class ScopedEnvironmentVariableOverride {
+ public:
+ ScopedEnvironmentVariableOverride(const std::string& variable_name,
+ const std::string& value);
+ ~ScopedEnvironmentVariableOverride();
+
+ private:
+ std::unique_ptr<base::Environment> environment_;
+ std::string variable_name_;
+ bool overridden_;
+ bool was_set_;
+ std::string old_value_;
+};
+
+ScopedEnvironmentVariableOverride::ScopedEnvironmentVariableOverride(
+ const std::string& variable_name,
+ const std::string& value)
+ : environment_(base::Environment::Create()),
+ variable_name_(variable_name),
+ overridden_(false),
+ was_set_(false) {
+ was_set_ = environment_->GetVar(variable_name, &old_value_);
+ overridden_ = environment_->SetVar(variable_name, value);
+}
+
+ScopedEnvironmentVariableOverride::~ScopedEnvironmentVariableOverride() {
+ if (overridden_) {
+ if (was_set_)
+ environment_->SetVar(variable_name_, old_value_);
+ else
+ environment_->UnSetVar(variable_name_);
+ }
+}
+
+} // namespace
+
TEST(ModuleInfoUtilTest, GetCertificateInfoUnsigned) {
base::FilePath path;
ASSERT_TRUE(base::PathService::Get(base::FILE_EXE, &path));
@@ -38,3 +78,46 @@ TEST(ModuleInfoUtilTest, GetCertificateInfoSigned) {
EXPECT_FALSE(cert_info.path.empty());
EXPECT_FALSE(cert_info.subject.empty());
}
+
+TEST(ModuleInfoUtilTest, GetEnvironmentVariablesMapping) {
+ ScopedEnvironmentVariableOverride scoped_override("foo", "C:\\bar\\");
+
+ // The mapping for these variables will be retrieved.
+ std::vector<base::string16> environment_variables = {
+ L"foo", L"SYSTEMROOT",
+ };
+ StringMapping string_mapping =
+ GetEnvironmentVariablesMapping(environment_variables);
+
+ ASSERT_EQ(2u, string_mapping.size());
+
+ EXPECT_STREQ(L"c:\\bar", string_mapping[0].first.c_str());
+ EXPECT_STREQ(L"%foo%", string_mapping[0].second.c_str());
+ EXPECT_FALSE(string_mapping[1].second.empty());
+}
+
+const struct CollapsePathList {
+ base::string16 expected_result;
+ base::string16 test_case;
+} kCollapsePathList[] = {
+ // Negative testing (should not collapse this path).
+ {L"c:\\a\\a.dll", L"c:\\a\\a.dll"},
+ // These two are to test that we select the maximum collapsed path.
+ {L"%foo%\\a.dll", L"c:\\foo\\a.dll"},
+ {L"%x%\\a.dll", L"c:\\foo\\bar\\a.dll"},
+ // Tests that only full path components are collapsed.
+ {L"c:\\foo_bar\\a.dll", L"c:\\foo_bar\\a.dll"},
+};
+
+TEST(ModuleInfoUtilTest, CollapseMatchingPrefixInPath) {
+ StringMapping string_mapping = {
+ std::make_pair(L"c:\\foo", L"%foo%"),
+ std::make_pair(L"c:\\foo\\bar", L"%x%"),
+ };
+
+ for (size_t i = 0; i < arraysize(kCollapsePathList); ++i) {
+ base::string16 test_case = kCollapsePathList[i].test_case;
+ CollapseMatchingPrefixInPath(string_mapping, &test_case);
+ EXPECT_EQ(kCollapsePathList[i].expected_result, test_case);
+ }
+}
« no previous file with comments | « chrome/browser/conflicts/module_info_util_win.cc ('k') | chrome/browser/conflicts/module_info_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698