| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shlwapi.h> // For SHDeleteKey. | 6 #include <shlwapi.h> // For SHDeleteKey. |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_reg_util_win.h" | 10 #include "base/test/test_reg_util_win.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 for (size_t i = 0; i < arraysize(prefixes); ++i) { | 96 for (size_t i = 0; i < arraysize(prefixes); ++i) { |
| 97 for (size_t j = 0; j < arraysize(expectations); ++j) { | 97 for (size_t j = 0; j < arraysize(expectations); ++j) { |
| 98 for (size_t k = 0; k < arraysize(suffixes); ++k) { | 98 for (size_t k = 0; k < arraysize(suffixes); ++k) { |
| 99 std::wstring ap = prefixes[i]; | 99 std::wstring ap = prefixes[i]; |
| 100 ap += expectations[j].ap_value; | 100 ap += expectations[j].ap_value; |
| 101 ap += suffixes[k]; | 101 ap += suffixes[k]; |
| 102 const wchar_t* channel = expectations[j].channel; | 102 const wchar_t* channel = expectations[j].channel; |
| 103 | 103 |
| 104 SetApField(install, ap.c_str()); | 104 SetApField(install, ap.c_str()); |
| 105 string16 ret_channel; | 105 base::string16 ret_channel; |
| 106 | 106 |
| 107 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( | 107 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( |
| 108 is_system, &ret_channel)); | 108 is_system, &ret_channel)); |
| 109 EXPECT_STREQ(channel, ret_channel.c_str()) | 109 EXPECT_STREQ(channel, ret_channel.c_str()) |
| 110 << "Expecting channel \"" << channel | 110 << "Expecting channel \"" << channel |
| 111 << "\" for ap=\"" << ap << "\""; | 111 << "\" for ap=\"" << ap << "\""; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Test the writing and deleting functionality of the experiments label | 117 // Test the writing and deleting functionality of the experiments label |
| 118 // helper. | 118 // helper. |
| 119 void TestExperimentsLabelHelper(SystemUserInstall install) { | 119 void TestExperimentsLabelHelper(SystemUserInstall install) { |
| 120 BrowserDistribution* chrome = | 120 BrowserDistribution* chrome = |
| 121 BrowserDistribution::GetSpecificDistribution( | 121 BrowserDistribution::GetSpecificDistribution( |
| 122 BrowserDistribution::CHROME_BROWSER); | 122 BrowserDistribution::CHROME_BROWSER); |
| 123 std::wstring value; | 123 std::wstring value; |
| 124 #if defined(GOOGLE_CHROME_BUILD) | 124 #if defined(GOOGLE_CHROME_BUILD) |
| 125 EXPECT_TRUE(chrome->ShouldSetExperimentLabels()); | 125 EXPECT_TRUE(chrome->ShouldSetExperimentLabels()); |
| 126 | 126 |
| 127 // Before anything is set, ReadExperimentLabels should succeed but return | 127 // Before anything is set, ReadExperimentLabels should succeed but return |
| 128 // an empty string. | 128 // an empty string. |
| 129 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( | 129 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( |
| 130 install == SYSTEM_INSTALL, &value)); | 130 install == SYSTEM_INSTALL, &value)); |
| 131 EXPECT_EQ(string16(), value); | 131 EXPECT_EQ(base::string16(), value); |
| 132 | 132 |
| 133 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( | 133 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( |
| 134 install == SYSTEM_INSTALL, kTestExperimentLabel)); | 134 install == SYSTEM_INSTALL, kTestExperimentLabel)); |
| 135 | 135 |
| 136 // Validate that something is written. Only worry about the label itself. | 136 // Validate that something is written. Only worry about the label itself. |
| 137 RegKey key; | 137 RegKey key; |
| 138 HKEY root = install == SYSTEM_INSTALL ? | 138 HKEY root = install == SYSTEM_INSTALL ? |
| 139 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 139 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 140 string16 state_key = install == SYSTEM_INSTALL ? | 140 base::string16 state_key = install == SYSTEM_INSTALL ? |
| 141 chrome->GetStateMediumKey() : chrome->GetStateKey(); | 141 chrome->GetStateMediumKey() : chrome->GetStateKey(); |
| 142 | 142 |
| 143 EXPECT_EQ(ERROR_SUCCESS, | 143 EXPECT_EQ(ERROR_SUCCESS, |
| 144 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); | 144 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); |
| 145 EXPECT_EQ(ERROR_SUCCESS, | 145 EXPECT_EQ(ERROR_SUCCESS, |
| 146 key.ReadValue(google_update::kExperimentLabels, &value)); | 146 key.ReadValue(google_update::kExperimentLabels, &value)); |
| 147 EXPECT_EQ(kTestExperimentLabel, value); | 147 EXPECT_EQ(kTestExperimentLabel, value); |
| 148 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( | 148 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( |
| 149 install == SYSTEM_INSTALL, &value)); | 149 install == SYSTEM_INSTALL, &value)); |
| 150 EXPECT_EQ(kTestExperimentLabel, value); | 150 EXPECT_EQ(kTestExperimentLabel, value); |
| 151 key.Close(); | 151 key.Close(); |
| 152 | 152 |
| 153 // Now that the label is set, test the delete functionality. An empty label | 153 // Now that the label is set, test the delete functionality. An empty label |
| 154 // should result in deleting the value. | 154 // should result in deleting the value. |
| 155 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( | 155 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( |
| 156 install == SYSTEM_INSTALL, string16())); | 156 install == SYSTEM_INSTALL, base::string16())); |
| 157 EXPECT_EQ(ERROR_SUCCESS, | 157 EXPECT_EQ(ERROR_SUCCESS, |
| 158 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); | 158 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); |
| 159 EXPECT_EQ(ERROR_FILE_NOT_FOUND, | 159 EXPECT_EQ(ERROR_FILE_NOT_FOUND, |
| 160 key.ReadValue(google_update::kExperimentLabels, &value)); | 160 key.ReadValue(google_update::kExperimentLabels, &value)); |
| 161 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( | 161 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( |
| 162 install == SYSTEM_INSTALL, &value)); | 162 install == SYSTEM_INSTALL, &value)); |
| 163 EXPECT_EQ(string16(), value); | 163 EXPECT_EQ(base::string16(), value); |
| 164 key.Close(); | 164 key.Close(); |
| 165 #else | 165 #else |
| 166 EXPECT_FALSE(chrome->ShouldSetExperimentLabels()); | 166 EXPECT_FALSE(chrome->ShouldSetExperimentLabels()); |
| 167 EXPECT_FALSE(GoogleUpdateSettings::ReadExperimentLabels( | 167 EXPECT_FALSE(GoogleUpdateSettings::ReadExperimentLabels( |
| 168 install == SYSTEM_INSTALL, &value)); | 168 install == SYSTEM_INSTALL, &value)); |
| 169 #endif // GOOGLE_CHROME_BUILD | 169 #endif // GOOGLE_CHROME_BUILD |
| 170 } | 170 } |
| 171 | 171 |
| 172 // Creates "ap" key with the value given as parameter. Also adds work | 172 // Creates "ap" key with the value given as parameter. Also adds work |
| 173 // items to work_item_list given so that they can be rolled back later. | 173 // items to work_item_list given so that they can be rolled back later. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 208 |
| 209 registry_util::RegistryOverrideManager registry_overrides_; | 209 registry_util::RegistryOverrideManager registry_overrides_; |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 } // namespace | 212 } // namespace |
| 213 | 213 |
| 214 // Verify that we return success on no registration (which means stable), | 214 // Verify that we return success on no registration (which means stable), |
| 215 // whether per-system or per-user install. | 215 // whether per-system or per-user install. |
| 216 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { | 216 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { |
| 217 // Per-system first. | 217 // Per-system first. |
| 218 string16 channel; | 218 base::string16 channel; |
| 219 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 219 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, |
| 220 &channel)); | 220 &channel)); |
| 221 EXPECT_STREQ(L"", channel.c_str()); | 221 EXPECT_STREQ(L"", channel.c_str()); |
| 222 | 222 |
| 223 // Then per-user. | 223 // Then per-user. |
| 224 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | 224 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, |
| 225 &channel)); | 225 &channel)); |
| 226 EXPECT_STREQ(L"", channel.c_str()); | 226 EXPECT_STREQ(L"", channel.c_str()); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Test an empty Ap key for system and user. | 229 // Test an empty Ap key for system and user. |
| 230 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptySystem) { | 230 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptySystem) { |
| 231 SetApField(SYSTEM_INSTALL, L""); | 231 SetApField(SYSTEM_INSTALL, L""); |
| 232 string16 channel; | 232 base::string16 channel; |
| 233 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 233 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, |
| 234 &channel)); | 234 &channel)); |
| 235 EXPECT_STREQ(L"", channel.c_str()); | 235 EXPECT_STREQ(L"", channel.c_str()); |
| 236 | 236 |
| 237 // Per-user lookups still succeed and return empty string. | 237 // Per-user lookups still succeed and return empty string. |
| 238 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | 238 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, |
| 239 &channel)); | 239 &channel)); |
| 240 EXPECT_STREQ(L"", channel.c_str()); | 240 EXPECT_STREQ(L"", channel.c_str()); |
| 241 } | 241 } |
| 242 | 242 |
| 243 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptyUser) { | 243 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptyUser) { |
| 244 SetApField(USER_INSTALL, L""); | 244 SetApField(USER_INSTALL, L""); |
| 245 // Per-system lookups still succeed and return empty string. | 245 // Per-system lookups still succeed and return empty string. |
| 246 string16 channel; | 246 base::string16 channel; |
| 247 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 247 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, |
| 248 &channel)); | 248 &channel)); |
| 249 EXPECT_STREQ(L"", channel.c_str()); | 249 EXPECT_STREQ(L"", channel.c_str()); |
| 250 | 250 |
| 251 // Per-user lookup should succeed. | 251 // Per-user lookup should succeed. |
| 252 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | 252 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, |
| 253 &channel)); | 253 &channel)); |
| 254 EXPECT_STREQ(L"", channel.c_str()); | 254 EXPECT_STREQ(L"", channel.c_str()); |
| 255 } | 255 } |
| 256 | 256 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 HKEY root_key_; | 658 HKEY root_key_; |
| 659 bool system_install_; | 659 bool system_install_; |
| 660 }; | 660 }; |
| 661 | 661 |
| 662 const wchar_t GetUninstallCommandLine::kDummyCommand[] = | 662 const wchar_t GetUninstallCommandLine::kDummyCommand[] = |
| 663 L"\"goopdate.exe\" /spam"; | 663 L"\"goopdate.exe\" /spam"; |
| 664 | 664 |
| 665 // Tests that GetUninstallCommandLine returns an empty string if there's no | 665 // Tests that GetUninstallCommandLine returns an empty string if there's no |
| 666 // Software\Google\Update key. | 666 // Software\Google\Update key. |
| 667 TEST_P(GetUninstallCommandLine, TestNoKey) { | 667 TEST_P(GetUninstallCommandLine, TestNoKey) { |
| 668 EXPECT_EQ(string16(), | 668 EXPECT_EQ(base::string16(), |
| 669 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); | 669 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 670 } | 670 } |
| 671 | 671 |
| 672 // Tests that GetUninstallCommandLine returns an empty string if there's no | 672 // Tests that GetUninstallCommandLine returns an empty string if there's no |
| 673 // UninstallCmdLine value in the Software\Google\Update key. | 673 // UninstallCmdLine value in the Software\Google\Update key. |
| 674 TEST_P(GetUninstallCommandLine, TestNoValue) { | 674 TEST_P(GetUninstallCommandLine, TestNoValue) { |
| 675 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE); | 675 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE); |
| 676 EXPECT_EQ(string16(), | 676 EXPECT_EQ(base::string16(), |
| 677 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); | 677 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 678 } | 678 } |
| 679 | 679 |
| 680 // Tests that GetUninstallCommandLine returns an empty string if there's an | 680 // Tests that GetUninstallCommandLine returns an empty string if there's an |
| 681 // empty UninstallCmdLine value in the Software\Google\Update key. | 681 // empty UninstallCmdLine value in the Software\Google\Update key. |
| 682 TEST_P(GetUninstallCommandLine, TestEmptyValue) { | 682 TEST_P(GetUninstallCommandLine, TestEmptyValue) { |
| 683 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE) | 683 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE) |
| 684 .WriteValue(google_update::kRegUninstallCmdLine, L""); | 684 .WriteValue(google_update::kRegUninstallCmdLine, L""); |
| 685 EXPECT_EQ(string16(), | 685 EXPECT_EQ(base::string16(), |
| 686 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); | 686 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 687 } | 687 } |
| 688 | 688 |
| 689 // Tests that GetUninstallCommandLine returns the correct string if there's an | 689 // Tests that GetUninstallCommandLine returns the correct string if there's an |
| 690 // UninstallCmdLine value in the Software\Google\Update key. | 690 // UninstallCmdLine value in the Software\Google\Update key. |
| 691 TEST_P(GetUninstallCommandLine, TestRealValue) { | 691 TEST_P(GetUninstallCommandLine, TestRealValue) { |
| 692 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE) | 692 RegKey(root_key_, google_update::kRegPathGoogleUpdate, KEY_SET_VALUE) |
| 693 .WriteValue(google_update::kRegUninstallCmdLine, kDummyCommand); | 693 .WriteValue(google_update::kRegUninstallCmdLine, kDummyCommand); |
| 694 EXPECT_EQ(string16(kDummyCommand), | 694 EXPECT_EQ(base::string16(kDummyCommand), |
| 695 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); | 695 GoogleUpdateSettings::GetUninstallCommandLine(system_install_)); |
| 696 // Make sure that there's no value in the other level (user or system). | 696 // Make sure that there's no value in the other level (user or system). |
| 697 EXPECT_EQ(string16(), | 697 EXPECT_EQ(base::string16(), |
| 698 GoogleUpdateSettings::GetUninstallCommandLine(!system_install_)); | 698 GoogleUpdateSettings::GetUninstallCommandLine(!system_install_)); |
| 699 } | 699 } |
| 700 | 700 |
| 701 INSTANTIATE_TEST_CASE_P(GetUninstallCommandLineAtLevel, GetUninstallCommandLine, | 701 INSTANTIATE_TEST_CASE_P(GetUninstallCommandLineAtLevel, GetUninstallCommandLine, |
| 702 testing::Bool()); | 702 testing::Bool()); |
| 703 | 703 |
| 704 // Test GoogleUpdateSettings::GetGoogleUpdateVersion at system- or user-level, | 704 // Test GoogleUpdateSettings::GetGoogleUpdateVersion at system- or user-level, |
| 705 // according to the param. | 705 // according to the param. |
| 706 class GetGoogleUpdateVersion : public GoogleUpdateSettingsTest, | 706 class GetGoogleUpdateVersion : public GoogleUpdateSettingsTest, |
| 707 public testing::WithParamInterface<bool> { | 707 public testing::WithParamInterface<bool> { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1016 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1017 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 1017 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), |
| 1018 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1018 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1019 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 1019 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), |
| 1020 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1020 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1021 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 1021 StatsState::TRUE_SETTING, StatsState::NO_SETTING), |
| 1022 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1022 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1023 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 1023 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), |
| 1024 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1024 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1025 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | 1025 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); |
| OLD | NEW |