| 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/util/installer_state.h" | 5 #include "chrome/installer/util/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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 const bool system_level = true; | 75 const bool system_level = true; |
| 76 base::CommandLine cmd_line = base::CommandLine::FromString( | 76 base::CommandLine cmd_line = base::CommandLine::FromString( |
| 77 std::wstring(L"setup.exe") + | 77 std::wstring(L"setup.exe") + |
| 78 (multi_install ? L" --multi-install --chrome" : L"") + | 78 (multi_install ? L" --multi-install --chrome" : L"") + |
| 79 (system_level ? L" --system-level" : L"")); | 79 (system_level ? L" --system-level" : L"")); |
| 80 MasterPreferences prefs(cmd_line); | 80 MasterPreferences prefs(cmd_line); |
| 81 InstallationState machine_state; | 81 InstallationState machine_state; |
| 82 machine_state.Initialize(); | 82 machine_state.Initialize(); |
| 83 MockInstallerState installer_state; | 83 MockInstallerState installer_state; |
| 84 installer_state.Initialize(cmd_line, prefs, machine_state); | 84 installer_state.Initialize(cmd_line, prefs, machine_state); |
| 85 installer_state.set_target_path(test_dir_.path()); | 85 installer_state.set_target_path(test_dir_.GetPath()); |
| 86 EXPECT_EQ(1U, installer_state.products().size()); | 86 EXPECT_EQ(1U, installer_state.products().size()); |
| 87 EXPECT_EQ(system_level, installer_state.system_install()); | 87 EXPECT_EQ(system_level, installer_state.system_install()); |
| 88 | 88 |
| 89 const char kCurrentVersion[] = "1.2.3.4"; | 89 const char kCurrentVersion[] = "1.2.3.4"; |
| 90 base::Version current_version(kCurrentVersion); | 90 base::Version current_version(kCurrentVersion); |
| 91 | 91 |
| 92 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 92 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 93 EXPECT_EQ(root, installer_state.root_key()); | 93 EXPECT_EQ(root, installer_state.root_key()); |
| 94 | 94 |
| 95 { | 95 { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 std::unique_ptr<base::Version> version( | 210 std::unique_ptr<base::Version> version( |
| 211 installer_state.GetCurrentVersion(machine_state)); | 211 installer_state.GetCurrentVersion(machine_state)); |
| 212 EXPECT_TRUE(version.get() != NULL); | 212 EXPECT_TRUE(version.get() != NULL); |
| 213 } | 213 } |
| 214 | 214 |
| 215 TEST_F(InstallerStateTest, IsFileInUse) { | 215 TEST_F(InstallerStateTest, IsFileInUse) { |
| 216 base::ScopedTempDir temp_dir; | 216 base::ScopedTempDir temp_dir; |
| 217 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 217 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 218 | 218 |
| 219 base::FilePath temp_file; | 219 base::FilePath temp_file; |
| 220 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); | 220 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &temp_file)); |
| 221 | 221 |
| 222 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); | 222 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); |
| 223 | 223 |
| 224 { | 224 { |
| 225 // Open a handle to the file with the same access mode and sharing options | 225 // Open a handle to the file with the same access mode and sharing options |
| 226 // as the loader. | 226 // as the loader. |
| 227 base::win::ScopedHandle temp_handle(CreateFile( | 227 base::win::ScopedHandle temp_handle(CreateFile( |
| 228 temp_file.value().c_str(), SYNCHRONIZE | FILE_EXECUTE, | 228 temp_file.value().c_str(), SYNCHRONIZE | FILE_EXECUTE, |
| 229 FILE_SHARE_DELETE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0)); | 229 FILE_SHARE_DELETE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0)); |
| 230 ASSERT_TRUE(temp_handle.IsValid()); | 230 ASSERT_TRUE(temp_handle.IsValid()); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 // Critical update newer than the new version. | 449 // Critical update newer than the new version. |
| 450 EXPECT_FALSE( | 450 EXPECT_FALSE( |
| 451 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 451 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
| 452 EXPECT_FALSE( | 452 EXPECT_FALSE( |
| 453 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 453 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
| 454 .IsValid()); | 454 .IsValid()); |
| 455 EXPECT_FALSE( | 455 EXPECT_FALSE( |
| 456 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 456 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
| 457 .IsValid()); | 457 .IsValid()); |
| 458 } | 458 } |
| OLD | NEW |