OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/setup/installer_state.h" | 5 #include "chrome/installer/setup/installer_state.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <fstream> | 10 #include <fstream> |
11 | 11 |
12 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/test/scoped_path_override.h" | 21 #include "base/test/scoped_path_override.h" |
22 #include "base/test/test_reg_util_win.h" | 22 #include "base/test/test_reg_util_win.h" |
23 #include "base/version.h" | 23 #include "base/version.h" |
24 #include "base/win/registry.h" | 24 #include "base/win/registry.h" |
25 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
26 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/installer/util/fake_installation_state.h" | 27 #include "chrome/installer/util/fake_installation_state.h" |
28 #include "chrome/installer/util/fake_product_state.h" | 28 #include "chrome/installer/util/fake_product_state.h" |
29 #include "chrome/installer/util/google_update_constants.h" | 29 #include "chrome/installer/util/google_update_constants.h" |
30 #include "chrome/installer/util/helper.h" | |
31 #include "chrome/installer/util/installation_state.h" | 30 #include "chrome/installer/util/installation_state.h" |
32 #include "chrome/installer/util/installer_util_strings.h" | 31 #include "chrome/installer/util/installer_util_strings.h" |
33 #include "chrome/installer/util/master_preferences.h" | 32 #include "chrome/installer/util/master_preferences.h" |
34 #include "chrome/installer/util/util_constants.h" | 33 #include "chrome/installer/util/util_constants.h" |
35 #include "chrome/installer/util/work_item.h" | 34 #include "chrome/installer/util/work_item.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
37 | 36 |
38 using base::win::RegKey; | 37 using base::win::RegKey; |
39 using installer::InstallationState; | 38 using installer::InstallationState; |
40 using installer::InstallerState; | 39 using installer::InstallerState; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 EXPECT_EQ(static_cast<DWORD>(installer::FIRST_INSTALL_SUCCESS), dw_value); | 143 EXPECT_EQ(static_cast<DWORD>(installer::FIRST_INSTALL_SUCCESS), dw_value); |
145 EXPECT_EQ(ERROR_SUCCESS, | 144 EXPECT_EQ(ERROR_SUCCESS, |
146 key.ReadValue(installer::kInstallerResultUIString, &value)); | 145 key.ReadValue(installer::kInstallerResultUIString, &value)); |
147 EXPECT_FALSE(value.empty()); | 146 EXPECT_FALSE(value.empty()); |
148 EXPECT_EQ(ERROR_SUCCESS, | 147 EXPECT_EQ(ERROR_SUCCESS, |
149 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | 148 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); |
150 EXPECT_EQ(launch_cmd, value); | 149 EXPECT_EQ(launch_cmd, value); |
151 } | 150 } |
152 } | 151 } |
153 | 152 |
154 // Test GetCurrentVersion when migrating single Chrome to multi | |
155 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { | |
156 using installer::FakeInstallationState; | |
157 | |
158 const bool system_install = false; | |
159 FakeInstallationState machine_state; | |
160 | |
161 // Pretend that this version of single-install Chrome is already installed. | |
162 machine_state.AddChrome(system_install, | |
163 new base::Version(chrome::kChromeVersion)); | |
164 | |
165 // Now we're invoked to install multi Chrome. | |
166 base::CommandLine cmd_line( | |
167 base::CommandLine::FromString(L"setup.exe --multi-install --chrome")); | |
168 MasterPreferences prefs(cmd_line); | |
169 InstallerState installer_state; | |
170 installer_state.Initialize(cmd_line, prefs, machine_state); | |
171 | |
172 // Is the Chrome version picked up? | |
173 std::unique_ptr<base::Version> version( | |
174 installer_state.GetCurrentVersion(machine_state)); | |
175 EXPECT_TRUE(version.get() != NULL); | |
176 } | |
177 | |
178 TEST_F(InstallerStateTest, InitializeTwice) { | 153 TEST_F(InstallerStateTest, InitializeTwice) { |
179 // Override these paths so that they can be found after the registry override | 154 // Override these paths so that they can be found after the registry override |
180 // manager is in place. | 155 // manager is in place. |
181 base::FilePath temp; | 156 base::FilePath temp; |
182 PathService::Get(base::DIR_PROGRAM_FILES, &temp); | 157 PathService::Get(base::DIR_PROGRAM_FILES, &temp); |
183 base::ScopedPathOverride program_files_override(base::DIR_PROGRAM_FILES, | 158 base::ScopedPathOverride program_files_override(base::DIR_PROGRAM_FILES, |
184 temp); | 159 temp); |
185 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp); | 160 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp); |
186 base::ScopedPathOverride program_filesx86_override(base::DIR_PROGRAM_FILESX86, | 161 base::ScopedPathOverride program_filesx86_override(base::DIR_PROGRAM_FILESX86, |
187 temp); | 162 temp); |
(...skipping 19 matching lines...) Expand all Loading... |
207 EXPECT_EQ(InstallerState::USER_LEVEL, installer_state.level()); | 182 EXPECT_EQ(InstallerState::USER_LEVEL, installer_state.level()); |
208 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE, | 183 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE, |
209 installer_state.operation()); | 184 installer_state.operation()); |
210 EXPECT_TRUE(wcsstr( | 185 EXPECT_TRUE(wcsstr( |
211 installer_state.target_path().value().c_str(), | 186 installer_state.target_path().value().c_str(), |
212 BrowserDistribution::GetDistribution()->GetInstallSubDir().c_str())); | 187 BrowserDistribution::GetDistribution()->GetInstallSubDir().c_str())); |
213 EXPECT_FALSE(installer_state.verbose_logging()); | 188 EXPECT_FALSE(installer_state.verbose_logging()); |
214 EXPECT_EQ(installer_state.state_key(), | 189 EXPECT_EQ(installer_state.state_key(), |
215 BrowserDistribution::GetDistribution()->GetStateKey()); | 190 BrowserDistribution::GetDistribution()->GetStateKey()); |
216 | 191 |
217 // Now initialize it to install system-level single Chrome. | 192 // Now initialize it to install system-level Chrome. |
218 { | 193 { |
219 base::CommandLine cmd_line(base::CommandLine::FromString( | 194 base::CommandLine cmd_line(base::CommandLine::FromString( |
220 L"setup.exe --system-level --verbose-logging")); | 195 L"setup.exe --system-level --verbose-logging")); |
221 MasterPreferences prefs(cmd_line); | 196 MasterPreferences prefs(cmd_line); |
222 installer_state.Initialize(cmd_line, prefs, machine_state); | 197 installer_state.Initialize(cmd_line, prefs, machine_state); |
223 } | 198 } |
224 | 199 |
225 // Confirm that the old state is gone. | 200 // Confirm that the old state is gone. |
226 EXPECT_EQ(InstallerState::SYSTEM_LEVEL, installer_state.level()); | 201 EXPECT_EQ(InstallerState::SYSTEM_LEVEL, installer_state.level()); |
227 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE, | 202 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 // Critical update newer than the new version. | 351 // Critical update newer than the new version. |
377 EXPECT_FALSE( | 352 EXPECT_FALSE( |
378 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 353 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
379 EXPECT_FALSE( | 354 EXPECT_FALSE( |
380 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 355 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
381 .IsValid()); | 356 .IsValid()); |
382 EXPECT_FALSE( | 357 EXPECT_FALSE( |
383 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 358 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
384 .IsValid()); | 359 .IsValid()); |
385 } | 360 } |
OLD | NEW |