| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (is_canary_) | 119 if (is_canary_) |
| 132 return; | 120 return; |
| 133 SetMultiInstallStateInRegistry(system_level_, true); | 121 SetMultiInstallStateInRegistry(system_level_, true); |
| 134 EXPECT_TRUE(IsMultiInstall(system_level_)); | 122 EXPECT_TRUE(IsMultiInstall(system_level_)); |
| 135 | 123 |
| 136 SetMultiInstallStateInRegistry(system_level_, false); | 124 SetMultiInstallStateInRegistry(system_level_, false); |
| 137 EXPECT_FALSE(IsMultiInstall(system_level_)); | 125 EXPECT_FALSE(IsMultiInstall(system_level_)); |
| 138 } | 126 } |
| 139 | 127 |
| 140 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { | 128 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { |
| 141 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 129 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
| 142 } | 130 } |
| 143 | 131 |
| 144 TEST_P(ChromeElfUtilTest, UsageStatsZero) { | 132 TEST_P(ChromeElfUtilTest, UsageStatsZero) { |
| 145 SetUsageStat(0, false); | 133 SetUsageStat(0, false); |
| 146 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 134 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
| 147 } | 135 } |
| 148 | 136 |
| 149 TEST_P(ChromeElfUtilTest, UsageStatsOne) { | 137 TEST_P(ChromeElfUtilTest, UsageStatsOne) { |
| 150 SetUsageStat(1, false); | 138 SetUsageStat(1, false); |
| 151 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | 139 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
| 152 if (is_canary_) { | 140 if (is_canary_) { |
| 153 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 141 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
| 154 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | 142 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
| 155 } else if (system_level_) { | 143 } else if (system_level_) { |
| 156 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 144 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
| 157 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 145 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
| 158 } else { | 146 } else { |
| 159 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 147 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
| 160 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | 148 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeSystemExePath)); |
| 161 } | 149 } |
| 162 } | 150 } |
| 163 | 151 |
| 164 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { | 152 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { |
| 165 if (!system_level_) | 153 if (!system_level_) |
| 166 return; | 154 return; |
| 167 SetUsageStat(0, true); | 155 SetUsageStat(0, true); |
| 168 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | 156 EXPECT_FALSE(GetCollectStatsConsentForTesting(chrome_path_)); |
| 169 } | 157 } |
| 170 | 158 |
| 171 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { | 159 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { |
| 172 if (!system_level_) | 160 if (!system_level_) |
| 173 return; | 161 return; |
| 174 SetUsageStat(1, true); | 162 SetUsageStat(1, true); |
| 175 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | 163 EXPECT_TRUE(GetCollectStatsConsentForTesting(chrome_path_)); |
| 176 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | 164 EXPECT_FALSE(GetCollectStatsConsentForTesting(kCanaryExePath)); |
| 177 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | 165 EXPECT_FALSE(GetCollectStatsConsentForTesting(kChromeUserExePath)); |
| 178 } | 166 } |
| 179 | 167 |
| 180 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, | 168 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, |
| 181 testing::Combine(testing::Values("canary"), | 169 testing::Combine(testing::Values("canary"), |
| 182 testing::Values("user"), | 170 testing::Values("user"), |
| 183 testing::Values("single"))); | 171 testing::Values("single"))); |
| 184 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, | 172 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, |
| 185 testing::Combine(testing::Values("google"), | 173 testing::Combine(testing::Values("google"), |
| 186 testing::Values("user", "system"), | 174 testing::Values("user", "system"), |
| 187 testing::Values("single", "multi"))); | 175 testing::Values("single", "multi"))); |
| 188 | 176 |
| 177 // Tests the MatchPattern function in the install_static library. |
| 178 // TODO(ananta) |
| 179 // Move this to install_static_unittests. |
| 180 // http://crbug.com/604923 |
| 181 TEST(MiscUtilTest, InstallStaticMatchPattern) { |
| 182 EXPECT_TRUE(install_static::MatchPattern(L"", L"")); |
| 183 EXPECT_TRUE(install_static::MatchPattern(L"", L"*")); |
| 184 EXPECT_FALSE(install_static::MatchPattern(L"", L"*a")); |
| 185 EXPECT_FALSE(install_static::MatchPattern(L"", L"abc")); |
| 186 EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*")); |
| 187 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?")); |
| 188 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*")); |
| 189 EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b")); |
| 190 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d")); |
| 191 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d")); |
| 192 EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh")); |
| 193 EXPECT_TRUE(install_static::MatchPattern(L"foobarabc", L"*bar*")); |
| 194 } |
| 195 |
| 189 } // namespace | 196 } // namespace |
| OLD | NEW |