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 <tuple> | 5 #include <tuple> |
6 | 6 |
7 #include "base/test/test_reg_util_win.h" | 7 #include "base/test/test_reg_util_win.h" |
8 #include "base/win/registry.h" | 8 #include "base/win/registry.h" |
9 #include "chrome/install_static/install_util.h" | 9 #include "chrome/install_static/install_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 | 12 |
| 13 using namespace install_static; |
| 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState"; | |
16 const wchar_t kRegPathClientStateMedium[] = | |
17 L"Software\\Google\\Update\\ClientStateMedium"; | |
18 const wchar_t kRegValueUsageStats[] = L"usagestats"; | |
19 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; | |
20 | |
21 const wchar_t kAppGuidCanary[] = | |
22 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; | |
23 const wchar_t kAppGuidGoogleChrome[] = | |
24 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | |
25 const wchar_t kAppGuidGoogleBinaries[] = | |
26 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | |
27 | |
28 const wchar_t kCanaryExePath[] = | 17 const wchar_t kCanaryExePath[] = |
29 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application" | 18 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application" |
30 L"\\chrome.exe"; | 19 L"\\chrome.exe"; |
31 const wchar_t kChromeSystemExePath[] = | 20 const wchar_t kChromeSystemExePath[] = |
32 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; | 21 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; |
33 const wchar_t kChromeUserExePath[] = | 22 const wchar_t kChromeUserExePath[] = |
34 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; | 23 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; |
35 const wchar_t kChromiumExePath[] = | 24 const wchar_t kChromiumExePath[] = |
36 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; | 25 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; |
37 | 26 |
38 | |
39 TEST(ChromeElfUtilTest, CanaryTest) { | 27 TEST(ChromeElfUtilTest, CanaryTest) { |
40 EXPECT_TRUE(IsCanary(kCanaryExePath)); | 28 EXPECT_TRUE(IsSxSChrome(kCanaryExePath)); |
41 EXPECT_FALSE(IsCanary(kChromeUserExePath)); | 29 EXPECT_FALSE(IsSxSChrome(kChromeUserExePath)); |
42 EXPECT_FALSE(IsCanary(kChromiumExePath)); | 30 EXPECT_FALSE(IsSxSChrome(kChromiumExePath)); |
43 } | 31 } |
44 | 32 |
45 TEST(ChromeElfUtilTest, SystemInstallTest) { | 33 TEST(ChromeElfUtilTest, SystemInstallTest) { |
46 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); | 34 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); |
47 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); | 35 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); |
48 } | 36 } |
49 | 37 |
50 TEST(ChromeElfUtilTest, BrowserProcessTest) { | 38 TEST(ChromeElfUtilTest, BrowserProcessTest) { |
51 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); | 39 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
52 InitializeProcessType(); | 40 InitializeProcessType(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 LONG result; | 100 LONG result; |
113 if (multi) { | 101 if (multi) { |
114 result = key.WriteValue(kUninstallArgumentsField, | 102 result = key.WriteValue(kUninstallArgumentsField, |
115 L"yadda yadda --multi-install yadda yadda"); | 103 L"yadda yadda --multi-install yadda yadda"); |
116 } else { | 104 } else { |
117 result = key.DeleteValue(kUninstallArgumentsField); | 105 result = key.DeleteValue(kUninstallArgumentsField); |
118 } | 106 } |
119 ASSERT_EQ(ERROR_SUCCESS, result); | 107 ASSERT_EQ(ERROR_SUCCESS, result); |
120 } | 108 } |
121 | 109 |
| 110 void SetChannelName(const base::string16& channel_name) { |
| 111 LONG result = base::win::RegKey( |
| 112 system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, |
| 113 BuildKey(kRegPathClientState, app_guid_).c_str(), |
| 114 KEY_SET_VALUE).WriteValue(kRegApField, channel_name.c_str()); |
| 115 ASSERT_EQ(ERROR_SUCCESS, result); |
| 116 } |
| 117 |
| 118 // This function tests the install_static::GetChromeChannelName function and |
| 119 // is based on the ChannelInfoTest.Channels in channel_info_unittest.cc. |
| 120 // The |add_modifier| parameter controls whether we expect modifiers in the |
| 121 // returned channel name. |
| 122 void PerformChannelNameTests(bool add_modifier) { |
| 123 // We can't test the channel name correctly for canary mode because the |
| 124 // install_static checks whether an exe is a canary executable is based on |
| 125 // the path where the exe is running from. |
| 126 if (is_canary_) |
| 127 return; |
| 128 SetChannelName(L""); |
| 129 base::string16 channel; |
| 130 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 131 &channel); |
| 132 if (multi_install_ && add_modifier) { |
| 133 EXPECT_EQ(L"-m", channel); |
| 134 } else { |
| 135 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 136 } |
| 137 |
| 138 SetChannelName(L"-full"); |
| 139 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 140 &channel); |
| 141 if (multi_install_ && add_modifier) { |
| 142 EXPECT_EQ(L"-m", channel); |
| 143 } else { |
| 144 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 145 } |
| 146 |
| 147 SetChannelName(L"1.1-beta"); |
| 148 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 149 &channel); |
| 150 if (multi_install_ && add_modifier) { |
| 151 EXPECT_EQ(L"beta-m", channel); |
| 152 } else { |
| 153 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 154 } |
| 155 |
| 156 SetChannelName(L"1.1-beta"); |
| 157 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 158 &channel); |
| 159 if (multi_install_ && add_modifier) { |
| 160 EXPECT_EQ(L"beta-m", channel); |
| 161 } else { |
| 162 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 163 } |
| 164 |
| 165 SetChannelName(L"1.1-bar"); |
| 166 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 167 &channel); |
| 168 if (multi_install_ && add_modifier) { |
| 169 EXPECT_EQ(L"beta-m", channel); |
| 170 } else { |
| 171 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 172 } |
| 173 |
| 174 SetChannelName(L"1n1-foobar"); |
| 175 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 176 &channel); |
| 177 if (multi_install_ && add_modifier) { |
| 178 EXPECT_EQ(L"beta-m", channel); |
| 179 } else { |
| 180 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 181 } |
| 182 |
| 183 SetChannelName(L"foo-1.1-beta"); |
| 184 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 185 &channel); |
| 186 if (multi_install_ && add_modifier) { |
| 187 EXPECT_EQ(L"-m", channel); |
| 188 } else { |
| 189 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 190 } |
| 191 SetChannelName(L"2.0-beta"); |
| 192 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 193 &channel); |
| 194 if (multi_install_ && add_modifier) { |
| 195 EXPECT_EQ(L"-m", channel); |
| 196 } else { |
| 197 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 198 } |
| 199 |
| 200 SetChannelName(L"2.0-dev"); |
| 201 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 202 &channel); |
| 203 if (multi_install_ && add_modifier) { |
| 204 EXPECT_EQ(L"dev-m", channel); |
| 205 } else { |
| 206 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 207 } |
| 208 SetChannelName(L"2.0-DEV"); |
| 209 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 210 &channel); |
| 211 if (multi_install_ && add_modifier) { |
| 212 EXPECT_EQ(L"dev-m", channel); |
| 213 } else { |
| 214 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 215 } |
| 216 SetChannelName(L"2.0-dev-eloper"); |
| 217 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 218 &channel); |
| 219 if (multi_install_ && add_modifier) { |
| 220 EXPECT_EQ(L"dev-m", channel); |
| 221 } else { |
| 222 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 223 } |
| 224 SetChannelName(L"2.0-doom"); |
| 225 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 226 &channel); |
| 227 if (multi_install_ && add_modifier) { |
| 228 EXPECT_EQ(L"dev-m", channel); |
| 229 } else { |
| 230 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 231 } |
| 232 SetChannelName(L"250-doom"); |
| 233 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 234 &channel); |
| 235 if (multi_install_ && add_modifier) { |
| 236 EXPECT_EQ(L"dev-m", channel); |
| 237 } else { |
| 238 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 239 } |
| 240 SetChannelName(L"bar-2.0-dev"); |
| 241 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 242 &channel); |
| 243 if (multi_install_ && add_modifier) { |
| 244 EXPECT_EQ(L"-m", channel); |
| 245 } else { |
| 246 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 247 } |
| 248 SetChannelName(L"1.0-dev"); |
| 249 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 250 &channel); |
| 251 if (multi_install_ && add_modifier) { |
| 252 EXPECT_EQ(L"-m", channel); |
| 253 } else { |
| 254 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 255 } |
| 256 |
| 257 SetChannelName(L"x64-beta"); |
| 258 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 259 &channel); |
| 260 if (multi_install_ && add_modifier) { |
| 261 EXPECT_EQ(L"beta-m", channel); |
| 262 } else { |
| 263 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 264 } |
| 265 SetChannelName(L"bar-x64-beta"); |
| 266 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 267 &channel); |
| 268 if (multi_install_ && add_modifier) { |
| 269 EXPECT_EQ(L"beta-m", channel); |
| 270 } else { |
| 271 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 272 } |
| 273 SetChannelName(L"x64-Beta"); |
| 274 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 275 &channel); |
| 276 if (multi_install_ && add_modifier) { |
| 277 EXPECT_EQ(L"beta-m", channel); |
| 278 } else { |
| 279 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 280 } |
| 281 |
| 282 SetChannelName(L"x64-stable"); |
| 283 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 284 &channel); |
| 285 if (multi_install_ && add_modifier) { |
| 286 EXPECT_EQ(L"-m", channel); |
| 287 } else { |
| 288 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 289 } |
| 290 SetChannelName(L"baz-x64-stable"); |
| 291 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 292 &channel); |
| 293 if (multi_install_ && add_modifier) { |
| 294 EXPECT_EQ(L"-m", channel); |
| 295 } else { |
| 296 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 297 } |
| 298 SetChannelName(L"x64-Stable"); |
| 299 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 300 &channel); |
| 301 if (multi_install_ && add_modifier) { |
| 302 EXPECT_EQ(L"-m", channel); |
| 303 } else { |
| 304 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 305 } |
| 306 |
| 307 SetChannelName(L"fuzzy"); |
| 308 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 309 &channel); |
| 310 if (multi_install_ && add_modifier) { |
| 311 EXPECT_EQ(L"-m", channel); |
| 312 } else { |
| 313 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 314 } |
| 315 SetChannelName(L"foo"); |
| 316 install_static::GetChromeChannelName(!system_level_, add_modifier, |
| 317 &channel); |
| 318 if (multi_install_ && add_modifier) { |
| 319 EXPECT_EQ(L"-m", channel); |
| 320 } else { |
| 321 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 322 } |
| 323 } |
| 324 |
122 const wchar_t* app_guid_; | 325 const wchar_t* app_guid_; |
123 const wchar_t* chrome_path_; | 326 const wchar_t* chrome_path_; |
124 bool system_level_; | 327 bool system_level_; |
125 bool multi_install_; | 328 bool multi_install_; |
126 bool is_canary_; | 329 bool is_canary_; |
127 registry_util::RegistryOverrideManager override_manager_; | 330 registry_util::RegistryOverrideManager override_manager_; |
128 }; | 331 }; |
129 | 332 |
130 TEST_P(ChromeElfUtilTest, MultiInstallTest) { | 333 TEST_P(ChromeElfUtilTest, MultiInstallTest) { |
131 if (is_canary_) | 334 if (is_canary_) |
132 return; | 335 return; |
133 SetMultiInstallStateInRegistry(system_level_, true); | 336 SetMultiInstallStateInRegistry(system_level_, true); |
134 EXPECT_TRUE(IsMultiInstall(system_level_)); | 337 EXPECT_TRUE(IsMultiInstall(system_level_)); |
135 | 338 |
136 SetMultiInstallStateInRegistry(system_level_, false); | 339 SetMultiInstallStateInRegistry(system_level_, false); |
137 EXPECT_FALSE(IsMultiInstall(system_level_)); | 340 EXPECT_FALSE(IsMultiInstall(system_level_)); |
138 } | 341 } |
139 | 342 |
140 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { | 343 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { |
141 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 344 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
142 } | 345 } |
143 | 346 |
144 TEST_P(ChromeElfUtilTest, UsageStatsZero) { | 347 TEST_P(ChromeElfUtilTest, UsageStatsZero) { |
145 SetUsageStat(0, false); | 348 SetUsageStat(0, false); |
146 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 349 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
147 } | 350 } |
148 | 351 |
149 TEST_P(ChromeElfUtilTest, UsageStatsOne) { | 352 TEST_P(ChromeElfUtilTest, UsageStatsOne) { |
150 SetUsageStat(1, false); | 353 SetUsageStat(1, false); |
151 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | 354 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
152 if (is_canary_) { | 355 if (is_canary_) { |
153 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 356 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
154 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | 357 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
155 } else if (system_level_) { | 358 } else if (system_level_) { |
156 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 359 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
157 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 360 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
158 } else { | 361 } else { |
159 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 362 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
160 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | 363 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
161 } | 364 } |
162 } | 365 } |
163 | 366 |
164 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { | 367 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { |
165 if (!system_level_) | 368 if (!system_level_) |
166 return; | 369 return; |
167 SetUsageStat(0, true); | 370 SetUsageStat(0, true); |
168 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 371 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
169 } | 372 } |
170 | 373 |
171 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { | 374 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { |
172 if (!system_level_) | 375 if (!system_level_) |
173 return; | 376 return; |
174 SetUsageStat(1, true); | 377 SetUsageStat(1, true); |
175 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | 378 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
176 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 379 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
177 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 380 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
| 381 } |
| 382 |
| 383 // TODO(ananta) |
| 384 // Move this to install_static_unittests. |
| 385 // http://crbug.com/604923 |
| 386 // This test tests the install_static::GetChromeChannelName function and is |
| 387 // based on the ChannelInfoTest.Channels in channel_info_unittest.cc |
| 388 TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) { |
| 389 PerformChannelNameTests(true); // add_modifier |
| 390 PerformChannelNameTests(false); // !add_modifier |
178 } | 391 } |
179 | 392 |
180 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, | 393 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, |
181 testing::Combine(testing::Values("canary"), | 394 testing::Combine(testing::Values("canary"), |
182 testing::Values("user"), | 395 testing::Values("user"), |
183 testing::Values("single"))); | 396 testing::Values("single"))); |
184 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, | 397 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, |
185 testing::Combine(testing::Values("google"), | 398 testing::Combine(testing::Values("google"), |
186 testing::Values("user", "system"), | 399 testing::Values("user", "system"), |
187 testing::Values("single", "multi"))); | 400 testing::Values("single", "multi"))); |
188 | 401 |
| 402 // Tests the MatchPattern function in the install_static library. |
| 403 // TODO(ananta) |
| 404 // Move this to install_static_unittests. |
| 405 // http://crbug.com/604923 |
| 406 TEST(MiscUtilTest, InstallStaticMatchPattern) { |
| 407 EXPECT_TRUE(install_static::MatchPattern(L"", L"")); |
| 408 EXPECT_TRUE(install_static::MatchPattern(L"", L"*")); |
| 409 EXPECT_FALSE(install_static::MatchPattern(L"", L"*a")); |
| 410 EXPECT_FALSE(install_static::MatchPattern(L"", L"abc")); |
| 411 EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*")); |
| 412 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?")); |
| 413 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*")); |
| 414 EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b")); |
| 415 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d")); |
| 416 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d")); |
| 417 EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh")); |
| 418 EXPECT_TRUE(install_static::MatchPattern(L"foobarabc", L"*bar*")); |
| 419 } |
| 420 |
189 } // namespace | 421 } // namespace |
OLD | NEW |