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

Side by Side Diff: chrome/installer/util/google_update_settings_unittest.cc

Issue 7111012: Return a new error code for multi-install updates if Group Policy settings blocking... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 <windows.h> 5 #include <windows.h>
6 #include <shlwapi.h> // For SHDeleteKey. 6 #include <shlwapi.h> // For SHDeleteKey.
7 7
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 10
(...skipping 13 matching lines...) Expand all
24 24
25 using base::win::RegKey; 25 using base::win::RegKey;
26 using installer::ChannelInfo; 26 using installer::ChannelInfo;
27 27
28 namespace { 28 namespace {
29 29
30 const wchar_t kHKCUReplacement[] = 30 const wchar_t kHKCUReplacement[] =
31 L"Software\\Google\\InstallUtilUnittest\\HKCU"; 31 L"Software\\Google\\InstallUtilUnittest\\HKCU";
32 const wchar_t kHKLMReplacement[] = 32 const wchar_t kHKLMReplacement[] =
33 L"Software\\Google\\InstallUtilUnittest\\HKLM"; 33 L"Software\\Google\\InstallUtilUnittest\\HKLM";
34 const wchar_t kGoogleUpdatePoliciesKey[] =
35 L"SOFTWARE\\Policies\\Google\\Update";
36 const wchar_t kGoogleUpdateUpdateDefault[] = L"UpdateDefault";
37 const wchar_t kGoogleUpdateUpdatePrefix[] = L"Update";
38 const GoogleUpdateSettings::UpdatePolicy kDefaultUpdatePolicy =
39 #if defined(GOOGLE_CHROME_BUILD)
40 GoogleUpdateSettings::AUTOMATIC_UPDATES;
41 #else
42 GoogleUpdateSettings::UPDATES_DISABLED;
43 #endif
34 44
35 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; 45 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}";
36 46
37 // This test fixture redirects the HKLM and HKCU registry hives for 47 // This test fixture redirects the HKLM and HKCU registry hives for
38 // the duration of the test to make it independent of the machine 48 // the duration of the test to make it independent of the machine
39 // and user settings. 49 // and user settings.
40 class GoogleUpdateSettingsTest: public testing::Test { 50 class GoogleUpdateSettingsTest: public testing::Test {
41 protected: 51 protected:
42 virtual void SetUp() { 52 virtual void SetUp() {
43 // Wipe the keys we redirect to. 53 // Wipe the keys we redirect to.
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 key.WriteValue(google_update::kRegEULAAceptedField, 468 key.WriteValue(google_update::kRegEULAAceptedField,
459 static_cast<DWORD>(0))); 469 static_cast<DWORD>(0)));
460 EXPECT_TRUE(GoogleUpdateSettings::SetEULAConsent(installer_state, true)); 470 EXPECT_TRUE(GoogleUpdateSettings::SetEULAConsent(installer_state, true));
461 EXPECT_EQ(ERROR_SUCCESS, 471 EXPECT_EQ(ERROR_SUCCESS,
462 key.Open(HKEY_LOCAL_MACHINE, chrome->GetStateMediumKey().c_str(), 472 key.Open(HKEY_LOCAL_MACHINE, chrome->GetStateMediumKey().c_str(),
463 KEY_QUERY_VALUE | KEY_SET_VALUE)); 473 KEY_QUERY_VALUE | KEY_SET_VALUE));
464 EXPECT_EQ(ERROR_SUCCESS, 474 EXPECT_EQ(ERROR_SUCCESS,
465 key.ReadValueDW(google_update::kRegEULAAceptedField, &value)); 475 key.ReadValueDW(google_update::kRegEULAAceptedField, &value));
466 EXPECT_EQ(1U, value); 476 EXPECT_EQ(1U, value);
467 } 477 }
478
479 // Test that the appropriate default is returned if no update override is
480 // present.
481 TEST_F(GoogleUpdateSettingsTest, GetAppUpdatePolicyNoOverride) {
482 // There are no policies at all.
483 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
484 RegKey().Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
485 KEY_QUERY_VALUE));
486 bool is_overridden = true;
487 EXPECT_EQ(kDefaultUpdatePolicy,
488 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
489 &is_overridden));
490 EXPECT_FALSE(is_overridden);
491
492 // The policy key exists, but there are no values of interest present.
493 EXPECT_EQ(ERROR_SUCCESS,
494 RegKey().Create(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
495 KEY_SET_VALUE));
496 EXPECT_EQ(ERROR_SUCCESS,
497 RegKey().Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
498 KEY_QUERY_VALUE));
499 is_overridden = true;
500 EXPECT_EQ(kDefaultUpdatePolicy,
501 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
502 &is_overridden));
503 EXPECT_FALSE(is_overridden);
504 }
505
506 #if defined(GOOGLE_CHROME_BUILD)
507
508 // Test that the default override is returned if no app-specific override is
509 // present.
510 TEST_F(GoogleUpdateSettingsTest, GetAppUpdatePolicyDefaultOverride) {
511 EXPECT_EQ(ERROR_SUCCESS,
512 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
513 KEY_SET_VALUE).WriteValue(kGoogleUpdateUpdateDefault,
514 static_cast<DWORD>(0)));
515 bool is_overridden = true;
516 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED,
517 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
518 &is_overridden));
519 EXPECT_FALSE(is_overridden);
520
521 EXPECT_EQ(ERROR_SUCCESS,
522 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
523 KEY_SET_VALUE).WriteValue(kGoogleUpdateUpdateDefault,
524 static_cast<DWORD>(1)));
525 is_overridden = true;
526 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES,
527 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
528 &is_overridden));
529 EXPECT_FALSE(is_overridden);
530
531 EXPECT_EQ(ERROR_SUCCESS,
532 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
533 KEY_SET_VALUE).WriteValue(kGoogleUpdateUpdateDefault,
534 static_cast<DWORD>(2)));
535 is_overridden = true;
536 EXPECT_EQ(GoogleUpdateSettings::MANUAL_UPDATES_ONLY,
537 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
538 &is_overridden));
539 EXPECT_FALSE(is_overridden);
540
541 // The default policy should be in force for bogus values.
542 EXPECT_EQ(ERROR_SUCCESS,
543 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
544 KEY_SET_VALUE).WriteValue(kGoogleUpdateUpdateDefault,
545 static_cast<DWORD>(3)));
546 is_overridden = true;
547 EXPECT_EQ(kDefaultUpdatePolicy,
548 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
549 &is_overridden));
550 EXPECT_FALSE(is_overridden);
551 }
552
553 // Test that an app-specific override is used if present.
554 TEST_F(GoogleUpdateSettingsTest, GetAppUpdatePolicyAppOverride) {
555 std::wstring app_policy_value(kGoogleUpdateUpdatePrefix);
556 app_policy_value.append(kTestProductGuid);
557
558 EXPECT_EQ(ERROR_SUCCESS,
559 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
560 KEY_SET_VALUE).WriteValue(kGoogleUpdateUpdateDefault,
561 static_cast<DWORD>(1)));
562 EXPECT_EQ(ERROR_SUCCESS,
563 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
564 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(),
565 static_cast<DWORD>(0)));
566 bool is_overridden = false;
567 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED,
568 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
569 &is_overridden));
570 EXPECT_TRUE(is_overridden);
571
572 EXPECT_EQ(ERROR_SUCCESS,
573 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
574 KEY_SET_VALUE).WriteValue(kGoogleUpdateUpdateDefault,
575 static_cast<DWORD>(0)));
576 EXPECT_EQ(ERROR_SUCCESS,
577 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
578 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(),
579 static_cast<DWORD>(1)));
580 is_overridden = false;
581 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES,
582 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
583 &is_overridden));
584 EXPECT_TRUE(is_overridden);
585
586 EXPECT_EQ(ERROR_SUCCESS,
587 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
588 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(),
589 static_cast<DWORD>(2)));
590 is_overridden = false;
591 EXPECT_EQ(GoogleUpdateSettings::MANUAL_UPDATES_ONLY,
592 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
593 &is_overridden));
594 EXPECT_TRUE(is_overridden);
595
596 // The default policy should be in force for bogus values.
597 EXPECT_EQ(ERROR_SUCCESS,
598 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
599 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(),
600 static_cast<DWORD>(3)));
601 is_overridden = true;
602 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED,
603 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
604 &is_overridden));
605 EXPECT_FALSE(is_overridden);
606 }
607
608 #endif // defined(GOOGLE_CHROME_BUILD)
OLDNEW
« no previous file with comments | « chrome/installer/util/google_update_settings.cc ('k') | chrome/installer/util/prebuild/create_string_rc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698