OLD | NEW |
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 |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "chrome/installer/util/work_item_list.h" | 32 #include "chrome/installer/util/work_item_list.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 | 34 |
35 using base::win::RegKey; | 35 using base::win::RegKey; |
36 using installer::ChannelInfo; | 36 using installer::ChannelInfo; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; | 40 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; |
41 | 41 |
42 #if defined(GOOGLE_CHROME_BUILD) | |
43 const wchar_t kTestExperimentLabel[] = L"test_label_value"; | 42 const wchar_t kTestExperimentLabel[] = L"test_label_value"; |
44 #endif | |
45 | 43 |
46 // This test fixture redirects the HKLM and HKCU registry hives for | 44 // This test fixture redirects the HKLM and HKCU registry hives for |
47 // the duration of the test to make it independent of the machine | 45 // the duration of the test to make it independent of the machine |
48 // and user settings. | 46 // and user settings. |
49 class GoogleUpdateSettingsTest : public testing::Test { | 47 class GoogleUpdateSettingsTest : public testing::Test { |
50 protected: | 48 protected: |
51 enum SystemUserInstall { | 49 enum SystemUserInstall { |
52 SYSTEM_INSTALL, | 50 SYSTEM_INSTALL, |
53 USER_INSTALL, | 51 USER_INSTALL, |
54 }; | 52 }; |
55 | 53 |
56 GoogleUpdateSettingsTest() | 54 GoogleUpdateSettingsTest() |
57 : program_files_override_(base::DIR_PROGRAM_FILES), | 55 : program_files_override_(base::DIR_PROGRAM_FILES), |
58 program_files_x86_override_(base::DIR_PROGRAM_FILESX86) {} | 56 program_files_x86_override_(base::DIR_PROGRAM_FILESX86) {} |
59 | 57 |
60 void SetUp() override { | 58 void SetUp() override { |
61 ASSERT_NO_FATAL_FAILURE( | 59 ASSERT_NO_FATAL_FAILURE( |
62 registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE)); | 60 registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE)); |
63 ASSERT_NO_FATAL_FAILURE( | 61 ASSERT_NO_FATAL_FAILURE( |
64 registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER)); | 62 registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER)); |
65 } | 63 } |
66 | 64 |
67 // Test the writing and deleting functionality of the experiments label | 65 // Test the writing and deleting functionality of the experiments label |
68 // helper. | 66 // helper. |
69 void TestExperimentsLabelHelper(SystemUserInstall install) { | 67 void TestExperimentsLabelHelper(SystemUserInstall install) { |
70 // Install a basic InstallDetails instance. | 68 // Install a basic InstallDetails instance. |
71 install_static::ScopedInstallDetails details(install == SYSTEM_INSTALL); | 69 install_static::ScopedInstallDetails details(install == SYSTEM_INSTALL); |
72 | 70 |
73 base::string16 value; | 71 base::string16 value; |
74 #if defined(GOOGLE_CHROME_BUILD) | |
75 // Before anything is set, ReadExperimentLabels should succeed but return | 72 // Before anything is set, ReadExperimentLabels should succeed but return |
76 // an empty string. | 73 // an empty string. |
77 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( | 74 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( |
78 install == SYSTEM_INSTALL, &value)); | 75 install == SYSTEM_INSTALL, &value)); |
79 EXPECT_EQ(base::string16(), value); | 76 EXPECT_EQ(base::string16(), value); |
80 | 77 |
81 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( | 78 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( |
82 install == SYSTEM_INSTALL, kTestExperimentLabel)); | 79 install == SYSTEM_INSTALL, kTestExperimentLabel)); |
83 | 80 |
84 // Validate that something is written. Only worry about the label itself. | 81 // Validate that something is written. Only worry about the label itself. |
(...skipping 19 matching lines...) Expand all Loading... |
104 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( | 101 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( |
105 install == SYSTEM_INSTALL, base::string16())); | 102 install == SYSTEM_INSTALL, base::string16())); |
106 EXPECT_EQ(ERROR_SUCCESS, | 103 EXPECT_EQ(ERROR_SUCCESS, |
107 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); | 104 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); |
108 EXPECT_EQ(ERROR_FILE_NOT_FOUND, | 105 EXPECT_EQ(ERROR_FILE_NOT_FOUND, |
109 key.ReadValue(google_update::kExperimentLabels, &value)); | 106 key.ReadValue(google_update::kExperimentLabels, &value)); |
110 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( | 107 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( |
111 install == SYSTEM_INSTALL, &value)); | 108 install == SYSTEM_INSTALL, &value)); |
112 EXPECT_EQ(base::string16(), value); | 109 EXPECT_EQ(base::string16(), value); |
113 key.Close(); | 110 key.Close(); |
114 #else | |
115 EXPECT_FALSE(GoogleUpdateSettings::ReadExperimentLabels( | |
116 install == SYSTEM_INSTALL, &value)); | |
117 #endif // GOOGLE_CHROME_BUILD | |
118 } | 111 } |
119 | 112 |
120 // Creates "ap" key with the value given as parameter. Also adds work | 113 // Creates "ap" key with the value given as parameter. Also adds work |
121 // items to work_item_list given so that they can be rolled back later. | 114 // items to work_item_list given so that they can be rolled back later. |
122 bool CreateApKey(WorkItemList* work_item_list, const base::string16& value) { | 115 bool CreateApKey(WorkItemList* work_item_list, const base::string16& value) { |
123 HKEY reg_root = HKEY_CURRENT_USER; | 116 HKEY reg_root = HKEY_CURRENT_USER; |
124 base::string16 reg_key = GetApKeyPath(); | 117 base::string16 reg_key = GetApKeyPath(); |
125 work_item_list->AddCreateRegKeyWorkItem( | 118 work_item_list->AddCreateRegKeyWorkItem( |
126 reg_root, reg_key, WorkItem::kWow64Default); | 119 reg_root, reg_key, WorkItem::kWow64Default); |
127 work_item_list->AddSetRegValueWorkItem(reg_root, | 120 work_item_list->AddSetRegValueWorkItem(reg_root, |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); | 766 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); |
774 | 767 |
775 // Set the update period to something unreasonable. | 768 // Set the update period to something unreasonable. |
776 EXPECT_TRUE(SetUpdateTimeoutOverride( | 769 EXPECT_TRUE(SetUpdateTimeoutOverride( |
777 GoogleUpdateSettings::kCheckPeriodOverrideMinutesMax + 1)); | 770 GoogleUpdateSettings::kCheckPeriodOverrideMinutesMax + 1)); |
778 EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled()); | 771 EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled()); |
779 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); | 772 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); |
780 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); | 773 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); |
781 } | 774 } |
782 | 775 |
| 776 #endif // defined(GOOGLE_CHROME_BUILD) |
| 777 |
783 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperSystem) { | 778 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperSystem) { |
784 TestExperimentsLabelHelper(SYSTEM_INSTALL); | 779 TestExperimentsLabelHelper(SYSTEM_INSTALL); |
785 } | 780 } |
786 | 781 |
787 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperUser) { | 782 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperUser) { |
788 TestExperimentsLabelHelper(USER_INSTALL); | 783 TestExperimentsLabelHelper(USER_INSTALL); |
789 } | 784 } |
790 | 785 |
791 #endif // defined(GOOGLE_CHROME_BUILD) | |
792 | |
793 TEST_F(GoogleUpdateSettingsTest, GetDownloadPreference) { | 786 TEST_F(GoogleUpdateSettingsTest, GetDownloadPreference) { |
794 RegKey policy_key; | 787 RegKey policy_key; |
795 | 788 |
796 if (policy_key.Open(HKEY_LOCAL_MACHINE, GoogleUpdateSettings::kPoliciesKey, | 789 if (policy_key.Open(HKEY_LOCAL_MACHINE, GoogleUpdateSettings::kPoliciesKey, |
797 KEY_SET_VALUE) == ERROR_SUCCESS) { | 790 KEY_SET_VALUE) == ERROR_SUCCESS) { |
798 policy_key.DeleteValue( | 791 policy_key.DeleteValue( |
799 GoogleUpdateSettings::kDownloadPreferencePolicyValue); | 792 GoogleUpdateSettings::kDownloadPreferencePolicyValue); |
800 } | 793 } |
801 policy_key.Close(); | 794 policy_key.Close(); |
802 | 795 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 StatsState::TRUE_SETTING), | 1169 StatsState::TRUE_SETTING), |
1177 StatsState(StatsState::kSystemLevel, | 1170 StatsState(StatsState::kSystemLevel, |
1178 StatsState::TRUE_SETTING, | 1171 StatsState::TRUE_SETTING, |
1179 StatsState::NO_SETTING), | 1172 StatsState::NO_SETTING), |
1180 StatsState(StatsState::kSystemLevel, | 1173 StatsState(StatsState::kSystemLevel, |
1181 StatsState::TRUE_SETTING, | 1174 StatsState::TRUE_SETTING, |
1182 StatsState::FALSE_SETTING), | 1175 StatsState::FALSE_SETTING), |
1183 StatsState(StatsState::kSystemLevel, | 1176 StatsState(StatsState::kSystemLevel, |
1184 StatsState::TRUE_SETTING, | 1177 StatsState::TRUE_SETTING, |
1185 StatsState::TRUE_SETTING))); | 1178 StatsState::TRUE_SETTING))); |
OLD | NEW |