OLD | NEW |
| (Empty) |
1 // Copyright 2007-2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #include <mstask.h> | |
17 #include "omaha/base/app_util.h" | |
18 #include "omaha/base/constants.h" | |
19 #include "omaha/base/error.h" | |
20 #include "omaha/base/file.h" | |
21 #include "omaha/base/path.h" | |
22 #include "omaha/base/reg_key.h" | |
23 #include "omaha/base/shell.h" | |
24 #include "omaha/base/time.h" | |
25 #include "omaha/base/utils.h" | |
26 #include "omaha/base/vistautil.h" | |
27 #include "omaha/client/install.h" | |
28 #include "omaha/client/install_internal.h" | |
29 #include "omaha/client/install_self_internal.h" | |
30 #include "omaha/common/config_manager.h" | |
31 #include "omaha/common/const_goopdate.h" | |
32 #include "omaha/common/scheduled_task_utils.h" | |
33 #include "omaha/testing/unit_test.h" | |
34 | |
35 namespace omaha { | |
36 | |
37 namespace { | |
38 | |
39 const TCHAR* const kExpectedIid = _T("{A972BB39-CCA3-4F25-9737-3308F5FA19B5}"); | |
40 const TCHAR* const kExpectedBrand = _T("GOOG"); | |
41 const TCHAR* const kExpectedClientId = _T("some_partner"); | |
42 | |
43 const TCHAR* const kXpSystemSetupKey = _T("HKLM\\System\\Setup"); | |
44 const TCHAR* const kVistaSetupStateKey = | |
45 _T("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State"); | |
46 | |
47 // Assumes the fixture is inherited from RegistryProtectedInstallTest, | |
48 // RegistryProtectedWithComInterfacesPrimedInstallTest if is_machine. | |
49 // If is_machine, the test must run | |
50 // scheduled_task_utils::UninstallGoopdateTasks(true)) upon completion. | |
51 // The method used to prevent installing Omaha still results in Setup attempting | |
52 // to start the Core. When is_machine is true, this includes starting the | |
53 // service or scheduled task. If neither are installed, this fails with an | |
54 // assert. To avoid the assert, install the scheduled tasks. This is simpler | |
55 // than installing the service and copying files such that it will succeed. | |
56 // TODO(omaha3): Use a different method of avoiding running Setup; maybe a mock. | |
57 void PreventSetupFromRunning(bool is_machine) { | |
58 const TCHAR* const kFutureVersionString = _T("10.9.8.7"); | |
59 EXPECT_SUCCEEDED(RegKey::SetValue(is_machine ? | |
60 MACHINE_REG_CLIENTS_GOOPDATE : | |
61 USER_REG_CLIENTS_GOOPDATE, | |
62 kRegValueProductVersion, | |
63 kFutureVersionString)); | |
64 | |
65 if (!is_machine) { | |
66 return; | |
67 } | |
68 const CString task_path = ConcatenatePath( | |
69 app_util::GetCurrentModuleDirectory(), | |
70 _T("unittest_support\\SaveArguments.exe")); | |
71 EXPECT_SUCCEEDED(scheduled_task_utils::InstallGoopdateTasks(task_path, true)); | |
72 } | |
73 | |
74 } // namespace | |
75 | |
76 class InstallHandoffTest : public testing::Test { | |
77 protected: | |
78 explicit InstallHandoffTest(bool is_machine) | |
79 : omaha_path_(is_machine ? GetGoogleUpdateMachinePath() : | |
80 GetGoogleUpdateUserPath()), | |
81 path_(ConcatenatePath(omaha_path_, kVersionString)) { | |
82 } | |
83 | |
84 virtual void SetUp() { | |
85 // Save the existing version if present. | |
86 RegKey::GetValue(USER_REG_CLIENTS_GOOPDATE, | |
87 kRegValueProductVersion, | |
88 &existing_version_); | |
89 InstallFiles(); | |
90 } | |
91 | |
92 virtual void TearDown() { | |
93 EXPECT_SUCCEEDED(DeleteDirectory(path_)); | |
94 if (existing_version_.IsEmpty()) { | |
95 EXPECT_SUCCEEDED(RegKey::DeleteValue(USER_REG_CLIENTS_GOOPDATE, | |
96 kRegValueProductVersion)); | |
97 } else { | |
98 EXPECT_SUCCEEDED(RegKey::SetValue(USER_REG_CLIENTS_GOOPDATE, | |
99 kRegValueProductVersion, | |
100 existing_version_)); | |
101 } | |
102 } | |
103 | |
104 void InstallFiles() { | |
105 DeleteDirectory(path_); | |
106 EXPECT_FALSE(File::IsDirectory(path_)); | |
107 | |
108 EXPECT_SUCCEEDED(CreateDir(path_, NULL)); | |
109 | |
110 EXPECT_SUCCEEDED(File::Copy( | |
111 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
112 kOmahaShellFileName), | |
113 omaha_path_ + kOmahaShellFileName, | |
114 false)); | |
115 | |
116 EXPECT_SUCCEEDED(File::Copy( | |
117 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
118 kOmahaDllName), | |
119 ConcatenatePath(path_, kOmahaDllName), | |
120 false)); | |
121 | |
122 EXPECT_SUCCEEDED(RegKey::SetValue(USER_REG_CLIENTS_GOOPDATE, | |
123 kRegValueProductVersion, | |
124 kVersionString)); | |
125 } | |
126 | |
127 CString existing_version_; // Saves the existing version from the registry. | |
128 const CString omaha_path_; | |
129 const CString path_; | |
130 static const TCHAR* const kVersionString; | |
131 static const TCHAR* const kAppGuid_; | |
132 static const TCHAR* const kSessionId_; | |
133 }; | |
134 | |
135 const TCHAR* const InstallHandoffTest::kVersionString = _T("9.8.7.6"); | |
136 const TCHAR* const InstallHandoffTest::kAppGuid_ = | |
137 _T("{01D33078-BA95-4da6-A3FC-F31593FD4AA2}"); | |
138 const TCHAR* const InstallHandoffTest::kSessionId_ = | |
139 _T("{6cb069db-b073-4a40-9983-846a3819876a}"); | |
140 | |
141 class InstallHandoffUserTest : public InstallHandoffTest { | |
142 protected: | |
143 InstallHandoffUserTest() | |
144 : InstallHandoffTest(false) { | |
145 } | |
146 }; | |
147 | |
148 class RegistryProtectedInstallTest | |
149 : public RegistryProtectedTest { | |
150 protected: | |
151 virtual void SetUp() { | |
152 RegistryProtectedTest::SetUp(); | |
153 | |
154 args_.extra.bundle_name = _T("bundle"); // Avoids assert in error cases. | |
155 args_.install_source = _T("unittest"); | |
156 } | |
157 | |
158 CommandLineArgs args_; | |
159 }; | |
160 | |
161 // Primes the Task Scheduler and XML interfaces before overriding the registry | |
162 // so the interfaces are available after overriding HKLM. This is necessary to | |
163 // allow tests to be run individually. | |
164 class RegistryProtectedWithComInterfacesPrimedInstallTest | |
165 : public RegistryProtectedInstallTest { | |
166 protected: | |
167 virtual void SetUp() { | |
168 CComPtr<ITaskScheduler> scheduler; | |
169 EXPECT_SUCCEEDED(scheduler.CoCreateInstance(CLSID_CTaskScheduler, | |
170 NULL, | |
171 CLSCTX_INPROC_SERVER)); | |
172 | |
173 EXPECT_TRUE(install_self::internal::HasXmlParser()); | |
174 | |
175 // Prime the special folder mapping. For some reason this works on | |
176 // Windows XP but calling functions like | |
177 // ConfigManager::GetMachineGoopdateInstallDir does not. | |
178 typedef std::map<CString, CString> mapping; | |
179 mapping folder_map; | |
180 ASSERT_SUCCEEDED(Shell::GetSpecialFolderKeywordsMapping(&folder_map)); | |
181 | |
182 RegistryProtectedInstallTest::SetUp(); | |
183 | |
184 // mpr.dll requires that the HwOrder key is present to be able to | |
185 // initialize (http://support.microsoft.com/kb/329316). On Windows Vista and | |
186 // later, its absence causes IPersistFile.Save() in | |
187 // scheduled_task_utils::CreateScheduledTask() to fail with | |
188 // ERROR_DLL_INIT_FAILED. | |
189 EXPECT_SUCCEEDED(RegKey::CreateKey( | |
190 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\") | |
191 _T("NetworkProvider\\HwOrder"))); | |
192 } | |
193 }; | |
194 | |
195 class InAuditModeTest | |
196 : public RegistryProtectedWithComInterfacesPrimedInstallTest { | |
197 protected: | |
198 virtual void SetUp() { | |
199 RegistryProtectedWithComInterfacesPrimedInstallTest::SetUp(); | |
200 | |
201 if (vista_util::IsVistaOrLater()) { | |
202 EXPECT_SUCCEEDED(RegKey::SetValue(kVistaSetupStateKey, | |
203 _T("ImageState"), | |
204 _T("IMAGE_STATE_UNDEPLOYABLE"))); | |
205 } else { | |
206 EXPECT_SUCCEEDED(RegKey::SetValue(kXpSystemSetupKey, | |
207 _T("AuditInProgress"), | |
208 static_cast<DWORD>(1))); | |
209 } | |
210 | |
211 EXPECT_TRUE(ConfigManager::Instance()->IsWindowsInstalling()); | |
212 } | |
213 }; | |
214 | |
215 TEST_F(InAuditModeTest, OemInstall_NotOffline) { | |
216 if (!vista_util::IsUserAdmin()) { | |
217 std::wcout << _T("\tTest did not run because the user is not an admin.") | |
218 << std::endl; | |
219 return; | |
220 } | |
221 | |
222 PreventSetupFromRunning(true); | |
223 | |
224 bool is_machine = true; | |
225 bool has_ui_been_displayed = false; | |
226 EXPECT_EQ(GOOPDATE_E_OEM_WITH_ONLINE_INSTALLER, | |
227 OemInstall(false, // is_interactive | |
228 true, // is_app_install | |
229 false, // is_eula_required | |
230 false, // is_install_elevated_instance | |
231 _T("unused"), // install_cmd_line | |
232 args_, | |
233 &is_machine, | |
234 &has_ui_been_displayed)); | |
235 EXPECT_FALSE(has_ui_been_displayed); | |
236 | |
237 EXPECT_SUCCEEDED(scheduled_task_utils::UninstallGoopdateTasks(true)); | |
238 } | |
239 | |
240 TEST_F(RegistryProtectedWithComInterfacesPrimedInstallTest, | |
241 Install_NotAppInstall_User_NoBrandSpecified_NoExistingBrand) { | |
242 if (vista_util::IsElevatedWithUACMaybeOn()) { | |
243 std::wcout << _T("\tSkipping test because user is elevated with UAC on.") | |
244 << std::endl; | |
245 return; | |
246 } | |
247 | |
248 PreventSetupFromRunning(false); | |
249 | |
250 bool is_machine = false; | |
251 bool has_ui_been_displayed = false; | |
252 EXPECT_EQ(S_OK, Install(false, // is_interactive | |
253 false, // is_app_install | |
254 false, // is_eula_required | |
255 false, // is_oem_install | |
256 false, // is_install_elevated_instance | |
257 _T("foo"), // install_cmd_line | |
258 args_, | |
259 &is_machine, | |
260 &has_ui_been_displayed)); | |
261 EXPECT_FALSE(has_ui_been_displayed); | |
262 | |
263 const uint32 now = Time64ToInt32(GetCurrent100NSTime()); | |
264 | |
265 EXPECT_FALSE(RegKey::HasValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
266 kRegValueInstallationId)); | |
267 EXPECT_STREQ(_T("GGLS"), GetSzValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
268 kRegValueBrandCode)); | |
269 EXPECT_FALSE(RegKey::HasValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
270 kRegValueClientId)); | |
271 EXPECT_FALSE(RegKey::HasValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
272 kRegValueReferralId)); | |
273 | |
274 const DWORD install_time = GetDwordValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
275 kRegValueInstallTimeSec); | |
276 EXPECT_GE(now, install_time); | |
277 EXPECT_GE(static_cast<uint32>(200), now - install_time); | |
278 } | |
279 | |
280 TEST_F(RegistryProtectedWithComInterfacesPrimedInstallTest, | |
281 Install_NotAppInstall_User_BrandSpecified_NoExistingBrand) { | |
282 if (vista_util::IsElevatedWithUACMaybeOn()) { | |
283 std::wcout << _T("\tSkipping test because user is elevated with UAC on.") | |
284 << std::endl; | |
285 return; | |
286 } | |
287 | |
288 PreventSetupFromRunning(false); | |
289 | |
290 args_.extra.installation_id = StringToGuid(kExpectedIid); | |
291 args_.extra.brand_code = kExpectedBrand; | |
292 args_.extra.client_id = kExpectedClientId; | |
293 | |
294 bool is_machine = false; | |
295 bool has_ui_been_displayed = false; | |
296 EXPECT_EQ(S_OK, Install(false, // is_interactive | |
297 false, // is_app_install | |
298 false, // is_eula_required | |
299 false, // is_oem_install | |
300 false, // is_install_elevated_instance | |
301 _T("foo"), // install_cmd_line | |
302 args_, | |
303 &is_machine, | |
304 &has_ui_been_displayed)); | |
305 EXPECT_FALSE(has_ui_been_displayed); | |
306 | |
307 const uint32 now = Time64ToInt32(GetCurrent100NSTime()); | |
308 | |
309 EXPECT_STREQ(kExpectedIid, GetSzValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
310 kRegValueInstallationId)); | |
311 EXPECT_STREQ(kExpectedBrand, GetSzValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
312 kRegValueBrandCode)); | |
313 EXPECT_STREQ(kExpectedClientId, GetSzValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
314 kRegValueClientId)); | |
315 EXPECT_FALSE(RegKey::HasValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
316 kRegValueReferralId)); | |
317 | |
318 const DWORD install_time = GetDwordValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
319 kRegValueInstallTimeSec); | |
320 EXPECT_GE(now, install_time); | |
321 EXPECT_GE(static_cast<uint32>(200), now - install_time); | |
322 } | |
323 | |
324 TEST_F(RegistryProtectedWithComInterfacesPrimedInstallTest, | |
325 Install_NotAppInstall_User_BrandSpecified_ExistingBrandAndInstallTime) { | |
326 if (vista_util::IsElevatedWithUACMaybeOn()) { | |
327 std::wcout << _T("\tSkipping test because user is elevated with UAC on.") | |
328 << std::endl; | |
329 return; | |
330 } | |
331 | |
332 PreventSetupFromRunning(false); | |
333 | |
334 const TCHAR* const kExistingBrand = _T("GOOG"); | |
335 const DWORD kExistingInstallTime = 1234567; | |
336 | |
337 EXPECT_SUCCEEDED(RegKey::SetValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
338 kRegValueBrandCode, | |
339 kExistingBrand)); | |
340 EXPECT_SUCCEEDED(RegKey::SetValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
341 kRegValueInstallTimeSec, | |
342 kExistingInstallTime)); | |
343 | |
344 args_.extra.installation_id = StringToGuid(kExpectedIid); | |
345 args_.extra.brand_code = kExpectedBrand; | |
346 args_.extra.client_id = kExpectedClientId; | |
347 | |
348 bool is_machine = false; | |
349 bool has_ui_been_displayed = false; | |
350 EXPECT_EQ(S_OK, Install(false, // is_interactive | |
351 false, // is_app_install | |
352 false, // is_eula_required | |
353 false, // is_oem_install | |
354 false, // is_install_elevated_instance | |
355 _T("foo"), // install_cmd_line | |
356 args_, | |
357 &is_machine, | |
358 &has_ui_been_displayed)); | |
359 EXPECT_FALSE(has_ui_been_displayed); | |
360 | |
361 const uint32 now = Time64ToInt32(GetCurrent100NSTime()); | |
362 | |
363 EXPECT_STREQ(kExpectedIid, GetSzValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
364 kRegValueInstallationId)); | |
365 EXPECT_STREQ(kExistingBrand, GetSzValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
366 kRegValueBrandCode)); | |
367 EXPECT_FALSE(RegKey::HasValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
368 kRegValueClientId)); | |
369 EXPECT_FALSE(RegKey::HasValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
370 kRegValueReferralId)); | |
371 | |
372 EXPECT_EQ(kExistingInstallTime, GetDwordValue(USER_REG_CLIENT_STATE_GOOPDATE, | |
373 kRegValueInstallTimeSec)); | |
374 } | |
375 | |
376 TEST_F(RegistryProtectedWithComInterfacesPrimedInstallTest, | |
377 Install_NotAppInstall_Machine_BrandSpecified_NoExistingBrand) { | |
378 PreventSetupFromRunning(true); | |
379 | |
380 args_.extra.installation_id = StringToGuid(kExpectedIid); | |
381 args_.extra.brand_code = kExpectedBrand; | |
382 args_.extra.client_id = kExpectedClientId; | |
383 | |
384 bool is_machine = true; | |
385 bool has_ui_been_displayed = false; | |
386 EXPECT_SUCCEEDED(Install(false, // is_interactive | |
387 false, // is_app_install | |
388 false, // is_eula_required | |
389 false, // is_oem_install | |
390 false, // is_install_elevated_instance | |
391 _T("foo"), // install_cmd_line | |
392 args_, | |
393 &is_machine, | |
394 &has_ui_been_displayed)); | |
395 EXPECT_FALSE(has_ui_been_displayed); | |
396 | |
397 const uint32 now = Time64ToInt32(GetCurrent100NSTime()); | |
398 | |
399 CString iid; | |
400 EXPECT_SUCCEEDED( | |
401 RegKey::GetValue(MACHINE_REG_CLIENT_STATE_GOOPDATE, _T("iid"), &iid)); | |
402 EXPECT_STREQ(kExpectedIid, iid); | |
403 | |
404 CString brand; | |
405 EXPECT_SUCCEEDED( | |
406 RegKey::GetValue(MACHINE_REG_CLIENT_STATE_GOOPDATE, _T("brand"), &brand)); | |
407 EXPECT_STREQ(kExpectedBrand, brand); | |
408 | |
409 CString client_id; | |
410 EXPECT_SUCCEEDED(RegKey::GetValue(MACHINE_REG_CLIENT_STATE_GOOPDATE, | |
411 _T("client"), | |
412 &client_id)); | |
413 EXPECT_STREQ(kExpectedClientId, client_id); | |
414 | |
415 EXPECT_FALSE( | |
416 RegKey::HasValue(MACHINE_REG_CLIENT_STATE_GOOPDATE, _T("referral"))); | |
417 | |
418 DWORD install_time(0); | |
419 EXPECT_SUCCEEDED(RegKey::GetValue(MACHINE_REG_CLIENT_STATE_GOOPDATE, | |
420 _T("InstallTime"), | |
421 &install_time)); | |
422 EXPECT_GE(now, install_time); | |
423 EXPECT_GE(static_cast<uint32>(200), now - install_time); | |
424 | |
425 EXPECT_SUCCEEDED(scheduled_task_utils::UninstallGoopdateTasks(true)); | |
426 } | |
427 | |
428 | |
429 TEST_F(RegistryProtectedWithComInterfacesPrimedInstallTest, | |
430 Install_EulaRequiredNotOffline_User) { | |
431 if (vista_util::IsElevatedWithUACMaybeOn()) { | |
432 std::wcout << _T("\tSkipping test because user is elevated with UAC on.") | |
433 << std::endl; | |
434 return; | |
435 } | |
436 | |
437 PreventSetupFromRunning(false); | |
438 | |
439 bool is_machine = false; | |
440 bool has_ui_been_displayed = false; | |
441 EXPECT_EQ(GOOPDATE_E_EULA_REQURED_WITH_ONLINE_INSTALLER, | |
442 Install(false, // is_interactive | |
443 true, // is_app_install | |
444 true, // is_eula_required | |
445 false, // is_oem_install | |
446 false, // is_install_elevated_instance | |
447 _T("unused"), // install_cmd_line | |
448 args_, | |
449 &is_machine, | |
450 &has_ui_been_displayed)); | |
451 EXPECT_FALSE(has_ui_been_displayed); | |
452 } | |
453 | |
454 TEST_F(RegistryProtectedWithComInterfacesPrimedInstallTest, | |
455 Install_EulaRequiredNotOffline_Machine) { | |
456 if (!vista_util::IsUserAdmin()) { | |
457 std::wcout << _T("\tTest did not run because the user is not an admin.") | |
458 << std::endl; | |
459 return; | |
460 } | |
461 | |
462 PreventSetupFromRunning(true); | |
463 | |
464 bool is_machine = true; | |
465 bool has_ui_been_displayed = false; | |
466 EXPECT_EQ(GOOPDATE_E_EULA_REQURED_WITH_ONLINE_INSTALLER, | |
467 Install(false, // is_interactive | |
468 true, // is_app_install | |
469 true, // is_eula_required | |
470 false, // is_oem_install | |
471 false, // is_install_elevated_instance | |
472 _T("unused"), // install_cmd_line | |
473 args_, | |
474 &is_machine, | |
475 &has_ui_been_displayed)); | |
476 EXPECT_FALSE(has_ui_been_displayed); | |
477 | |
478 EXPECT_SUCCEEDED(scheduled_task_utils::UninstallGoopdateTasks(true)); | |
479 } | |
480 | |
481 TEST_F(RegistryProtectedInstallTest, Install_NeedsElevation_Silent) { | |
482 if (vista_util::IsUserAdmin()) { | |
483 std::wcout << _T("\tTest did not run because the user IS an admin.") | |
484 << std::endl; | |
485 return; | |
486 } | |
487 | |
488 bool is_machine = true; | |
489 bool has_ui_been_displayed = false; | |
490 EXPECT_EQ(GOOPDATE_E_SILENT_INSTALL_NEEDS_ELEVATION, | |
491 Install(false, // is_interactive | |
492 true, // is_app_install | |
493 false, // is_eula_required | |
494 false, // is_oem_install | |
495 false, // is_install_elevated_instance | |
496 _T("unused"), // install_cmd_line | |
497 args_, | |
498 &is_machine, | |
499 &has_ui_been_displayed)); | |
500 EXPECT_FALSE(has_ui_been_displayed); | |
501 } | |
502 | |
503 // Tests that non-app installs can request elevation. | |
504 // TODO(omaha3): Once the elevation code is finalized, figure out a way to cause | |
505 // it to fail without a UAC prompt. Then change the expected error code to a | |
506 // list of possible values. | |
507 TEST_F(RegistryProtectedInstallTest, Install_NeedsElevation_NotAppInstall) { | |
508 if (vista_util::IsUserAdmin()) { | |
509 std::wcout << _T("\tTest did not run because the user IS an admin.") | |
510 << std::endl; | |
511 return; | |
512 } | |
513 | |
514 bool is_machine = true; | |
515 bool has_ui_been_displayed = false; | |
516 EXPECT_NE(GOOPDATE_E_SILENT_INSTALL_NEEDS_ELEVATION, | |
517 Install(true, // is_interactive | |
518 false, // is_app_install | |
519 false, // is_eula_required | |
520 false, // is_oem_install | |
521 false, // is_install_elevated_instance | |
522 _T("unused"), // install_cmd_line | |
523 args_, | |
524 &is_machine, | |
525 &has_ui_been_displayed)); | |
526 EXPECT_FALSE(has_ui_been_displayed); | |
527 } | |
528 | |
529 TEST_F(RegistryProtectedInstallTest, Install_NeedsElevation_ElevatedInstance) { | |
530 if (vista_util::IsUserAdmin()) { | |
531 std::wcout << _T("\tTest did not run because the user IS an admin.") | |
532 << std::endl; | |
533 return; | |
534 } | |
535 | |
536 bool is_machine = true; | |
537 | |
538 // is_interactive is true to get past that check. | |
539 bool has_ui_been_displayed = false; | |
540 EXPECT_EQ(GOOPDATE_E_INSTALL_ELEVATED_PROCESS_NEEDS_ELEVATION, | |
541 Install(true, // is_interactive | |
542 true, // is_app_install | |
543 false, // is_eula_required | |
544 false, // is_oem_install | |
545 true, // is_install_elevated_instance | |
546 _T("unused"), // install_cmd_line | |
547 args_, | |
548 &is_machine, | |
549 &has_ui_been_displayed)); | |
550 EXPECT_FALSE(has_ui_been_displayed); | |
551 } | |
552 | |
553 // This test will never run because developers do not run XP as non-admin. | |
554 // TODO(omaha3): Implement some way to fake/mock IsUserAdmin(), etc. | |
555 TEST_F(RegistryProtectedInstallTest, Install_NeedsElevation_XpNonAdmin) { | |
556 if (vista_util::IsVistaOrLater()) { | |
557 std::wcout << _T("\tTest did not run because OS is Vista or later.") | |
558 << std::endl; | |
559 return; | |
560 } | |
561 if (vista_util::IsUserAdmin()) { | |
562 std::wcout << _T("\tTest did not run because the user IS an admin.") | |
563 << std::endl; | |
564 return; | |
565 } | |
566 | |
567 bool is_machine = true; | |
568 | |
569 // is_interactive is true to get past that check. | |
570 bool has_ui_been_displayed = false; | |
571 EXPECT_EQ(GOOPDATE_E_NONADMIN_INSTALL_ADMIN_APP, | |
572 Install(true, // is_interactive | |
573 true, // is_app_install | |
574 false, // is_eula_required | |
575 false, // is_oem_install | |
576 false, // is_install_elevated_instance | |
577 _T("unused"), // install_cmd_line | |
578 args_, | |
579 &is_machine, | |
580 &has_ui_been_displayed)); | |
581 EXPECT_FALSE(has_ui_been_displayed); | |
582 } | |
583 | |
584 | |
585 // TODO(omaha3): Once the elevation code is finalized, figure out a way to cause | |
586 // it to fail before the UAC prompt and test GOOPDATE_E_ELEVATION_FAILED_ADMIN | |
587 // and GOOPDATE_E_ELEVATION_FAILED_NON_ADMIN. Check the command line used for | |
588 // elevation if possible. | |
589 | |
590 // TODO(omaha3): If UI ends up not being handled in this method, test | |
591 // is_interactive variations too. | |
592 | |
593 // TODO(omaha3): Test more success cases, including Setup and handoff. | |
594 | |
595 // TODO(omaha3): Enable when support for offline builds is finalized. | |
596 #if 0 | |
597 class SetupOfflineInstallerTest : public testing::Test { | |
598 protected: | |
599 static bool CallCopyOfflineFiles(const CommandLineArgs& args, | |
600 const CString& target_location) { | |
601 omaha::Setup setup(false, &args); | |
602 return setup.CopyOfflineFiles(target_location); | |
603 } | |
604 | |
605 static HRESULT CallCopyOfflineFilesForGuid(const CString& app_guid, | |
606 const CString& target_location) { | |
607 return omaha::Setup::CopyOfflineFilesForGuid(app_guid, target_location); | |
608 } | |
609 }; | |
610 | |
611 TEST_F(SetupOfflineInstallerTest, ValidOfflineInstaller) { | |
612 CString guid_string = _T("{CDABE316-39CD-43BA-8440-6D1E0547AEE6}"); | |
613 | |
614 CString offline_manifest_path(guid_string); | |
615 offline_manifest_path += _T(".gup"); | |
616 offline_manifest_path = ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
617 offline_manifest_path); | |
618 EXPECT_SUCCEEDED(File::Copy( | |
619 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
620 _T("server_manifest_one_app.xml")), | |
621 offline_manifest_path, | |
622 false)); | |
623 | |
624 CString installer_exe = _T("foo_installer.exe"); | |
625 CString tarred_installer_path; | |
626 tarred_installer_path.Format(_T("%s.%s"), installer_exe, guid_string); | |
627 tarred_installer_path = ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
628 tarred_installer_path); | |
629 | |
630 EXPECT_SUCCEEDED(File::Copy( | |
631 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
632 kOmahaShellFileName), | |
633 tarred_installer_path, | |
634 false)); | |
635 | |
636 CommandLineArgs args; | |
637 CommandLineAppArgs app1; | |
638 app1.app_guid = StringToGuid(guid_string); | |
639 args.extra.apps.push_back(app1); | |
640 CString target_location = ConcatenatePath( | |
641 app_util::GetCurrentModuleDirectory(), | |
642 _T("offline_test")); | |
643 | |
644 EXPECT_TRUE(CallCopyOfflineFiles(args, target_location)); | |
645 | |
646 CString target_manifest = ConcatenatePath(target_location, | |
647 guid_string + _T(".gup")); | |
648 EXPECT_TRUE(File::Exists(target_manifest)); | |
649 CString target_file = ConcatenatePath( | |
650 ConcatenatePath(target_location, guid_string), installer_exe); | |
651 EXPECT_TRUE(File::Exists(target_file)); | |
652 | |
653 EXPECT_SUCCEEDED(DeleteDirectory(target_location)); | |
654 EXPECT_SUCCEEDED(File::Remove(tarred_installer_path)); | |
655 EXPECT_SUCCEEDED(File::Remove(offline_manifest_path)); | |
656 } | |
657 | |
658 TEST_F(SetupOfflineInstallerTest, NoOfflineInstaller) { | |
659 CString guid_string = _T("{CDABE316-39CD-43BA-8440-6D1E0547AEE6}"); | |
660 CommandLineArgs args; | |
661 CommandLineAppArgs app1; | |
662 app1.app_guid = StringToGuid(guid_string); | |
663 args.extra.apps.push_back(app1); | |
664 CString target_location = ConcatenatePath( | |
665 app_util::GetCurrentModuleDirectory(), | |
666 _T("offline_test")); | |
667 | |
668 EXPECT_FALSE(CallCopyOfflineFiles(args, target_location)); | |
669 } | |
670 | |
671 TEST_F(SetupOfflineInstallerTest, ValidCopyOfflineFilesForGuid) { | |
672 CString guid_string = _T("{CDABE316-39CD-43BA-8440-6D1E0547AEE6}"); | |
673 | |
674 CString offline_manifest_path(guid_string); | |
675 offline_manifest_path += _T(".gup"); | |
676 offline_manifest_path = ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
677 offline_manifest_path); | |
678 EXPECT_SUCCEEDED(File::Copy( | |
679 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
680 _T("server_manifest_one_app.xml")), | |
681 offline_manifest_path, | |
682 false)); | |
683 | |
684 CString installer_exe = _T("foo_installer.exe"); | |
685 CString tarred_installer_path; | |
686 tarred_installer_path.Format(_T("%s.%s"), installer_exe, guid_string); | |
687 tarred_installer_path = ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
688 tarred_installer_path); | |
689 | |
690 EXPECT_SUCCEEDED(File::Copy( | |
691 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
692 kOmahaShellFileName), | |
693 tarred_installer_path, | |
694 false)); | |
695 | |
696 CString target_location = ConcatenatePath( | |
697 app_util::GetCurrentModuleDirectory(), | |
698 _T("offline_test")); | |
699 | |
700 EXPECT_SUCCEEDED(CallCopyOfflineFilesForGuid(guid_string, target_location)); | |
701 | |
702 CString target_manifest = ConcatenatePath(target_location, | |
703 guid_string + _T(".gup")); | |
704 EXPECT_TRUE(File::Exists(target_manifest)); | |
705 CString target_file = ConcatenatePath( | |
706 ConcatenatePath(target_location, guid_string), installer_exe); | |
707 EXPECT_TRUE(File::Exists(target_file)); | |
708 | |
709 EXPECT_SUCCEEDED(DeleteDirectory(target_location)); | |
710 EXPECT_SUCCEEDED(File::Remove(tarred_installer_path)); | |
711 EXPECT_SUCCEEDED(File::Remove(offline_manifest_path)); | |
712 } | |
713 | |
714 TEST_F(SetupOfflineInstallerTest, NoCopyOfflineFilesForGuid) { | |
715 CString guid_string = _T("{CDABE316-39CD-43BA-8440-6D1E0547AEE6}"); | |
716 CString target_location = ConcatenatePath( | |
717 app_util::GetCurrentModuleDirectory(), | |
718 _T("offline_test")); | |
719 | |
720 EXPECT_EQ(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), | |
721 CallCopyOfflineFilesForGuid(guid_string, target_location)); | |
722 } | |
723 #endif | |
724 | |
725 // TODO(omaha): Duplicate these tests for machine. | |
726 TEST_F(InstallHandoffUserTest, InstallApplications_HandoffWithShellMissing) { | |
727 CString shell_path = ConcatenatePath(omaha_path_, kOmahaShellFileName); | |
728 EXPECT_TRUE(SUCCEEDED(File::DeleteAfterReboot(shell_path)) || | |
729 !vista_util::IsUserAdmin()); | |
730 EXPECT_FALSE(File::Exists(shell_path)); | |
731 | |
732 CommandLineArgs args; | |
733 args.extra_args_str = _T("appguid={BF85992F-2E0F-4700-9A6C-FEC9126CEE4B}&") | |
734 _T("appname=Foo&needsadmin=False&"); | |
735 args.install_source = _T("unittest"); | |
736 bool ui_displayed = false; | |
737 bool has_launched_handoff = false; | |
738 EXPECT_EQ(GOOPDATE_E_HANDOFF_FAILED, | |
739 internal::InstallApplications(false, | |
740 false, | |
741 args, | |
742 kSessionId_, | |
743 NULL, | |
744 &has_launched_handoff, | |
745 &ui_displayed)); | |
746 // TODO(omaha3): Verify the actual error when this is implemented. | |
747 #if 0 | |
748 EXPECT_EQ(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), extra_code1); | |
749 #endif | |
750 EXPECT_FALSE(ui_displayed); | |
751 } | |
752 | |
753 TEST_F(InstallHandoffUserTest, | |
754 InstallApplications_HandoffWithGoopdateDllMissing) { | |
755 CString dll_path = ConcatenatePath(path_, kOmahaDllName); | |
756 EXPECT_SUCCEEDED(File::Remove(dll_path)); | |
757 EXPECT_FALSE(File::Exists(dll_path)); | |
758 | |
759 CommandLineArgs args; | |
760 args.extra_args_str = _T("appguid={BF85992F-2E0F-4700-9A6C-FEC9126CEE4B}&") | |
761 _T("appname=Foo&needsadmin=False&"); | |
762 args.install_source = _T("unittest"); | |
763 bool ui_displayed = false; | |
764 bool has_launched_handoff = false; | |
765 EXPECT_EQ(GOOGLEUPDATE_E_DLL_NOT_FOUND, | |
766 internal::InstallApplications(false, | |
767 false, | |
768 args, | |
769 kSessionId_, | |
770 NULL, | |
771 &ui_displayed, | |
772 &has_launched_handoff)); | |
773 // TODO(omaha3): Verify the actual error when this is implemented. | |
774 #if 0 | |
775 EXPECT_EQ(0, setup_->extra_code1()); | |
776 #endif | |
777 // TODO(omaha3): ui_displayed is temporarily always set to true. | |
778 #if 0 | |
779 EXPECT_FALSE(ui_displayed); | |
780 #else | |
781 EXPECT_TRUE(ui_displayed); | |
782 #endif | |
783 } | |
784 | |
785 } // namespace omaha | |
OLD | NEW |