OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/installer/util/beacons.h" | 5 #include "chrome/installer/util/beacons.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include <memory> |
8 #include <tuple> | |
9 | |
10 #include "base/memory/ptr_util.h" | |
8 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
9 #include "base/path_service.h" | 12 #include "base/path_service.h" |
10 #include "base/test/scoped_path_override.h" | |
11 #include "base/test/test_reg_util_win.h" | 13 #include "base/test/test_reg_util_win.h" |
12 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
13 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
14 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
15 #include "base/win/win_util.h" | 17 #include "base/win/win_util.h" |
18 #include "chrome/install_static/install_details.h" | |
19 #include "chrome/install_static/install_modes.h" | |
20 #include "chrome/install_static/test/scoped_install_details.h" | |
16 #include "chrome/installer/util/browser_distribution.h" | 21 #include "chrome/installer/util/browser_distribution.h" |
17 #include "chrome/installer/util/install_util.h" | 22 #include "chrome/installer/util/install_util.h" |
18 #include "chrome/installer/util/test_app_registration_data.h" | 23 #include "chrome/installer/util/test_app_registration_data.h" |
19 #include "chrome/installer/util/util_constants.h" | 24 #include "chrome/installer/util/util_constants.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
21 | 26 |
22 using ::testing::Bool; | 27 using ::testing::Bool; |
23 using ::testing::Combine; | 28 using ::testing::Combine; |
24 using ::testing::Values; | 29 using ::testing::Values; |
25 using BeaconType = installer_util::Beacon::BeaconType; | 30 using BeaconType = installer_util::Beacon::BeaconType; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 137 } |
133 | 138 |
134 // Run the tests for all combinations of beacon type, scope, and install level. | 139 // Run the tests for all combinations of beacon type, scope, and install level. |
135 INSTANTIATE_TEST_CASE_P(BeaconTest, | 140 INSTANTIATE_TEST_CASE_P(BeaconTest, |
136 BeaconTest, | 141 BeaconTest, |
137 Combine(Values(BeaconType::FIRST, BeaconType::LAST), | 142 Combine(Values(BeaconType::FIRST, BeaconType::LAST), |
138 Values(BeaconScope::PER_USER, | 143 Values(BeaconScope::PER_USER, |
139 BeaconScope::PER_INSTALL), | 144 BeaconScope::PER_INSTALL), |
140 Bool())); | 145 Bool())); |
141 | 146 |
142 enum class DistributionVariant { | |
143 SYSTEM_LEVEL, | |
144 USER_LEVEL, | |
145 SXS, | |
146 }; | |
147 | |
148 class DefaultBrowserBeaconTest | 147 class DefaultBrowserBeaconTest |
149 : public ::testing::TestWithParam<DistributionVariant> { | 148 : public ::testing::TestWithParam< |
149 std::tuple<install_static::InstallConstantIndex, const char*>> { | |
150 protected: | 150 protected: |
151 using Super = ::testing::TestWithParam<DistributionVariant>; | 151 using Super = ::testing::TestWithParam< |
152 | 152 std::tuple<install_static::InstallConstantIndex, const char*>>; |
153 DefaultBrowserBeaconTest() | |
154 : system_install_(GetParam() == DistributionVariant::SYSTEM_LEVEL), | |
155 chrome_sxs_(GetParam() == DistributionVariant::SXS), | |
156 chrome_exe_(GetChromePathForParams()), | |
157 distribution_(nullptr) {} | |
158 | 153 |
159 void SetUp() override { | 154 void SetUp() override { |
160 Super::SetUp(); | 155 Super::SetUp(); |
161 | 156 |
162 // Override FILE_EXE so that various InstallUtil functions will consider | 157 install_static::InstallConstantIndex mode_index; |
163 // this to be a user/system Chrome or Chrome SxS. | 158 const char* level; |
164 path_overrides_.push_back(new base::ScopedPathOverride( | 159 std::tie(mode_index, level) = GetParam(); |
165 base::FILE_EXE, chrome_exe_, true /* is_absolute */, | |
166 false /* !create */)); | |
167 | 160 |
168 // Override these paths with their own values so that they can be found | 161 system_install_ = (std::string(level) != "user"); |
gab
2017/02/14 16:57:56
Why not just strcmp?
| |
169 // after the registry override manager is in place. Getting them would | 162 |
170 // otherwise fail since the underlying calls to the OS need to see the real | 163 // Configure InstallDetails for the test. |
171 // contents of the registry. | 164 scoped_install_details_ = |
172 static const int kPathKeys[] = { | 165 base::MakeUnique<install_static::ScopedInstallDetails>(system_install_, |
173 base::DIR_PROGRAM_FILES, | 166 mode_index); |
174 base::DIR_PROGRAM_FILESX86, | 167 chrome_exe_ = GetChromePath(); |
175 base::DIR_LOCAL_APP_DATA, | |
176 }; | |
177 for (int key : kPathKeys) { | |
178 base::FilePath temp; | |
179 PathService::Get(key, &temp); | |
180 path_overrides_.push_back(new base::ScopedPathOverride(key, temp)); | |
181 } | |
182 | 168 |
183 // Override the registry so that tests can freely push state to it. | 169 // Override the registry so that tests can freely push state to it. |
184 ASSERT_NO_FATAL_FAILURE( | 170 ASSERT_NO_FATAL_FAILURE( |
185 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER)); | 171 registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER)); |
186 ASSERT_NO_FATAL_FAILURE( | 172 ASSERT_NO_FATAL_FAILURE( |
187 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE)); | 173 registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE)); |
188 | 174 |
189 // Ensure that IsPerUserInstall returns the proper value. | 175 // Ensure that IsPerUserInstall returns the proper value. |
190 ASSERT_EQ(!system_install_, InstallUtil::IsPerUserInstall(chrome_exe_)); | 176 ASSERT_EQ(!system_install_, InstallUtil::IsPerUserInstall(chrome_exe_)); |
191 | 177 |
192 distribution_ = BrowserDistribution::GetDistribution(); | 178 distribution_ = BrowserDistribution::GetDistribution(); |
193 } | 179 } |
194 | 180 |
195 bool system_install_; | 181 bool system_install_ = false; |
196 bool chrome_sxs_; | |
197 base::FilePath chrome_exe_; | 182 base::FilePath chrome_exe_; |
198 BrowserDistribution* distribution_; | 183 BrowserDistribution* distribution_ = nullptr; |
199 | 184 |
200 private: | 185 private: |
201 base::FilePath GetChromePathForParams() const { | 186 base::FilePath GetChromePath() const { |
202 base::FilePath chrome_exe; | 187 base::FilePath chrome_exe; |
203 int dir_key = base::DIR_LOCAL_APP_DATA; | 188 int dir_key = base::DIR_LOCAL_APP_DATA; |
204 | 189 |
205 if (system_install_) { | 190 if (system_install_) { |
206 #if defined(_WIN64) | 191 #if defined(_WIN64) |
207 static const int kSystemKey = base::DIR_PROGRAM_FILESX86; | 192 static const int kSystemKey = base::DIR_PROGRAM_FILESX86; |
208 #else | 193 #else |
209 static const int kSystemKey = base::DIR_PROGRAM_FILES; | 194 static const int kSystemKey = base::DIR_PROGRAM_FILES; |
210 #endif | 195 #endif |
211 dir_key = kSystemKey; | 196 dir_key = kSystemKey; |
212 } | 197 } |
213 PathService::Get(dir_key, &chrome_exe); | 198 PathService::Get(dir_key, &chrome_exe); |
214 #if defined(GOOGLE_CHROME_BUILD) | 199 if (*install_static::kCompanyPathName) |
215 chrome_exe = chrome_exe.Append(installer::kGoogleChromeInstallSubDir1); | 200 chrome_exe = chrome_exe.Append(install_static::kCompanyPathName); |
216 if (chrome_sxs_) { | 201 chrome_exe = chrome_exe.Append( |
217 chrome_exe = chrome_exe.Append( | 202 base::string16(install_static::kProductPathName) |
218 base::string16(installer::kGoogleChromeInstallSubDir2) + | 203 .append(install_static::InstallDetails::Get().install_suffix())); |
219 installer::kSxSSuffix); | |
220 } else { | |
221 chrome_exe = chrome_exe.Append(installer::kGoogleChromeInstallSubDir2); | |
222 } | |
223 #else | |
224 chrome_exe = chrome_exe.AppendASCII("Chromium"); | |
225 #endif | |
226 chrome_exe = chrome_exe.Append(installer::kInstallBinaryDir); | 204 chrome_exe = chrome_exe.Append(installer::kInstallBinaryDir); |
227 return chrome_exe.Append(installer::kChromeExe); | 205 return chrome_exe.Append(installer::kChromeExe); |
228 } | 206 } |
229 | 207 |
230 ScopedVector<base::ScopedPathOverride> path_overrides_; | 208 std::unique_ptr<install_static::ScopedInstallDetails> scoped_install_details_; |
231 registry_util::RegistryOverrideManager registry_override_manager_; | 209 registry_util::RegistryOverrideManager registry_override_manager_; |
232 }; | 210 }; |
233 | 211 |
234 // Tests that the default browser beacons work as expected. | 212 // Tests that the default browser beacons work as expected. |
235 TEST_P(DefaultBrowserBeaconTest, All) { | 213 TEST_P(DefaultBrowserBeaconTest, All) { |
236 std::unique_ptr<Beacon> last_was_default(MakeLastWasDefaultBeacon( | 214 std::unique_ptr<Beacon> last_was_default(MakeLastWasDefaultBeacon( |
237 system_install_, distribution_->GetAppRegistrationData())); | 215 system_install_, distribution_->GetAppRegistrationData())); |
238 std::unique_ptr<Beacon> first_not_default(MakeFirstNotDefaultBeacon( | 216 std::unique_ptr<Beacon> first_not_default(MakeFirstNotDefaultBeacon( |
239 system_install_, distribution_->GetAppRegistrationData())); | 217 system_install_, distribution_->GetAppRegistrationData())); |
240 | 218 |
(...skipping 24 matching lines...) Expand all Loading... | |
265 ASSERT_FALSE(last_was_default->Get().is_null()); | 243 ASSERT_FALSE(last_was_default->Get().is_null()); |
266 ASSERT_FALSE(first_not_default->Get().is_null()); | 244 ASSERT_FALSE(first_not_default->Get().is_null()); |
267 | 245 |
268 // And it still isn't. | 246 // And it still isn't. |
269 UpdateDefaultBrowserBeaconWithState(chrome_exe_, distribution_, | 247 UpdateDefaultBrowserBeaconWithState(chrome_exe_, distribution_, |
270 ShellUtil::NOT_DEFAULT); | 248 ShellUtil::NOT_DEFAULT); |
271 ASSERT_FALSE(last_was_default->Get().is_null()); | 249 ASSERT_FALSE(last_was_default->Get().is_null()); |
272 ASSERT_FALSE(first_not_default->Get().is_null()); | 250 ASSERT_FALSE(first_not_default->Get().is_null()); |
273 } | 251 } |
274 | 252 |
275 INSTANTIATE_TEST_CASE_P(SystemLevelChrome, | 253 #if defined(GOOGLE_CHROME_BUILD) |
276 DefaultBrowserBeaconTest, | 254 // Stable supports user and system levels. |
277 Values(DistributionVariant::SYSTEM_LEVEL)); | 255 INSTANTIATE_TEST_CASE_P( |
278 INSTANTIATE_TEST_CASE_P(UserLevelChrome, | 256 Stable, |
279 DefaultBrowserBeaconTest, | 257 DefaultBrowserBeaconTest, |
280 Values(DistributionVariant::USER_LEVEL)); | 258 testing::Combine(testing::Values(install_static::STABLE_INDEX), |
281 #if 0 && defined(GOOGLE_CHROME_BUILD) | 259 testing::Values("user", "system"))); |
282 // Disabled for now since InstallUtil::IsChromeSxSProcess makes this impossible. | 260 // Canary is only at user level. |
gab
2017/02/14 16:57:56
Nice :)! Was there an associated bug that this res
grt (UTC plus 2)
2017/02/14 21:04:23
Hooray for test seams! I can't find a bug for this
| |
283 INSTANTIATE_TEST_CASE_P(ChromeSxS, DefaultBrowserBeaconTest, | 261 INSTANTIATE_TEST_CASE_P( |
284 Values(DistributionVariant::SXS)); | 262 Canary, |
285 #endif | 263 DefaultBrowserBeaconTest, |
264 testing::Combine(testing::Values(install_static::CANARY_INDEX), | |
265 testing::Values("user"))); | |
266 #else // GOOGLE_CHROME_BUILD | |
267 // Chromium supports user and system levels. | |
268 INSTANTIATE_TEST_CASE_P( | |
269 Chromium, | |
270 DefaultBrowserBeaconTest, | |
271 testing::Combine(testing::Values(install_static::CHROMIUM_INDEX), | |
272 testing::Values("user", "system"))); | |
273 #endif // !GOOGLE_CHROME_BUILD | |
gab
2017/02/14 16:57:56
remove "!"
| |
286 | 274 |
287 } // namespace installer_util | 275 } // namespace installer_util |
OLD | NEW |