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 // ApplicationUsageData unit tests | |
17 | |
18 #include "omaha/base/reg_key.h" | |
19 #include "omaha/base/user_info.h" | |
20 #include "omaha/base/utils.h" | |
21 #include "omaha/base/vistautil.h" | |
22 #include "omaha/testing/unit_test.h" | |
23 #include "omaha/goopdate/application_usage_data.h" | |
24 | |
25 namespace omaha { | |
26 | |
27 const TCHAR kAppDidRunValueName[] = _T("dr"); | |
28 const TCHAR kHKCUClientStateKeyName[] = | |
29 _T("HKCU\\Software\\") SHORT_COMPANY_NAME _T("\\") PRODUCT_NAME | |
30 _T("\\ClientState\\{6ACB7D4D-E5BA-48b0-85FE-A4051500A1BD}"); | |
31 const TCHAR kMachineClientState[] = | |
32 _T("HKLM\\Software\\") SHORT_COMPANY_NAME _T("\\") PRODUCT_NAME | |
33 _T("\\ClientState\\{6ACB7D4D-E5BA-48b0-85FE-A4051500A1BD}"); | |
34 const TCHAR kLowIntegrityIEHKCU[] = | |
35 _T("HKCU\\Software\\Microsoft\\Internet Explorer\\") | |
36 _T("InternetRegistry\\REGISTRY\\USER\\"); | |
37 const TCHAR kAppGuid[] = _T("{6ACB7D4D-E5BA-48b0-85FE-A4051500A1BD}"); | |
38 const TCHAR kRelativeClientState[] = | |
39 _T("Software\\") SHORT_COMPANY_NAME _T("\\") PRODUCT_NAME | |
40 _T("\\ClientState\\{6ACB7D4D-E5BA-48b0-85FE-A4051500A1BD}"); | |
41 | |
42 // TODO(omaha): Expected and actual are reversed throughout this file. Fix. | |
43 | |
44 class ApplicationUsageDataTest : public testing::Test { | |
45 protected: | |
46 virtual void SetUp() { | |
47 CString sid; | |
48 ASSERT_SUCCEEDED(user_info::GetProcessUser(NULL, NULL, &sid)); | |
49 low_integrity_key_name_ = AppendRegKeyPath(kLowIntegrityIEHKCU, | |
50 sid, | |
51 kRelativeClientState); | |
52 TearDown(); | |
53 } | |
54 | |
55 virtual void TearDown() { | |
56 RegKey::DeleteKey(kHKCUClientStateKeyName); | |
57 RegKey::DeleteKey(kMachineClientState); | |
58 RegKey::DeleteKey(low_integrity_key_name_); | |
59 } | |
60 | |
61 void CreateMachineDidRunValue(bool value) { | |
62 if (!vista_util::IsUserAdmin()) { | |
63 return; | |
64 } | |
65 RegKey key; | |
66 ASSERT_SUCCEEDED(key.Create(kMachineClientState)); | |
67 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, | |
68 value == true ? _T("1") : _T("0"))); | |
69 } | |
70 | |
71 void CreateMachineDidRunDwordValue(bool value) { | |
72 if (!vista_util::IsUserAdmin()) { | |
73 return; | |
74 } | |
75 RegKey key; | |
76 DWORD new_value = (value == true ? 1 : 0); | |
77 ASSERT_SUCCEEDED(key.Create(kMachineClientState)); | |
78 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, new_value)); | |
79 } | |
80 | |
81 bool MachineDidRunValueExists() { | |
82 if (!vista_util::IsUserAdmin()) { | |
83 return true; | |
84 } | |
85 RegKey key; | |
86 if (FAILED(key.Open(kMachineClientState))) { | |
87 return false; | |
88 } | |
89 | |
90 CString did_run_str(_T("0")); | |
91 if (FAILED(key.GetValue(kAppDidRunValueName, &did_run_str))) { | |
92 return false; | |
93 } | |
94 | |
95 return true; | |
96 } | |
97 | |
98 void DeleteMachineDidRunValue() { | |
99 if (!vista_util::IsUserAdmin()) { | |
100 return; | |
101 } | |
102 ASSERT_SUCCEEDED(RegKey::DeleteValue(kMachineClientState, | |
103 kAppDidRunValueName)); | |
104 } | |
105 | |
106 void CheckMachineDidRunValue(bool expected) { | |
107 if (!vista_util::IsUserAdmin()) { | |
108 return; | |
109 } | |
110 RegKey key; | |
111 ASSERT_SUCCEEDED(key.Open(kMachineClientState)); | |
112 | |
113 CString did_run_str(_T("0")); | |
114 ASSERT_SUCCEEDED(key.GetValue(kAppDidRunValueName, &did_run_str)); | |
115 bool value = (did_run_str == _T("1")) ? true : false; | |
116 | |
117 ASSERT_EQ(value, expected); | |
118 } | |
119 | |
120 void CreateUserDidRunValue(bool value) { | |
121 RegKey key; | |
122 ASSERT_SUCCEEDED(key.Create(kHKCUClientStateKeyName)); | |
123 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, | |
124 (value == true) ? _T("1") : _T("0"))); | |
125 } | |
126 | |
127 void CreateUserDidRunDwordValue(bool value) { | |
128 RegKey key; | |
129 DWORD new_value = (value == true ? 1 : 0); | |
130 ASSERT_SUCCEEDED(key.Create(kHKCUClientStateKeyName)); | |
131 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, new_value)); | |
132 } | |
133 | |
134 void DeleteUserDidRunValue() { | |
135 ASSERT_SUCCEEDED(RegKey::DeleteValue(kHKCUClientStateKeyName, | |
136 kAppDidRunValueName)); | |
137 } | |
138 | |
139 void CheckUserDidRunValue(bool expected) { | |
140 RegKey key; | |
141 ASSERT_SUCCEEDED(key.Open(kHKCUClientStateKeyName)); | |
142 | |
143 CString did_run_str(_T("0")); | |
144 ASSERT_SUCCEEDED(key.GetValue(kAppDidRunValueName, &did_run_str)); | |
145 bool value = (did_run_str == _T("1")) ? true : false; | |
146 | |
147 ASSERT_EQ(value, expected); | |
148 } | |
149 | |
150 bool UserDidRunValueExists() { | |
151 RegKey key; | |
152 if (FAILED(key.Open(kHKCUClientStateKeyName))) { | |
153 return false; | |
154 } | |
155 | |
156 CString did_run_str(_T("0")); | |
157 if (FAILED(key.GetValue(kAppDidRunValueName, &did_run_str))) { | |
158 return false; | |
159 } | |
160 | |
161 return true; | |
162 } | |
163 | |
164 void CreateLowIntegrityUserDidRunValue(bool value) { | |
165 RegKey key; | |
166 ASSERT_SUCCEEDED(key.Create(low_integrity_key_name_)); | |
167 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, | |
168 (value == true) ? _T("1") : _T("0"))); | |
169 } | |
170 | |
171 void CreateLowIntegrityUserDidRunDwordValue(bool value) { | |
172 RegKey key; | |
173 DWORD new_value = (value == true ? 1 : 0); | |
174 ASSERT_SUCCEEDED(key.Create(low_integrity_key_name_)); | |
175 ASSERT_SUCCEEDED(key.SetValue(kAppDidRunValueName, new_value)); | |
176 } | |
177 | |
178 void DeleteLowIntegrityUserDidRunValue() { | |
179 ASSERT_SUCCEEDED(RegKey::DeleteValue(low_integrity_key_name_, | |
180 kAppDidRunValueName)); | |
181 } | |
182 | |
183 void CheckLowIntegrityUserDidRunValue(bool expected) { | |
184 RegKey key; | |
185 ASSERT_SUCCEEDED(key.Open(low_integrity_key_name_)); | |
186 | |
187 CString did_run_str(_T("0")); | |
188 ASSERT_SUCCEEDED(key.GetValue(kAppDidRunValueName, &did_run_str)); | |
189 bool value = (did_run_str == _T("1")) ? true : false; | |
190 | |
191 ASSERT_EQ(value, expected); | |
192 } | |
193 | |
194 bool LowIntegrityUserDidRunValueExists() { | |
195 RegKey key; | |
196 if (FAILED(key.Open(low_integrity_key_name_))) { | |
197 return false; | |
198 } | |
199 | |
200 CString did_run_str(_T("0")); | |
201 if (FAILED(key.GetValue(kAppDidRunValueName, &did_run_str))) { | |
202 return false; | |
203 } | |
204 | |
205 return true; | |
206 } | |
207 | |
208 // This method takes in machine_did_run, user_did_run and | |
209 // low_user_did_run as int's. The idea is that the test tries to simulate | |
210 // all of these values as being not-present, and if present then true or | |
211 // false. | |
212 // -1 indicates non-presense, 1 indicates true, and 0 false. The caller | |
213 // then loops over all these values to capture testing all the permutations. | |
214 void TestUserAndMachineDidRun(int machine_did_run, | |
215 int user_did_run, | |
216 int low_user_did_run, | |
217 bool expected_exists, | |
218 bool expected_did_run, | |
219 int is_vista) { | |
220 ApplicationUsageData data(true, is_vista ? true : false); | |
221 | |
222 // Set up the registry for the test. | |
223 if (machine_did_run != -1) { | |
224 CreateMachineDidRunValue((machine_did_run == 1) ? true: false); | |
225 } | |
226 | |
227 if (user_did_run != -1) { | |
228 CreateUserDidRunValue((user_did_run == 1) ? true: false); | |
229 } | |
230 | |
231 if (low_user_did_run != -1) { | |
232 CreateLowIntegrityUserDidRunValue((low_user_did_run == 1) ? true: false); | |
233 } | |
234 | |
235 // Perform the test. | |
236 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
237 ASSERT_EQ(data.exists(), expected_exists); | |
238 ASSERT_EQ(data.did_run(), expected_did_run); | |
239 | |
240 // Check the return values. | |
241 if (machine_did_run == -1) { | |
242 ASSERT_FALSE(MachineDidRunValueExists()); | |
243 } else { | |
244 CheckMachineDidRunValue((machine_did_run == 1) ? true: false); | |
245 } | |
246 | |
247 if (user_did_run == -1) { | |
248 ASSERT_FALSE(UserDidRunValueExists()); | |
249 } else { | |
250 CheckUserDidRunValue((user_did_run == 1) ? true: false); | |
251 } | |
252 | |
253 if (low_user_did_run == -1) { | |
254 ASSERT_FALSE(LowIntegrityUserDidRunValueExists()); | |
255 } else { | |
256 CheckLowIntegrityUserDidRunValue((low_user_did_run == 1) ? true: false); | |
257 } | |
258 } | |
259 | |
260 void TestUserAndMachineDidRunPostProcess(int machine_did_run, | |
261 int user_did_run, | |
262 int low_user_did_run, | |
263 bool expected_exists, | |
264 int is_vista) { | |
265 ApplicationUsageData data(true, is_vista ? true : false); | |
266 | |
267 // Setup the registry for the test. | |
268 if (machine_did_run != -1) { | |
269 CreateMachineDidRunValue((machine_did_run == 1) ? true: false); | |
270 } | |
271 | |
272 if (user_did_run != -1) { | |
273 CreateUserDidRunValue((user_did_run == 1) ? true: false); | |
274 } | |
275 | |
276 if (low_user_did_run != -1) { | |
277 CreateLowIntegrityUserDidRunValue((low_user_did_run == 1) ? true: false); | |
278 } | |
279 | |
280 // Run the test. | |
281 ASSERT_SUCCEEDED(data.ResetDidRun(kAppGuid)); | |
282 if (user_did_run == -1) { | |
283 ASSERT_FALSE(UserDidRunValueExists()); | |
284 } else { | |
285 CheckUserDidRunValue(false); | |
286 } | |
287 | |
288 if (low_user_did_run == -1) { | |
289 ASSERT_FALSE(LowIntegrityUserDidRunValueExists()); | |
290 } else { | |
291 if (is_vista) { | |
292 CheckLowIntegrityUserDidRunValue(false); | |
293 } else { | |
294 CheckLowIntegrityUserDidRunValue((low_user_did_run == 1) ? true: false); | |
295 } | |
296 } | |
297 | |
298 if (machine_did_run == -1) { | |
299 ASSERT_FALSE(MachineDidRunValueExists()); | |
300 } else { | |
301 if (user_did_run != -1 || (is_vista && low_user_did_run != -1)) { | |
302 // This means that the user keys exists for this application | |
303 // we should have delete the machine key. | |
304 ASSERT_EQ(MachineDidRunValueExists(), false); | |
305 } else { | |
306 CheckMachineDidRunValue(false); | |
307 } | |
308 } | |
309 | |
310 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
311 ASSERT_EQ(data.exists(), expected_exists); | |
312 ASSERT_EQ(data.did_run(), false); | |
313 } | |
314 | |
315 void UserTestDidRunPreProcess(int user_did_run, | |
316 int low_user_did_run, | |
317 int is_vista, | |
318 bool expected_exists, | |
319 bool expected_did_run) { | |
320 ApplicationUsageData data(false, is_vista ? true : false); | |
321 | |
322 // Set up the registry for the test. | |
323 CreateMachineDidRunValue(true); | |
324 | |
325 if (user_did_run != -1) { | |
326 CreateUserDidRunValue((user_did_run == 1) ? true: false); | |
327 } | |
328 | |
329 if (low_user_did_run != -1) { | |
330 CreateLowIntegrityUserDidRunValue((low_user_did_run == 1) ? true: false); | |
331 } | |
332 | |
333 // Perform the test. | |
334 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
335 ASSERT_EQ(data.exists(), expected_exists); | |
336 ASSERT_EQ(data.did_run(), expected_did_run); | |
337 | |
338 // The machine value should not have changed from what we set it to. | |
339 CheckMachineDidRunValue(true); | |
340 if (user_did_run == -1) { | |
341 // If we did not create the user value it should not exist. | |
342 ASSERT_FALSE(UserDidRunValueExists()); | |
343 } | |
344 | |
345 if (low_user_did_run == -1) { | |
346 // If we did not create the low integrity user value it should not exist. | |
347 ASSERT_FALSE(LowIntegrityUserDidRunValueExists()); | |
348 } | |
349 } | |
350 | |
351 void UserTestDidRunPostProcess(int user_did_run, | |
352 int low_user_did_run, | |
353 int is_vista) { | |
354 // Create a user ApplicationUsageData class. | |
355 ApplicationUsageData data(false, is_vista ? true : false); | |
356 | |
357 // This should not affect the test. | |
358 CreateMachineDidRunValue(true); | |
359 | |
360 if (user_did_run != -1) { | |
361 CreateUserDidRunValue((user_did_run == 1) ? true: false); | |
362 } | |
363 | |
364 if (low_user_did_run != -1) { | |
365 CreateLowIntegrityUserDidRunValue((low_user_did_run == 1) ? true: false); | |
366 } | |
367 | |
368 ASSERT_SUCCEEDED(data.ResetDidRun(kAppGuid)); | |
369 | |
370 // The machine did run shold never get affected. | |
371 CheckMachineDidRunValue(true); | |
372 if (user_did_run == -1) { | |
373 ASSERT_FALSE(UserDidRunValueExists()); | |
374 } else { | |
375 // In all cases if the HKCU did run is set, it should get cleared. | |
376 CheckUserDidRunValue(false); | |
377 } | |
378 | |
379 if (low_user_did_run == -1) { | |
380 ASSERT_FALSE(LowIntegrityUserDidRunValueExists()); | |
381 } else { | |
382 // In case of vista, the low integrity user value should get reset. | |
383 CheckLowIntegrityUserDidRunValue(is_vista ? false : | |
384 (low_user_did_run == 1) ? true : false); | |
385 } | |
386 } | |
387 | |
388 private: | |
389 CString low_integrity_key_name_; | |
390 }; | |
391 | |
392 TEST_F(ApplicationUsageDataTest, ReadDidRunUser1) { | |
393 ApplicationUsageData data(true, false); | |
394 | |
395 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
396 ASSERT_EQ(data.exists(), false); | |
397 ASSERT_EQ(data.did_run(), false); | |
398 | |
399 // Test with false user value. | |
400 CreateUserDidRunValue(false); | |
401 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
402 ASSERT_EQ(data.exists(), true); | |
403 ASSERT_EQ(data.did_run(), false); | |
404 } | |
405 | |
406 TEST_F(ApplicationUsageDataTest, ReadDwordDidRunUser1) { | |
407 ApplicationUsageData data(true, false); | |
408 | |
409 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
410 ASSERT_EQ(data.exists(), false); | |
411 ASSERT_EQ(data.did_run(), false); | |
412 | |
413 // Test with false user value. | |
414 CreateUserDidRunDwordValue(false); | |
415 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
416 ASSERT_EQ(data.exists(), true); | |
417 ASSERT_EQ(data.did_run(), false); | |
418 } | |
419 | |
420 TEST_F(ApplicationUsageDataTest, ReadDidRunUser2) { | |
421 // Test with true user value. | |
422 ApplicationUsageData data1(true, false); | |
423 CreateUserDidRunValue(true); | |
424 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
425 ASSERT_EQ(data1.exists(), true); | |
426 ASSERT_EQ(data1.did_run(), true); | |
427 } | |
428 | |
429 TEST_F(ApplicationUsageDataTest, ReadDwordDidRunUser2) { | |
430 // Test with true user value. | |
431 ApplicationUsageData data1(true, false); | |
432 CreateUserDidRunDwordValue(true); | |
433 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
434 ASSERT_EQ(data1.exists(), true); | |
435 ASSERT_EQ(data1.did_run(), true); | |
436 } | |
437 | |
438 TEST_F(ApplicationUsageDataTest, ReadDidRunUser3) { | |
439 // low integrity user = false, vista | |
440 ApplicationUsageData data2(true, true); | |
441 CreateLowIntegrityUserDidRunValue(false); | |
442 ASSERT_SUCCEEDED(data2.ReadDidRun(kAppGuid)); | |
443 ASSERT_EQ(data2.exists(), true); | |
444 ASSERT_EQ(data2.did_run(), false); | |
445 } | |
446 | |
447 TEST_F(ApplicationUsageDataTest, ReadDwordDidRunUser3) { | |
448 // low integrity user = false, vista | |
449 ApplicationUsageData data2(true, true); | |
450 CreateLowIntegrityUserDidRunDwordValue(false); | |
451 ASSERT_SUCCEEDED(data2.ReadDidRun(kAppGuid)); | |
452 ASSERT_EQ(data2.exists(), true); | |
453 ASSERT_EQ(data2.did_run(), false); | |
454 } | |
455 | |
456 TEST_F(ApplicationUsageDataTest, ReadDidRunUser4) { | |
457 // low integrity user = true, vista | |
458 ApplicationUsageData data2(true, true); | |
459 CreateLowIntegrityUserDidRunValue(true); | |
460 ASSERT_SUCCEEDED(data2.ReadDidRun(kAppGuid)); | |
461 ASSERT_EQ(data2.exists(), true); | |
462 ASSERT_EQ(data2.did_run(), true); | |
463 } | |
464 | |
465 TEST_F(ApplicationUsageDataTest, ReadDwordDidRunUser4) { | |
466 // low integrity user = true, vista | |
467 ApplicationUsageData data2(true, true); | |
468 CreateLowIntegrityUserDidRunDwordValue(true); | |
469 ASSERT_SUCCEEDED(data2.ReadDidRun(kAppGuid)); | |
470 ASSERT_EQ(data2.exists(), true); | |
471 ASSERT_EQ(data2.did_run(), true); | |
472 } | |
473 | |
474 TEST_F(ApplicationUsageDataTest, ReadDidRunUser5) { | |
475 // low integrity user = true, not vista | |
476 ApplicationUsageData data2(true, false); | |
477 CreateLowIntegrityUserDidRunValue(true); | |
478 ASSERT_SUCCEEDED(data2.ReadDidRun(kAppGuid)); | |
479 ASSERT_EQ(data2.exists(), false); | |
480 ASSERT_EQ(data2.did_run(), false); | |
481 } | |
482 | |
483 TEST_F(ApplicationUsageDataTest, ReadDwordDidRunUser5) { | |
484 // low integrity user = true, not vista | |
485 ApplicationUsageData data2(true, false); | |
486 CreateLowIntegrityUserDidRunDwordValue(true); | |
487 ASSERT_SUCCEEDED(data2.ReadDidRun(kAppGuid)); | |
488 ASSERT_EQ(data2.exists(), false); | |
489 ASSERT_EQ(data2.did_run(), false); | |
490 } | |
491 | |
492 TEST_F(ApplicationUsageDataTest, ReadDidRunMachine1) { | |
493 if (!vista_util::IsUserAdmin()) { | |
494 return; | |
495 } | |
496 | |
497 ApplicationUsageData data(true, true); | |
498 | |
499 // create machine application key and test | |
500 CreateMachineDidRunValue(false); | |
501 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
502 ASSERT_EQ(data.exists(), true); | |
503 ASSERT_EQ(data.did_run(), false); | |
504 } | |
505 | |
506 TEST_F(ApplicationUsageDataTest, ReadDwordDidRunMachine1) { | |
507 if (!vista_util::IsUserAdmin()) { | |
508 return; | |
509 } | |
510 | |
511 ApplicationUsageData data(true, true); | |
512 | |
513 // create machine application key and test | |
514 CreateMachineDidRunDwordValue(false); | |
515 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
516 ASSERT_EQ(data.exists(), true); | |
517 ASSERT_EQ(data.did_run(), false); | |
518 } | |
519 | |
520 TEST_F(ApplicationUsageDataTest, ReadDidRunMachine2) { | |
521 if (!vista_util::IsUserAdmin()) { | |
522 return; | |
523 } | |
524 | |
525 ApplicationUsageData data1(true, true); | |
526 CreateMachineDidRunValue(true); | |
527 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
528 ASSERT_EQ(data1.exists(), true); | |
529 ASSERT_EQ(data1.did_run(), true); | |
530 } | |
531 | |
532 TEST_F(ApplicationUsageDataTest, ReadDwordDidRunMachine2) { | |
533 if (!vista_util::IsUserAdmin()) { | |
534 return; | |
535 } | |
536 | |
537 ApplicationUsageData data1(true, true); | |
538 CreateMachineDidRunDwordValue(true); | |
539 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
540 ASSERT_EQ(data1.exists(), true); | |
541 ASSERT_EQ(data1.did_run(), true); | |
542 } | |
543 | |
544 TEST_F(ApplicationUsageDataTest, ReadDidRunBoth1) { | |
545 if (!vista_util::IsUserAdmin()) { | |
546 return; | |
547 } | |
548 | |
549 // We try all combinations of machine, user and low integrity user | |
550 // registry value for did run. -1 indicates the value does not exist | |
551 // 1 indicates true and 0 indicates false. | |
552 for (int vista = 0; vista < 2; ++vista) { | |
553 for (int machine = -1; machine < 2; ++machine) { | |
554 for (int user = -1; user < 2; ++user) { | |
555 for (int lowuser = -1; lowuser < 2; ++lowuser) { | |
556 bool expected_did_run = false; | |
557 bool expected_exists = false; | |
558 | |
559 if (machine > -1 || user > -1 || (vista && lowuser > -1)) { | |
560 expected_exists = true; | |
561 } | |
562 | |
563 if (machine > 0 || user > 0 || (vista && lowuser > 0)) { | |
564 expected_did_run = true; | |
565 } | |
566 | |
567 TestUserAndMachineDidRun(machine, user, lowuser, | |
568 expected_exists, | |
569 expected_did_run, | |
570 vista); | |
571 TearDown(); | |
572 } | |
573 } | |
574 } | |
575 } | |
576 } | |
577 | |
578 TEST_F(ApplicationUsageDataTest, ResetDidRunUser1) { | |
579 ApplicationUsageData data(true, true); | |
580 | |
581 // create user application key and test | |
582 CreateUserDidRunValue(false); | |
583 ASSERT_SUCCEEDED(data.ResetDidRun(kAppGuid)); | |
584 CheckUserDidRunValue(false); | |
585 | |
586 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
587 ASSERT_EQ(data.exists(), true); | |
588 ASSERT_EQ(data.did_run(), false); | |
589 } | |
590 | |
591 TEST_F(ApplicationUsageDataTest, ResetDidRunUser2) { | |
592 ApplicationUsageData data1(true, true); | |
593 CreateUserDidRunValue(true); | |
594 ASSERT_SUCCEEDED(data1.ResetDidRun(kAppGuid)); | |
595 CheckUserDidRunValue(false); | |
596 | |
597 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
598 ASSERT_EQ(data1.exists(), true); | |
599 ASSERT_EQ(data1.did_run(), false); | |
600 } | |
601 | |
602 TEST_F(ApplicationUsageDataTest, ResetDidRunUser3) { | |
603 ApplicationUsageData data(true, true); | |
604 | |
605 // create user application key and test | |
606 CreateUserDidRunDwordValue(false); | |
607 ASSERT_SUCCEEDED(data.ResetDidRun(kAppGuid)); | |
608 CheckUserDidRunValue(false); | |
609 | |
610 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
611 ASSERT_EQ(data.exists(), true); | |
612 ASSERT_EQ(data.did_run(), false); | |
613 } | |
614 | |
615 TEST_F(ApplicationUsageDataTest, ResetDidRunUser4) { | |
616 ApplicationUsageData data1(true, true); | |
617 CreateUserDidRunDwordValue(true); | |
618 ASSERT_SUCCEEDED(data1.ResetDidRun(kAppGuid)); | |
619 CheckUserDidRunValue(false); | |
620 | |
621 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
622 ASSERT_EQ(data1.exists(), true); | |
623 ASSERT_EQ(data1.did_run(), false); | |
624 } | |
625 | |
626 TEST_F(ApplicationUsageDataTest, ResetDidRunMachine1) { | |
627 if (!vista_util::IsUserAdmin()) { | |
628 return; | |
629 } | |
630 | |
631 ApplicationUsageData data(true, true); | |
632 CreateMachineDidRunValue(false); | |
633 ASSERT_SUCCEEDED(data.ResetDidRun(kAppGuid)); | |
634 CheckMachineDidRunValue(false); | |
635 | |
636 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
637 ASSERT_EQ(data.exists(), true); | |
638 ASSERT_EQ(data.did_run(), false); | |
639 } | |
640 | |
641 TEST_F(ApplicationUsageDataTest, ResetDidRunMachine2) { | |
642 if (!vista_util::IsUserAdmin()) { | |
643 return; | |
644 } | |
645 | |
646 ApplicationUsageData data1(true, true); | |
647 CreateMachineDidRunValue(true); | |
648 ASSERT_SUCCEEDED(data1.ResetDidRun(kAppGuid)); | |
649 CheckMachineDidRunValue(false); | |
650 | |
651 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
652 ASSERT_EQ(data1.exists(), true); | |
653 ASSERT_EQ(data1.did_run(), false); | |
654 } | |
655 | |
656 TEST_F(ApplicationUsageDataTest, ResetDidRunMachine3) { | |
657 if (!vista_util::IsUserAdmin()) { | |
658 return; | |
659 } | |
660 | |
661 ApplicationUsageData data(true, true); | |
662 CreateMachineDidRunDwordValue(false); | |
663 ASSERT_SUCCEEDED(data.ResetDidRun(kAppGuid)); | |
664 CheckMachineDidRunValue(false); | |
665 | |
666 ASSERT_SUCCEEDED(data.ReadDidRun(kAppGuid)); | |
667 ASSERT_EQ(data.exists(), true); | |
668 ASSERT_EQ(data.did_run(), false); | |
669 } | |
670 | |
671 TEST_F(ApplicationUsageDataTest, ResetDidRunMachine4) { | |
672 if (!vista_util::IsUserAdmin()) { | |
673 return; | |
674 } | |
675 | |
676 ApplicationUsageData data1(true, true); | |
677 CreateMachineDidRunDwordValue(true); | |
678 ASSERT_SUCCEEDED(data1.ResetDidRun(kAppGuid)); | |
679 CheckMachineDidRunValue(false); | |
680 | |
681 ASSERT_SUCCEEDED(data1.ReadDidRun(kAppGuid)); | |
682 ASSERT_EQ(data1.exists(), true); | |
683 ASSERT_EQ(data1.did_run(), false); | |
684 } | |
685 | |
686 TEST_F(ApplicationUsageDataTest, ResetDidRunBoth) { | |
687 if (!vista_util::IsUserAdmin()) { | |
688 return; | |
689 } | |
690 | |
691 // We try all combinations of machine, user and low integrity user | |
692 // registry value for did run. -1 indicates the value does not exist | |
693 // 1 indicates true and 0 indicates false. | |
694 for (int vista = 0; vista < 2; ++vista) { | |
695 for (int machine = -1; machine < 2; ++machine) { | |
696 for (int user = -1; user < 2; ++user) { | |
697 for (int lowuser = -1; lowuser < 2; ++lowuser) { | |
698 bool expected_exists = false; | |
699 if (machine > -1 || user > -1 || (vista && lowuser > -1)) { | |
700 expected_exists = true; | |
701 } | |
702 | |
703 TestUserAndMachineDidRunPostProcess(machine, user, lowuser, | |
704 expected_exists, | |
705 vista); | |
706 TearDown(); | |
707 } | |
708 } | |
709 } | |
710 } | |
711 } | |
712 | |
713 TEST_F(ApplicationUsageDataTest, UserReadDidRunUser) { | |
714 for (int vista = 0; vista < 2; ++vista) { | |
715 for (int user = -1; user < 2; ++user) { | |
716 for (int lowuser = -1; lowuser < 2; ++lowuser) { | |
717 bool expected_exists = false; | |
718 bool expected_did_run = false; | |
719 | |
720 if (user != -1 || (vista && lowuser != -1)) { | |
721 expected_exists = true; | |
722 } | |
723 | |
724 if (user > 0 || (vista && lowuser > 0)) { | |
725 expected_did_run = true; | |
726 } | |
727 | |
728 UserTestDidRunPreProcess(user, lowuser, vista, expected_exists, | |
729 expected_did_run); | |
730 TearDown(); | |
731 } | |
732 } | |
733 } | |
734 } | |
735 | |
736 TEST_F(ApplicationUsageDataTest, UserResetDidRunUser1) { | |
737 for (int vista = 0; vista < 2; ++vista) { | |
738 for (int user = -1; user < 2; ++user) { | |
739 for (int lowuser = -1; lowuser < 2; ++lowuser) { | |
740 UserTestDidRunPostProcess(user, lowuser, vista); | |
741 TearDown(); | |
742 } | |
743 } | |
744 } | |
745 } | |
746 | |
747 } // namespace omaha | |
OLD | NEW |