| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 #include <utility> |
| 6 | 7 |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "base/win/registry.h" | 9 #include "base/win/registry.h" |
| 9 #include "chrome/installer/util/browser_distribution.h" | 10 #include "chrome/installer/util/browser_distribution.h" |
| 10 #include "chrome/installer/util/installation_state.h" | 11 #include "chrome/installer/util/installation_state.h" |
| 11 #include "chrome/installer/util/installer_state.h" | 12 #include "chrome/installer/util/installer_state.h" |
| 12 #include "chrome/installer/util/install_util.h" | 13 #include "chrome/installer/util/install_util.h" |
| 13 #include "chrome/installer/util/master_preferences.h" | 14 #include "chrome/installer/util/master_preferences.h" |
| 14 #include "chrome/installer/util/product_unittest.h" | 15 #include "chrome/installer/util/product_unittest.h" |
| 15 | 16 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 bool multi_install = false; | 28 bool multi_install = false; |
| 28 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 29 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 29 | 30 |
| 30 RegKey key; | 31 RegKey key; |
| 31 std::wstring launch_cmd = L"hey diddle diddle"; | 32 std::wstring launch_cmd = L"hey diddle diddle"; |
| 32 std::wstring value; | 33 std::wstring value; |
| 33 | 34 |
| 34 // check results for a fresh install of single Chrome | 35 // check results for a fresh install of single Chrome |
| 35 { | 36 { |
| 36 TempRegKeyOverride override(root, L"root_inst_res"); | 37 TempRegKeyOverride override(root, L"root_inst_res"); |
| 37 const MasterPreferences prefs( | 38 CommandLine cmd_line = CommandLine::FromString(L"setup.exe --system-level"); |
| 38 CommandLine::FromString(L"setup.exe --system-level")); | 39 const MasterPreferences prefs(cmd_line); |
| 39 InstallationState machine_state; | 40 InstallationState machine_state; |
| 40 machine_state.Initialize(prefs); | 41 machine_state.Initialize(); |
| 41 InstallerState state; | 42 InstallerState state; |
| 42 state.Initialize(prefs, machine_state); | 43 state.Initialize(cmd_line, prefs, machine_state); |
| 43 InstallUtil::WriteInstallerResult(system_level, state.state_key(), | 44 InstallUtil::WriteInstallerResult(system_level, state.state_key(), |
| 44 installer::FIRST_INSTALL_SUCCESS, 0, &launch_cmd); | 45 installer::FIRST_INSTALL_SUCCESS, 0, &launch_cmd); |
| 45 BrowserDistribution* distribution = | 46 BrowserDistribution* distribution = |
| 46 BrowserDistribution::GetSpecificDistribution( | 47 BrowserDistribution::GetSpecificDistribution( |
| 47 BrowserDistribution::CHROME_BROWSER, prefs); | 48 BrowserDistribution::CHROME_BROWSER); |
| 48 EXPECT_EQ(ERROR_SUCCESS, | 49 EXPECT_EQ(ERROR_SUCCESS, |
| 49 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); | 50 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); |
| 50 EXPECT_EQ(ERROR_SUCCESS, | 51 EXPECT_EQ(ERROR_SUCCESS, |
| 51 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | 52 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); |
| 52 EXPECT_EQ(launch_cmd, value); | 53 EXPECT_EQ(launch_cmd, value); |
| 53 } | 54 } |
| 54 TempRegKeyOverride::DeleteAllTempKeys(); | 55 TempRegKeyOverride::DeleteAllTempKeys(); |
| 55 | 56 |
| 56 // check results for a fresh install of multi Chrome | 57 // check results for a fresh install of multi Chrome |
| 57 { | 58 { |
| 58 TempRegKeyOverride override(root, L"root_inst_res"); | 59 TempRegKeyOverride override(root, L"root_inst_res"); |
| 59 const MasterPreferences prefs( | 60 CommandLine cmd_line = CommandLine::FromString( |
| 60 CommandLine::FromString( | 61 L"setup.exe --system-level --multi-install --chrome"); |
| 61 L"setup.exe --system-level --multi-install --chrome")); | 62 const MasterPreferences prefs(cmd_line); |
| 62 InstallationState machine_state; | 63 InstallationState machine_state; |
| 63 machine_state.Initialize(prefs); | 64 machine_state.Initialize(); |
| 64 InstallerState state; | 65 InstallerState state; |
| 65 state.Initialize(prefs, machine_state); | 66 state.Initialize(cmd_line, prefs, machine_state); |
| 66 InstallUtil::WriteInstallerResult(system_level, state.state_key(), | 67 InstallUtil::WriteInstallerResult(system_level, state.state_key(), |
| 67 installer::FIRST_INSTALL_SUCCESS, 0, &launch_cmd); | 68 installer::FIRST_INSTALL_SUCCESS, 0, &launch_cmd); |
| 68 BrowserDistribution* distribution = | 69 BrowserDistribution* distribution = |
| 69 BrowserDistribution::GetSpecificDistribution( | 70 BrowserDistribution::GetSpecificDistribution( |
| 70 BrowserDistribution::CHROME_BROWSER, prefs); | 71 BrowserDistribution::CHROME_BROWSER); |
| 71 EXPECT_EQ(ERROR_SUCCESS, | 72 EXPECT_EQ(ERROR_SUCCESS, |
| 72 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); | 73 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); |
| 73 EXPECT_EQ(ERROR_SUCCESS, | 74 EXPECT_EQ(ERROR_SUCCESS, |
| 74 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | 75 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); |
| 75 EXPECT_EQ(launch_cmd, value); | 76 EXPECT_EQ(launch_cmd, value); |
| 76 key.Close(); | 77 key.Close(); |
| 77 } | 78 } |
| 78 TempRegKeyOverride::DeleteAllTempKeys(); | 79 TempRegKeyOverride::DeleteAllTempKeys(); |
| 79 } | 80 } |
| 81 |
| 82 TEST_F(InstallUtilTest, MakeUninstallCommand) { |
| 83 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 84 |
| 85 std::pair<std::wstring, std::wstring> params[] = { |
| 86 std::make_pair(std::wstring(L""), std::wstring(L"")), |
| 87 std::make_pair(std::wstring(L""), std::wstring(L"--do-something --silly")), |
| 88 std::make_pair(std::wstring(L"spam.exe"), std::wstring(L"")), |
| 89 std::make_pair(std::wstring(L"spam.exe"), |
| 90 std::wstring(L"--do-something --silly")), |
| 91 }; |
| 92 for (int i = 0; i < arraysize(params); ++i) { |
| 93 std::pair<std::wstring, std::wstring>& param = params[i]; |
| 94 InstallUtil::MakeUninstallCommand(param.first, param.second, &command_line); |
| 95 EXPECT_EQ(param.first, command_line.GetProgram().value()); |
| 96 if (param.second.empty()) { |
| 97 EXPECT_EQ(0U, command_line.GetSwitchCount()); |
| 98 } else { |
| 99 EXPECT_EQ(2U, command_line.GetSwitchCount()); |
| 100 EXPECT_TRUE(command_line.HasSwitch("do-something")); |
| 101 EXPECT_TRUE(command_line.HasSwitch("silly")); |
| 102 } |
| 103 } |
| 104 } |
| OLD | NEW |