Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/installer/setup/installer_state_unittest.cc

Issue 2589753002: Remove multi-install from chrome/installer/setup. (Closed)
Patch Set: gab and robertshield comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 DISALLOW_COPY_AND_ASSIGN(InstallerStateTest); 55 DISALLOW_COPY_AND_ASSIGN(InstallerStateTest);
56 }; 56 };
57 57
58 // An installer state on which we can access otherwise protected members. 58 // An installer state on which we can access otherwise protected members.
59 class MockInstallerState : public InstallerState { 59 class MockInstallerState : public InstallerState {
60 public: 60 public:
61 MockInstallerState() : InstallerState() { } 61 MockInstallerState() : InstallerState() { }
62 void set_target_path(const base::FilePath& target_path) { 62 void set_target_path(const base::FilePath& target_path) {
63 target_path_ = target_path; 63 target_path_ = target_path;
64 } 64 }
65 static bool IsFileInUse(const base::FilePath& file) {
66 return InstallerState::IsFileInUse(file);
67 }
68 const base::Version& critical_update_version() const { 65 const base::Version& critical_update_version() const {
69 return critical_update_version_; 66 return critical_update_version_;
70 } 67 }
71 }; 68 };
72 69
73 TEST_F(InstallerStateTest, WithProduct) { 70 TEST_F(InstallerStateTest, WithProduct) {
74 const bool multi_install = false;
75 const bool system_level = true; 71 const bool system_level = true;
76 base::CommandLine cmd_line = base::CommandLine::FromString( 72 base::CommandLine cmd_line = base::CommandLine::FromString(
77 std::wstring(L"setup.exe") + 73 std::wstring(L"setup.exe") +
78 (multi_install ? L" --multi-install --chrome" : L"") +
79 (system_level ? L" --system-level" : L"")); 74 (system_level ? L" --system-level" : L""));
80 MasterPreferences prefs(cmd_line); 75 MasterPreferences prefs(cmd_line);
81 InstallationState machine_state; 76 InstallationState machine_state;
82 machine_state.Initialize(); 77 machine_state.Initialize();
83 MockInstallerState installer_state; 78 MockInstallerState installer_state;
84 installer_state.Initialize(cmd_line, prefs, machine_state); 79 installer_state.Initialize(cmd_line, prefs, machine_state);
85 installer_state.set_target_path(test_dir_.GetPath()); 80 installer_state.set_target_path(test_dir_.GetPath());
86 EXPECT_EQ(1U, installer_state.products().size());
87 EXPECT_EQ(system_level, installer_state.system_install()); 81 EXPECT_EQ(system_level, installer_state.system_install());
88 82
89 const char kCurrentVersion[] = "1.2.3.4"; 83 const char kCurrentVersion[] = "1.2.3.4";
90 base::Version current_version(kCurrentVersion); 84 base::Version current_version(kCurrentVersion);
91 85
92 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 86 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
93 EXPECT_EQ(root, installer_state.root_key()); 87 EXPECT_EQ(root, installer_state.root_key());
94 88
95 { 89 {
96 RegistryOverrideManager override_manager; 90 RegistryOverrideManager override_manager;
(...skipping 19 matching lines...) Expand all
116 110
117 TEST_F(InstallerStateTest, InstallerResult) { 111 TEST_F(InstallerStateTest, InstallerResult) {
118 const bool system_level = true; 112 const bool system_level = true;
119 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 113 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
120 114
121 RegKey key; 115 RegKey key;
122 std::wstring launch_cmd = L"hey diddle diddle"; 116 std::wstring launch_cmd = L"hey diddle diddle";
123 std::wstring value; 117 std::wstring value;
124 DWORD dw_value; 118 DWORD dw_value;
125 119
126 // Check results for a fresh install of single Chrome and the same for an 120 // Check results for a fresh install of Chrome and the same for an attempt at
127 // attempt at multi-install, which is now ignored. 121 // multi-install, which is now ignored.
128 static constexpr const wchar_t* kCommandLines[] = { 122 static constexpr const wchar_t* kCommandLines[] = {
129 L"setup.exe --system-level", 123 L"setup.exe --system-level",
130 L"setup.exe --system-level --multi-install --chrome", 124 L"setup.exe --system-level --multi-install --chrome",
131 }; 125 };
132 for (const wchar_t* command_line : kCommandLines) { 126 for (const wchar_t* command_line : kCommandLines) {
133 RegistryOverrideManager override_manager; 127 RegistryOverrideManager override_manager;
134 override_manager.OverrideRegistry(root); 128 override_manager.OverrideRegistry(root);
135 base::CommandLine cmd_line = base::CommandLine::FromString(command_line); 129 base::CommandLine cmd_line = base::CommandLine::FromString(command_line);
136 const MasterPreferences prefs(cmd_line); 130 const MasterPreferences prefs(cmd_line);
137 InstallationState machine_state; 131 InstallationState machine_state;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 MasterPreferences prefs(cmd_line); 171 MasterPreferences prefs(cmd_line);
178 InstallerState installer_state; 172 InstallerState installer_state;
179 installer_state.Initialize(cmd_line, prefs, machine_state); 173 installer_state.Initialize(cmd_line, prefs, machine_state);
180 174
181 // Is the Chrome version picked up? 175 // Is the Chrome version picked up?
182 std::unique_ptr<base::Version> version( 176 std::unique_ptr<base::Version> version(
183 installer_state.GetCurrentVersion(machine_state)); 177 installer_state.GetCurrentVersion(machine_state));
184 EXPECT_TRUE(version.get() != NULL); 178 EXPECT_TRUE(version.get() != NULL);
185 } 179 }
186 180
187 TEST_F(InstallerStateTest, IsFileInUse) {
188 base::ScopedTempDir temp_dir;
189 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
190
191 base::FilePath temp_file;
192 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &temp_file));
193
194 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file));
195
196 {
197 // Open a handle to the file with the same access mode and sharing options
198 // as the loader.
199 base::win::ScopedHandle temp_handle(CreateFile(
200 temp_file.value().c_str(), SYNCHRONIZE | FILE_EXECUTE,
201 FILE_SHARE_DELETE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0));
202 ASSERT_TRUE(temp_handle.IsValid());
203
204 // The file should now be in use.
205 EXPECT_TRUE(MockInstallerState::IsFileInUse(temp_file));
206 }
207
208 // And once the handle is gone, it should no longer be in use.
209 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file));
210 }
211
212 TEST_F(InstallerStateTest, InitializeTwice) { 181 TEST_F(InstallerStateTest, InitializeTwice) {
213 // Override these paths so that they can be found after the registry override 182 // Override these paths so that they can be found after the registry override
214 // manager is in place. 183 // manager is in place.
215 base::FilePath temp; 184 base::FilePath temp;
216 PathService::Get(base::DIR_PROGRAM_FILES, &temp); 185 PathService::Get(base::DIR_PROGRAM_FILES, &temp);
217 base::ScopedPathOverride program_files_override(base::DIR_PROGRAM_FILES, 186 base::ScopedPathOverride program_files_override(base::DIR_PROGRAM_FILES,
218 temp); 187 temp);
219 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp); 188 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp);
220 base::ScopedPathOverride program_filesx86_override(base::DIR_PROGRAM_FILESX86, 189 base::ScopedPathOverride program_filesx86_override(base::DIR_PROGRAM_FILESX86,
221 temp); 190 temp);
(...skipping 10 matching lines...) Expand all
232 InstallerState installer_state; 201 InstallerState installer_state;
233 202
234 // Initialize the instance to install user-level Chrome. 203 // Initialize the instance to install user-level Chrome.
235 { 204 {
236 base::CommandLine cmd_line(base::CommandLine::FromString(L"setup.exe")); 205 base::CommandLine cmd_line(base::CommandLine::FromString(L"setup.exe"));
237 MasterPreferences prefs(cmd_line); 206 MasterPreferences prefs(cmd_line);
238 installer_state.Initialize(cmd_line, prefs, machine_state); 207 installer_state.Initialize(cmd_line, prefs, machine_state);
239 } 208 }
240 // Confirm the expected state. 209 // Confirm the expected state.
241 EXPECT_EQ(InstallerState::USER_LEVEL, installer_state.level()); 210 EXPECT_EQ(InstallerState::USER_LEVEL, installer_state.level());
242 EXPECT_EQ(InstallerState::SINGLE_PACKAGE, installer_state.package_type());
243 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE, 211 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE,
244 installer_state.operation()); 212 installer_state.operation());
245 EXPECT_TRUE(wcsstr(installer_state.target_path().value().c_str(), 213 EXPECT_TRUE(wcsstr(installer_state.target_path().value().c_str(),
246 BrowserDistribution::GetSpecificDistribution( 214 BrowserDistribution::GetSpecificDistribution(
247 BrowserDistribution::CHROME_BROWSER) 215 BrowserDistribution::CHROME_BROWSER)
248 ->GetInstallSubDir() 216 ->GetInstallSubDir()
249 .c_str())); 217 .c_str()));
250 EXPECT_FALSE(installer_state.verbose_logging()); 218 EXPECT_FALSE(installer_state.verbose_logging());
251 EXPECT_EQ(installer_state.state_key(), 219 EXPECT_EQ(installer_state.state_key(),
252 BrowserDistribution::GetSpecificDistribution( 220 BrowserDistribution::GetSpecificDistribution(
253 BrowserDistribution::CHROME_BROWSER)->GetStateKey()); 221 BrowserDistribution::CHROME_BROWSER)->GetStateKey());
254 EXPECT_EQ(installer_state.state_type(), BrowserDistribution::CHROME_BROWSER); 222 EXPECT_EQ(installer_state.state_type(), BrowserDistribution::CHROME_BROWSER);
255 EXPECT_TRUE(installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER));
256 223
257 // Now initialize it to install system-level single Chrome. 224 // Now initialize it to install system-level single Chrome.
258 { 225 {
259 base::CommandLine cmd_line(base::CommandLine::FromString( 226 base::CommandLine cmd_line(base::CommandLine::FromString(
260 L"setup.exe --system-level --verbose-logging")); 227 L"setup.exe --system-level --verbose-logging"));
261 MasterPreferences prefs(cmd_line); 228 MasterPreferences prefs(cmd_line);
262 installer_state.Initialize(cmd_line, prefs, machine_state); 229 installer_state.Initialize(cmd_line, prefs, machine_state);
263 } 230 }
264 231
265 // Confirm that the old state is gone. 232 // Confirm that the old state is gone.
266 EXPECT_EQ(InstallerState::SYSTEM_LEVEL, installer_state.level()); 233 EXPECT_EQ(InstallerState::SYSTEM_LEVEL, installer_state.level());
267 EXPECT_EQ(InstallerState::SINGLE_PACKAGE, installer_state.package_type());
268 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE, 234 EXPECT_EQ(InstallerState::SINGLE_INSTALL_OR_UPDATE,
269 installer_state.operation()); 235 installer_state.operation());
270 EXPECT_TRUE(wcsstr(installer_state.target_path().value().c_str(), 236 EXPECT_TRUE(wcsstr(installer_state.target_path().value().c_str(),
271 BrowserDistribution::GetSpecificDistribution( 237 BrowserDistribution::GetSpecificDistribution(
272 BrowserDistribution::CHROME_BROWSER)-> 238 BrowserDistribution::CHROME_BROWSER)->
273 GetInstallSubDir().c_str())); 239 GetInstallSubDir().c_str()));
274 EXPECT_TRUE(installer_state.verbose_logging()); 240 EXPECT_TRUE(installer_state.verbose_logging());
275 EXPECT_EQ(installer_state.state_key(), 241 EXPECT_EQ(installer_state.state_key(),
276 BrowserDistribution::GetSpecificDistribution( 242 BrowserDistribution::GetSpecificDistribution(
277 BrowserDistribution::CHROME_BROWSER)->GetStateKey()); 243 BrowserDistribution::CHROME_BROWSER)->GetStateKey());
278 EXPECT_EQ(installer_state.state_type(), BrowserDistribution::CHROME_BROWSER); 244 EXPECT_EQ(installer_state.state_type(), BrowserDistribution::CHROME_BROWSER);
279 EXPECT_TRUE(installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER));
280 } 245 }
281 246
282 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual 247 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual
283 // tests must invoke Initialize() with a critical version. 248 // tests must invoke Initialize() with a critical version.
284 class InstallerStateCriticalVersionTest : public ::testing::Test { 249 class InstallerStateCriticalVersionTest : public ::testing::Test {
285 protected: 250 protected:
286 InstallerStateCriticalVersionTest() 251 InstallerStateCriticalVersionTest()
287 : cmd_line_(base::CommandLine::NO_PROGRAM) {} 252 : cmd_line_(base::CommandLine::NO_PROGRAM) {}
288 253
289 // Creates a set of versions for use by all test runs. 254 // Creates a set of versions for use by all test runs.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // Critical update newer than the new version. 386 // Critical update newer than the new version.
422 EXPECT_FALSE( 387 EXPECT_FALSE(
423 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); 388 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
424 EXPECT_FALSE( 389 EXPECT_FALSE(
425 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) 390 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
426 .IsValid()); 391 .IsValid());
427 EXPECT_FALSE( 392 EXPECT_FALSE(
428 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) 393 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
429 .IsValid()); 394 .IsValid());
430 } 395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698