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

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

Issue 2718063002: Use install_static::GetAppGuid in place of BrowserDistribution and AppRegistrationData. (Closed)
Patch Set: huangs feedback plus Chromium test fix Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/installer/util/google_update_settings.h" 5 #include "chrome/installer/util/google_update_settings.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shlwapi.h> // For SHDeleteKey. 8 #include <shlwapi.h> // For SHDeleteKey.
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "base/base_paths.h" 13 #include "base/base_paths.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/test/scoped_path_override.h" 18 #include "base/test/scoped_path_override.h"
19 #include "base/test/test_reg_util_win.h" 19 #include "base/test/test_reg_util_win.h"
20 #include "base/win/registry.h" 20 #include "base/win/registry.h"
21 #include "base/win/win_util.h" 21 #include "base/win/win_util.h"
22 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
23 #include "chrome/install_static/install_util.h"
23 #include "chrome/install_static/test/scoped_install_details.h" 24 #include "chrome/install_static/test/scoped_install_details.h"
24 #include "chrome/installer/util/app_registration_data.h" 25 #include "chrome/installer/util/app_registration_data.h"
25 #include "chrome/installer/util/browser_distribution.h" 26 #include "chrome/installer/util/browser_distribution.h"
26 #include "chrome/installer/util/channel_info.h" 27 #include "chrome/installer/util/channel_info.h"
27 #include "chrome/installer/util/fake_installation_state.h" 28 #include "chrome/installer/util/fake_installation_state.h"
28 #include "chrome/installer/util/google_update_constants.h" 29 #include "chrome/installer/util/google_update_constants.h"
29 #include "chrome/installer/util/helper.h" 30 #include "chrome/installer/util/helper.h"
30 #include "chrome/installer/util/util_constants.h" 31 #include "chrome/installer/util/util_constants.h"
31 #include "chrome/installer/util/work_item_list.h" 32 #include "chrome/installer/util/work_item_list.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(), 700 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(),
700 static_cast<DWORD>(4))); 701 static_cast<DWORD>(4)));
701 is_overridden = true; 702 is_overridden = true;
702 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, 703 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED,
703 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, 704 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
704 &is_overridden)); 705 &is_overridden));
705 EXPECT_FALSE(is_overridden); 706 EXPECT_FALSE(is_overridden);
706 } 707 }
707 708
708 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesDisabledByPolicy) { 709 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesDisabledByPolicy) {
709 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 710 const wchar_t* app_guid = install_static::GetAppGuid();
710 EXPECT_TRUE( 711 EXPECT_TRUE(SetUpdatePolicyForAppGuid(
711 SetUpdatePolicyForAppGuid(dist->GetAppGuid(), 712 app_guid, GoogleUpdateSettings::UPDATES_DISABLED));
712 GoogleUpdateSettings::UPDATES_DISABLED));
713 bool is_overridden = false; 713 bool is_overridden = false;
714 GoogleUpdateSettings::UpdatePolicy update_policy = 714 GoogleUpdateSettings::UpdatePolicy update_policy =
715 GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(), 715 GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, &is_overridden);
716 &is_overridden);
717 EXPECT_TRUE(is_overridden); 716 EXPECT_TRUE(is_overridden);
718 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, update_policy); 717 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, update_policy);
719 EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled()); 718 EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled());
720 719
721 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); 720 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
722 update_policy = GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(), 721 update_policy =
723 &is_overridden); 722 GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, &is_overridden);
724 // Should still have a policy but now that policy should explicitly enable 723 // Should still have a policy but now that policy should explicitly enable
725 // updates. 724 // updates.
726 EXPECT_TRUE(is_overridden); 725 EXPECT_TRUE(is_overridden);
727 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy); 726 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy);
728 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); 727 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
729 } 728 }
730 729
731 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesEnabledWithGlobalDisabled) { 730 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesEnabledWithGlobalDisabled) {
732 // Disable updates globally but enable them for Chrome (the app-specific 731 // Disable updates globally but enable them for Chrome (the app-specific
733 // setting should take precedence). 732 // setting should take precedence).
734 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 733 const wchar_t* app_guid = install_static::GetAppGuid();
735 EXPECT_TRUE( 734 EXPECT_TRUE(SetUpdatePolicyForAppGuid(
736 SetUpdatePolicyForAppGuid(dist->GetAppGuid(), 735 app_guid, GoogleUpdateSettings::AUTOMATIC_UPDATES));
737 GoogleUpdateSettings::AUTOMATIC_UPDATES));
738 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); 736 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED));
739 737
740 // Make sure we read this as still having updates enabled. 738 // Make sure we read this as still having updates enabled.
741 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); 739 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
742 740
743 // Make sure that the reset action returns true and is a no-op. 741 // Make sure that the reset action returns true and is a no-op.
744 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); 742 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
745 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, 743 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES,
746 GetUpdatePolicyForAppGuid(dist->GetAppGuid())); 744 GetUpdatePolicyForAppGuid(app_guid));
747 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, GetGlobalUpdatePolicy()); 745 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, GetGlobalUpdatePolicy());
748 } 746 }
749 747
750 TEST_F(GoogleUpdateSettingsTest, GlobalUpdatesDisabledByPolicy) { 748 TEST_F(GoogleUpdateSettingsTest, GlobalUpdatesDisabledByPolicy) {
751 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 749 const wchar_t* app_guid = install_static::GetAppGuid();
752 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); 750 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED));
753 bool is_overridden = false; 751 bool is_overridden = false;
754 752
755 // The contract for GetAppUpdatePolicy states that |is_overridden| should be 753 // The contract for GetAppUpdatePolicy states that |is_overridden| should be
756 // set to false when updates are disabled on a non-app-specific basis. 754 // set to false when updates are disabled on a non-app-specific basis.
757 GoogleUpdateSettings::UpdatePolicy update_policy = 755 GoogleUpdateSettings::UpdatePolicy update_policy =
758 GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(), 756 GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, &is_overridden);
759 &is_overridden);
760 EXPECT_FALSE(is_overridden); 757 EXPECT_FALSE(is_overridden);
761 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, update_policy); 758 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, update_policy);
762 EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled()); 759 EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled());
763 760
764 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); 761 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
765 update_policy = GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(), 762 update_policy =
766 &is_overridden); 763 GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, &is_overridden);
767 // Policy should now be to enable updates, |is_overridden| should still be 764 // Policy should now be to enable updates, |is_overridden| should still be
768 // false. 765 // false.
769 EXPECT_FALSE(is_overridden); 766 EXPECT_FALSE(is_overridden);
770 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy); 767 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy);
771 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); 768 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
772 } 769 }
773 770
774 TEST_F(GoogleUpdateSettingsTest, UpdatesDisabledByTimeout) { 771 TEST_F(GoogleUpdateSettingsTest, UpdatesDisabledByTimeout) {
775 // Disable updates altogether. 772 // Disable updates altogether.
776 EXPECT_TRUE(SetUpdateTimeoutOverride(0)); 773 EXPECT_TRUE(SetUpdateTimeoutOverride(0));
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 StatsState::TRUE_SETTING), 1179 StatsState::TRUE_SETTING),
1183 StatsState(StatsState::kSystemLevel, 1180 StatsState(StatsState::kSystemLevel,
1184 StatsState::TRUE_SETTING, 1181 StatsState::TRUE_SETTING,
1185 StatsState::NO_SETTING), 1182 StatsState::NO_SETTING),
1186 StatsState(StatsState::kSystemLevel, 1183 StatsState(StatsState::kSystemLevel,
1187 StatsState::TRUE_SETTING, 1184 StatsState::TRUE_SETTING,
1188 StatsState::FALSE_SETTING), 1185 StatsState::FALSE_SETTING),
1189 StatsState(StatsState::kSystemLevel, 1186 StatsState(StatsState::kSystemLevel,
1190 StatsState::TRUE_SETTING, 1187 StatsState::TRUE_SETTING,
1191 StatsState::TRUE_SETTING))); 1188 StatsState::TRUE_SETTING)));
OLDNEW
« no previous file with comments | « chrome/installer/util/google_update_settings.cc ('k') | chrome/installer/util/non_updating_app_registration_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698