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

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

Issue 6288009: More installer refactoring in the interest of fixing some bugs and cleaning t... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
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 "chrome/installer/setup/install_worker.h" 5 #include "chrome/installer/setup/install_worker.h"
6 6
7 #include "base/win/registry.h" 7 #include "base/win/registry.h"
8 #include "base/version.h" 8 #include "base/version.h"
9 #include "chrome/installer/util/installation_state.h" 9 #include "chrome/installer/util/installation_state.h"
10 #include "chrome/installer/util/installer_state.h" 10 #include "chrome/installer/util/installer_state.h"
11 #include "chrome/installer/util/package.h"
12 #include "chrome/installer/util/package_properties.h"
13 #include "chrome/installer/util/work_item_list.h" 11 #include "chrome/installer/util/work_item_list.h"
14 12
15 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
17 15
18 using installer::ChromiumPackageProperties;
19 using installer::InstallationState; 16 using installer::InstallationState;
20 using installer::InstallerState; 17 using installer::InstallerState;
21 using installer::Package;
22 using installer::PackageProperties;
23 using installer::PackagePropertiesImpl;
24 using installer::ProductState; 18 using installer::ProductState;
25 19
26 using ::testing::_; 20 using ::testing::_;
27 using ::testing::AtLeast; 21 using ::testing::AtLeast;
28 22
29 // Mock classes to help with testing 23 // Mock classes to help with testing
30 //------------------------------------------------------------------------------ 24 //------------------------------------------------------------------------------
31 25
32 class MockWorkItemList : public WorkItemList { 26 class MockWorkItemList : public WorkItemList {
33 public: 27 public:
(...skipping 25 matching lines...) Expand all
59 MOCK_METHOD5(AddSetRegValueWorkItem, WorkItem* (HKEY, 53 MOCK_METHOD5(AddSetRegValueWorkItem, WorkItem* (HKEY,
60 const std::wstring&, 54 const std::wstring&,
61 const std::wstring&, 55 const std::wstring&,
62 DWORD, 56 DWORD,
63 bool)); 57 bool));
64 MOCK_METHOD3(AddSelfRegWorkItem, WorkItem* (const std::wstring&, 58 MOCK_METHOD3(AddSelfRegWorkItem, WorkItem* (const std::wstring&,
65 bool, 59 bool,
66 bool)); 60 bool));
67 }; 61 };
68 62
63 class MockProductState : public ProductState {
64 public:
65 // Takes ownership of |version|.
66 void set_version(Version* version) { version_.reset(version); }
67 };
68
69 // Okay, so this isn't really a mock as such, but it does add setter methods 69 // Okay, so this isn't really a mock as such, but it does add setter methods
70 // to make it easier to build custom InstallationStates. 70 // to make it easier to build custom InstallationStates.
71 class MockInstallationState : public InstallationState { 71 class MockInstallationState : public InstallationState {
72 public: 72 public:
73 // Included for testing. 73 // Included for testing.
74 void SetMultiPackageState(bool system_install,
75 const ProductState& package_state) {
76 ProductState& target =
77 (system_install ? system_products_ : user_products_)
78 [MULTI_PACKAGE_INDEX];
79 target.CopyFrom(package_state);
80 }
81
82 // Included for testing.
83 void SetProductState(bool system_install, 74 void SetProductState(bool system_install,
84 BrowserDistribution::Type type, 75 BrowserDistribution::Type type,
85 const ProductState& product_state) { 76 const ProductState& product_state) {
86 ProductState& target = (system_install ? system_products_ : 77 ProductState& target = (system_install ? system_products_ :
87 user_products_)[IndexFromDistType(type)]; 78 user_products_)[IndexFromDistType(type)];
88 target.CopyFrom(product_state); 79 target.CopyFrom(product_state);
89 } 80 }
90 }; 81 };
91 82
92 class MockInstallerState : public InstallerState { 83 class MockInstallerState : public InstallerState {
93 public: 84 public:
94 void set_system_install(bool system_install) { 85 void set_level(Level level) {
95 system_install_ = system_install; 86 level_ = level;
96 } 87 }
97 88
98 void set_operation(Operation operation) { operation_ = operation; } 89 void set_operation(Operation operation) { operation_ = operation; }
99 90
100 void set_state_key(const std::wstring& state_key) { 91 void set_state_key(const std::wstring& state_key) {
101 state_key_ = state_key; 92 state_key_ = state_key;
102 } 93 }
103 }; 94 };
104 95
105 // The test fixture 96 // The test fixture
(...skipping 12 matching lines...) Expand all
118 // TODO(robertshield): Take this from the BrowserDistribution once that 109 // TODO(robertshield): Take this from the BrowserDistribution once that
119 // no longer depends on MasterPreferences. 110 // no longer depends on MasterPreferences.
120 installation_path_ = FilePath(L"C:\\Program Files\\Google\\Chrome\\"); 111 installation_path_ = FilePath(L"C:\\Program Files\\Google\\Chrome\\");
121 src_path_ = 112 src_path_ =
122 FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin"); 113 FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin");
123 setup_path_ = FilePath(L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe"); 114 setup_path_ = FilePath(L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe");
124 temp_dir_ = FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123"); 115 temp_dir_ = FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123");
125 } 116 }
126 117
127 virtual void TearDown() { 118 virtual void TearDown() {
128
129 } 119 }
130 120
131 MockInstallationState* BuildChromeSingleSystemInstallationState() { 121 MockInstallationState* BuildChromeSingleSystemInstallationState() {
132 scoped_ptr<MockInstallationState> installation_state( 122 scoped_ptr<MockInstallationState> installation_state(
133 new MockInstallationState()); 123 new MockInstallationState());
134 124
135 ProductState product_state; 125 MockProductState product_state;
136 product_state.set_version(current_version_->Clone()); 126 product_state.set_version(current_version_->Clone());
137 // Do not call SetMultiPackageState since this is a single install. 127 // Do not call SetMultiPackageState since this is a single install.
138 installation_state->SetProductState(true, 128 installation_state->SetProductState(true,
139 BrowserDistribution::CHROME_BROWSER, 129 BrowserDistribution::CHROME_BROWSER,
140 product_state); 130 product_state);
141 131
142 return installation_state.release(); 132 return installation_state.release();
143 } 133 }
144 134
145 MockInstallerState* BuildChromeSingleSystemInstallerState() { 135 MockInstallerState* BuildChromeSingleSystemInstallerState(
136 const InstallationState& machine_state) {
146 scoped_ptr<MockInstallerState> installer_state(new MockInstallerState()); 137 scoped_ptr<MockInstallerState> installer_state(new MockInstallerState());
147 138
148 installer_state->set_system_install(true); 139 installer_state->set_level(InstallerState::SYSTEM_LEVEL);
149 installer_state->set_operation(InstallerState::SINGLE_INSTALL_OR_UPDATE); 140 installer_state->set_operation(InstallerState::SINGLE_INSTALL_OR_UPDATE);
150 // Hope this next one isn't checked for now. 141 // Hope this next one isn't checked for now.
151 installer_state->set_state_key(L"PROBABLY_INVALID_REG_PATH"); 142 installer_state->set_state_key(L"PROBABLY_INVALID_REG_PATH");
152 143 const ProductState* chrome =
144 machine_state.GetProductState(true,
145 BrowserDistribution::CHROME_BROWSER);
146 installer_state->AddProductFromState(BrowserDistribution::CHROME_BROWSER,
147 *chrome);
153 return installer_state.release(); 148 return installer_state.release();
154 } 149 }
155 150
156 protected: 151 protected:
157 scoped_ptr<Version> current_version_; 152 scoped_ptr<Version> current_version_;
158 scoped_ptr<Version> new_version_; 153 scoped_ptr<Version> new_version_;
159 FilePath archive_path_; 154 FilePath archive_path_;
160 FilePath installation_path_; 155 FilePath installation_path_;
161 FilePath setup_path_; 156 FilePath setup_path_;
162 FilePath src_path_; 157 FilePath src_path_;
163 FilePath temp_dir_; 158 FilePath temp_dir_;
164 }; 159 };
165 160
166 // Tests 161 // Tests
167 //------------------------------------------------------------------------------ 162 //------------------------------------------------------------------------------
168 163
169 TEST_F(InstallWorkerTest, TestInstallChromeSingleSystem) { 164 TEST_F(InstallWorkerTest, TestInstallChromeSingleSystem) {
170 MockWorkItemList work_item_list; 165 MockWorkItemList work_item_list;
171 166
172 scoped_ptr<InstallationState> installation_state( 167 scoped_ptr<InstallationState> installation_state(
173 BuildChromeSingleSystemInstallationState()); 168 BuildChromeSingleSystemInstallationState());
174 169
175 scoped_ptr<InstallerState> installer_state( 170 scoped_ptr<InstallerState> installer_state(
176 BuildChromeSingleSystemInstallerState()); 171 BuildChromeSingleSystemInstallerState(*installation_state));
177
178 // This MUST outlive the package, since the package doesn't assume ownership
179 // of it. Note: This feels like an implementation bug:
180 // The PackageProperties <-> Package relationship is 1:1 and nothing else
181 // uses the PackageProperties. I have the feeling that PackageProperties, and
182 // perhaps Package itself should not exist at all.
183 scoped_ptr<PackageProperties> package_properties(
184 new ChromiumPackageProperties());
185
186 scoped_refptr<Package> package(
187 new Package(false, true, installation_path_, package_properties.get()));
188 172
189 // Set up some expectations. 173 // Set up some expectations.
190 // TODO(robertshield): Set up some real expectations. 174 // TODO(robertshield): Set up some real expectations.
191 EXPECT_CALL(work_item_list, AddCopyTreeWorkItem(_,_,_,_,_)) 175 EXPECT_CALL(work_item_list, AddCopyTreeWorkItem(_,_,_,_,_))
192 .Times(AtLeast(1)); 176 .Times(AtLeast(1));
193 177
194 AddInstallWorkItems(*installation_state.get(), 178 AddInstallWorkItems(*installation_state.get(),
195 *installer_state.get(), 179 *installer_state.get(),
196 false,
197 setup_path_, 180 setup_path_,
198 archive_path_, 181 archive_path_,
199 src_path_, 182 src_path_,
200 temp_dir_, 183 temp_dir_,
201 *new_version_.get(), 184 *new_version_.get(),
202 &current_version_, 185 &current_version_,
203 *package.get(),
204 &work_item_list); 186 &work_item_list);
205 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698