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