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

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

Issue 2619323003: Remove uses of BrowserDistribution::CHROME_BINARIES in installer_util. (Closed)
Patch Set: Created 3 years, 11 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/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
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
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 base::string16 ret_channel;
huangs 2017/01/09 21:27:08 Combine with line below?
grt (UTC plus 2) 2017/01/10 08:43:56 Done.
139 109
140 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( 110 ret_channel = GoogleUpdateSettings::GetChromeChannel(is_system);
141 is_system, &ret_channel));
142 111
143 // If prefixes are not supported for a channel, we expect the channel 112 // 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. 113 // to be "unknown" if a non-empty prefix is present in ap_value.
145 if (!expectation.supports_prefixes && wcslen(prefix) > 0) { 114 if (!expectation.supports_prefixes && wcslen(prefix) > 0) {
146 EXPECT_STREQ(installer::kChromeChannelUnknown, ret_channel.c_str()) 115 EXPECT_STREQ(installer::kChromeChannelUnknown, ret_channel.c_str())
147 << "Expecting channel \"" << installer::kChromeChannelUnknown 116 << "Expecting channel \"" << installer::kChromeChannelUnknown
148 << "\" for ap=\"" << ap << "\""; 117 << "\" for ap=\"" << ap << "\"";
149 } else { 118 } else {
150 EXPECT_STREQ(channel, ret_channel.c_str()) 119 EXPECT_STREQ(channel, ret_channel.c_str())
151 << "Expecting channel \"" << channel 120 << "Expecting channel \"" << channel
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 registry_util::RegistryOverrideManager registry_overrides_; 294 registry_util::RegistryOverrideManager registry_overrides_;
326 }; 295 };
327 296
328 } // namespace 297 } // namespace
329 298
330 // Verify that we return success on no registration (which means stable), 299 // Verify that we return success on no registration (which means stable),
331 // whether per-system or per-user install. 300 // whether per-system or per-user install.
332 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { 301 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) {
333 // Per-system first. 302 // Per-system first.
334 base::string16 channel; 303 base::string16 channel;
335 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, 304 channel = GoogleUpdateSettings::GetChromeChannel(true);
336 &channel));
337 EXPECT_STREQ(L"", channel.c_str()); 305 EXPECT_STREQ(L"", channel.c_str());
338 306
339 // Then per-user. 307 // Then per-user.
340 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, 308 channel = GoogleUpdateSettings::GetChromeChannel(false);
341 &channel));
342 EXPECT_STREQ(L"", channel.c_str()); 309 EXPECT_STREQ(L"", channel.c_str());
343 } 310 }
344 311
345 // Test an empty Ap key for system and user. 312 // Test an empty Ap key for system and user.
346 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptySystem) { 313 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptySystem) {
347 SetApField(SYSTEM_INSTALL, L""); 314 SetApField(SYSTEM_INSTALL, L"");
348 base::string16 channel; 315 base::string16 channel;
349 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, 316 channel = GoogleUpdateSettings::GetChromeChannel(true);
350 &channel));
351 EXPECT_STREQ(L"", channel.c_str()); 317 EXPECT_STREQ(L"", channel.c_str());
352 318
353 // Per-user lookups still succeed and return empty string. 319 // Per-user lookups still succeed and return empty string.
354 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, 320 channel = GoogleUpdateSettings::GetChromeChannel(false);
355 &channel));
356 EXPECT_STREQ(L"", channel.c_str()); 321 EXPECT_STREQ(L"", channel.c_str());
357 } 322 }
358 323
359 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptyUser) { 324 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptyUser) {
360 SetApField(USER_INSTALL, L""); 325 SetApField(USER_INSTALL, L"");
361 // Per-system lookups still succeed and return empty string. 326 // Per-system lookups still succeed and return empty string.
362 base::string16 channel; 327 base::string16 channel;
363 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, 328 channel = GoogleUpdateSettings::GetChromeChannel(true);
364 &channel));
365 EXPECT_STREQ(L"", channel.c_str()); 329 EXPECT_STREQ(L"", channel.c_str());
366 330
367 // Per-user lookup should succeed. 331 // Per-user lookup should succeed.
368 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, 332 channel = GoogleUpdateSettings::GetChromeChannel(false);
369 &channel));
370 EXPECT_STREQ(L"", channel.c_str()); 333 EXPECT_STREQ(L"", channel.c_str());
371 } 334 }
372 335
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) { 336 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) {
397 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); 337 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL);
398 } 338 }
399 339
400 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { 340 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) {
401 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); 341 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL);
402 } 342 }
403 343
404 // Run through all combinations of diff vs. full install, single vs. multi 344 // 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 345 // results, and a fistful of initial "ap" values checking that the expected
406 // checking that the expected final "ap" value is generated by 346 // final "ap" value is generated by
407 // GoogleUpdateSettings::UpdateGoogleUpdateApKey. 347 // GoogleUpdateSettings::UpdateGoogleUpdateApKey.
408 TEST_F(GoogleUpdateSettingsTest, UpdateGoogleUpdateApKey) { 348 TEST_F(GoogleUpdateSettingsTest, UpdateGoogleUpdateApKey) {
409 const installer::ArchiveType archive_types[] = { 349 const installer::ArchiveType archive_types[] = {
410 installer::UNKNOWN_ARCHIVE_TYPE, 350 installer::UNKNOWN_ARCHIVE_TYPE,
411 installer::FULL_ARCHIVE_TYPE, 351 installer::FULL_ARCHIVE_TYPE,
412 installer::INCREMENTAL_ARCHIVE_TYPE 352 installer::INCREMENTAL_ARCHIVE_TYPE
413 }; 353 };
414 const int results[] = { 354 const int results[] = {
415 installer::FIRST_INSTALL_SUCCESS, 355 installer::FIRST_INSTALL_SUCCESS,
416 installer::INSTALL_FAILED 356 installer::INSTALL_FAILED
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // updates. 841 // updates.
902 EXPECT_TRUE(is_overridden); 842 EXPECT_TRUE(is_overridden);
903 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy); 843 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy);
904 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); 844 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
905 } 845 }
906 846
907 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesEnabledWithGlobalDisabled) { 847 TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesEnabledWithGlobalDisabled) {
908 // Disable updates globally but enable them for Chrome (the app-specific 848 // Disable updates globally but enable them for Chrome (the app-specific
909 // setting should take precedence). 849 // setting should take precedence).
910 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 850 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
911 BrowserDistribution* binaries = BrowserDistribution::GetSpecificDistribution(
912 BrowserDistribution::CHROME_BINARIES);
913 EXPECT_TRUE( 851 EXPECT_TRUE(
914 SetUpdatePolicyForAppGuid(dist->GetAppGuid(), 852 SetUpdatePolicyForAppGuid(dist->GetAppGuid(),
915 GoogleUpdateSettings::AUTOMATIC_UPDATES)); 853 GoogleUpdateSettings::AUTOMATIC_UPDATES));
916 EXPECT_TRUE(
917 SetUpdatePolicyForAppGuid(binaries->GetAppGuid(),
918 GoogleUpdateSettings::AUTOMATIC_UPDATES));
919 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); 854 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED));
920 855
921 // Make sure we read this as still having updates enabled. 856 // Make sure we read this as still having updates enabled.
922 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled()); 857 EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
923 858
924 // Make sure that the reset action returns true and is a no-op. 859 // Make sure that the reset action returns true and is a no-op.
925 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates()); 860 EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
926 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, 861 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES,
927 GetUpdatePolicyForAppGuid(dist->GetAppGuid())); 862 GetUpdatePolicyForAppGuid(dist->GetAppGuid()));
928 EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES,
929 GetUpdatePolicyForAppGuid(binaries->GetAppGuid()));
930 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, GetGlobalUpdatePolicy()); 863 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, GetGlobalUpdatePolicy());
931 } 864 }
932 865
933 TEST_F(GoogleUpdateSettingsTest, GlobalUpdatesDisabledByPolicy) { 866 TEST_F(GoogleUpdateSettingsTest, GlobalUpdatesDisabledByPolicy) {
934 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 867 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
935 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED)); 868 EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED));
936 bool is_overridden = false; 869 bool is_overridden = false;
937 870
938 // The contract for GetAppUpdatePolicy states that |is_overridden| should be 871 // The contract for GetAppUpdatePolicy states that |is_overridden| should be
939 // set to false when updates are disabled on a non-app-specific basis. 872 // 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
1182 GoogleUpdateSettings::GetGoogleUpdateVersion(!system_install_) 1115 GoogleUpdateSettings::GetGoogleUpdateVersion(!system_install_)
1183 .IsValid()); 1116 .IsValid());
1184 } 1117 }
1185 1118
1186 INSTANTIATE_TEST_CASE_P(GetGoogleUpdateVersionAtLevel, GetGoogleUpdateVersion, 1119 INSTANTIATE_TEST_CASE_P(GetGoogleUpdateVersionAtLevel, GetGoogleUpdateVersion,
1187 testing::Bool()); 1120 testing::Bool());
1188 1121
1189 // Test values for use by the CollectStatsConsent test fixture. 1122 // Test values for use by the CollectStatsConsent test fixture.
1190 class StatsState { 1123 class StatsState {
1191 public: 1124 public:
1192 enum InstallType {
1193 SINGLE_INSTALL,
1194 MULTI_INSTALL,
1195 };
1196 enum StateSetting { 1125 enum StateSetting {
1197 NO_SETTING, 1126 NO_SETTING,
1198 FALSE_SETTING, 1127 FALSE_SETTING,
1199 TRUE_SETTING, 1128 TRUE_SETTING,
1200 }; 1129 };
1201 struct UserLevelState {}; 1130 struct UserLevelState {};
1202 struct SystemLevelState {}; 1131 struct SystemLevelState {};
1203 static const UserLevelState kUserLevel; 1132 static const UserLevelState kUserLevel;
1204 static const SystemLevelState kSystemLevel; 1133 static const SystemLevelState kSystemLevel;
1205 1134
1206 StatsState(const UserLevelState&, 1135 StatsState(const UserLevelState&,
1207 InstallType install_type,
1208 StateSetting state_value) 1136 StateSetting state_value)
1209 : system_level_(false), 1137 : system_level_(false),
1210 multi_install_(install_type == MULTI_INSTALL),
1211 state_value_(state_value), 1138 state_value_(state_value),
1212 state_medium_value_(NO_SETTING) { 1139 state_medium_value_(NO_SETTING) {
1213 } 1140 }
1214 StatsState(const SystemLevelState&, 1141 StatsState(const SystemLevelState&,
1215 InstallType install_type,
1216 StateSetting state_value, 1142 StateSetting state_value,
1217 StateSetting state_medium_value) 1143 StateSetting state_medium_value)
1218 : system_level_(true), 1144 : system_level_(true),
1219 multi_install_(install_type == MULTI_INSTALL),
1220 state_value_(state_value), 1145 state_value_(state_value),
1221 state_medium_value_(state_medium_value) { 1146 state_medium_value_(state_medium_value) {
1222 } 1147 }
1223 bool system_level() const { return system_level_; } 1148 bool system_level() const { return system_level_; }
1224 bool multi_install() const { return multi_install_; }
1225 HKEY root_key() const { 1149 HKEY root_key() const {
1226 return system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 1150 return system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
1227 } 1151 }
1228 StateSetting state_value() const { return state_value_; } 1152 StateSetting state_value() const { return state_value_; }
1229 StateSetting state_medium_value() const { 1153 StateSetting state_medium_value() const {
1230 return state_medium_value_; 1154 return state_medium_value_;
1231 } 1155 }
1232 bool is_consent_granted() const { 1156 bool is_consent_granted() const {
1233 return (system_level_ && state_medium_value_ != NO_SETTING) ? 1157 return (system_level_ && state_medium_value_ != NO_SETTING) ?
1234 (state_medium_value_ == TRUE_SETTING) : 1158 (state_medium_value_ == TRUE_SETTING) :
1235 (state_value_ == TRUE_SETTING); 1159 (state_value_ == TRUE_SETTING);
1236 } 1160 }
1237 1161
1238 private: 1162 private:
1239 bool system_level_; 1163 bool system_level_;
1240 bool multi_install_;
1241 StateSetting state_value_; 1164 StateSetting state_value_;
1242 StateSetting state_medium_value_; 1165 StateSetting state_medium_value_;
1243 }; 1166 };
1244 1167
1245 const StatsState::UserLevelState StatsState::kUserLevel = {}; 1168 const StatsState::UserLevelState StatsState::kUserLevel = {};
1246 const StatsState::SystemLevelState StatsState::kSystemLevel = {}; 1169 const StatsState::SystemLevelState StatsState::kSystemLevel = {};
1247 1170
1248 // A value parameterized test for testing the stats collection consent setting. 1171 // A value parameterized test for testing the stats collection consent setting.
1249 class CollectStatsConsent : public ::testing::TestWithParam<StatsState> { 1172 class CollectStatsConsent : public ::testing::TestWithParam<StatsState> {
1250 public: 1173 public:
1251 static void SetUpTestCase(); 1174 static void SetUpTestCase();
1252 static void TearDownTestCase(); 1175 static void TearDownTestCase();
1253 protected: 1176 protected:
1254 void SetUp() override; 1177 void SetUp() override;
1255 static void MakeChromeMultiInstall(HKEY root_key);
1256 static void ApplySetting(StatsState::StateSetting setting, 1178 static void ApplySetting(StatsState::StateSetting setting,
1257 HKEY root_key, 1179 HKEY root_key,
1258 const base::string16& reg_key); 1180 const base::string16& reg_key);
1259 1181
1260 static base::string16* chrome_version_key_; 1182 static base::string16* chrome_version_key_;
huangs 2017/01/09 21:27:08 Kinda weird that these are pointers, and we call d
grt (UTC plus 2) 2017/01/10 08:43:56 Indeed. Already fixed in https://codereview.chromi
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
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* const reg_keys[] = {
huangs 2017/01/09 21:27:08 Can simplify these 6 lines to const base::string1
grt (UTC plus 2) 2017/01/10 08:43:56 Done.
1374 chrome_state_key_, 1263 chrome_state_key_,
1375 chrome_state_medium_key_, 1264 chrome_state_medium_key_,
1376 binaries_state_key_,
1377 binaries_state_medium_key_,
1378 }; 1265 };
1379 int key_index = ((GetParam().system_level() ? 1 : 0) + 1266 int key_index = (GetParam().system_level() ? 1 : 0);
1380 (GetParam().multi_install() ? 2 : 0));
1381 const base::string16& reg_key = *reg_keys[key_index]; 1267 const base::string16& reg_key = *reg_keys[key_index];
1382 DWORD value = 0; 1268 DWORD value = 0;
1383 EXPECT_EQ( 1269 EXPECT_EQ(
1384 ERROR_SUCCESS, 1270 ERROR_SUCCESS,
1385 RegKey(GetParam().root_key(), reg_key.c_str(), 1271 RegKey(GetParam().root_key(), reg_key.c_str(),
1386 KEY_QUERY_VALUE).ReadValueDW(google_update::kRegUsageStatsField, 1272 KEY_QUERY_VALUE).ReadValueDW(google_update::kRegUsageStatsField,
1387 &value)); 1273 &value));
1388 if (GetParam().is_consent_granted()) { 1274 if (GetParam().is_consent_granted()) {
1389 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( 1275 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel(
1390 GetParam().system_level())); 1276 GetParam().system_level()));
1391 EXPECT_EQ(0UL, value); 1277 EXPECT_EQ(0UL, value);
1392 } else { 1278 } else {
1393 EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( 1279 EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel(
1394 GetParam().system_level())); 1280 GetParam().system_level()));
1395 EXPECT_EQ(1UL, value); 1281 EXPECT_EQ(1UL, value);
1396 // Verify that backup client info has been cleared. 1282 // Verify that backup client info has been cleared.
1397 EXPECT_FALSE(GoogleUpdateSettings::LoadMetricsClientInfo()); 1283 EXPECT_FALSE(GoogleUpdateSettings::LoadMetricsClientInfo());
1398 } 1284 }
1399 } 1285 }
1400 1286
1401 INSTANTIATE_TEST_CASE_P( 1287 INSTANTIATE_TEST_CASE_P(
1402 UserLevelSingleInstall, 1288 UserLevel,
1403 CollectStatsConsent, 1289 CollectStatsConsent,
1404 ::testing::Values( 1290 ::testing::Values(
1405 StatsState(StatsState::kUserLevel, StatsState::SINGLE_INSTALL, 1291 StatsState(StatsState::kUserLevel, StatsState::NO_SETTING),
1406 StatsState::NO_SETTING), 1292 StatsState(StatsState::kUserLevel, StatsState::FALSE_SETTING),
1407 StatsState(StatsState::kUserLevel, StatsState::SINGLE_INSTALL, 1293 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( 1294 INSTANTIATE_TEST_CASE_P(
1412 UserLevelMultiInstall, 1295 SystemLevel,
1413 CollectStatsConsent, 1296 CollectStatsConsent,
1414 ::testing::Values( 1297 ::testing::Values(StatsState(StatsState::kSystemLevel,
1415 StatsState(StatsState::kUserLevel, StatsState::MULTI_INSTALL, 1298 StatsState::NO_SETTING,
1416 StatsState::NO_SETTING), 1299 StatsState::NO_SETTING),
1417 StatsState(StatsState::kUserLevel, StatsState::MULTI_INSTALL, 1300 StatsState(StatsState::kSystemLevel,
1418 StatsState::FALSE_SETTING), 1301 StatsState::NO_SETTING,
1419 StatsState(StatsState::kUserLevel, StatsState::MULTI_INSTALL, 1302 StatsState::FALSE_SETTING),
1420 StatsState::TRUE_SETTING))); 1303 StatsState(StatsState::kSystemLevel,
1421 INSTANTIATE_TEST_CASE_P( 1304 StatsState::NO_SETTING,
1422 SystemLevelSingleInstall, 1305 StatsState::TRUE_SETTING),
1423 CollectStatsConsent, 1306 StatsState(StatsState::kSystemLevel,
1424 ::testing::Values( 1307 StatsState::FALSE_SETTING,
1425 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1308 StatsState::NO_SETTING),
1426 StatsState::NO_SETTING, StatsState::NO_SETTING), 1309 StatsState(StatsState::kSystemLevel,
1427 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1310 StatsState::FALSE_SETTING,
1428 StatsState::NO_SETTING, StatsState::FALSE_SETTING), 1311 StatsState::FALSE_SETTING),
1429 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1312 StatsState(StatsState::kSystemLevel,
1430 StatsState::NO_SETTING, StatsState::TRUE_SETTING), 1313 StatsState::FALSE_SETTING,
1431 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1314 StatsState::TRUE_SETTING),
1432 StatsState::FALSE_SETTING, StatsState::NO_SETTING), 1315 StatsState(StatsState::kSystemLevel,
1433 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1316 StatsState::TRUE_SETTING,
1434 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), 1317 StatsState::NO_SETTING),
1435 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1318 StatsState(StatsState::kSystemLevel,
1436 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), 1319 StatsState::TRUE_SETTING,
1437 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1320 StatsState::FALSE_SETTING),
1438 StatsState::TRUE_SETTING, StatsState::NO_SETTING), 1321 StatsState(StatsState::kSystemLevel,
1439 StatsState(StatsState::kSystemLevel, StatsState::SINGLE_INSTALL, 1322 StatsState::TRUE_SETTING,
1440 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), 1323 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)));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698