[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 5 | #include <tuple> |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 6 | #include <windows.h> |
| 7 | #include <versionhelpers.h> // windows.h must be before. |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 8 | |
| 9 | #include "base/test/test_reg_util_win.h" |
| 10 | #include "base/win/registry.h" |
ananta | 0a700e2 | 2016-04-21 03:00:46 | [diff] [blame] | 11 | #include "chrome/install_static/install_util.h" |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 12 | #include "chrome_elf/chrome_elf_constants.h" |
pennymac | 4e0b5f2 | 2016-07-19 19:15:45 | [diff] [blame^] | 13 | #include "chrome_elf/chrome_elf_security.h" |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 14 | #include "chrome_elf/nt_registry/nt_registry.h" |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
| 16 | #include "testing/platform_test.h" |
| 17 | |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 18 | using namespace install_static; |
| 19 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 20 | namespace { |
| 21 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 22 | const wchar_t kCanaryExePath[] = |
| 23 | L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application" |
| 24 | L"\\chrome.exe"; |
| 25 | const wchar_t kChromeSystemExePath[] = |
| 26 | L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; |
| 27 | const wchar_t kChromeUserExePath[] = |
| 28 | L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; |
| 29 | const wchar_t kChromiumExePath[] = |
| 30 | L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; |
| 31 | |
pennymac | 4e0b5f2 | 2016-07-19 19:15:45 | [diff] [blame^] | 32 | bool SetSecurityFinchFlag(bool creation) { |
| 33 | bool success = true; |
| 34 | base::win::RegKey security_key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); |
| 35 | |
| 36 | if (creation) { |
| 37 | if (ERROR_SUCCESS != |
| 38 | security_key.CreateKey(elf_sec::kRegSecurityFinchPath, KEY_QUERY_VALUE)) |
| 39 | success = false; |
| 40 | } else { |
| 41 | if (ERROR_SUCCESS != security_key.DeleteKey(elf_sec::kRegSecurityFinchPath)) |
| 42 | success = false; |
| 43 | } |
| 44 | |
| 45 | security_key.Close(); |
| 46 | return success; |
| 47 | } |
| 48 | |
| 49 | bool IsSecuritySet() { |
| 50 | typedef decltype(GetProcessMitigationPolicy)* GetProcessMitigationPolicyFunc; |
| 51 | |
| 52 | // Check the settings from EarlyBrowserSecurity(). |
| 53 | if (::IsWindows8OrGreater()) { |
| 54 | GetProcessMitigationPolicyFunc get_process_mitigation_policy = |
| 55 | reinterpret_cast<GetProcessMitigationPolicyFunc>(::GetProcAddress( |
| 56 | ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
| 57 | if (!get_process_mitigation_policy) |
| 58 | return false; |
| 59 | |
| 60 | // Check that extension points are disabled. |
| 61 | // (Legacy hooking.) |
| 62 | PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {}; |
| 63 | if (!get_process_mitigation_policy(::GetCurrentProcess(), |
| 64 | ProcessExtensionPointDisablePolicy, |
| 65 | &policy, sizeof(policy))) |
| 66 | return false; |
| 67 | |
| 68 | return policy.DisableExtensionPoints; |
| 69 | } |
| 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | void RegRedirect(nt::ROOT_KEY key, |
| 75 | registry_util::RegistryOverrideManager& rom) { |
| 76 | base::string16 temp; |
| 77 | |
| 78 | if (key == nt::HKCU) { |
| 79 | rom.OverrideRegistry(HKEY_CURRENT_USER, &temp); |
| 80 | ::wcsncpy(nt::HKCU_override, temp.c_str(), nt::g_kRegMaxPathLen - 1); |
| 81 | } else if (key == nt::HKLM) { |
| 82 | rom.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp); |
| 83 | ::wcsncpy(nt::HKLM_override, temp.c_str(), nt::g_kRegMaxPathLen - 1); |
| 84 | } |
| 85 | // nt::AUTO should not be passed into this function. |
| 86 | } |
| 87 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 88 | TEST(ChromeElfUtilTest, CanaryTest) { |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 89 | EXPECT_TRUE(IsSxSChrome(kCanaryExePath)); |
| 90 | EXPECT_FALSE(IsSxSChrome(kChromeUserExePath)); |
| 91 | EXPECT_FALSE(IsSxSChrome(kChromiumExePath)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | TEST(ChromeElfUtilTest, SystemInstallTest) { |
| 95 | EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); |
| 96 | EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); |
| 97 | } |
| 98 | |
caitkp | c393a5b | 2015-05-14 19:56:33 | [diff] [blame] | 99 | TEST(ChromeElfUtilTest, BrowserProcessTest) { |
| 100 | EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
| 101 | InitializeProcessType(); |
| 102 | EXPECT_FALSE(IsNonBrowserProcess()); |
| 103 | } |
| 104 | |
pennymac | 4e0b5f2 | 2016-07-19 19:15:45 | [diff] [blame^] | 105 | TEST(ChromeElfUtilTest, BrowserProcessSecurityTest) { |
| 106 | if (!::IsWindows8OrGreater()) |
| 107 | return; |
| 108 | |
| 109 | // Set up registry override for this test. |
| 110 | registry_util::RegistryOverrideManager override_manager; |
| 111 | RegRedirect(nt::HKCU, override_manager); |
| 112 | |
| 113 | // First, ensure that the emergency-off finch signal works. |
| 114 | EXPECT_TRUE(SetSecurityFinchFlag(true)); |
| 115 | EarlyBrowserSecurity(); |
| 116 | EXPECT_FALSE(IsSecuritySet()); |
| 117 | EXPECT_TRUE(SetSecurityFinchFlag(false)); |
| 118 | |
| 119 | // Second, test that the process mitigation is set when no finch signal. |
| 120 | EarlyBrowserSecurity(); |
| 121 | EXPECT_TRUE(IsSecuritySet()); |
| 122 | } |
| 123 | |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 124 | //------------------------------------------------------------------------------ |
| 125 | // NT registry API tests (chrome_elf_reg) |
| 126 | //------------------------------------------------------------------------------ |
| 127 | |
| 128 | TEST(ChromeElfUtilTest, NTRegistry) { |
| 129 | HANDLE key_handle; |
| 130 | const wchar_t* dword_val_name = L"DwordTestValue"; |
| 131 | DWORD dword_val = 1234; |
| 132 | const wchar_t* sz_val_name = L"SzTestValue"; |
| 133 | base::string16 sz_val = L"blah de blah de blahhhhh."; |
| 134 | const wchar_t* sz_val_name2 = L"SzTestValueEmpty"; |
| 135 | base::string16 sz_val2 = L""; |
| 136 | const wchar_t* multisz_val_name = L"SzmultiTestValue"; |
| 137 | std::vector<base::string16> multisz_val; |
| 138 | base::string16 multi1 = L"one"; |
| 139 | base::string16 multi2 = L"two"; |
| 140 | base::string16 multi3 = L"three"; |
| 141 | const wchar_t* multisz_val_name2 = L"SzmultiTestValueBad"; |
| 142 | base::string16 multi_empty = L""; |
| 143 | const wchar_t* sz_new_key_1 = L"test\\new\\subkey"; |
| 144 | const wchar_t* sz_new_key_2 = L"test\\new\\subkey\\blah\\"; |
| 145 | const wchar_t* sz_new_key_3 = L"\\test\\new\\subkey\\\\blah2"; |
| 146 | |
| 147 | // Set up registry override for this test. |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 148 | registry_util::RegistryOverrideManager override_manager; |
pennymac | 4e0b5f2 | 2016-07-19 19:15:45 | [diff] [blame^] | 149 | RegRedirect(nt::HKCU, override_manager); |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 150 | |
| 151 | // Create a temp key to play under. |
| 152 | ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, elf_sec::kRegSecurityPath, |
| 153 | KEY_ALL_ACCESS, &key_handle)); |
| 154 | |
| 155 | // Exercise the supported getter & setter functions. |
| 156 | EXPECT_TRUE(nt::SetRegValueDWORD(key_handle, dword_val_name, dword_val)); |
| 157 | EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name, sz_val)); |
| 158 | EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name2, sz_val2)); |
| 159 | |
| 160 | DWORD get_dword = 0; |
| 161 | base::string16 get_sz; |
| 162 | EXPECT_TRUE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword) && |
| 163 | get_dword == dword_val); |
| 164 | EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz) && |
| 165 | get_sz.compare(sz_val) == 0); |
| 166 | EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name2, &get_sz) && |
| 167 | get_sz.compare(sz_val2) == 0); |
| 168 | |
| 169 | multisz_val.push_back(multi1); |
| 170 | multisz_val.push_back(multi2); |
| 171 | multisz_val.push_back(multi3); |
| 172 | EXPECT_TRUE( |
| 173 | nt::SetRegValueMULTISZ(key_handle, multisz_val_name, multisz_val)); |
| 174 | multisz_val.clear(); |
| 175 | multisz_val.push_back(multi_empty); |
| 176 | EXPECT_TRUE( |
| 177 | nt::SetRegValueMULTISZ(key_handle, multisz_val_name2, multisz_val)); |
| 178 | multisz_val.clear(); |
| 179 | |
| 180 | EXPECT_TRUE( |
| 181 | nt::QueryRegValueMULTISZ(key_handle, multisz_val_name, &multisz_val)); |
| 182 | if (multisz_val.size() == 3) { |
| 183 | EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0); |
| 184 | EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0); |
| 185 | EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0); |
| 186 | } else { |
| 187 | EXPECT_TRUE(false); |
| 188 | } |
| 189 | multisz_val.clear(); |
| 190 | |
| 191 | EXPECT_TRUE( |
| 192 | nt::QueryRegValueMULTISZ(key_handle, multisz_val_name2, &multisz_val)); |
| 193 | if (multisz_val.size() == 1) { |
| 194 | EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0); |
| 195 | } else { |
| 196 | EXPECT_TRUE(false); |
| 197 | } |
| 198 | multisz_val.clear(); |
| 199 | |
| 200 | // Clean up |
| 201 | EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 202 | nt::CloseRegKey(key_handle); |
| 203 | |
| 204 | // More tests for CreateRegKey recursion. |
| 205 | ASSERT_TRUE( |
| 206 | nt::CreateRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, nullptr)); |
| 207 | EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, |
| 208 | &key_handle, nullptr)); |
| 209 | EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 210 | nt::CloseRegKey(key_handle); |
| 211 | |
| 212 | ASSERT_TRUE( |
| 213 | nt::CreateRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, nullptr)); |
| 214 | EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, |
| 215 | &key_handle, nullptr)); |
| 216 | EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 217 | nt::CloseRegKey(key_handle); |
| 218 | |
| 219 | ASSERT_TRUE( |
| 220 | nt::CreateRegKey(nt::HKCU, sz_new_key_3, KEY_ALL_ACCESS, nullptr)); |
| 221 | EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, L"test\\new\\subkey\\blah2", |
| 222 | KEY_ALL_ACCESS, &key_handle, nullptr)); |
| 223 | EXPECT_TRUE(nt::DeleteRegKey(key_handle)); |
| 224 | nt::CloseRegKey(key_handle); |
| 225 | |
| 226 | ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, nullptr, KEY_ALL_ACCESS, &key_handle)); |
| 227 | nt::CloseRegKey(key_handle); |
| 228 | } |
| 229 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 230 | // Parameterized test with paramters: |
| 231 | // 1: product: "canary" or "google" |
| 232 | // 2: install level: "user" or "system" |
| 233 | // 3: install mode: "single" or "multi" |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 234 | class ChromeElfUtilTest |
| 235 | : public testing::TestWithParam< |
| 236 | std::tuple<const char*, const char*, const char*>> { |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 237 | protected: |
nick | 5c1d060 | 2015-04-23 04:43:32 | [diff] [blame] | 238 | void SetUp() override { |
pennymac | 4e0b5f2 | 2016-07-19 19:15:45 | [diff] [blame^] | 239 | // Set up registry override for these tests. |
| 240 | RegRedirect(nt::HKLM, override_manager_); |
| 241 | RegRedirect(nt::HKCU, override_manager_); |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 242 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 243 | const char* app; |
| 244 | const char* level; |
| 245 | const char* mode; |
| 246 | std::tie(app, level, mode) = GetParam(); |
| 247 | is_canary_ = (std::string(app) == "canary"); |
| 248 | system_level_ = (std::string(level) != "user"); |
| 249 | multi_install_ = (std::string(mode) != "single"); |
| 250 | if (is_canary_) { |
| 251 | ASSERT_FALSE(system_level_); |
| 252 | ASSERT_FALSE(multi_install_); |
| 253 | app_guid_ = kAppGuidCanary; |
| 254 | chrome_path_ = kCanaryExePath; |
| 255 | } else { |
| 256 | app_guid_ = kAppGuidGoogleChrome; |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 257 | chrome_path_ = |
| 258 | (system_level_ ? kChromeSystemExePath : kChromeUserExePath); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 259 | } |
| 260 | if (multi_install_) { |
| 261 | SetMultiInstallStateInRegistry(system_level_, true); |
| 262 | app_guid_ = kAppGuidGoogleBinaries; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) { |
| 267 | base::string16 full_key_path(path); |
| 268 | full_key_path.append(1, L'\\'); |
| 269 | full_key_path.append(guid); |
| 270 | return full_key_path; |
| 271 | } |
| 272 | |
| 273 | void SetUsageStat(DWORD value, bool state_medium) { |
| 274 | LONG result = base::win::RegKey( |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 275 | system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, |
| 276 | BuildKey(state_medium ? kRegPathClientStateMedium |
| 277 | : kRegPathClientState, |
| 278 | app_guid_) |
| 279 | .c_str(), |
| 280 | KEY_SET_VALUE) |
| 281 | .WriteValue(kRegValueUsageStats, value); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 282 | ASSERT_EQ(ERROR_SUCCESS, result); |
| 283 | } |
| 284 | |
| 285 | void SetMultiInstallStateInRegistry(bool system_install, bool multi) { |
| 286 | base::win::RegKey key( |
| 287 | system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, |
| 288 | BuildKey(kRegPathClientState, kAppGuidGoogleChrome).c_str(), |
| 289 | KEY_SET_VALUE); |
| 290 | LONG result; |
| 291 | if (multi) { |
| 292 | result = key.WriteValue(kUninstallArgumentsField, |
| 293 | L"yadda yadda --multi-install yadda yadda"); |
| 294 | } else { |
| 295 | result = key.DeleteValue(kUninstallArgumentsField); |
| 296 | } |
| 297 | ASSERT_EQ(ERROR_SUCCESS, result); |
| 298 | } |
| 299 | |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 300 | void SetChannelName(const base::string16& channel_name) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 301 | LONG result = |
| 302 | base::win::RegKey( |
| 303 | system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, |
| 304 | BuildKey(kRegPathClientState, app_guid_).c_str(), KEY_SET_VALUE) |
| 305 | .WriteValue(kRegApField, channel_name.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 306 | ASSERT_EQ(ERROR_SUCCESS, result); |
| 307 | } |
| 308 | |
| 309 | // This function tests the install_static::GetChromeChannelName function and |
| 310 | // is based on the ChannelInfoTest.Channels in channel_info_unittest.cc. |
| 311 | // The |add_modifier| parameter controls whether we expect modifiers in the |
| 312 | // returned channel name. |
| 313 | void PerformChannelNameTests(bool add_modifier) { |
| 314 | // We can't test the channel name correctly for canary mode because the |
| 315 | // install_static checks whether an exe is a canary executable is based on |
| 316 | // the path where the exe is running from. |
| 317 | if (is_canary_) |
| 318 | return; |
| 319 | SetChannelName(L""); |
| 320 | base::string16 channel; |
| 321 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 322 | &channel); |
| 323 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 324 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 325 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 326 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | SetChannelName(L"-full"); |
| 330 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 331 | &channel); |
| 332 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 333 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 334 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 335 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | SetChannelName(L"1.1-beta"); |
| 339 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 340 | &channel); |
| 341 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 342 | EXPECT_STREQ(L"beta-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 343 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 344 | EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | SetChannelName(L"1.1-beta"); |
| 348 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 349 | &channel); |
| 350 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 351 | EXPECT_STREQ(L"beta-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 352 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 353 | EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | SetChannelName(L"1.1-bar"); |
| 357 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 358 | &channel); |
| 359 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 360 | EXPECT_STREQ(L"beta-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 361 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 362 | EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | SetChannelName(L"1n1-foobar"); |
| 366 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 367 | &channel); |
| 368 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 369 | EXPECT_STREQ(L"beta-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 370 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 371 | EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | SetChannelName(L"foo-1.1-beta"); |
| 375 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 376 | &channel); |
| 377 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 378 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 379 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 380 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 381 | } |
| 382 | SetChannelName(L"2.0-beta"); |
| 383 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 384 | &channel); |
| 385 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 386 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 387 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 388 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | SetChannelName(L"2.0-dev"); |
| 392 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 393 | &channel); |
| 394 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 395 | EXPECT_STREQ(L"dev-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 396 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 397 | EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 398 | } |
| 399 | SetChannelName(L"2.0-DEV"); |
| 400 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 401 | &channel); |
| 402 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 403 | EXPECT_STREQ(L"dev-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 404 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 405 | EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 406 | } |
| 407 | SetChannelName(L"2.0-dev-eloper"); |
| 408 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 409 | &channel); |
| 410 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 411 | EXPECT_STREQ(L"dev-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 412 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 413 | EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 414 | } |
| 415 | SetChannelName(L"2.0-doom"); |
| 416 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 417 | &channel); |
| 418 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 419 | EXPECT_STREQ(L"dev-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 420 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 421 | EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 422 | } |
| 423 | SetChannelName(L"250-doom"); |
| 424 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 425 | &channel); |
| 426 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 427 | EXPECT_STREQ(L"dev-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 428 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 429 | EXPECT_STREQ(install_static::kChromeChannelDev, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 430 | } |
| 431 | SetChannelName(L"bar-2.0-dev"); |
| 432 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 433 | &channel); |
| 434 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 435 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 436 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 437 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 438 | } |
| 439 | SetChannelName(L"1.0-dev"); |
| 440 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 441 | &channel); |
| 442 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 443 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 444 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 445 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | SetChannelName(L"x64-beta"); |
| 449 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 450 | &channel); |
| 451 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 452 | EXPECT_STREQ(L"beta-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 453 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 454 | EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 455 | } |
| 456 | SetChannelName(L"bar-x64-beta"); |
| 457 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 458 | &channel); |
| 459 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 460 | EXPECT_STREQ(L"beta-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 461 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 462 | EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 463 | } |
| 464 | SetChannelName(L"x64-Beta"); |
| 465 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 466 | &channel); |
| 467 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 468 | EXPECT_STREQ(L"beta-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 469 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 470 | EXPECT_STREQ(install_static::kChromeChannelBeta, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | SetChannelName(L"x64-stable"); |
| 474 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 475 | &channel); |
| 476 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 477 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 478 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 479 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 480 | } |
| 481 | SetChannelName(L"baz-x64-stable"); |
| 482 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 483 | &channel); |
| 484 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 485 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 486 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 487 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 488 | } |
| 489 | SetChannelName(L"x64-Stable"); |
| 490 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 491 | &channel); |
| 492 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 493 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 494 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 495 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | SetChannelName(L"fuzzy"); |
| 499 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 500 | &channel); |
| 501 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 502 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 503 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 504 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 505 | } |
| 506 | SetChannelName(L"foo"); |
| 507 | install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 508 | &channel); |
| 509 | if (multi_install_ && add_modifier) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 510 | EXPECT_STREQ(L"-m", channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 511 | } else { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 512 | EXPECT_STREQ(install_static::kChromeChannelStable, channel.c_str()); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 516 | const wchar_t* app_guid_; |
| 517 | const wchar_t* chrome_path_; |
| 518 | bool system_level_; |
| 519 | bool multi_install_; |
| 520 | bool is_canary_; |
| 521 | registry_util::RegistryOverrideManager override_manager_; |
| 522 | }; |
| 523 | |
| 524 | TEST_P(ChromeElfUtilTest, MultiInstallTest) { |
| 525 | if (is_canary_) |
| 526 | return; |
| 527 | SetMultiInstallStateInRegistry(system_level_, true); |
| 528 | EXPECT_TRUE(IsMultiInstall(system_level_)); |
| 529 | |
| 530 | SetMultiInstallStateInRegistry(system_level_, false); |
| 531 | EXPECT_FALSE(IsMultiInstall(system_level_)); |
| 532 | } |
| 533 | |
| 534 | TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 535 | EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | TEST_P(ChromeElfUtilTest, UsageStatsZero) { |
| 539 | SetUsageStat(0, false); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 540 | EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | TEST_P(ChromeElfUtilTest, UsageStatsOne) { |
| 544 | SetUsageStat(1, false); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 545 | EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 546 | if (is_canary_) { |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 547 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
| 548 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 549 | } else if (system_level_) { |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 550 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
| 551 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 552 | } else { |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 553 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
| 554 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
| 558 | TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { |
| 559 | if (!system_level_) |
| 560 | return; |
| 561 | SetUsageStat(0, true); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 562 | EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { |
| 566 | if (!system_level_) |
| 567 | return; |
| 568 | SetUsageStat(1, true); |
ananta | 69086d7 | 2016-05-12 23:29:04 | [diff] [blame] | 569 | EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
| 570 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
| 571 | EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
| 572 | } |
| 573 | |
| 574 | // TODO(ananta) |
| 575 | // Move this to install_static_unittests. |
| 576 | // http://crbug.com/604923 |
| 577 | // This test tests the install_static::GetChromeChannelName function and is |
| 578 | // based on the ChannelInfoTest.Channels in channel_info_unittest.cc |
| 579 | TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) { |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 580 | PerformChannelNameTests(true); // add_modifier |
| 581 | PerformChannelNameTests(false); // !add_modifier |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 582 | } |
| 583 | |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 584 | INSTANTIATE_TEST_CASE_P(Canary, |
| 585 | ChromeElfUtilTest, |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 586 | testing::Combine(testing::Values("canary"), |
| 587 | testing::Values("user"), |
| 588 | testing::Values("single"))); |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 589 | INSTANTIATE_TEST_CASE_P(GoogleChrome, |
| 590 | ChromeElfUtilTest, |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 591 | testing::Combine(testing::Values("google"), |
| 592 | testing::Values("user", "system"), |
| 593 | testing::Values("single", "multi"))); |
| 594 | |
[email protected] | 5a54207 | 2014-02-24 02:12:09 | [diff] [blame] | 595 | } // namespace |