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 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ASSERT_EQ(ERROR_SUCCESS, | 93 ASSERT_EQ(ERROR_SUCCESS, |
94 update_key.WriteValue(installer::kUninstallArgumentsField, | 94 update_key.WriteValue(installer::kUninstallArgumentsField, |
95 L"--multi-install")); | 95 L"--multi-install")); |
96 } | 96 } |
97 | 97 |
98 // Tests setting the ap= value to various combinations of values with | 98 // Tests setting the ap= value to various combinations of values with |
99 // suffixes, while asserting on the correct channel value. | 99 // suffixes, while asserting on the correct channel value. |
100 // Note that ap= value has to match "^2.0-d.*" or ".*x64-dev.*" and "^1.1-.*" | 100 // Note that ap= value has to match "^2.0-d.*" or ".*x64-dev.*" and "^1.1-.*" |
101 // or ".*x64-beta.*" for dev and beta channels respectively. | 101 // or ".*x64-beta.*" for dev and beta channels respectively. |
102 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { | 102 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { |
103 static struct Expectations { | 103 static struct Expectation { |
104 const wchar_t* ap_value; | 104 const wchar_t* ap_value; |
105 const wchar_t* channel; | 105 const wchar_t* channel; |
106 bool supports_prefixes; | 106 bool supports_prefixes; |
107 } expectations[] = { | 107 } expectations[] = { |
108 { L"2.0-dev", installer::kChromeChannelDev, false}, | 108 { L"2.0-dev", installer::kChromeChannelDev, false}, |
109 { L"1.1-beta", installer::kChromeChannelBeta, false}, | 109 { L"1.1-beta", installer::kChromeChannelBeta, false}, |
110 { L"x64-dev", installer::kChromeChannelDev, true}, | 110 { L"x64-dev", installer::kChromeChannelDev, true}, |
111 { L"x64-beta", installer::kChromeChannelBeta, true}, | 111 { L"x64-beta", installer::kChromeChannelBeta, true}, |
112 { L"x64-stable", installer::kChromeChannelStable, true}, | 112 { L"x64-stable", installer::kChromeChannelStable, true}, |
113 }; | 113 }; |
114 bool is_system = install == SYSTEM_INSTALL; | 114 bool is_system = install == SYSTEM_INSTALL; |
115 const wchar_t* prefixes[] = { | 115 const wchar_t* prefixes[] = { |
116 L"", | 116 L"", |
117 L"prefix", | 117 L"prefix", |
118 L"prefix-with-dash", | 118 L"prefix-with-dash", |
119 }; | 119 }; |
120 const wchar_t* suffixes[] = { | 120 const wchar_t* suffixes[] = { |
121 L"", | 121 L"", |
122 L"suffix", | 122 L"suffix", |
123 L"suffix-with-dash", | 123 L"suffix-with-dash", |
124 }; | 124 }; |
125 | 125 |
126 for (size_t i = 0; i < arraysize(prefixes); ++i) { | 126 for (const wchar_t* prefix : prefixes) { |
127 for (size_t j = 0; j < arraysize(expectations); ++j) { | 127 for (const Expectation& expectation : expectations) { |
128 for (size_t k = 0; k < arraysize(suffixes); ++k) { | 128 for (const wchar_t* suffix : suffixes) { |
129 base::string16 ap = prefixes[i]; | 129 base::string16 ap = prefix; |
130 ap += expectations[j].ap_value; | 130 ap += expectation.ap_value; |
131 ap += suffixes[k]; | 131 ap += suffix; |
132 const wchar_t* channel = expectations[j].channel; | 132 const wchar_t* channel = expectation.channel; |
133 | 133 |
134 SetApField(install, ap.c_str()); | 134 SetApField(install, ap.c_str()); |
135 base::string16 ret_channel; | 135 base::string16 ret_channel; |
136 | 136 |
137 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( | 137 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( |
138 is_system, &ret_channel)); | 138 is_system, &ret_channel)); |
139 | 139 |
140 // If prefixes are not supported for a channel, we expect the channel | 140 // If prefixes are not supported for a channel, we expect the channel |
141 // to be "unknown" if a non-empty prefix is present in ap_value. | 141 // to be "unknown" if a non-empty prefix is present in ap_value. |
142 if (!expectations[j].supports_prefixes && wcslen(prefixes[i]) > 0) { | 142 if (!expectation.supports_prefixes && wcslen(prefix) > 0) { |
143 EXPECT_STREQ(installer::kChromeChannelUnknown, ret_channel.c_str()) | 143 EXPECT_STREQ(installer::kChromeChannelUnknown, ret_channel.c_str()) |
144 << "Expecting channel \"" << installer::kChromeChannelUnknown | 144 << "Expecting channel \"" << installer::kChromeChannelUnknown |
145 << "\" for ap=\"" << ap << "\""; | 145 << "\" for ap=\"" << ap << "\""; |
146 } else { | 146 } else { |
147 EXPECT_STREQ(channel, ret_channel.c_str()) | 147 EXPECT_STREQ(channel, ret_channel.c_str()) |
148 << "Expecting channel \"" << channel | 148 << "Expecting channel \"" << channel |
149 << "\" for ap=\"" << ap << "\""; | 149 << "\" for ap=\"" << ap << "\""; |
150 } | 150 } |
151 } | 151 } |
152 } | 152 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 }; | 437 }; |
438 static_assert(arraysize(multifail_full) == arraysize(plain), | 438 static_assert(arraysize(multifail_full) == arraysize(plain), |
439 "bad multifail_full array size"); | 439 "bad multifail_full array size"); |
440 const wchar_t* const* input_arrays[] = { | 440 const wchar_t* const* input_arrays[] = { |
441 plain, | 441 plain, |
442 full, | 442 full, |
443 multifail, | 443 multifail, |
444 multifail_full | 444 multifail_full |
445 }; | 445 }; |
446 ChannelInfo v; | 446 ChannelInfo v; |
447 for (int type_idx = 0; type_idx < arraysize(archive_types); ++type_idx) { | 447 for (const installer::ArchiveType archive_type : archive_types) { |
448 const installer::ArchiveType archive_type = archive_types[type_idx]; | 448 for (const int result : results) { |
449 for (int result_idx = 0; result_idx < arraysize(results); ++result_idx) { | |
450 const int result = results[result_idx]; | |
451 // The archive type will/must always be known on install success. | 449 // The archive type will/must always be known on install success. |
452 if (archive_type == installer::UNKNOWN_ARCHIVE_TYPE && | 450 if (archive_type == installer::UNKNOWN_ARCHIVE_TYPE && |
453 result == installer::FIRST_INSTALL_SUCCESS) { | 451 result == installer::FIRST_INSTALL_SUCCESS) { |
454 continue; | 452 continue; |
455 } | 453 } |
456 const wchar_t* const* outputs = NULL; | 454 const wchar_t* const* outputs = NULL; |
457 if (result == installer::FIRST_INSTALL_SUCCESS || | 455 if (result == installer::FIRST_INSTALL_SUCCESS || |
458 archive_type == installer::FULL_ARCHIVE_TYPE) { | 456 archive_type == installer::FULL_ARCHIVE_TYPE) { |
459 outputs = plain; | 457 outputs = plain; |
460 } else if (archive_type == installer::INCREMENTAL_ARCHIVE_TYPE) { | 458 } else if (archive_type == installer::INCREMENTAL_ARCHIVE_TYPE) { |
461 outputs = full; | 459 outputs = full; |
462 } // else if (archive_type == UNKNOWN) see below | 460 } // else if (archive_type == UNKNOWN) see below |
463 | 461 |
464 for (int inputs_idx = 0; inputs_idx < arraysize(input_arrays); | 462 for (const wchar_t* const* inputs : input_arrays) { |
465 ++inputs_idx) { | |
466 const wchar_t* const* inputs = input_arrays[inputs_idx]; | |
467 if (archive_type == installer::UNKNOWN_ARCHIVE_TYPE) { | 463 if (archive_type == installer::UNKNOWN_ARCHIVE_TYPE) { |
468 // "-full" is untouched if the archive type is unknown. | 464 // "-full" is untouched if the archive type is unknown. |
469 // "-multifail" is unconditionally removed. | 465 // "-multifail" is unconditionally removed. |
470 if (inputs == full || inputs == multifail_full) | 466 if (inputs == full || inputs == multifail_full) |
471 outputs = full; | 467 outputs = full; |
472 else | 468 else |
473 outputs = plain; | 469 outputs = plain; |
474 } | 470 } |
475 for (int input_idx = 0; input_idx < arraysize(plain); ++input_idx) { | 471 for (size_t input_idx = 0; input_idx < arraysize(plain); ++input_idx) { |
476 const wchar_t* input = inputs[input_idx]; | 472 const wchar_t* input = inputs[input_idx]; |
477 const wchar_t* output = outputs[input_idx]; | 473 const wchar_t* output = outputs[input_idx]; |
478 | 474 |
479 v.set_value(input); | 475 v.set_value(input); |
480 if (output == v.value()) { | 476 if (output == v.value()) { |
481 EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey( | 477 EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey( |
482 archive_type, result, &v)) | 478 archive_type, result, &v)) |
483 << "archive_type: " << archive_type | 479 << "archive_type: " << archive_type |
484 << ", result: " << result | 480 << ", result: " << result |
485 << ", input ap value: " << input; | 481 << ", input ap value: " << input; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 RegKey(HKEY_LOCAL_MACHINE, num_signed_in_path.c_str(), | 709 RegKey(HKEY_LOCAL_MACHINE, num_signed_in_path.c_str(), |
714 KEY_QUERY_VALUE).ReadValueDW(uniquename.c_str(), | 710 KEY_QUERY_VALUE).ReadValueDW(uniquename.c_str(), |
715 &num_signed_in)); | 711 &num_signed_in)); |
716 EXPECT_EQ( | 712 EXPECT_EQ( |
717 ERROR_SUCCESS, | 713 ERROR_SUCCESS, |
718 RegKey(HKEY_LOCAL_MACHINE, num_signed_in_path.c_str(), | 714 RegKey(HKEY_LOCAL_MACHINE, num_signed_in_path.c_str(), |
719 KEY_QUERY_VALUE).ReadValue(google_update::kRegAggregateMethod, | 715 KEY_QUERY_VALUE).ReadValue(google_update::kRegAggregateMethod, |
720 &aggregate)); | 716 &aggregate)); |
721 | 717 |
722 // Verify the correct values were written. | 718 // Verify the correct values were written. |
723 EXPECT_EQ(3, num_profiles); | 719 EXPECT_EQ(3u, num_profiles); |
724 EXPECT_EQ(2, num_signed_in); | 720 EXPECT_EQ(2u, num_signed_in); |
725 EXPECT_EQ(L"sum()", aggregate); | 721 EXPECT_EQ(L"sum()", aggregate); |
726 } | 722 } |
727 | 723 |
728 TEST_F(GoogleUpdateSettingsTest, UpdateProfileCountsUserInstall) { | 724 TEST_F(GoogleUpdateSettingsTest, UpdateProfileCountsUserInstall) { |
729 // Unit tests never operate as an installed application, so will never | 725 // Unit tests never operate as an installed application, so will never |
730 // be a system install. | 726 // be a system install. |
731 | 727 |
732 // No profile count values present yet. | 728 // No profile count values present yet. |
733 const base::string16& state_key = BrowserDistribution::GetDistribution()-> | 729 const base::string16& state_key = BrowserDistribution::GetDistribution()-> |
734 GetAppRegistrationData().GetStateKey(); | 730 GetAppRegistrationData().GetStateKey(); |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1364 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1369 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 1365 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), |
1370 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1366 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1371 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 1367 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), |
1372 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1368 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1373 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 1369 StatsState::TRUE_SETTING, StatsState::NO_SETTING), |
1374 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1370 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1375 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 1371 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), |
1376 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1372 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1377 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | 1373 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); |
OLD | NEW |