| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome_elf/chrome_elf_util.h" | 5 #include "chrome_elf/chrome_elf_util.h" |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 #include <windows.h> |
| 9 #include <versionhelpers.h> // windows.h must be before. |
| 8 | 10 |
| 9 #include "base/test/test_reg_util_win.h" | 11 #include "base/test/test_reg_util_win.h" |
| 10 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
| 13 #include "chrome_elf/chrome_elf_constants.h" |
| 14 #include "chrome_elf/chrome_elf_reg.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
| 13 | 17 |
| 14 namespace { | 18 namespace { |
| 15 | 19 |
| 16 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState"; | 20 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState"; |
| 17 const wchar_t kRegPathClientStateMedium[] = | 21 const wchar_t kRegPathClientStateMedium[] = |
| 18 L"Software\\Google\\Update\\ClientStateMedium"; | 22 L"Software\\Google\\Update\\ClientStateMedium"; |
| 19 const wchar_t kRegValueUsageStats[] = L"usagestats"; | 23 const wchar_t kRegValueUsageStats[] = L"usagestats"; |
| 20 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; | 24 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); | 51 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); |
| 48 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); | 52 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); |
| 49 } | 53 } |
| 50 | 54 |
| 51 TEST(ChromeElfUtilTest, BrowserProcessTest) { | 55 TEST(ChromeElfUtilTest, BrowserProcessTest) { |
| 52 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); | 56 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
| 53 InitializeProcessType(); | 57 InitializeProcessType(); |
| 54 EXPECT_FALSE(IsNonBrowserProcess()); | 58 EXPECT_FALSE(IsNonBrowserProcess()); |
| 55 } | 59 } |
| 56 | 60 |
| 61 //------------------------------------------------------------------------------ |
| 62 // NT registry API tests (chrome_elf_reg) |
| 63 //------------------------------------------------------------------------------ |
| 64 |
| 65 TEST(ChromeElfUtilTest, NTRegistry) { |
| 66 HANDLE key_handle; |
| 67 wchar_t* dword_val_name = L"DwordTestValue"; |
| 68 DWORD dword_val = 1234; |
| 69 wchar_t* sz_val_name = L"SzTestValue"; |
| 70 base::string16 sz_val = L"blah de blah de blahhhhh."; |
| 71 wchar_t* sz_val_name2 = L"SzTestValueEmpty"; |
| 72 base::string16 sz_val2 = L""; |
| 73 wchar_t* multisz_val_name = L"SzmultiTestValue"; |
| 74 std::vector<base::string16> multisz_val; |
| 75 base::string16 multi1 = L"one"; |
| 76 base::string16 multi2 = L"two"; |
| 77 base::string16 multi3 = L"three"; |
| 78 wchar_t* multisz_val_name2 = L"SzmultiTestValueBad"; |
| 79 base::string16 multi_empty = L""; |
| 80 |
| 81 // Create a temp key to play under. |
| 82 ASSERT_TRUE(nt::CreateRegKey(nt::AUTO, elf_sec::kRegSecurityPath, |
| 83 KEY_ALL_ACCESS, &key_handle)); |
| 84 |
| 85 // Exercise the supported getter & setter functions. |
| 86 EXPECT_TRUE(nt::SetRegValue_DWORD(key_handle, dword_val_name, dword_val)); |
| 87 EXPECT_TRUE(nt::SetRegValue_SZ(key_handle, sz_val_name, &sz_val)); |
| 88 EXPECT_TRUE(nt::SetRegValue_SZ(key_handle, sz_val_name2, &sz_val2)); |
| 89 |
| 90 DWORD get_dword = 0; |
| 91 base::string16 get_sz; |
| 92 EXPECT_TRUE(nt::GetRegValue_DWORD(key_handle, dword_val_name, &get_dword) && |
| 93 get_dword == dword_val); |
| 94 EXPECT_TRUE(nt::GetRegValue_SZ(key_handle, sz_val_name, &get_sz) && |
| 95 get_sz.compare(sz_val) == 0); |
| 96 EXPECT_TRUE(nt::GetRegValue_SZ(key_handle, sz_val_name2, &get_sz) && |
| 97 get_sz.compare(sz_val2) == 0); |
| 98 |
| 99 multisz_val.push_back(multi1); |
| 100 multisz_val.push_back(multi2); |
| 101 multisz_val.push_back(multi3); |
| 102 EXPECT_TRUE( |
| 103 nt::SetRegValue_MULTI_SZ(key_handle, multisz_val_name, &multisz_val)); |
| 104 multisz_val.clear(); |
| 105 multisz_val.push_back(multi_empty); |
| 106 EXPECT_TRUE( |
| 107 nt::SetRegValue_MULTI_SZ(key_handle, multisz_val_name2, &multisz_val)); |
| 108 multisz_val.clear(); |
| 109 |
| 110 EXPECT_TRUE( |
| 111 nt::GetRegValue_MULTI_SZ(key_handle, multisz_val_name, &multisz_val)); |
| 112 if (multisz_val.size() == 3) { |
| 113 EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0); |
| 114 EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0); |
| 115 EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0); |
| 116 } else { |
| 117 EXPECT_TRUE(false); |
| 118 } |
| 119 multisz_val.clear(); |
| 120 |
| 121 EXPECT_TRUE( |
| 122 nt::GetRegValue_MULTI_SZ(key_handle, multisz_val_name2, &multisz_val)); |
| 123 if (multisz_val.size() == 1) { |
| 124 EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0); |
| 125 } else { |
| 126 EXPECT_TRUE(false); |
| 127 } |
| 128 multisz_val.clear(); |
| 129 |
| 130 // Clean up |
| 131 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 132 nt::CloseRegKey(key_handle); |
| 133 } |
| 134 |
| 57 // Parameterized test with paramters: | 135 // Parameterized test with paramters: |
| 58 // 1: product: "canary" or "google" | 136 // 1: product: "canary" or "google" |
| 59 // 2: install level: "user" or "system" | 137 // 2: install level: "user" or "system" |
| 60 // 3: install mode: "single" or "multi" | 138 // 3: install mode: "single" or "multi" |
| 61 class ChromeElfUtilTest : | 139 class ChromeElfUtilTest : |
| 62 public testing::TestWithParam<std::tuple<const char*, | 140 public testing::TestWithParam<std::tuple<const char*, |
| 63 const char*, | 141 const char*, |
| 64 const char*> > { | 142 const char*> > { |
| 65 protected: | 143 protected: |
| 66 void SetUp() override { | 144 void SetUp() override { |
| 67 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); | 145 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, &nt::HKLM_override); |
| 68 override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | 146 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, &nt::HKCU_override); |
| 147 |
| 69 const char* app; | 148 const char* app; |
| 70 const char* level; | 149 const char* level; |
| 71 const char* mode; | 150 const char* mode; |
| 72 std::tie(app, level, mode) = GetParam(); | 151 std::tie(app, level, mode) = GetParam(); |
| 73 is_canary_ = (std::string(app) == "canary"); | 152 is_canary_ = (std::string(app) == "canary"); |
| 74 system_level_ = (std::string(level) != "user"); | 153 system_level_ = (std::string(level) != "user"); |
| 75 multi_install_ = (std::string(mode) != "single"); | 154 multi_install_ = (std::string(mode) != "single"); |
| 76 if (is_canary_) { | 155 if (is_canary_) { |
| 77 ASSERT_FALSE(system_level_); | 156 ASSERT_FALSE(system_level_); |
| 78 ASSERT_FALSE(multi_install_); | 157 ASSERT_FALSE(multi_install_); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, | 260 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, |
| 182 testing::Combine(testing::Values("canary"), | 261 testing::Combine(testing::Values("canary"), |
| 183 testing::Values("user"), | 262 testing::Values("user"), |
| 184 testing::Values("single"))); | 263 testing::Values("single"))); |
| 185 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, | 264 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, |
| 186 testing::Combine(testing::Values("google"), | 265 testing::Combine(testing::Values("google"), |
| 187 testing::Values("user", "system"), | 266 testing::Values("user", "system"), |
| 188 testing::Values("single", "multi"))); | 267 testing::Values("single", "multi"))); |
| 189 | 268 |
| 190 } // namespace | 269 } // namespace |
| OLD | NEW |