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 <map> | |
6 | |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/file_path.h" | 8 #include "base/file_path.h" |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
9 #include "base/version.h" | 11 #include "base/version.h" |
10 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
11 #include "chrome/installer/util/channel_info.h" | 13 #include "chrome/installer/util/channel_info.h" |
12 #include "chrome/installer/util/helper.h" | 14 #include "chrome/installer/util/helper.h" |
13 #include "chrome/installer/util/installation_state.h" | 15 #include "chrome/installer/util/installation_state.h" |
14 #include "chrome/installer/util/installation_validator.h" | 16 #include "chrome/installer/util/installation_validator.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
18 using installer::ChannelInfo; | 20 using installer::ChannelInfo; |
19 using installer::InstallationValidator; | 21 using installer::InstallationValidator; |
20 using installer::InstallationState; | 22 using installer::InstallationState; |
23 using installer::ProductCommand; | |
21 using installer::ProductState; | 24 using installer::ProductState; |
22 using testing::_; | 25 using testing::_; |
23 using testing::StrictMock; | 26 using testing::StrictMock; |
27 using testing::Values; | |
24 | 28 |
25 namespace { | 29 namespace { |
26 | 30 |
27 enum Channel { | 31 enum Channel { |
28 STABLE_CHANNEL, | 32 STABLE_CHANNEL, |
29 BETA_CHANNEL, | 33 BETA_CHANNEL, |
30 DEV_CHANNEL | 34 DEV_CHANNEL |
31 }; | 35 }; |
32 | 36 |
33 enum PackageType { | 37 enum PackageType { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 class FakeProductState : public ProductState { | 72 class FakeProductState : public ProductState { |
69 public: | 73 public: |
70 void Clear(); | 74 void Clear(); |
71 void SetChannel(const wchar_t* base, int channel_modifiers); | 75 void SetChannel(const wchar_t* base, int channel_modifiers); |
72 void SetVersion(const char* version); | 76 void SetVersion(const char* version); |
73 void SetUninstallCommand(BrowserDistribution::Type dist_type, | 77 void SetUninstallCommand(BrowserDistribution::Type dist_type, |
74 Level install_level, | 78 Level install_level, |
75 const char* version, | 79 const char* version, |
76 int channel_modifiers, | 80 int channel_modifiers, |
77 Vehicle vehicle); | 81 Vehicle vehicle); |
82 void AddQuickEnableCfCommand(BrowserDistribution::Type dist_type, | |
83 Level install_level, | |
84 const char* version, | |
85 int channel_modifiers); | |
86 void RemoveQuickEnableCfCommand(BrowserDistribution::Type dist_type); | |
78 void set_multi_install(bool is_multi_install) { | 87 void set_multi_install(bool is_multi_install) { |
79 multi_install_ = is_multi_install; | 88 multi_install_ = is_multi_install; |
80 } | 89 } |
90 installer::ProductCommands& commands() { return commands_; } | |
81 | 91 |
82 protected: | 92 protected: |
83 struct ChannelMethodForModifier { | 93 struct ChannelMethodForModifier { |
84 ChannelModifier modifier; | 94 ChannelModifier modifier; |
85 bool (ChannelInfo::*method)(bool value); | 95 bool (ChannelInfo::*method)(bool value); |
86 }; | 96 }; |
87 | 97 |
98 static FilePath GetSetupExePath( | |
99 BrowserDistribution::Type dist_type, | |
100 Level install_level, | |
101 const char* version, | |
102 int channel_modifiers); | |
103 | |
88 static const ChannelMethodForModifier kChannelMethods[]; | 104 static const ChannelMethodForModifier kChannelMethods[]; |
89 }; | 105 }; |
90 | 106 |
91 class FakeInstallationState : public InstallationState { | 107 class FakeInstallationState : public InstallationState { |
92 public: | 108 public: |
93 void SetProductState(BrowserDistribution::Type type, | 109 void SetProductState(BrowserDistribution::Type type, |
94 Level install_level, | 110 Level install_level, |
95 const ProductState& product) { | 111 const ProductState& product) { |
96 GetProducts(install_level)[IndexFromDistType(type)].CopyFrom(product); | 112 GetProducts(install_level)[IndexFromDistType(type)].CopyFrom(product); |
97 } | 113 } |
98 | 114 |
99 protected: | 115 protected: |
100 ProductState* GetProducts(Level install_level) { | 116 ProductState* GetProducts(Level install_level) { |
101 return install_level == USER_LEVEL ? user_products_ : system_products_; | 117 return install_level == USER_LEVEL ? user_products_ : system_products_; |
102 } | 118 } |
103 }; | 119 }; |
104 | 120 |
105 // static | 121 // static |
106 const FakeProductState::ChannelMethodForModifier | 122 const FakeProductState::ChannelMethodForModifier |
107 FakeProductState::kChannelMethods[] = { | 123 FakeProductState::kChannelMethods[] = { |
108 { CM_MULTI, &ChannelInfo::SetMultiInstall }, | 124 { CM_MULTI, &ChannelInfo::SetMultiInstall }, |
109 { CM_CHROME, &ChannelInfo::SetChrome }, | 125 { CM_CHROME, &ChannelInfo::SetChrome }, |
110 { CM_CHROME_FRAME, &ChannelInfo::SetChromeFrame }, | 126 { CM_CHROME_FRAME, &ChannelInfo::SetChromeFrame }, |
111 { CM_READY_MODE, &ChannelInfo::SetReadyMode }, | 127 { CM_READY_MODE, &ChannelInfo::SetReadyMode }, |
112 { CM_FULL, &ChannelInfo::SetFullSuffix } | 128 { CM_FULL, &ChannelInfo::SetFullSuffix } |
113 }; | 129 }; |
114 | 130 |
131 // static | |
132 FilePath FakeProductState::GetSetupExePath(BrowserDistribution::Type dist_type, | |
133 Level install_level, | |
134 const char* version, | |
135 int channel_modifiers) { | |
136 const bool is_multi_install = (channel_modifiers & CM_MULTI) != 0; | |
137 FilePath setup_path = installer::GetChromeInstallPath( | |
138 install_level == SYSTEM_LEVEL, | |
139 BrowserDistribution::GetSpecificDistribution(is_multi_install ? | |
140 BrowserDistribution::CHROME_BINARIES : dist_type)); | |
141 return setup_path | |
142 .AppendASCII(version) | |
143 .Append(installer::kInstallerDir) | |
144 .Append(installer::kSetupExe); | |
145 } | |
146 | |
115 void FakeProductState::Clear() { | 147 void FakeProductState::Clear() { |
116 channel_.set_value(std::wstring()); | 148 channel_.set_value(std::wstring()); |
117 version_.reset(); | 149 version_.reset(); |
118 old_version_.reset(); | 150 old_version_.reset(); |
119 rename_cmd_.clear(); | 151 rename_cmd_.clear(); |
120 uninstall_command_ = CommandLine(CommandLine::NO_PROGRAM); | 152 uninstall_command_ = CommandLine(CommandLine::NO_PROGRAM); |
153 commands_.Clear(); | |
121 msi_ = false; | 154 msi_ = false; |
122 multi_install_ = false; | 155 multi_install_ = false; |
123 } | 156 } |
124 | 157 |
125 // Sets the channel_ member of this instance according to a base channel value | 158 // Sets the channel_ member of this instance according to a base channel value |
126 // and a set of modifiers. | 159 // and a set of modifiers. |
127 void FakeProductState::SetChannel(const wchar_t* base, int channel_modifiers) { | 160 void FakeProductState::SetChannel(const wchar_t* base, int channel_modifiers) { |
128 channel_.set_value(base); | 161 channel_.set_value(base); |
129 for (size_t i = 0; i < arraysize(kChannelMethods); ++i) { | 162 for (size_t i = 0; i < arraysize(kChannelMethods); ++i) { |
130 if ((channel_modifiers & kChannelMethods[i].modifier) != 0) | 163 if ((channel_modifiers & kChannelMethods[i].modifier) != 0) |
131 (channel_.*kChannelMethods[i].method)(true); | 164 (channel_.*kChannelMethods[i].method)(true); |
132 } | 165 } |
133 } | 166 } |
134 | 167 |
135 void FakeProductState::SetVersion(const char* version) { | 168 void FakeProductState::SetVersion(const char* version) { |
136 version_.reset( | 169 version_.reset( |
137 version == NULL ? NULL : Version::GetVersionFromString(version)); | 170 version == NULL ? NULL : Version::GetVersionFromString(version)); |
138 } | 171 } |
139 | 172 |
140 // Sets the uninstall command for this object. | 173 // Sets the uninstall command for this object. |
141 void FakeProductState::SetUninstallCommand(BrowserDistribution::Type dist_type, | 174 void FakeProductState::SetUninstallCommand(BrowserDistribution::Type dist_type, |
142 Level install_level, | 175 Level install_level, |
143 const char* version, | 176 const char* version, |
144 int channel_modifiers, | 177 int channel_modifiers, |
145 Vehicle vehicle) { | 178 Vehicle vehicle) { |
146 DCHECK(version); | 179 DCHECK(version); |
147 | 180 |
148 const bool is_multi_install = (channel_modifiers & CM_MULTI) != 0; | 181 const bool is_multi_install = (channel_modifiers & CM_MULTI) != 0; |
149 FilePath setup_path = installer::GetChromeInstallPath( | 182 uninstall_command_ = CommandLine(GetSetupExePath(dist_type, install_level, |
150 install_level == SYSTEM_LEVEL, | 183 version, channel_modifiers)); |
151 BrowserDistribution::GetSpecificDistribution(is_multi_install ? | |
152 BrowserDistribution::CHROME_BINARIES : dist_type)); | |
153 setup_path = setup_path | |
154 .AppendASCII(version) | |
155 .Append(installer::kInstallerDir) | |
156 .Append(installer::kSetupExe); | |
157 uninstall_command_ = CommandLine(setup_path); | |
158 uninstall_command_.AppendSwitch(installer::switches::kUninstall); | 184 uninstall_command_.AppendSwitch(installer::switches::kUninstall); |
159 if (install_level == SYSTEM_LEVEL) | 185 if (install_level == SYSTEM_LEVEL) |
160 uninstall_command_.AppendSwitch(installer::switches::kSystemLevel); | 186 uninstall_command_.AppendSwitch(installer::switches::kSystemLevel); |
161 if (is_multi_install) { | 187 if (is_multi_install) { |
162 uninstall_command_.AppendSwitch(installer::switches::kMultiInstall); | 188 uninstall_command_.AppendSwitch(installer::switches::kMultiInstall); |
163 if (dist_type == BrowserDistribution::CHROME_BROWSER) { | 189 if (dist_type == BrowserDistribution::CHROME_BROWSER) { |
164 uninstall_command_.AppendSwitch(installer::switches::kChrome); | 190 uninstall_command_.AppendSwitch(installer::switches::kChrome); |
165 if ((channel_modifiers & CM_READY_MODE) != 0) { | 191 if ((channel_modifiers & CM_READY_MODE) != 0) { |
166 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); | 192 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); |
167 uninstall_command_.AppendSwitch( | 193 uninstall_command_.AppendSwitch( |
168 installer::switches::kChromeFrameReadyMode); | 194 installer::switches::kChromeFrameReadyMode); |
169 } | 195 } |
196 } else if (dist_type == BrowserDistribution::CHROME_FRAME) { | |
197 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); | |
198 if ((channel_modifiers & CM_READY_MODE) != 0) { | |
199 uninstall_command_.AppendSwitch( | |
200 installer::switches::kChromeFrameReadyMode); | |
201 } | |
170 } | 202 } |
171 } else if (dist_type == BrowserDistribution::CHROME_FRAME) { | 203 } else if (dist_type == BrowserDistribution::CHROME_FRAME) { |
172 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); | 204 uninstall_command_.AppendSwitch(installer::switches::kChromeFrame); |
173 } | 205 } |
174 if (vehicle == MSI) | 206 if (vehicle == MSI) |
175 uninstall_command_.AppendSwitch(installer::switches::kMsi); | 207 uninstall_command_.AppendSwitch(installer::switches::kMsi); |
176 } | 208 } |
177 | 209 |
178 // Populates |chrome_state| with the state of a valid Chrome browser | 210 // Adds the "quick-enable-cf" Google Update product command. |
179 // installation. |channel_modifiers|, a field of bits defined by enum | 211 void FakeProductState::AddQuickEnableCfCommand( |
180 // ChannelModifier, dictate properties of the installation (multi-install, | 212 BrowserDistribution::Type dist_type, |
181 // ready-mode, etc). | 213 Level install_level, |
182 void MakeChromeState(Level install_level, | 214 const char* version, |
183 Channel channel, | 215 int channel_modifiers) { |
184 int channel_modifiers, | 216 DCHECK_EQ(dist_type, BrowserDistribution::CHROME_BINARIES); |
185 Vehicle vehicle, | 217 DCHECK_NE(channel_modifiers & CM_MULTI, 0); |
186 FakeProductState* chrome_state) { | 218 |
187 chrome_state->Clear(); | 219 CommandLine cmd_line(GetSetupExePath(dist_type, install_level, version, |
188 chrome_state->SetChannel(kChromeChannels[channel], channel_modifiers); | 220 channel_modifiers)); |
189 chrome_state->SetVersion(chrome::kChromeVersion); | 221 cmd_line.AppendSwitch(installer::switches::kMultiInstall); |
190 chrome_state->SetUninstallCommand(BrowserDistribution::CHROME_BROWSER, | 222 if (install_level == SYSTEM_LEVEL) |
191 install_level, chrome::kChromeVersion, | 223 cmd_line.AppendSwitch(installer::switches::kSystemLevel); |
192 channel_modifiers, vehicle); | 224 cmd_line.AppendSwitch(installer::switches::kChromeFrameQuickEnable); |
193 chrome_state->set_multi_install((channel_modifiers & CM_MULTI) != 0); | 225 commands_.Set(installer::kCmdQuickEnableCf, |
226 ProductCommand(cmd_line.command_line_string(), true, true)); | |
227 } | |
228 | |
229 // Removes the "quick-enable-cf" Google Update product command. | |
230 void FakeProductState::RemoveQuickEnableCfCommand( | |
231 BrowserDistribution::Type dist_type) { | |
232 DCHECK_EQ(dist_type, BrowserDistribution::CHROME_BINARIES); | |
233 | |
234 commands_.Remove(installer::kCmdQuickEnableCf); | |
194 } | 235 } |
195 | 236 |
196 } // namespace | 237 } // namespace |
197 | 238 |
198 // Fixture for testing the InstallationValidator. Errors logged by the | 239 // Fixture for testing the InstallationValidator. Errors logged by the |
199 // validator are sent to an optional mock recipient (see | 240 // validator are sent to an optional mock recipient (see |
200 // set_validation_error_recipient) upon which expectations can be placed. | 241 // set_validation_error_recipient) upon which expectations can be placed. |
201 class InstallationValidatorTest : public testing::Test { | 242 class InstallationValidatorTest |
243 : public testing::TestWithParam<InstallationValidator::InstallationType> { | |
244 public: | |
245 | |
246 // These shouldn't need to be public, but there seems to be some interaction | |
247 // with parameterized tests that requires it. | |
248 static void SetUpTestCase(); | |
249 static void TearDownTestCase(); | |
250 | |
251 // Returns the multi channel modifiers for a given installation type. | |
252 static int GetChannelModifiers(InstallationValidator::InstallationType type); | |
253 | |
202 protected: | 254 protected: |
255 typedef std::map<InstallationValidator::InstallationType, int> | |
256 InstallationTypeToModifiers; | |
257 | |
203 class ValidationErrorRecipient { | 258 class ValidationErrorRecipient { |
204 public: | 259 public: |
205 virtual ~ValidationErrorRecipient() { } | 260 virtual ~ValidationErrorRecipient() { } |
206 virtual void ReceiveValidationError(const char* file, | 261 virtual void ReceiveValidationError(const char* file, |
207 int line, | 262 int line, |
208 const char* message) = 0; | 263 const char* message) = 0; |
209 }; | 264 }; |
210 class MockValidationErrorRecipient : public ValidationErrorRecipient { | 265 class MockValidationErrorRecipient : public ValidationErrorRecipient { |
211 public: | 266 public: |
212 MOCK_METHOD3(ReceiveValidationError, void(const char* file, | 267 MOCK_METHOD3(ReceiveValidationError, void(const char* file, |
213 int line, | 268 int line, |
214 const char* message)); | 269 const char* message)); |
215 }; | 270 }; |
216 | 271 |
217 static void SetUpTestCase(); | 272 protected: |
218 static void TearDownTestCase(); | |
219 static bool HandleLogMessage(int severity, | 273 static bool HandleLogMessage(int severity, |
220 const char* file, | 274 const char* file, |
221 int line, | 275 int line, |
222 size_t message_start, | 276 size_t message_start, |
223 const std::string& str); | 277 const std::string& str); |
224 static void set_validation_error_recipient( | 278 static void set_validation_error_recipient( |
225 ValidationErrorRecipient* recipient); | 279 ValidationErrorRecipient* recipient); |
226 | 280 static void MakeProductState( |
281 BrowserDistribution::Type prod_type, | |
282 InstallationValidator::InstallationType inst_type, | |
283 Level install_level, | |
284 Channel channel, | |
285 Vehicle vehicle, | |
286 FakeProductState* state); | |
287 static void MakeMachineState( | |
288 InstallationValidator::InstallationType inst_type, | |
289 Level install_level, | |
290 Channel channel, | |
291 Vehicle vehicle, | |
292 FakeInstallationState* state); | |
227 virtual void TearDown(); | 293 virtual void TearDown(); |
228 | 294 |
229 static logging::LogMessageHandlerFunction old_log_message_handler_; | 295 static logging::LogMessageHandlerFunction old_log_message_handler_; |
230 static ValidationErrorRecipient* validation_error_recipient_; | 296 static ValidationErrorRecipient* validation_error_recipient_; |
297 static InstallationTypeToModifiers* type_to_modifiers_; | |
231 }; | 298 }; |
232 | 299 |
233 // static | 300 // static |
234 logging::LogMessageHandlerFunction | 301 logging::LogMessageHandlerFunction |
235 InstallationValidatorTest::old_log_message_handler_ = NULL; | 302 InstallationValidatorTest::old_log_message_handler_ = NULL; |
236 | 303 |
237 // static | 304 // static |
238 InstallationValidatorTest::ValidationErrorRecipient* | 305 InstallationValidatorTest::ValidationErrorRecipient* |
239 InstallationValidatorTest::validation_error_recipient_ = NULL; | 306 InstallationValidatorTest::validation_error_recipient_ = NULL; |
240 | 307 |
241 // static | 308 // static |
309 InstallationValidatorTest::InstallationTypeToModifiers* | |
310 InstallationValidatorTest::type_to_modifiers_ = NULL; | |
311 | |
312 // static | |
313 int InstallationValidatorTest::GetChannelModifiers( | |
314 InstallationValidator::InstallationType type) { | |
315 DCHECK(type_to_modifiers_); | |
316 DCHECK(type_to_modifiers_->find(type) != type_to_modifiers_->end()); | |
317 | |
318 return (*type_to_modifiers_)[type]; | |
319 } | |
320 | |
321 // static | |
242 void InstallationValidatorTest::SetUpTestCase() { | 322 void InstallationValidatorTest::SetUpTestCase() { |
243 old_log_message_handler_ = logging::GetLogMessageHandler(); | 323 old_log_message_handler_ = logging::GetLogMessageHandler(); |
244 logging::SetLogMessageHandler(&HandleLogMessage); | 324 logging::SetLogMessageHandler(&HandleLogMessage); |
325 | |
326 type_to_modifiers_ = new InstallationTypeToModifiers(); | |
tommi (sloooow) - chröme
2011/03/01 23:33:13
DCHECK(type_to_modifiers_ == NULL) first?
grt (UTC plus 2)
2011/03/02 19:48:28
Done.
| |
327 InstallationTypeToModifiers& ttm = *type_to_modifiers_; | |
328 ttm[InstallationValidator::NO_PRODUCTS] = 0; | |
329 ttm[InstallationValidator::CHROME_SINGLE] = 0; | |
330 ttm[InstallationValidator::CHROME_MULTI] = CM_MULTI | CM_CHROME; | |
331 ttm[InstallationValidator::CHROME_FRAME_SINGLE] = 0; | |
332 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE] = 0; | |
333 ttm[InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI] = | |
334 CM_MULTI | CM_CHROME; | |
335 ttm[InstallationValidator::CHROME_FRAME_MULTI] = CM_MULTI | CM_CHROME_FRAME; | |
336 ttm[InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI] = | |
337 CM_MULTI | CM_CHROME_FRAME | CM_CHROME; | |
338 ttm[InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI] = | |
339 CM_MULTI | CM_CHROME_FRAME | CM_CHROME | CM_READY_MODE; | |
245 } | 340 } |
246 | 341 |
247 // static | 342 // static |
248 void InstallationValidatorTest::TearDownTestCase() { | 343 void InstallationValidatorTest::TearDownTestCase() { |
249 logging::SetLogMessageHandler(old_log_message_handler_); | 344 logging::SetLogMessageHandler(old_log_message_handler_); |
250 old_log_message_handler_ = NULL; | 345 old_log_message_handler_ = NULL; |
346 | |
347 delete type_to_modifiers_; | |
348 type_to_modifiers_ = NULL; | |
251 } | 349 } |
252 | 350 |
253 // static | 351 // static |
254 bool InstallationValidatorTest::HandleLogMessage(int severity, | 352 bool InstallationValidatorTest::HandleLogMessage(int severity, |
255 const char* file, | 353 const char* file, |
256 int line, | 354 int line, |
257 size_t message_start, | 355 size_t message_start, |
258 const std::string& str) { | 356 const std::string& str) { |
259 // All validation failures result in LOG(ERROR) | 357 // All validation failures result in LOG(ERROR) |
260 if (severity == logging::LOG_ERROR) { | 358 if (severity == logging::LOG_ERROR && !str.empty()) { |
359 // Remove the trailing newline, if present. | |
360 std::streamsize message_length = str.size() - message_start; | |
361 if (*str.rbegin() == '\n') | |
362 --message_length; | |
261 if (validation_error_recipient_ != NULL) { | 363 if (validation_error_recipient_ != NULL) { |
262 validation_error_recipient_->ReceiveValidationError( | 364 validation_error_recipient_->ReceiveValidationError( |
263 file, line, str.c_str() + message_start); | 365 file, line, str.substr(message_start, message_length).c_str()); |
264 } else { | 366 } else { |
265 // Fail the test if an error wasn't handled. | 367 // Fail the test if an error wasn't handled. |
266 ADD_FAILURE_AT(file, line) << (str.c_str() + message_start); | 368 ADD_FAILURE_AT(file, line) |
369 << base::StringPiece(str.c_str() + message_start, message_length); | |
267 } | 370 } |
268 return true; | 371 return true; |
269 } | 372 } |
270 | 373 |
271 if (old_log_message_handler_ != NULL) | 374 if (old_log_message_handler_ != NULL) |
272 return (old_log_message_handler_)(severity, file, line, message_start, str); | 375 return (old_log_message_handler_)(severity, file, line, message_start, str); |
273 | 376 |
274 return false; | 377 return false; |
275 } | 378 } |
276 | 379 |
277 // static | 380 // static |
278 void InstallationValidatorTest::set_validation_error_recipient( | 381 void InstallationValidatorTest::set_validation_error_recipient( |
279 ValidationErrorRecipient* recipient) { | 382 ValidationErrorRecipient* recipient) { |
280 validation_error_recipient_ = recipient; | 383 validation_error_recipient_ = recipient; |
281 } | 384 } |
282 | 385 |
386 // static | |
387 // Populates |state| with the state of a valid installation of product | |
388 // |prod_type|. |inst_type| dictates properties of the installation | |
389 // (multi-install, ready-mode, etc). | |
390 void InstallationValidatorTest::MakeProductState( | |
391 BrowserDistribution::Type prod_type, | |
392 InstallationValidator::InstallationType inst_type, | |
393 Level install_level, | |
394 Channel channel, | |
395 Vehicle vehicle, | |
396 FakeProductState* state) { | |
397 DCHECK(state); | |
398 | |
399 const bool is_multi_install = | |
400 prod_type == BrowserDistribution::CHROME_BINARIES || | |
401 (prod_type == BrowserDistribution::CHROME_BROWSER && | |
402 (inst_type & InstallationValidator::ProductBits::CHROME_MULTI) != 0) || | |
403 (prod_type == BrowserDistribution::CHROME_FRAME && | |
404 (inst_type & | |
405 (InstallationValidator::ProductBits::CHROME_FRAME_MULTI | | |
406 InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE)) != 0); | |
407 | |
408 const wchar_t* const* channels = &kChromeChannels[0]; | |
409 if (prod_type == BrowserDistribution::CHROME_FRAME && !is_multi_install) | |
410 channels = &kChromeFrameChannels[0]; // SxS GCF has its own channel names. | |
411 const int channel_modifiers = | |
412 is_multi_install ? GetChannelModifiers(inst_type) : 0; | |
413 | |
414 state->Clear(); | |
415 state->SetChannel(channels[channel], channel_modifiers); | |
416 state->SetVersion(chrome::kChromeVersion); | |
417 state->SetUninstallCommand(prod_type, install_level, chrome::kChromeVersion, | |
418 channel_modifiers, vehicle); | |
419 state->set_multi_install(is_multi_install); | |
420 if (prod_type == BrowserDistribution::CHROME_BINARIES && | |
421 (inst_type == InstallationValidator::CHROME_MULTI || | |
422 inst_type == | |
423 InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI)) { | |
424 state->AddQuickEnableCfCommand(prod_type, install_level, | |
425 chrome::kChromeVersion, channel_modifiers); | |
426 } | |
427 } | |
428 | |
429 // static | |
430 // Populates |state| with the state of a valid installation of |inst_type|. | |
431 void InstallationValidatorTest::MakeMachineState( | |
432 InstallationValidator::InstallationType inst_type, | |
433 Level install_level, | |
434 Channel channel, | |
435 Vehicle vehicle, | |
436 FakeInstallationState* state) { | |
437 DCHECK(state); | |
438 | |
439 static const int kChromeMask = | |
440 (InstallationValidator::ProductBits::CHROME_SINGLE | | |
441 InstallationValidator::ProductBits::CHROME_MULTI); | |
442 static const int kChromeFrameMask = | |
443 (InstallationValidator::ProductBits::CHROME_FRAME_SINGLE | | |
444 InstallationValidator::ProductBits::CHROME_FRAME_MULTI | | |
445 InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE); | |
446 static const int kBinariesMask = | |
447 (InstallationValidator::ProductBits::CHROME_MULTI | | |
448 InstallationValidator::ProductBits::CHROME_FRAME_MULTI | | |
449 InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE); | |
450 | |
451 FakeProductState prod_state; | |
452 | |
453 if ((inst_type & kChromeMask) != 0) { | |
454 MakeProductState(BrowserDistribution::CHROME_BROWSER, inst_type, | |
455 install_level, channel, vehicle, &prod_state); | |
456 state->SetProductState(BrowserDistribution::CHROME_BROWSER, install_level, | |
457 prod_state); | |
458 } | |
459 | |
460 if ((inst_type & kChromeFrameMask) != 0) { | |
461 MakeProductState(BrowserDistribution::CHROME_FRAME, inst_type, | |
462 install_level, channel, vehicle, &prod_state); | |
463 state->SetProductState(BrowserDistribution::CHROME_FRAME, install_level, | |
464 prod_state); | |
465 } | |
466 | |
467 if ((inst_type & kBinariesMask) != 0) { | |
468 MakeProductState(BrowserDistribution::CHROME_BINARIES, inst_type, | |
469 install_level, channel, vehicle, &prod_state); | |
470 state->SetProductState(BrowserDistribution::CHROME_BINARIES, install_level, | |
471 prod_state); | |
472 } | |
473 } | |
474 | |
283 void InstallationValidatorTest::TearDown() { | 475 void InstallationValidatorTest::TearDown() { |
284 validation_error_recipient_ = NULL; | 476 validation_error_recipient_ = NULL; |
285 } | 477 } |
286 | 478 |
287 // Test that NO_PRODUCTS is returned. | 479 // Builds a proper machine state for a given InstallationType, then validates |
288 TEST_F(InstallationValidatorTest, NoProducts) { | 480 // it. |
289 InstallationState empty_state; | 481 TEST_P(InstallationValidatorTest, TestValidInstallation) { |
290 InstallationValidator::InstallationType type = | 482 const InstallationValidator::InstallationType inst_type = GetParam(); |
291 static_cast<InstallationValidator::InstallationType>(-1); | |
292 StrictMock<MockValidationErrorRecipient> recipient; | |
293 set_validation_error_recipient(&recipient); | |
294 | |
295 EXPECT_TRUE(InstallationValidator::ValidateInstallationTypeForState( | |
296 empty_state, true, &type)); | |
297 EXPECT_EQ(InstallationValidator::NO_PRODUCTS, type); | |
298 } | |
299 | |
300 // Test valid single Chrome. | |
301 TEST_F(InstallationValidatorTest, ChromeVersion) { | |
302 FakeProductState chrome_state; | |
303 FakeInstallationState machine_state; | 483 FakeInstallationState machine_state; |
304 InstallationValidator::InstallationType type; | 484 InstallationValidator::InstallationType type; |
305 StrictMock<MockValidationErrorRecipient> recipient; | 485 StrictMock<MockValidationErrorRecipient> recipient; |
306 set_validation_error_recipient(&recipient); | 486 set_validation_error_recipient(&recipient); |
307 | 487 |
308 MakeChromeState(SYSTEM_LEVEL, STABLE_CHANNEL, 0, GOOGLE_UPDATE, | 488 MakeMachineState(inst_type, SYSTEM_LEVEL, STABLE_CHANNEL, GOOGLE_UPDATE, |
309 &chrome_state); | 489 &machine_state); |
310 machine_state.SetProductState(BrowserDistribution::CHROME_BROWSER, | |
311 SYSTEM_LEVEL, chrome_state); | |
312 EXPECT_TRUE(InstallationValidator::ValidateInstallationTypeForState( | 490 EXPECT_TRUE(InstallationValidator::ValidateInstallationTypeForState( |
313 machine_state, true, &type)); | 491 machine_state, true, &type)); |
314 EXPECT_EQ(InstallationValidator::CHROME_SINGLE, type); | 492 EXPECT_EQ(inst_type, type); |
315 } | 493 } |
494 | |
495 // Run the test for all installation types. | |
496 INSTANTIATE_TEST_CASE_P( | |
497 AllValidInstallations, | |
498 InstallationValidatorTest, | |
499 Values(InstallationValidator::NO_PRODUCTS, | |
500 InstallationValidator::CHROME_SINGLE, | |
501 InstallationValidator::CHROME_MULTI, | |
502 InstallationValidator::CHROME_FRAME_SINGLE, | |
503 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_SINGLE, | |
504 InstallationValidator::CHROME_FRAME_SINGLE_CHROME_MULTI, | |
505 InstallationValidator::CHROME_FRAME_MULTI, | |
506 InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI, | |
507 InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI)); | |
OLD | NEW |