| 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 565785f95d6cd9020a5379d625118cdf0d15cbe1..c94ffcc35ed68e7907b1a1ee2d2a6ef49d350b18 100644
|
| --- a/chrome_elf/chrome_elf_util_unittest.cc
|
| +++ b/chrome_elf/chrome_elf_util_unittest.cc
|
| @@ -5,9 +5,13 @@
|
| #include "chrome_elf/chrome_elf_util.h"
|
|
|
| #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_elf/chrome_elf_constants.h"
|
| +#include "chrome_elf/chrome_elf_reg.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/platform_test.h"
|
|
|
| @@ -54,6 +58,80 @@ TEST(ChromeElfUtilTest, BrowserProcessTest) {
|
| EXPECT_FALSE(IsNonBrowserProcess());
|
| }
|
|
|
| +//------------------------------------------------------------------------------
|
| +// NT registry API tests (chrome_elf_reg)
|
| +//------------------------------------------------------------------------------
|
| +
|
| +TEST(ChromeElfUtilTest, NTRegistry) {
|
| + HANDLE key_handle;
|
| + wchar_t* dword_val_name = L"DwordTestValue";
|
| + DWORD dword_val = 1234;
|
| + wchar_t* sz_val_name = L"SzTestValue";
|
| + base::string16 sz_val = L"blah de blah de blahhhhh.";
|
| + wchar_t* sz_val_name2 = L"SzTestValueEmpty";
|
| + base::string16 sz_val2 = L"";
|
| + 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";
|
| + 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::SetRegValue_DWORD(key_handle, dword_val_name, dword_val));
|
| + EXPECT_TRUE(nt::SetRegValue_SZ(key_handle, sz_val_name, &sz_val));
|
| + EXPECT_TRUE(nt::SetRegValue_SZ(key_handle, sz_val_name2, &sz_val2));
|
| +
|
| + DWORD get_dword = 0;
|
| + base::string16 get_sz;
|
| + EXPECT_TRUE(nt::GetRegValue_DWORD(key_handle, dword_val_name, &get_dword) &&
|
| + get_dword == dword_val);
|
| + EXPECT_TRUE(nt::GetRegValue_SZ(key_handle, sz_val_name, &get_sz) &&
|
| + get_sz.compare(sz_val) == 0);
|
| + EXPECT_TRUE(nt::GetRegValue_SZ(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::SetRegValue_MULTI_SZ(key_handle, multisz_val_name, &multisz_val));
|
| + multisz_val.clear();
|
| + multisz_val.push_back(multi_empty);
|
| + EXPECT_TRUE(
|
| + nt::SetRegValue_MULTI_SZ(key_handle, multisz_val_name2, &multisz_val));
|
| + multisz_val.clear();
|
| +
|
| + EXPECT_TRUE(
|
| + nt::GetRegValue_MULTI_SZ(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::GetRegValue_MULTI_SZ(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"
|
| @@ -64,8 +142,9 @@ class ChromeElfUtilTest :
|
| 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;
|
|
|