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 |
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/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/test/scoped_path_override.h" | 17 #include "base/test/scoped_path_override.h" |
18 #include "base/test/test_reg_util_win.h" | 18 #include "base/test/test_reg_util_win.h" |
19 #include "base/win/registry.h" | 19 #include "base/win/registry.h" |
20 #include "base/win/win_util.h" | 20 #include "base/win/win_util.h" |
21 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/installer/util/app_registration_data.h" | 22 #include "chrome/installer/util/app_registration_data.h" |
23 #include "chrome/installer/util/browser_distribution.h" | 23 #include "chrome/installer/util/browser_distribution.h" |
24 #include "chrome/installer/util/channel_info.h" | 24 #include "chrome/installer/util/channel_info.h" |
25 #include "chrome/installer/util/fake_installation_state.h" | 25 #include "chrome/installer/util/fake_installation_state.h" |
26 #include "chrome/installer/util/google_update_constants.h" | 26 #include "chrome/installer/util/google_update_constants.h" |
| 27 #include "chrome/installer/util/helper.h" |
27 #include "chrome/installer/util/util_constants.h" | 28 #include "chrome/installer/util/util_constants.h" |
28 #include "chrome/installer/util/work_item_list.h" | 29 #include "chrome/installer/util/work_item_list.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 | 31 |
31 using base::win::RegKey; | 32 using base::win::RegKey; |
32 using installer::ChannelInfo; | 33 using installer::ChannelInfo; |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; | 37 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; |
(...skipping 23 matching lines...) Expand all Loading... |
60 HKEY root = is_system == SYSTEM_INSTALL ? | 61 HKEY root = is_system == SYSTEM_INSTALL ? |
61 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 62 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
62 | 63 |
63 RegKey update_key; | 64 RegKey update_key; |
64 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 65 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
65 base::string16 path = dist->GetStateKey(); | 66 base::string16 path = dist->GetStateKey(); |
66 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), KEY_WRITE)); | 67 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), KEY_WRITE)); |
67 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); | 68 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); |
68 } | 69 } |
69 | 70 |
70 // Sets the "ap" field for a multi-install product (both the product and | |
71 // the binaries). | |
72 void SetMultiApField(SystemUserInstall is_system, const wchar_t* value) { | |
73 // Caller must specify a multi-install ap value. | |
74 ASSERT_NE(base::string16::npos, base::string16(value).find(L"-multi")); | |
75 HKEY root = is_system == SYSTEM_INSTALL ? | |
76 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
77 RegKey update_key; | |
78 | |
79 // Write the ap value for both the product and the binaries. | |
80 BrowserDistribution* const kDists[] = { | |
81 BrowserDistribution::GetDistribution(), | |
82 BrowserDistribution::GetSpecificDistribution( | |
83 BrowserDistribution::CHROME_BINARIES) | |
84 }; | |
85 for (size_t i = 0; i < arraysize(kDists); ++i) { | |
86 base::string16 path = kDists[i]->GetStateKey(); | |
87 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), | |
88 KEY_WRITE)); | |
89 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); | |
90 } | |
91 | |
92 // Make the product technically multi-install. | |
93 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
94 ASSERT_EQ(ERROR_SUCCESS, | |
95 update_key.Create(root, dist->GetStateKey().c_str(), KEY_WRITE)); | |
96 ASSERT_EQ(ERROR_SUCCESS, | |
97 update_key.WriteValue(installer::kUninstallArgumentsField, | |
98 L"--multi-install")); | |
99 } | |
100 | |
101 // Tests setting the ap= value to various combinations of values with | 71 // Tests setting the ap= value to various combinations of values with |
102 // suffixes, while asserting on the correct channel value. | 72 // suffixes, while asserting on the correct channel value. |
103 // Note that ap= value has to match "^2.0-d.*" or ".*x64-dev.*" and "^1.1-.*" | 73 // Note that ap= value has to match "^2.0-d.*" or ".*x64-dev.*" and "^1.1-.*" |
104 // or ".*x64-beta.*" for dev and beta channels respectively. | 74 // or ".*x64-beta.*" for dev and beta channels respectively. |
105 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { | 75 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { |
106 static struct Expectation { | 76 static struct Expectation { |
107 const wchar_t* ap_value; | 77 const wchar_t* ap_value; |
108 const wchar_t* channel; | 78 const wchar_t* channel; |
109 bool supports_prefixes; | 79 bool supports_prefixes; |
110 } expectations[] = { | 80 } expectations[] = { |
(...skipping 17 matching lines...) Expand all Loading... |
128 | 98 |
129 for (const wchar_t* prefix : prefixes) { | 99 for (const wchar_t* prefix : prefixes) { |
130 for (const Expectation& expectation : expectations) { | 100 for (const Expectation& expectation : expectations) { |
131 for (const wchar_t* suffix : suffixes) { | 101 for (const wchar_t* suffix : suffixes) { |
132 base::string16 ap = prefix; | 102 base::string16 ap = prefix; |
133 ap += expectation.ap_value; | 103 ap += expectation.ap_value; |
134 ap += suffix; | 104 ap += suffix; |
135 const wchar_t* channel = expectation.channel; | 105 const wchar_t* channel = expectation.channel; |
136 | 106 |
137 SetApField(install, ap.c_str()); | 107 SetApField(install, ap.c_str()); |
138 base::string16 ret_channel; | 108 const base::string16 ret_channel = |
139 | 109 GoogleUpdateSettings::GetChromeChannel(is_system); |
140 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( | |
141 is_system, &ret_channel)); | |
142 | 110 |
143 // If prefixes are not supported for a channel, we expect the channel | 111 // If prefixes are not supported for a channel, we expect the channel |
144 // to be "unknown" if a non-empty prefix is present in ap_value. | 112 // to be "unknown" if a non-empty prefix is present in ap_value. |
145 if (!expectation.supports_prefixes && wcslen(prefix) > 0) { | 113 if (!expectation.supports_prefixes && wcslen(prefix) > 0) { |
146 EXPECT_STREQ(installer::kChromeChannelUnknown, ret_channel.c_str()) | 114 EXPECT_STREQ(installer::kChromeChannelUnknown, ret_channel.c_str()) |
147 << "Expecting channel \"" << installer::kChromeChannelUnknown | 115 << "Expecting channel \"" << installer::kChromeChannelUnknown |
148 << "\" for ap=\"" << ap << "\""; | 116 << "\" for ap=\"" << ap << "\""; |
149 } else { | 117 } else { |
150 EXPECT_STREQ(channel, ret_channel.c_str()) | 118 EXPECT_STREQ(channel, ret_channel.c_str()) |
151 << "Expecting channel \"" << channel | 119 << "Expecting channel \"" << channel |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 registry_util::RegistryOverrideManager registry_overrides_; | 293 registry_util::RegistryOverrideManager registry_overrides_; |
326 }; | 294 }; |
327 | 295 |
328 } // namespace | 296 } // namespace |
329 | 297 |
330 // Verify that we return success on no registration (which means stable), | 298 // Verify that we return success on no registration (which means stable), |
331 // whether per-system or per-user install. | 299 // whether per-system or per-user install. |
332 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { | 300 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { |
333 // Per-system first. | 301 // Per-system first. |
334 base::string16 channel; | 302 base::string16 channel; |
335 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 303 channel = GoogleUpdateSettings::GetChromeChannel(true); |
336 &channel)); | |
337 EXPECT_STREQ(L"", channel.c_str()); | 304 EXPECT_STREQ(L"", channel.c_str()); |
338 | 305 |
339 // Then per-user. | 306 // Then per-user. |
340 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | 307 channel = GoogleUpdateSettings::GetChromeChannel(false); |
341 &channel)); | |
342 EXPECT_STREQ(L"", channel.c_str()); | 308 EXPECT_STREQ(L"", channel.c_str()); |
343 } | 309 } |
344 | 310 |
345 // Test an empty Ap key for system and user. | 311 // Test an empty Ap key for system and user. |
346 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptySystem) { | 312 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptySystem) { |
347 SetApField(SYSTEM_INSTALL, L""); | 313 SetApField(SYSTEM_INSTALL, L""); |
348 base::string16 channel; | 314 base::string16 channel; |
349 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 315 channel = GoogleUpdateSettings::GetChromeChannel(true); |
350 &channel)); | |
351 EXPECT_STREQ(L"", channel.c_str()); | 316 EXPECT_STREQ(L"", channel.c_str()); |
352 | 317 |
353 // Per-user lookups still succeed and return empty string. | 318 // Per-user lookups still succeed and return empty string. |
354 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | 319 channel = GoogleUpdateSettings::GetChromeChannel(false); |
355 &channel)); | |
356 EXPECT_STREQ(L"", channel.c_str()); | 320 EXPECT_STREQ(L"", channel.c_str()); |
357 } | 321 } |
358 | 322 |
359 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptyUser) { | 323 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptyUser) { |
360 SetApField(USER_INSTALL, L""); | 324 SetApField(USER_INSTALL, L""); |
361 // Per-system lookups still succeed and return empty string. | 325 // Per-system lookups still succeed and return empty string. |
362 base::string16 channel; | 326 base::string16 channel; |
363 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 327 channel = GoogleUpdateSettings::GetChromeChannel(true); |
364 &channel)); | |
365 EXPECT_STREQ(L"", channel.c_str()); | 328 EXPECT_STREQ(L"", channel.c_str()); |
366 | 329 |
367 // Per-user lookup should succeed. | 330 // Per-user lookup should succeed. |
368 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | 331 channel = GoogleUpdateSettings::GetChromeChannel(false); |
369 &channel)); | |
370 EXPECT_STREQ(L"", channel.c_str()); | 332 EXPECT_STREQ(L"", channel.c_str()); |
371 } | 333 } |
372 | 334 |
373 // Test that the channel is pulled from the binaries for multi-install products. | |
374 TEST_F(GoogleUpdateSettingsTest, MultiInstallChannelFromBinaries) { | |
375 SetMultiApField(USER_INSTALL, L"2.0-dev-multi-chrome"); | |
376 base::string16 channel; | |
377 | |
378 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | |
379 &channel)); | |
380 EXPECT_STREQ(L"dev-m", channel.c_str()); | |
381 | |
382 // See if the same happens if the product's ap is cleared. | |
383 SetApField(USER_INSTALL, L""); | |
384 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | |
385 &channel)); | |
386 EXPECT_STREQ(L"dev-m", channel.c_str()); | |
387 | |
388 // Test the converse (binaries are stable, Chrome is other). | |
389 SetMultiApField(USER_INSTALL, L"-multi-chrome"); | |
390 SetApField(USER_INSTALL, L"2.0-dev-multi-chrome"); | |
391 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | |
392 &channel)); | |
393 EXPECT_STREQ(L"m", channel.c_str()); | |
394 } | |
395 | |
396 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { | 335 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { |
397 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); | 336 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); |
398 } | 337 } |
399 | 338 |
400 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { | 339 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { |
401 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); | 340 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); |
402 } | 341 } |
403 | 342 |
404 // Run through all combinations of diff vs. full install, single vs. multi | 343 // Run through all combinations of diff vs. full install, success and failure |
405 // install, success and failure results, and a fistful of initial "ap" values | 344 // results, and a fistful of initial "ap" values checking that the expected |
406 // checking that the expected final "ap" value is generated by | 345 // final "ap" value is generated by |
407 // GoogleUpdateSettings::UpdateGoogleUpdateApKey. | 346 // GoogleUpdateSettings::UpdateGoogleUpdateApKey. |
408 TEST_F(GoogleUpdateSettingsTest, UpdateGoogleUpdateApKey) { | 347 TEST_F(GoogleUpdateSettingsTest, UpdateGoogleUpdateApKey) { |
409 const installer::ArchiveType archive_types[] = { | 348 const installer::ArchiveType archive_types[] = { |
410 installer::UNKNOWN_ARCHIVE_TYPE, | 349 installer::UNKNOWN_ARCHIVE_TYPE, |
411 installer::FULL_ARCHIVE_TYPE, | 350 installer::FULL_ARCHIVE_TYPE, |
412 installer::INCREMENTAL_ARCHIVE_TYPE | 351 installer::INCREMENTAL_ARCHIVE_TYPE |
413 }; | 352 }; |
414 const int results[] = { | 353 const int results[] = { |
415 installer::FIRST_INSTALL_SUCCESS, | 354 installer::FIRST_INSTALL_SUCCESS, |
416 installer::INSTALL_FAILED | 355 installer::INSTALL_FAILED |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 // updates. | 840 // updates. |
902 EXPECT_TRUE(is_overridden); | 841 EXPECT_TRUE(is_overridden); |
903 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy); | 842 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy); |
904 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); | 843 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); |
905 } | 844 } |
906 | 845 |
907 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesEnabledWithGlobalDisabled) { | 846 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesEnabledWithGlobalDisabled) { |
908 // Disable updates globally but enable them for Chrome (the app-specific | 847 // Disable updates globally but enable them for Chrome (the app-specific |
909 // setting should take precedence). | 848 // setting should take precedence). |
910 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 849 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
911 BrowserDistribution* binaries = BrowserDistribution::GetSpecificDistribution( | |
912 BrowserDistribution::CHROME_BINARIES); | |
913 EXPECT_TRUE( | 850 EXPECT_TRUE( |
914 SetUpdatePolicyForAppGuid(dist->GetAppGuid(), | 851 SetUpdatePolicyForAppGuid(dist->GetAppGuid(), |
915 GoogleUpdateSettings::AUTOMATIC_UPDATES)); | 852 GoogleUpdateSettings::AUTOMATIC_UPDATES)); |
916 EXPECT_TRUE( | |
917 SetUpdatePolicyForAppGuid(binaries->GetAppGuid(), | |
918 GoogleUpdateSettings::AUTOMATIC_UPDATES)); | |
919 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); | 853 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); |
920 | 854 |
921 // Make sure we read this as still having updates enabled. | 855 // Make sure we read this as still having updates enabled. |
922 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); | 856 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); |
923 | 857 |
924 // Make sure that the reset action returns true and is a no-op. | 858 // Make sure that the reset action returns true and is a no-op. |
925 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); | 859 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); |
926 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, | 860 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, |
927 GetUpdatePolicyForAppGuid(dist->GetAppGuid())); | 861 GetUpdatePolicyForAppGuid(dist->GetAppGuid())); |
928 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, | |
929 GetUpdatePolicyForAppGuid(binaries->GetAppGuid())); | |
930 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, GetGlobalUpdatePolicy()); | 862 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, GetGlobalUpdatePolicy()); |
931 } | 863 } |
932 | 864 |
933 TEST_F(GoogleUpdateSettingsTest, GlobalUpdatesDisabledByPolicy) { | 865 TEST_F(GoogleUpdateSettingsTest, GlobalUpdatesDisabledByPolicy) { |
934 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 866 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
935 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); | 867 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); |
936 bool is_overridden = false; | 868 bool is_overridden = false; |
937 | 869 |
938 // The contract for GetAppUpdatePolicy states that |is_overridden| should be | 870 // The contract for GetAppUpdatePolicy states that |is_overridden| should be |
939 // set to false when updates are disabled on a non-app-specific basis. | 871 // set to false when updates are disabled on a non-app-specific basis. |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 GoogleUpdateSettings::GetGoogleUpdateVersion(!system_install_) | 1114 GoogleUpdateSettings::GetGoogleUpdateVersion(!system_install_) |
1183 .IsValid()); | 1115 .IsValid()); |
1184 } | 1116 } |
1185 | 1117 |
1186 INSTANTIATE_TEST_CASE_P(GetGoogleUpdateVersionAtLevel, GetGoogleUpdateVersion, | 1118 INSTANTIATE_TEST_CASE_P(GetGoogleUpdateVersionAtLevel, GetGoogleUpdateVersion, |
1187 testing::Bool()); | 1119 testing::Bool()); |
1188 | 1120 |
1189 // Test values for use by the CollectStatsConsent test fixture. | 1121 // Test values for use by the CollectStatsConsent test fixture. |
1190 class StatsState { | 1122 class StatsState { |
1191 public: | 1123 public: |
1192 enum InstallType { | |
1193 SINGLE_INSTALL, | |
1194 MULTI_INSTALL, | |
1195 }; | |
1196 enum StateSetting { | 1124 enum StateSetting { |
1197 NO_SETTING, | 1125 NO_SETTING, |
1198 FALSE_SETTING, | 1126 FALSE_SETTING, |
1199 TRUE_SETTING, | 1127 TRUE_SETTING, |
1200 }; | 1128 }; |
1201 struct UserLevelState {}; | 1129 struct UserLevelState {}; |
1202 struct SystemLevelState {}; | 1130 struct SystemLevelState {}; |
1203 static const UserLevelState kUserLevel; | 1131 static const UserLevelState kUserLevel; |
1204 static const SystemLevelState kSystemLevel; | 1132 static const SystemLevelState kSystemLevel; |
1205 | 1133 |
1206 StatsState(const UserLevelState&, | 1134 StatsState(const UserLevelState&, |
1207 InstallType install_type, | |
1208 StateSetting state_value) | 1135 StateSetting state_value) |
1209 : system_level_(false), | 1136 : system_level_(false), |
1210 multi_install_(install_type == MULTI_INSTALL), | |
1211 state_value_(state_value), | 1137 state_value_(state_value), |
1212 state_medium_value_(NO_SETTING) { | 1138 state_medium_value_(NO_SETTING) { |
1213 } | 1139 } |
1214 StatsState(const SystemLevelState&, | 1140 StatsState(const SystemLevelState&, |
1215 InstallType install_type, | |
1216 StateSetting state_value, | 1141 StateSetting state_value, |
1217 StateSetting state_medium_value) | 1142 StateSetting state_medium_value) |
1218 : system_level_(true), | 1143 : system_level_(true), |
1219 multi_install_(install_type == MULTI_INSTALL), | |
1220 state_value_(state_value), | 1144 state_value_(state_value), |
1221 state_medium_value_(state_medium_value) { | 1145 state_medium_value_(state_medium_value) { |
1222 } | 1146 } |
1223 bool system_level() const { return system_level_; } | 1147 bool system_level() const { return system_level_; } |
1224 bool multi_install() const { return multi_install_; } | |
1225 HKEY root_key() const { | 1148 HKEY root_key() const { |
1226 return system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 1149 return system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
1227 } | 1150 } |
1228 StateSetting state_value() const { return state_value_; } | 1151 StateSetting state_value() const { return state_value_; } |
1229 StateSetting state_medium_value() const { | 1152 StateSetting state_medium_value() const { |
1230 return state_medium_value_; | 1153 return state_medium_value_; |
1231 } | 1154 } |
1232 bool is_consent_granted() const { | 1155 bool is_consent_granted() const { |
1233 return (system_level_ && state_medium_value_ != NO_SETTING) ? | 1156 return (system_level_ && state_medium_value_ != NO_SETTING) ? |
1234 (state_medium_value_ == TRUE_SETTING) : | 1157 (state_medium_value_ == TRUE_SETTING) : |
1235 (state_value_ == TRUE_SETTING); | 1158 (state_value_ == TRUE_SETTING); |
1236 } | 1159 } |
1237 | 1160 |
1238 private: | 1161 private: |
1239 bool system_level_; | 1162 bool system_level_; |
1240 bool multi_install_; | |
1241 StateSetting state_value_; | 1163 StateSetting state_value_; |
1242 StateSetting state_medium_value_; | 1164 StateSetting state_medium_value_; |
1243 }; | 1165 }; |
1244 | 1166 |
1245 const StatsState::UserLevelState StatsState::kUserLevel = {}; | 1167 const StatsState::UserLevelState StatsState::kUserLevel = {}; |
1246 const StatsState::SystemLevelState StatsState::kSystemLevel = {}; | 1168 const StatsState::SystemLevelState StatsState::kSystemLevel = {}; |
1247 | 1169 |
1248 // A value parameterized test for testing the stats collection consent setting. | 1170 // A value parameterized test for testing the stats collection consent setting. |
1249 class CollectStatsConsent : public ::testing::TestWithParam<StatsState> { | 1171 class CollectStatsConsent : public ::testing::TestWithParam<StatsState> { |
1250 public: | 1172 public: |
1251 static void SetUpTestCase(); | 1173 static void SetUpTestCase(); |
1252 static void TearDownTestCase(); | 1174 static void TearDownTestCase(); |
1253 protected: | 1175 protected: |
1254 void SetUp() override; | 1176 void SetUp() override; |
1255 static void MakeChromeMultiInstall(HKEY root_key); | |
1256 static void ApplySetting(StatsState::StateSetting setting, | 1177 static void ApplySetting(StatsState::StateSetting setting, |
1257 HKEY root_key, | 1178 HKEY root_key, |
1258 const base::string16& reg_key); | 1179 const base::string16& reg_key); |
1259 | 1180 |
| 1181 // TODO(grt): Get rid of these statics and SetUpTestCase. |
1260 static base::string16* chrome_version_key_; | 1182 static base::string16* chrome_version_key_; |
1261 static base::string16* chrome_state_key_; | 1183 static base::string16* chrome_state_key_; |
1262 static base::string16* chrome_state_medium_key_; | 1184 static base::string16* chrome_state_medium_key_; |
1263 static base::string16* binaries_state_key_; | |
1264 static base::string16* binaries_state_medium_key_; | |
1265 registry_util::RegistryOverrideManager override_manager_; | 1185 registry_util::RegistryOverrideManager override_manager_; |
1266 }; | 1186 }; |
1267 | 1187 |
1268 base::string16* CollectStatsConsent::chrome_version_key_; | 1188 base::string16* CollectStatsConsent::chrome_version_key_; |
1269 base::string16* CollectStatsConsent::chrome_state_key_; | 1189 base::string16* CollectStatsConsent::chrome_state_key_; |
1270 base::string16* CollectStatsConsent::chrome_state_medium_key_; | 1190 base::string16* CollectStatsConsent::chrome_state_medium_key_; |
1271 base::string16* CollectStatsConsent::binaries_state_key_; | |
1272 base::string16* CollectStatsConsent::binaries_state_medium_key_; | |
1273 | 1191 |
1274 void CollectStatsConsent::SetUpTestCase() { | 1192 void CollectStatsConsent::SetUpTestCase() { |
1275 BrowserDistribution* dist = | 1193 BrowserDistribution* dist = |
1276 BrowserDistribution::GetSpecificDistribution( | 1194 BrowserDistribution::GetSpecificDistribution( |
1277 BrowserDistribution::CHROME_BROWSER); | 1195 BrowserDistribution::CHROME_BROWSER); |
1278 chrome_version_key_ = new base::string16(dist->GetVersionKey()); | 1196 chrome_version_key_ = new base::string16(dist->GetVersionKey()); |
1279 chrome_state_key_ = new base::string16(dist->GetStateKey()); | 1197 chrome_state_key_ = new base::string16(dist->GetStateKey()); |
1280 chrome_state_medium_key_ = new base::string16(dist->GetStateMediumKey()); | 1198 chrome_state_medium_key_ = new base::string16(dist->GetStateMediumKey()); |
1281 | |
1282 dist = BrowserDistribution::GetSpecificDistribution( | |
1283 BrowserDistribution::CHROME_BINARIES); | |
1284 binaries_state_key_ = new base::string16(dist->GetStateKey()); | |
1285 binaries_state_medium_key_ = new base::string16(dist->GetStateMediumKey()); | |
1286 } | 1199 } |
1287 | 1200 |
1288 void CollectStatsConsent::TearDownTestCase() { | 1201 void CollectStatsConsent::TearDownTestCase() { |
1289 delete chrome_version_key_; | 1202 delete chrome_version_key_; |
1290 delete chrome_state_key_; | 1203 delete chrome_state_key_; |
1291 delete chrome_state_medium_key_; | 1204 delete chrome_state_medium_key_; |
1292 delete binaries_state_key_; | |
1293 delete binaries_state_medium_key_; | |
1294 } | 1205 } |
1295 | 1206 |
1296 // Install the registry override and apply the settings to the registry. | 1207 // Install the registry override and apply the settings to the registry. |
1297 void CollectStatsConsent::SetUp() { | 1208 void CollectStatsConsent::SetUp() { |
1298 // Override both HKLM and HKCU as tests may touch either/both. | 1209 // Override both HKLM and HKCU as tests may touch either/both. |
1299 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); | 1210 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE); |
1300 override_manager_.OverrideRegistry(HKEY_CURRENT_USER); | 1211 override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
1301 | 1212 |
1302 const StatsState& stats_state = GetParam(); | 1213 const StatsState& stats_state = GetParam(); |
1303 const HKEY root_key = stats_state.root_key(); | 1214 const HKEY root_key = stats_state.root_key(); |
1304 if (stats_state.multi_install()) { | 1215 ApplySetting(stats_state.state_value(), root_key, *chrome_state_key_); |
1305 MakeChromeMultiInstall(root_key); | 1216 ApplySetting(stats_state.state_medium_value(), root_key, |
1306 ApplySetting(stats_state.state_value(), root_key, *binaries_state_key_); | 1217 *chrome_state_medium_key_); |
1307 ApplySetting(stats_state.state_medium_value(), root_key, | |
1308 *binaries_state_medium_key_); | |
1309 } else { | |
1310 ApplySetting(stats_state.state_value(), root_key, *chrome_state_key_); | |
1311 ApplySetting(stats_state.state_medium_value(), root_key, | |
1312 *chrome_state_medium_key_); | |
1313 } | |
1314 } | |
1315 | |
1316 // Write values into the registry so that Chrome is considered to be installed | |
1317 // as multi-install. | |
1318 void CollectStatsConsent::MakeChromeMultiInstall(HKEY root_key) { | |
1319 ASSERT_EQ( | |
1320 ERROR_SUCCESS, | |
1321 RegKey(root_key, chrome_version_key_->c_str(), | |
1322 KEY_SET_VALUE).WriteValue(google_update::kRegVersionField, | |
1323 L"1.2.3.4")); | |
1324 ASSERT_EQ( | |
1325 ERROR_SUCCESS, | |
1326 RegKey(root_key, chrome_state_key_->c_str(), | |
1327 KEY_SET_VALUE).WriteValue(installer::kUninstallArgumentsField, | |
1328 L"--multi-install")); | |
1329 } | 1218 } |
1330 | 1219 |
1331 // Write the correct value to represent |setting| in the registry. | 1220 // Write the correct value to represent |setting| in the registry. |
1332 void CollectStatsConsent::ApplySetting(StatsState::StateSetting setting, | 1221 void CollectStatsConsent::ApplySetting(StatsState::StateSetting setting, |
1333 HKEY root_key, | 1222 HKEY root_key, |
1334 const base::string16& reg_key) { | 1223 const base::string16& reg_key) { |
1335 if (setting != StatsState::NO_SETTING) { | 1224 if (setting != StatsState::NO_SETTING) { |
1336 DWORD value = setting != StatsState::FALSE_SETTING ? 1 : 0; | 1225 DWORD value = setting != StatsState::FALSE_SETTING ? 1 : 0; |
1337 ASSERT_EQ( | 1226 ASSERT_EQ( |
1338 ERROR_SUCCESS, | 1227 ERROR_SUCCESS, |
(...skipping 24 matching lines...) Expand all Loading... |
1363 client_info.client_id = "01234567-89ab-cdef-fedc-ba9876543210"; | 1252 client_info.client_id = "01234567-89ab-cdef-fedc-ba9876543210"; |
1364 client_info.installation_date = 123; | 1253 client_info.installation_date = 123; |
1365 client_info.reporting_enabled_date = 345; | 1254 client_info.reporting_enabled_date = 345; |
1366 GoogleUpdateSettings::StoreMetricsClientInfo(client_info); | 1255 GoogleUpdateSettings::StoreMetricsClientInfo(client_info); |
1367 } | 1256 } |
1368 | 1257 |
1369 EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsentAtLevel( | 1258 EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsentAtLevel( |
1370 GetParam().system_level(), | 1259 GetParam().system_level(), |
1371 !GetParam().is_consent_granted())); | 1260 !GetParam().is_consent_granted())); |
1372 | 1261 |
1373 const base::string16* const reg_keys[] = { | 1262 const base::string16& reg_key = GetParam().system_level() |
1374 chrome_state_key_, | 1263 ? *chrome_state_medium_key_ |
1375 chrome_state_medium_key_, | 1264 : *chrome_state_key_; |
1376 binaries_state_key_, | |
1377 binaries_state_medium_key_, | |
1378 }; | |
1379 int key_index = ((GetParam().system_level() ? 1 : 0) + | |
1380 (GetParam().multi_install() ? 2 : 0)); | |
1381 const base::string16& reg_key = *reg_keys[key_index]; | |
1382 DWORD value = 0; | 1265 DWORD value = 0; |
1383 EXPECT_EQ( | 1266 EXPECT_EQ( |
1384 ERROR_SUCCESS, | 1267 ERROR_SUCCESS, |
1385 RegKey(GetParam().root_key(), reg_key.c_str(), | 1268 RegKey(GetParam().root_key(), reg_key.c_str(), |
1386 KEY_QUERY_VALUE).ReadValueDW(google_update::kRegUsageStatsField, | 1269 KEY_QUERY_VALUE).ReadValueDW(google_update::kRegUsageStatsField, |
1387 &value)); | 1270 &value)); |
1388 if (GetParam().is_consent_granted()) { | 1271 if (GetParam().is_consent_granted()) { |
1389 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( | 1272 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( |
1390 GetParam().system_level())); | 1273 GetParam().system_level())); |
1391 EXPECT_EQ(0UL, value); | 1274 EXPECT_EQ(0UL, value); |
1392 } else { | 1275 } else { |
1393 EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( | 1276 EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( |
1394 GetParam().system_level())); | 1277 GetParam().system_level())); |
1395 EXPECT_EQ(1UL, value); | 1278 EXPECT_EQ(1UL, value); |
1396 // Verify that backup client info has been cleared. | 1279 // Verify that backup client info has been cleared. |
1397 EXPECT_FALSE(GoogleUpdateSettings::LoadMetricsClientInfo()); | 1280 EXPECT_FALSE(GoogleUpdateSettings::LoadMetricsClientInfo()); |
1398 } | 1281 } |
1399 } | 1282 } |
1400 | 1283 |
1401 INSTANTIATE_TEST_CASE_P( | 1284 INSTANTIATE_TEST_CASE_P( |
1402 UserLevelSingleInstall, | 1285 UserLevel, |
1403 CollectStatsConsent, | 1286 CollectStatsConsent, |
1404 ::testing::Values( | 1287 ::testing::Values( |
1405 StatsState(StatsState::kUserLevel, StatsState::SINGLE_INSTALL, | 1288 StatsState(StatsState::kUserLevel, StatsState::NO_SETTING), |
1406 StatsState::NO_SETTING), | 1289 StatsState(StatsState::kUserLevel, StatsState::FALSE_SETTING), |
1407 StatsState(StatsState::kUserLevel, StatsState::SINGLE_INSTALL, | 1290 StatsState(StatsState::kUserLevel, StatsState::TRUE_SETTING))); |
1408 StatsState::FALSE_SETTING), | |
1409 StatsState(StatsState::kUserLevel, StatsState::SINGLE_INSTALL, | |
1410 StatsState::TRUE_SETTING))); | |
1411 INSTANTIATE_TEST_CASE_P( | 1291 INSTANTIATE_TEST_CASE_P( |
1412 UserLevelMultiInstall, | 1292 SystemLevel, |
1413 CollectStatsConsent, | 1293 CollectStatsConsent, |
1414 ::testing::Values( | 1294 ::testing::Values(StatsState(StatsState::kSystemLevel, |
1415 StatsState(StatsState::kUserLevel, StatsState::MULTI_INSTALL, | 1295 StatsState::NO_SETTING, |
1416 StatsState::NO_SETTING), | 1296 StatsState::NO_SETTING), |
1417 StatsState(StatsState::kUserLevel, StatsState::MULTI_INSTALL, | 1297 StatsState(StatsState::kSystemLevel, |
1418 StatsState::FALSE_SETTING), | 1298 StatsState::NO_SETTING, |
1419 StatsState(StatsState::kUserLevel, StatsState::MULTI_INSTALL, | 1299 StatsState::FALSE_SETTING), |
1420 StatsState::TRUE_SETTING))); | 1300 StatsState(StatsState::kSystemLevel, |
1421 INSTANTIATE_TEST_CASE_P( | 1301 StatsState::NO_SETTING, |
1422 SystemLevelSingleInstall, | 1302 StatsState::TRUE_SETTING), |
1423 CollectStatsConsent, | 1303 StatsState(StatsState::kSystemLevel, |
1424 ::testing::Values( | 1304 StatsState::FALSE_SETTING, |
1425 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1305 StatsState::NO_SETTING), |
1426 StatsState::NO_SETTING, StatsState::NO_SETTING), | 1306 StatsState(StatsState::kSystemLevel, |
1427 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1307 StatsState::FALSE_SETTING, |
1428 StatsState::NO_SETTING, StatsState::FALSE_SETTING), | 1308 StatsState::FALSE_SETTING), |
1429 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1309 StatsState(StatsState::kSystemLevel, |
1430 StatsState::NO_SETTING, StatsState::TRUE_SETTING), | 1310 StatsState::FALSE_SETTING, |
1431 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1311 StatsState::TRUE_SETTING), |
1432 StatsState::FALSE_SETTING, StatsState::NO_SETTING), | 1312 StatsState(StatsState::kSystemLevel, |
1433 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1313 StatsState::TRUE_SETTING, |
1434 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 1314 StatsState::NO_SETTING), |
1435 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1315 StatsState(StatsState::kSystemLevel, |
1436 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 1316 StatsState::TRUE_SETTING, |
1437 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1317 StatsState::FALSE_SETTING), |
1438 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 1318 StatsState(StatsState::kSystemLevel, |
1439 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | 1319 StatsState::TRUE_SETTING, |
1440 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 1320 StatsState::TRUE_SETTING))); |
1441 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, | |
1442 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | |
1443 INSTANTIATE_TEST_CASE_P( | |
1444 SystemLevelMultiInstall, | |
1445 CollectStatsConsent, | |
1446 ::testing::Values( | |
1447 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1448 StatsState::NO_SETTING, StatsState::NO_SETTING), | |
1449 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1450 StatsState::NO_SETTING, StatsState::FALSE_SETTING), | |
1451 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1452 StatsState::NO_SETTING, StatsState::TRUE_SETTING), | |
1453 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1454 StatsState::FALSE_SETTING, StatsState::NO_SETTING), | |
1455 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1456 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | |
1457 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1458 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | |
1459 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1460 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | |
1461 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1462 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | |
1463 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | |
1464 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | |
OLD | NEW |