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

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

Issue 2720513005: Add InspectModule() that returns a populated ModuleInspectionResult struct (Closed)
Patch Set: a Created 3 years, 10 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
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..4065592a270f1b5d9dff683d226ef215312e5134 100644
--- a/chrome/browser/conflicts/module_info_util_win_unittest.cc
+++ b/chrome/browser/conflicts/module_info_util_win_unittest.cc
@@ -14,6 +14,44 @@
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+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 +76,44 @@ TEST(ModuleInfoUtilTest, GetCertificateInfoSigned) {
EXPECT_FALSE(cert_info.path.empty());
EXPECT_FALSE(cert_info.subject.empty());
}
+
+TEST(ModuleInfoUtilTest, GetEnvironmentVariablesMapping) {
+ ScopedEnvironmentVariableOverride scoped_override("foo", "bar");
+
+ // The mapping for these variables will be retrived.
chrisha 2017/02/28 18:51:29 retrieved
Patrick Monette 2017/02/28 23:37:38 Done.
+ std::vector<base::string16> environment_variables = {
+ L"foo", L"SYSTEMROOT",
+ };
+ StringMapping string_mapping =
+ GetEnvironmentVariablesMapping(environment_variables);
+
+ ASSERT_EQ(2, string_mapping.size());
+
+ EXPECT_STREQ(L"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.
chrisha 2017/02/28 18:51:29 I don't think we actually want this logic.
Patrick Monette 2017/02/28 23:37:38 Chatted offline. Ignored.
+ {L"%foo%\\a.dll", L"c:\\foo\\a.dll"},
+ {L"%x%\\a.dll", L"c:\\foo\\bar\\a.dll"},
+};
+
+TEST(ModuleInfoUtilTest, CollapseMatchingPrefixInString) {
+ 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;
+ CollapseMatchingPrefixInString(string_mapping, &test_case);
+ EXPECT_EQ(kCollapsePathList[i].expected_result, test_case);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698