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

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 30 matching lines...) Expand all
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
69 // Okay, so this isn't really a mock as such, but it does add setter methods 63 // 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. 64 // to make it easier to build custom InstallationStates.
71 class MockInstallationState : public InstallationState { 65 class MockInstallationState : public InstallationState {
72 public: 66 public:
73 // Included for testing. 67 // 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, 68 void SetProductState(bool system_install,
84 BrowserDistribution::Type type, 69 BrowserDistribution::Type type,
85 const ProductState& product_state) { 70 const ProductState& product_state) {
86 ProductState& target = (system_install ? system_products_ : 71 ProductState& target = (system_install ? system_products_ :
87 user_products_)[IndexFromDistType(type)]; 72 user_products_)[IndexFromDistType(type)];
88 target.CopyFrom(product_state); 73 target.CopyFrom(product_state);
89 } 74 }
90 }; 75 };
91 76
92 class MockInstallerState : public InstallerState { 77 class MockInstallerState : public InstallerState {
93 public: 78 public:
94 void set_system_install(bool system_install) { 79 void set_level(Level level) {
95 system_install_ = system_install; 80 level_ = level;
96 } 81 }
97 82
98 void set_operation(Operation operation) { operation_ = operation; } 83 void set_operation(Operation operation) { operation_ = operation; }
99 84
100 void set_state_key(const std::wstring& state_key) { 85 void set_state_key(const std::wstring& state_key) {
101 state_key_ = state_key; 86 state_key_ = state_key;
102 } 87 }
103 }; 88 };
104 89
105 // The test fixture 90 // The test fixture
(...skipping 12 matching lines...) Expand all
118 // TODO(robertshield): Take this from the BrowserDistribution once that 103 // TODO(robertshield): Take this from the BrowserDistribution once that
119 // no longer depends on MasterPreferences. 104 // no longer depends on MasterPreferences.
120 installation_path_ = FilePath(L"C:\\Program Files\\Google\\Chrome\\"); 105 installation_path_ = FilePath(L"C:\\Program Files\\Google\\Chrome\\");
121 src_path_ = 106 src_path_ =
122 FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin"); 107 FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin");
123 setup_path_ = FilePath(L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe"); 108 setup_path_ = FilePath(L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe");
124 temp_dir_ = FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123"); 109 temp_dir_ = FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123");
125 } 110 }
126 111
127 virtual void TearDown() { 112 virtual void TearDown() {
128
129 } 113 }
130 114
131 MockInstallationState* BuildChromeSingleSystemInstallationState() { 115 MockInstallationState* BuildChromeSingleSystemInstallationState() {
132 scoped_ptr<MockInstallationState> installation_state( 116 scoped_ptr<MockInstallationState> installation_state(
133 new MockInstallationState()); 117 new MockInstallationState());
134 118
135 ProductState product_state; 119 ProductState product_state;
136 product_state.set_version(current_version_->Clone()); 120 product_state.set_version(current_version_->Clone());
137 // Do not call SetMultiPackageState since this is a single install. 121 // Do not call SetMultiPackageState since this is a single install.
138 installation_state->SetProductState(true, 122 installation_state->SetProductState(true,
139 BrowserDistribution::CHROME_BROWSER, 123 BrowserDistribution::CHROME_BROWSER,
140 product_state); 124 product_state);
141 125
142 return installation_state.release(); 126 return installation_state.release();
143 } 127 }
144 128
145 MockInstallerState* BuildChromeSingleSystemInstallerState() { 129 MockInstallerState* BuildChromeSingleSystemInstallerState(
130 const InstallationState& machine_state) {
146 scoped_ptr<MockInstallerState> installer_state(new MockInstallerState()); 131 scoped_ptr<MockInstallerState> installer_state(new MockInstallerState());
147 132
148 installer_state->set_system_install(true); 133 installer_state->set_level(InstallerState::SYSTEM_LEVEL);
149 installer_state->set_operation(InstallerState::SINGLE_INSTALL_OR_UPDATE); 134 installer_state->set_operation(InstallerState::SINGLE_INSTALL_OR_UPDATE);
150 // Hope this next one isn't checked for now. 135 // Hope this next one isn't checked for now.
151 installer_state->set_state_key(L"PROBABLY_INVALID_REG_PATH"); 136 installer_state->set_state_key(L"PROBABLY_INVALID_REG_PATH");
152 137 const ProductState* chrome =
138 machine_state.GetProductState(true,
139 BrowserDistribution::CHROME_BROWSER);
140 installer_state->AddProductFromState(BrowserDistribution::CHROME_BROWSER,
141 *chrome);
153 return installer_state.release(); 142 return installer_state.release();
154 } 143 }
155 144
156 protected: 145 protected:
157 scoped_ptr<Version> current_version_; 146 scoped_ptr<Version> current_version_;
158 scoped_ptr<Version> new_version_; 147 scoped_ptr<Version> new_version_;
159 FilePath archive_path_; 148 FilePath archive_path_;
160 FilePath installation_path_; 149 FilePath installation_path_;
161 FilePath setup_path_; 150 FilePath setup_path_;
162 FilePath src_path_; 151 FilePath src_path_;
163 FilePath temp_dir_; 152 FilePath temp_dir_;
164 }; 153 };
165 154
166 // Tests 155 // Tests
167 //------------------------------------------------------------------------------ 156 //------------------------------------------------------------------------------
168 157
169 TEST_F(InstallWorkerTest, TestInstallChromeSingleSystem) { 158 TEST_F(InstallWorkerTest, TestInstallChromeSingleSystem) {
170 MockWorkItemList work_item_list; 159 MockWorkItemList work_item_list;
171 160
172 scoped_ptr<InstallationState> installation_state( 161 scoped_ptr<InstallationState> installation_state(
173 BuildChromeSingleSystemInstallationState()); 162 BuildChromeSingleSystemInstallationState());
174 163
175 scoped_ptr<InstallerState> installer_state( 164 scoped_ptr<InstallerState> installer_state(
176 BuildChromeSingleSystemInstallerState()); 165 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 166
189 // Set up some expectations. 167 // Set up some expectations.
190 // TODO(robertshield): Set up some real expectations. 168 // TODO(robertshield): Set up some real expectations.
191 EXPECT_CALL(work_item_list, AddCopyTreeWorkItem(_,_,_,_,_)) 169 EXPECT_CALL(work_item_list, AddCopyTreeWorkItem(_,_,_,_,_))
192 .Times(AtLeast(1)); 170 .Times(AtLeast(1));
193 171
194 AddInstallWorkItems(*installation_state.get(), 172 AddInstallWorkItems(*installation_state.get(),
195 *installer_state.get(), 173 *installer_state.get(),
196 false,
197 setup_path_, 174 setup_path_,
198 archive_path_, 175 archive_path_,
199 src_path_, 176 src_path_,
200 temp_dir_, 177 temp_dir_,
201 *new_version_.get(), 178 *new_version_.get(),
202 &current_version_, 179 &current_version_,
203 *package.get(),
204 &work_item_list); 180 &work_item_list);
205 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698