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 |
122 const wchar_t* app_guid_; | 118 const wchar_t* app_guid_; |
123 const wchar_t* chrome_path_; | 119 const wchar_t* chrome_path_; |
124 bool system_level_; | 120 bool system_level_; |
125 bool multi_install_; | 121 bool multi_install_; |
126 bool is_canary_; | 122 bool is_canary_; |
127 registry_util::RegistryOverrideManager override_manager_; | 123 registry_util::RegistryOverrideManager override_manager_; |
128 }; | 124 }; |
129 | 125 |
130 TEST_P(ChromeElfUtilTest, MultiInstallTest) { | 126 TEST_P(ChromeElfUtilTest, MultiInstallTest) { |
131 if (is_canary_) | 127 if (is_canary_) |
132 return; | 128 return; |
133 SetMultiInstallStateInRegistry(system_level_, true); | 129 SetMultiInstallStateInRegistry(system_level_, true); |
134 EXPECT_TRUE(IsMultiInstall(system_level_)); | 130 EXPECT_TRUE(IsMultiInstall(system_level_)); |
135 | 131 |
136 SetMultiInstallStateInRegistry(system_level_, false); | 132 SetMultiInstallStateInRegistry(system_level_, false); |
137 EXPECT_FALSE(IsMultiInstall(system_level_)); | 133 EXPECT_FALSE(IsMultiInstall(system_level_)); |
138 } | 134 } |
139 | 135 |
140 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { | 136 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { |
141 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 137 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
142 } | 138 } |
143 | 139 |
144 TEST_P(ChromeElfUtilTest, UsageStatsZero) { | 140 TEST_P(ChromeElfUtilTest, UsageStatsZero) { |
145 SetUsageStat(0, false); | 141 SetUsageStat(0, false); |
146 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 142 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
147 } | 143 } |
148 | 144 |
149 TEST_P(ChromeElfUtilTest, UsageStatsOne) { | 145 TEST_P(ChromeElfUtilTest, UsageStatsOne) { |
150 SetUsageStat(1, false); | 146 SetUsageStat(1, false); |
151 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | 147 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
152 if (is_canary_) { | 148 if (is_canary_) { |
153 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 149 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
154 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | 150 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
155 } else if (system_level_) { | 151 } else if (system_level_) { |
156 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 152 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
157 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 153 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
158 } else { | 154 } else { |
159 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 155 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
160 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | 156 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
161 } | 157 } |
162 } | 158 } |
163 | 159 |
164 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { | 160 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { |
165 if (!system_level_) | 161 if (!system_level_) |
166 return; | 162 return; |
167 SetUsageStat(0, true); | 163 SetUsageStat(0, true); |
168 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 164 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
169 } | 165 } |
170 | 166 |
171 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { | 167 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { |
172 if (!system_level_) | 168 if (!system_level_) |
173 return; | 169 return; |
174 SetUsageStat(1, true); | 170 SetUsageStat(1, true); |
175 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | 171 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
176 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 172 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
177 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 173 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
| 174 } |
| 175 |
| 176 // TODO(ananta) |
| 177 // Move this to install_static_unittests. |
| 178 // http://crbug.com/604923 |
| 179 // This test tests the install_static::GetChromeChannelName function and is |
| 180 // based on the ChannelInfoTest.Channels in channel_info_unittest.cc |
| 181 TEST_P(ChromeElfUtilTest, InstallStaticGetChannelNameTest) { |
| 182 // We can't test the channel name correctly for canary mode because the |
| 183 // install_static checks whether an exe is a canary executable is based on |
| 184 // the path where the exe is running from. |
| 185 if (is_canary_) |
| 186 return; |
| 187 SetChannelName(L""); |
| 188 base::string16 channel; |
| 189 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 190 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 191 |
| 192 SetChannelName(L"-full"); |
| 193 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 194 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 195 |
| 196 SetChannelName(L"1.1-beta"); |
| 197 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 198 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 199 SetChannelName(L"1.1-beta"); |
| 200 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 201 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 202 SetChannelName(L"1.1-bar"); |
| 203 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 204 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 205 SetChannelName(L"1n1-foobar"); |
| 206 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 207 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 208 SetChannelName(L"foo-1.1-beta"); |
| 209 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 210 EXPECT_TRUE(channel.empty()); |
| 211 SetChannelName(L"2.0-beta"); |
| 212 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 213 EXPECT_TRUE(channel.empty()); |
| 214 |
| 215 SetChannelName(L"2.0-dev"); |
| 216 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 217 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 218 SetChannelName(L"2.0-DEV"); |
| 219 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 220 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 221 SetChannelName(L"2.0-dev-eloper"); |
| 222 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 223 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 224 SetChannelName(L"2.0-doom"); |
| 225 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 226 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 227 SetChannelName(L"250-doom"); |
| 228 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 229 EXPECT_EQ(install_static::kChromeChannelDev, channel); |
| 230 SetChannelName(L"bar-2.0-dev"); |
| 231 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 232 EXPECT_TRUE(channel.empty()); |
| 233 SetChannelName(L"1.0-dev"); |
| 234 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 235 EXPECT_TRUE(channel.empty()); |
| 236 |
| 237 SetChannelName(L"x64-beta"); |
| 238 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 239 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 240 SetChannelName(L"bar-x64-beta"); |
| 241 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 242 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 243 SetChannelName(L"x64-Beta"); |
| 244 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 245 EXPECT_EQ(install_static::kChromeChannelBeta, channel); |
| 246 |
| 247 SetChannelName(L"x64-stable"); |
| 248 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 249 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 250 SetChannelName(L"baz-x64-stable"); |
| 251 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 252 EXPECT_EQ(install_static::kChromeChannelStable, channel); |
| 253 SetChannelName(L"x64-Stable"); |
| 254 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 255 EXPECT_TRUE(channel.empty()); |
| 256 |
| 257 SetChannelName(L"fuzzy"); |
| 258 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 259 EXPECT_TRUE(channel.empty()); |
| 260 SetChannelName(L"foo"); |
| 261 install_static::GetChromeChannelName(!system_level_, true, &channel); |
| 262 EXPECT_TRUE(channel.empty()); |
178 } | 263 } |
179 | 264 |
180 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, | 265 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, |
181 testing::Combine(testing::Values("canary"), | 266 testing::Combine(testing::Values("canary"), |
182 testing::Values("user"), | 267 testing::Values("user"), |
183 testing::Values("single"))); | 268 testing::Values("single"))); |
184 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, | 269 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, |
185 testing::Combine(testing::Values("google"), | 270 testing::Combine(testing::Values("google"), |
186 testing::Values("user", "system"), | 271 testing::Values("user", "system"), |
187 testing::Values("single", "multi"))); | 272 testing::Values("single", "multi"))); |
188 | 273 |
| 274 // Tests the MatchPattern function in the install_static library. |
| 275 // TODO(ananta) |
| 276 // Move this to install_static_unittests. |
| 277 // http://crbug.com/604923 |
| 278 TEST(MiscUtilTest, InstallStaticMatchPattern) { |
| 279 EXPECT_TRUE(install_static::MatchPattern(L"", L"")); |
| 280 EXPECT_TRUE(install_static::MatchPattern(L"", L"*")); |
| 281 EXPECT_FALSE(install_static::MatchPattern(L"", L"*a")); |
| 282 EXPECT_FALSE(install_static::MatchPattern(L"", L"abc")); |
| 283 EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*")); |
| 284 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?")); |
| 285 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*")); |
| 286 EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b")); |
| 287 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d")); |
| 288 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d")); |
| 289 EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh")); |
| 290 EXPECT_TRUE(install_static::MatchPattern(L"foobarabc", L"*bar*")); |
| 291 } |
| 292 |
189 } // namespace | 293 } // namespace |
OLD | NEW |