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

Unified Diff: chrome_elf/chrome_elf_util_unittest.cc

Issue 1841573002: [Chrome ELF] New NT registry API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit fixes & CreateRegKey now recursive. 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 side-by-side diff with in-line comments
Download patch
Index: chrome_elf/chrome_elf_util_unittest.cc
diff --git a/chrome_elf/chrome_elf_util_unittest.cc b/chrome_elf/chrome_elf_util_unittest.cc
index 210901e82106a9a39d916c12692a0c83f83b7a44..b0193f97ec5a4e1012fbfb93631765ffe624bb17 100644
--- a/chrome_elf/chrome_elf_util_unittest.cc
+++ b/chrome_elf/chrome_elf_util_unittest.cc
@@ -3,10 +3,14 @@
// found in the LICENSE file.
#include <tuple>
+#include <windows.h>
+#include <versionhelpers.h> // windows.h must be before.
#include "base/test/test_reg_util_win.h"
#include "base/win/registry.h"
#include "chrome/install_static/install_util.h"
+#include "chrome_elf/chrome_elf_constants.h"
+#include "chrome_elf/nt_registry/nt_registry.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -41,18 +45,92 @@ TEST(ChromeElfUtilTest, BrowserProcessTest) {
EXPECT_FALSE(IsNonBrowserProcess());
}
+//------------------------------------------------------------------------------
+// NT registry API tests (chrome_elf_reg)
+//------------------------------------------------------------------------------
+
+TEST(ChromeElfUtilTest, NTRegistry) {
+ HANDLE key_handle;
+ const wchar_t* dword_val_name = L"DwordTestValue";
+ DWORD dword_val = 1234;
+ const wchar_t* sz_val_name = L"SzTestValue";
+ base::string16 sz_val = L"blah de blah de blahhhhh.";
+ const wchar_t* sz_val_name2 = L"SzTestValueEmpty";
+ base::string16 sz_val2 = L"";
+ const wchar_t* multisz_val_name = L"SzmultiTestValue";
+ std::vector<base::string16> multisz_val;
+ base::string16 multi1 = L"one";
+ base::string16 multi2 = L"two";
+ base::string16 multi3 = L"three";
+ const wchar_t* multisz_val_name2 = L"SzmultiTestValueBad";
+ base::string16 multi_empty = L"";
+
+ // Create a temp key to play under.
+ ASSERT_TRUE(nt::CreateRegKey(nt::AUTO, elf_sec::kRegSecurityPath,
+ KEY_ALL_ACCESS, &key_handle));
+
+ // Exercise the supported getter & setter functions.
+ EXPECT_TRUE(nt::SetRegValueDWORD(key_handle, dword_val_name, dword_val));
+ EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name, sz_val));
+ EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name2, sz_val2));
+
+ DWORD get_dword = 0;
+ base::string16 get_sz;
+ EXPECT_TRUE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword) &&
+ get_dword == dword_val);
+ EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz) &&
+ get_sz.compare(sz_val) == 0);
+ EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name2, &get_sz) &&
+ get_sz.compare(sz_val2) == 0);
+
+ multisz_val.push_back(multi1);
+ multisz_val.push_back(multi2);
+ multisz_val.push_back(multi3);
+ EXPECT_TRUE(
+ nt::SetRegValueMULTISZ(key_handle, multisz_val_name, multisz_val));
+ multisz_val.clear();
+ multisz_val.push_back(multi_empty);
+ EXPECT_TRUE(
+ nt::SetRegValueMULTISZ(key_handle, multisz_val_name2, multisz_val));
+ multisz_val.clear();
+
+ EXPECT_TRUE(
+ nt::QueryRegValueMULTISZ(key_handle, multisz_val_name, &multisz_val));
+ if (multisz_val.size() == 3) {
+ EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0);
+ EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0);
+ EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0);
+ } else {
+ EXPECT_TRUE(false);
+ }
+ multisz_val.clear();
+
+ EXPECT_TRUE(
+ nt::QueryRegValueMULTISZ(key_handle, multisz_val_name2, &multisz_val));
+ if (multisz_val.size() == 1) {
+ EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0);
+ } else {
+ EXPECT_TRUE(false);
+ }
+ multisz_val.clear();
+
+ // Clean up
+ EXPECT_TRUE(nt::DeleteRegKey(key_handle));
+ nt::CloseRegKey(key_handle);
+}
+
// Parameterized test with paramters:
// 1: product: "canary" or "google"
// 2: install level: "user" or "system"
// 3: install mode: "single" or "multi"
-class ChromeElfUtilTest :
- public testing::TestWithParam<std::tuple<const char*,
- const char*,
- const char*> > {
+class ChromeElfUtilTest
+ : public testing::TestWithParam<
+ std::tuple<const char*, const char*, const char*>> {
protected:
void SetUp() override {
- override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
- override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
+ override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, &nt::HKLM_override);
+ override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &nt::HKCU_override);
+
const char* app;
const char* level;
const char* mode;
@@ -67,8 +145,8 @@ class ChromeElfUtilTest :
chrome_path_ = kCanaryExePath;
} else {
app_guid_ = kAppGuidGoogleChrome;
- chrome_path_ = (system_level_ ? kChromeSystemExePath :
- kChromeUserExePath);
+ chrome_path_ =
+ (system_level_ ? kChromeSystemExePath : kChromeUserExePath);
}
if (multi_install_) {
SetMultiInstallStateInRegistry(system_level_, true);
@@ -85,10 +163,13 @@ class ChromeElfUtilTest :
void SetUsageStat(DWORD value, bool state_medium) {
LONG result = base::win::RegKey(
- system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
- BuildKey(state_medium ? kRegPathClientStateMedium : kRegPathClientState,
- app_guid_).c_str(),
- KEY_SET_VALUE).WriteValue(kRegValueUsageStats, value);
+ system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
+ BuildKey(state_medium ? kRegPathClientStateMedium
+ : kRegPathClientState,
+ app_guid_)
+ .c_str(),
+ KEY_SET_VALUE)
+ .WriteValue(kRegValueUsageStats, value);
ASSERT_EQ(ERROR_SUCCESS, result);
}
@@ -108,10 +189,11 @@ class ChromeElfUtilTest :
}
void SetChannelName(const base::string16& channel_name) {
- LONG result = base::win::RegKey(
- system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
- BuildKey(kRegPathClientState, app_guid_).c_str(),
- KEY_SET_VALUE).WriteValue(kRegApField, channel_name.c_str());
+ LONG result =
+ base::win::RegKey(
+ system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
+ BuildKey(kRegPathClientState, app_guid_).c_str(), KEY_SET_VALUE)
+ .WriteValue(kRegApField, channel_name.c_str());
ASSERT_EQ(ERROR_SUCCESS, result);
}
@@ -130,195 +212,195 @@ class ChromeElfUtilTest :
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"-full");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"1.1-beta");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"beta-m", channel);
+ EXPECT_STREQ(L"beta-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelBeta, channel);
+ EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
}
SetChannelName(L"1.1-beta");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"beta-m", channel);
+ EXPECT_STREQ(L"beta-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelBeta, channel);
+ EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
}
SetChannelName(L"1.1-bar");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"beta-m", channel);
+ EXPECT_STREQ(L"beta-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelBeta, channel);
+ EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
}
SetChannelName(L"1n1-foobar");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"beta-m", channel);
+ EXPECT_STREQ(L"beta-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelBeta, channel);
+ EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
}
SetChannelName(L"foo-1.1-beta");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"2.0-beta");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"2.0-dev");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"dev-m", channel);
+ EXPECT_STREQ(L"dev-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelDev, channel);
+ EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
}
SetChannelName(L"2.0-DEV");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"dev-m", channel);
+ EXPECT_STREQ(L"dev-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelDev, channel);
+ EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
}
SetChannelName(L"2.0-dev-eloper");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"dev-m", channel);
+ EXPECT_STREQ(L"dev-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelDev, channel);
+ EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
}
SetChannelName(L"2.0-doom");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"dev-m", channel);
+ EXPECT_STREQ(L"dev-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelDev, channel);
+ EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
}
SetChannelName(L"250-doom");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"dev-m", channel);
+ EXPECT_STREQ(L"dev-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelDev, channel);
+ EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str());
}
SetChannelName(L"bar-2.0-dev");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"1.0-dev");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"x64-beta");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"beta-m", channel);
+ EXPECT_STREQ(L"beta-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelBeta, channel);
+ EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
}
SetChannelName(L"bar-x64-beta");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"beta-m", channel);
+ EXPECT_STREQ(L"beta-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelBeta, channel);
+ EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
}
SetChannelName(L"x64-Beta");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"beta-m", channel);
+ EXPECT_STREQ(L"beta-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelBeta, channel);
+ EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str());
}
SetChannelName(L"x64-stable");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"baz-x64-stable");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"x64-Stable");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"fuzzy");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
SetChannelName(L"foo");
install_static::GetChromeChannelName(!system_level_, add_modifier,
&channel);
if (multi_install_ && add_modifier) {
- EXPECT_EQ(L"-m", channel);
+ EXPECT_STREQ(L"-m", channel.c_str());
} else {
- EXPECT_EQ(install_static::kChromeChannelStable, channel);
+ EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str());
}
}
@@ -386,15 +468,17 @@ TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) {
// This test tests the install_static::GetChromeChannelName function and is
// based on the ChannelInfoTest.Channels in channel_info_unittest.cc
TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) {
- PerformChannelNameTests(true); // add_modifier
- PerformChannelNameTests(false); // !add_modifier
+ PerformChannelNameTests(true); // add_modifier
+ PerformChannelNameTests(false); // !add_modifier
}
-INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest,
+INSTANTIATE_TEST_CASE_P(Canary,
+ ChromeElfUtilTest,
testing::Combine(testing::Values("canary"),
testing::Values("user"),
testing::Values("single")));
-INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest,
+INSTANTIATE_TEST_CASE_P(GoogleChrome,
+ ChromeElfUtilTest,
testing::Combine(testing::Values("google"),
testing::Values("user", "system"),
testing::Values("single", "multi")));

Powered by Google App Engine
This is Rietveld 408576698