OLD | NEW |
---|---|
(Empty) | |
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 | |
5 #include "chrome_elf/chrome_elf_util.h" | |
6 | |
7 #include <tuple> | |
8 | |
9 #include "base/test/test_reg_util_win.h" | |
10 #include "base/win/registry.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "testing/platform_test.h" | |
13 | |
14 namespace { | |
15 | |
16 const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState"; | |
17 const wchar_t kRegPathClientStateMedium[] = | |
18 L"Software\\Google\\Update\\ClientStateMedium"; | |
19 const wchar_t kRegValueUsageStats[] = L"usagestats"; | |
20 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; | |
21 | |
22 const wchar_t kAppGuidCanary[] = | |
23 L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; | |
24 const wchar_t kAppGuidGoogleChrome[] = | |
25 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | |
26 const wchar_t kAppGuidGoogleBinaries[] = | |
27 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | |
28 | |
29 const wchar_t kCanaryExePath[] = | |
30 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.e xe"; | |
31 const wchar_t kChromeSystemExePath[] = | |
32 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; | |
33 const wchar_t kChromeUserExePath[] = | |
34 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; | |
35 const wchar_t kChromiumExePath[] = | |
36 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; | |
37 | |
38 // Parameterized test with paramters: | |
39 // 1: product: "canary" or "google" | |
40 // 2: install level: "user" or "system" | |
41 // 3: install mode: "single" or "multi" | |
42 class ChromeElfUtilTest : | |
43 public testing::TestWithParam<std::tuple<const char*, | |
44 const char*, | |
45 const char*> > { | |
46 protected: | |
47 virtual void SetUp() OVERRIDE { | |
48 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, | |
49 L"chrome_elf_test_local"); | |
50 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, | |
51 L"chrome_elf_test_current"); | |
52 const char* app; | |
53 const char* level; | |
54 const char* mode; | |
55 std::tie(app, level, mode) = GetParam(); | |
56 is_canary_ = (std::string(app) == "canary"); | |
57 system_level_ = (std::string(level) != "user"); | |
58 multi_install_ = (std::string(mode) != "single"); | |
59 if (is_canary_) { | |
60 ASSERT_FALSE(system_level_); | |
61 ASSERT_FALSE(multi_install_); | |
62 app_guid_ = kAppGuidCanary; | |
63 chrome_path_ = kCanaryExePath; | |
64 } else { | |
65 app_guid_ = kAppGuidGoogleChrome; | |
66 chrome_path_ = (system_level_ ? kChromeSystemExePath : | |
67 kChromeUserExePath); | |
68 } | |
69 if (multi_install_) { | |
70 SetMultiInstallStateInRegistry(system_level_, true); | |
71 app_guid_ = kAppGuidGoogleBinaries; | |
72 } | |
73 } | |
74 | |
75 base::string16 BuildKey(const wchar_t* path, const wchar_t* guid) { | |
76 base::string16 full_key_path(path); | |
77 full_key_path.append(1, L'\\'); | |
78 full_key_path.append(guid); | |
79 return full_key_path; | |
80 } | |
81 | |
82 void SetUsageStat(DWORD value, bool state_medium, bool system_install) { | |
83 LONG result = base::win::RegKey( | |
84 system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | |
grt (UTC plus 2)
2014/02/17 20:49:39
use system_install_ member rather than passing it
Cait (Slow)
2014/02/18 23:03:12
Done.
| |
85 BuildKey(state_medium ? kRegPathClientStateMedium : kRegPathClientState, | |
86 app_guid_).c_str(), | |
87 KEY_SET_VALUE).WriteValue(kRegValueUsageStats, value); | |
88 ASSERT_EQ(ERROR_SUCCESS, result); | |
89 } | |
90 | |
91 void SetMultiInstallStateInRegistry(bool system_install, bool multi) { | |
92 base::win::RegKey key( | |
93 system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, | |
94 BuildKey(kRegPathClientState, kAppGuidGoogleChrome).c_str(), | |
95 KEY_SET_VALUE); | |
96 LONG result; | |
97 if (multi) { | |
98 result = key.WriteValue(kUninstallArgumentsField, | |
99 L"yadda yadda --multi-install yadda yadda"); | |
100 } else { | |
101 result = key.DeleteValue(kUninstallArgumentsField); | |
102 } | |
103 ASSERT_EQ(ERROR_SUCCESS, result); | |
104 } | |
105 | |
106 const wchar_t* app_guid_; | |
107 const wchar_t* chrome_path_; | |
108 bool system_level_; | |
109 bool multi_install_; | |
110 bool is_canary_; | |
111 registry_util::RegistryOverrideManager override_manager_; | |
112 }; | |
113 | |
114 TEST_P(ChromeElfUtilTest, CanaryTest) { | |
grt (UTC plus 2)
2014/02/17 20:49:39
if this test doesn't use anything in the ChromeElf
Cait (Slow)
2014/02/18 23:03:12
Done.
| |
115 EXPECT_TRUE(IsCanary(kCanaryExePath)); | |
116 EXPECT_FALSE(IsCanary(kChromeUserExePath)); | |
117 EXPECT_FALSE(IsCanary(kChromiumExePath)); | |
118 } | |
119 | |
120 TEST_P(ChromeElfUtilTest, SystemInstallTest) { | |
121 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); | |
122 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); | |
123 } | |
124 | |
125 TEST_P(ChromeElfUtilTest, MultiInstallTest) { | |
126 if (is_canary_) | |
127 return; | |
128 SetMultiInstallStateInRegistry(system_level_, true); | |
129 EXPECT_TRUE(IsMultiInstall(system_level_)); | |
130 | |
131 SetMultiInstallStateInRegistry(system_level_, false); | |
132 EXPECT_FALSE(IsMultiInstall(system_level_)); | |
133 } | |
134 | |
135 TEST_P(ChromeElfUtilTest, UsageStatsAbsent) { | |
136 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | |
137 } | |
138 | |
139 TEST_P(ChromeElfUtilTest, UsageStatsZero) { | |
140 SetUsageStat(0, false, system_level_); | |
141 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | |
142 } | |
143 | |
144 TEST_P(ChromeElfUtilTest, UsageStatsOne) { | |
145 SetUsageStat(1, false, system_level_); | |
146 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | |
147 if (is_canary_) { | |
148 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | |
149 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | |
150 } else if (system_level_) { | |
151 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | |
152 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | |
153 } else { | |
154 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | |
155 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | |
156 } | |
157 } | |
158 | |
159 TEST_P(ChromeElfUtilTest, UsageStatsZeroInStateMedium) { | |
160 if (!system_level_) | |
161 return; | |
162 SetUsageStat(0, true, system_level_); | |
163 EXPECT_FALSE(AreUsageStatsEnabled(chrome_path_)); | |
164 } | |
165 | |
166 TEST_P(ChromeElfUtilTest, UsageStatsOneInStateMedium) { | |
167 if (!system_level_) | |
168 return; | |
169 SetUsageStat(1, true, system_level_); | |
170 EXPECT_TRUE(AreUsageStatsEnabled(chrome_path_)); | |
171 if (is_canary_) { | |
grt (UTC plus 2)
2014/02/17 20:49:39
this will never be true since canary is never at s
Cait (Slow)
2014/02/18 23:03:12
Done.
| |
172 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | |
173 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | |
174 } else if (system_level_) { | |
grt (UTC plus 2)
2014/02/17 20:49:39
this will always be true as a result of line 168
Cait (Slow)
2014/02/18 23:03:12
Done.
| |
175 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | |
176 EXPECT_FALSE(AreUsageStatsEnabled(kChromeUserExePath)); | |
177 } else { | |
178 EXPECT_FALSE(AreUsageStatsEnabled(kCanaryExePath)); | |
179 EXPECT_FALSE(AreUsageStatsEnabled(kChromeSystemExePath)); | |
180 } | |
181 } | |
182 | |
183 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, | |
184 testing::Combine(testing::Values("canary"), | |
185 testing::Values("user"), | |
186 testing::Values("single"))); | |
187 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, | |
188 testing::Combine(testing::Values("google"), | |
189 testing::Values("user", "system"), | |
190 testing::Values("single", "multi"))); | |
191 | |
192 } // namespace | |
OLD | NEW |