OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <utility> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/win/registry.h" | 9 #include "base/win/registry.h" |
10 #include "chrome/installer/util/browser_distribution.h" | |
11 #include "chrome/installer/util/google_update_constants.h" | 10 #include "chrome/installer/util/google_update_constants.h" |
12 #include "chrome/installer/util/installation_state.h" | |
13 #include "chrome/installer/util/installer_state.h" | |
14 #include "chrome/installer/util/install_util.h" | 11 #include "chrome/installer/util/install_util.h" |
15 #include "chrome/installer/util/master_preferences.h" | |
16 #include "chrome/installer/util/product_unittest.h" | 12 #include "chrome/installer/util/product_unittest.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
18 | 14 |
19 using base::win::RegKey; | 15 using base::win::RegKey; |
20 using installer::InstallationState; | |
21 using installer::InstallerState; | |
22 using installer::MasterPreferences; | |
23 using ::testing::_; | 16 using ::testing::_; |
24 using ::testing::Return; | 17 using ::testing::Return; |
25 using ::testing::StrEq; | 18 using ::testing::StrEq; |
26 | 19 |
27 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { | 20 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { |
28 public: | 21 public: |
29 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&)); | 22 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&)); |
30 }; | 23 }; |
31 | 24 |
32 class InstallUtilTest : public TestWithTempDirAndDeleteTempOverrideKeys { | 25 class InstallUtilTest : public TestWithTempDirAndDeleteTempOverrideKeys { |
33 protected: | 26 protected: |
34 }; | 27 }; |
35 | 28 |
36 TEST_F(InstallUtilTest, InstallerResult) { | |
37 const bool system_level = true; | |
38 bool multi_install = false; | |
39 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
40 | |
41 RegKey key; | |
42 std::wstring launch_cmd = L"hey diddle diddle"; | |
43 std::wstring value; | |
44 | |
45 // check results for a fresh install of single Chrome | |
46 { | |
47 TempRegKeyOverride override(root, L"root_inst_res"); | |
48 CommandLine cmd_line = CommandLine::FromString(L"setup.exe --system-level"); | |
49 const MasterPreferences prefs(cmd_line); | |
50 InstallationState machine_state; | |
51 machine_state.Initialize(); | |
52 InstallerState state; | |
53 state.Initialize(cmd_line, prefs, machine_state); | |
54 InstallUtil::WriteInstallerResult(system_level, state.state_key(), | |
55 installer::FIRST_INSTALL_SUCCESS, 0, &launch_cmd); | |
56 BrowserDistribution* distribution = | |
57 BrowserDistribution::GetSpecificDistribution( | |
58 BrowserDistribution::CHROME_BROWSER); | |
59 EXPECT_EQ(ERROR_SUCCESS, | |
60 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); | |
61 EXPECT_EQ(ERROR_SUCCESS, | |
62 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | |
63 EXPECT_EQ(launch_cmd, value); | |
64 } | |
65 TempRegKeyOverride::DeleteAllTempKeys(); | |
66 | |
67 // check results for a fresh install of multi Chrome | |
68 { | |
69 TempRegKeyOverride override(root, L"root_inst_res"); | |
70 CommandLine cmd_line = CommandLine::FromString( | |
71 L"setup.exe --system-level --multi-install --chrome"); | |
72 const MasterPreferences prefs(cmd_line); | |
73 InstallationState machine_state; | |
74 machine_state.Initialize(); | |
75 InstallerState state; | |
76 state.Initialize(cmd_line, prefs, machine_state); | |
77 InstallUtil::WriteInstallerResult(system_level, state.state_key(), | |
78 installer::FIRST_INSTALL_SUCCESS, 0, &launch_cmd); | |
79 BrowserDistribution* distribution = | |
80 BrowserDistribution::GetSpecificDistribution( | |
81 BrowserDistribution::CHROME_BROWSER); | |
82 EXPECT_EQ(ERROR_SUCCESS, | |
83 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); | |
84 EXPECT_EQ(ERROR_SUCCESS, | |
85 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | |
86 EXPECT_EQ(launch_cmd, value); | |
87 key.Close(); | |
88 } | |
89 TempRegKeyOverride::DeleteAllTempKeys(); | |
90 } | |
91 | |
92 TEST_F(InstallUtilTest, MakeUninstallCommand) { | 29 TEST_F(InstallUtilTest, MakeUninstallCommand) { |
93 CommandLine command_line(CommandLine::NO_PROGRAM); | 30 CommandLine command_line(CommandLine::NO_PROGRAM); |
94 | 31 |
95 std::pair<std::wstring, std::wstring> params[] = { | 32 std::pair<std::wstring, std::wstring> params[] = { |
96 std::make_pair(std::wstring(L""), std::wstring(L"")), | 33 std::make_pair(std::wstring(L""), std::wstring(L"")), |
97 std::make_pair(std::wstring(L""), std::wstring(L"--do-something --silly")), | 34 std::make_pair(std::wstring(L""), std::wstring(L"--do-something --silly")), |
98 std::make_pair(std::wstring(L"spam.exe"), std::wstring(L"")), | 35 std::make_pair(std::wstring(L"spam.exe"), std::wstring(L"")), |
99 std::make_pair(std::wstring(L"spam.exe"), | 36 std::make_pair(std::wstring(L"spam.exe"), |
100 std::wstring(L"--do-something --silly")), | 37 std::wstring(L"--do-something --silly")), |
101 }; | 38 }; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 281 |
345 TEST_F(InstallUtilTest, ValueEquals) { | 282 TEST_F(InstallUtilTest, ValueEquals) { |
346 InstallUtil::ValueEquals pred(L"howdy"); | 283 InstallUtil::ValueEquals pred(L"howdy"); |
347 | 284 |
348 EXPECT_FALSE(pred.Evaluate(L"")); | 285 EXPECT_FALSE(pred.Evaluate(L"")); |
349 EXPECT_FALSE(pred.Evaluate(L"Howdy")); | 286 EXPECT_FALSE(pred.Evaluate(L"Howdy")); |
350 EXPECT_FALSE(pred.Evaluate(L"howdy!")); | 287 EXPECT_FALSE(pred.Evaluate(L"howdy!")); |
351 EXPECT_FALSE(pred.Evaluate(L"!howdy")); | 288 EXPECT_FALSE(pred.Evaluate(L"!howdy")); |
352 EXPECT_TRUE(pred.Evaluate(L"howdy")); | 289 EXPECT_TRUE(pred.Evaluate(L"howdy")); |
353 } | 290 } |
OLD | NEW |