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" |
| 6 |
5 #include <windows.h> | 7 #include <windows.h> |
6 #include <shlwapi.h> // For SHDeleteKey. | 8 #include <shlwapi.h> // For SHDeleteKey. |
7 | 9 |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/test_reg_util_win.h" | 12 #include "base/test/test_reg_util_win.h" |
11 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
12 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/installer/util/browser_distribution.h" | 15 #include "chrome/installer/util/browser_distribution.h" |
14 #include "chrome/installer/util/channel_info.h" | 16 #include "chrome/installer/util/channel_info.h" |
15 #include "chrome/installer/util/fake_installation_state.h" | 17 #include "chrome/installer/util/fake_installation_state.h" |
16 #include "chrome/installer/util/google_update_constants.h" | 18 #include "chrome/installer/util/google_update_constants.h" |
17 #include "chrome/installer/util/google_update_experiment_util.h" | 19 #include "chrome/installer/util/google_update_experiment_util.h" |
18 #include "chrome/installer/util/google_update_settings.h" | |
19 #include "chrome/installer/util/util_constants.h" | 20 #include "chrome/installer/util/util_constants.h" |
20 #include "chrome/installer/util/work_item_list.h" | 21 #include "chrome/installer/util/work_item_list.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using base::win::RegKey; | 24 using base::win::RegKey; |
24 using installer::ChannelInfo; | 25 using installer::ChannelInfo; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; | 29 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; |
(...skipping 13 matching lines...) Expand all Loading... |
42 SYSTEM_INSTALL, | 43 SYSTEM_INSTALL, |
43 USER_INSTALL, | 44 USER_INSTALL, |
44 }; | 45 }; |
45 | 46 |
46 void SetApField(SystemUserInstall is_system, const wchar_t* value) { | 47 void SetApField(SystemUserInstall is_system, const wchar_t* value) { |
47 HKEY root = is_system == SYSTEM_INSTALL ? | 48 HKEY root = is_system == SYSTEM_INSTALL ? |
48 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 49 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
49 | 50 |
50 RegKey update_key; | 51 RegKey update_key; |
51 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 52 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
52 std::wstring path = dist->GetStateKey(); | 53 base::string16 path = dist->GetStateKey(); |
53 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), KEY_WRITE)); | 54 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), KEY_WRITE)); |
54 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); | 55 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); |
55 } | 56 } |
56 | 57 |
57 // Sets the "ap" field for a multi-install product (both the product and | 58 // Sets the "ap" field for a multi-install product (both the product and |
58 // the binaries). | 59 // the binaries). |
59 void SetMultiApField(SystemUserInstall is_system, const wchar_t* value) { | 60 void SetMultiApField(SystemUserInstall is_system, const wchar_t* value) { |
60 // Caller must specify a multi-install ap value. | 61 // Caller must specify a multi-install ap value. |
61 ASSERT_NE(std::wstring::npos, std::wstring(value).find(L"-multi")); | 62 ASSERT_NE(base::string16::npos, base::string16(value).find(L"-multi")); |
62 HKEY root = is_system == SYSTEM_INSTALL ? | 63 HKEY root = is_system == SYSTEM_INSTALL ? |
63 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 64 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
64 RegKey update_key; | 65 RegKey update_key; |
65 | 66 |
66 // Write the ap value for both the product and the binaries. | 67 // Write the ap value for both the product and the binaries. |
67 BrowserDistribution* const kDists[] = { | 68 BrowserDistribution* const kDists[] = { |
68 BrowserDistribution::GetDistribution(), | 69 BrowserDistribution::GetDistribution(), |
69 BrowserDistribution::GetSpecificDistribution( | 70 BrowserDistribution::GetSpecificDistribution( |
70 BrowserDistribution::CHROME_BINARIES) | 71 BrowserDistribution::CHROME_BINARIES) |
71 }; | 72 }; |
72 for (size_t i = 0; i < arraysize(kDists); ++i) { | 73 for (size_t i = 0; i < arraysize(kDists); ++i) { |
73 std::wstring path = kDists[i]->GetStateKey(); | 74 base::string16 path = kDists[i]->GetStateKey(); |
74 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), | 75 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), |
75 KEY_WRITE)); | 76 KEY_WRITE)); |
76 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); | 77 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); |
77 } | 78 } |
78 | 79 |
79 // Make the product technically multi-install. | 80 // Make the product technically multi-install. |
80 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 81 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
81 ASSERT_EQ(ERROR_SUCCESS, | 82 ASSERT_EQ(ERROR_SUCCESS, |
82 update_key.Create(root, dist->GetStateKey().c_str(), KEY_WRITE)); | 83 update_key.Create(root, dist->GetStateKey().c_str(), KEY_WRITE)); |
83 ASSERT_EQ(ERROR_SUCCESS, | 84 ASSERT_EQ(ERROR_SUCCESS, |
(...skipping 25 matching lines...) Expand all Loading... |
109 }; | 110 }; |
110 const wchar_t* suffixes[] = { | 111 const wchar_t* suffixes[] = { |
111 L"", | 112 L"", |
112 L"suffix", | 113 L"suffix", |
113 L"suffix-with-dash", | 114 L"suffix-with-dash", |
114 }; | 115 }; |
115 | 116 |
116 for (size_t i = 0; i < arraysize(prefixes); ++i) { | 117 for (size_t i = 0; i < arraysize(prefixes); ++i) { |
117 for (size_t j = 0; j < arraysize(expectations); ++j) { | 118 for (size_t j = 0; j < arraysize(expectations); ++j) { |
118 for (size_t k = 0; k < arraysize(suffixes); ++k) { | 119 for (size_t k = 0; k < arraysize(suffixes); ++k) { |
119 std::wstring ap = prefixes[i]; | 120 base::string16 ap = prefixes[i]; |
120 ap += expectations[j].ap_value; | 121 ap += expectations[j].ap_value; |
121 ap += suffixes[k]; | 122 ap += suffixes[k]; |
122 const wchar_t* channel = expectations[j].channel; | 123 const wchar_t* channel = expectations[j].channel; |
123 | 124 |
124 SetApField(install, ap.c_str()); | 125 SetApField(install, ap.c_str()); |
125 base::string16 ret_channel; | 126 base::string16 ret_channel; |
126 | 127 |
127 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( | 128 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( |
128 is_system, &ret_channel)); | 129 is_system, &ret_channel)); |
129 EXPECT_STREQ(channel, ret_channel.c_str()) | 130 EXPECT_STREQ(channel, ret_channel.c_str()) |
130 << "Expecting channel \"" << channel | 131 << "Expecting channel \"" << channel |
131 << "\" for ap=\"" << ap << "\""; | 132 << "\" for ap=\"" << ap << "\""; |
132 } | 133 } |
133 } | 134 } |
134 } | 135 } |
135 } | 136 } |
136 | 137 |
137 // Test the writing and deleting functionality of the experiments label | 138 // Test the writing and deleting functionality of the experiments label |
138 // helper. | 139 // helper. |
139 void TestExperimentsLabelHelper(SystemUserInstall install) { | 140 void TestExperimentsLabelHelper(SystemUserInstall install) { |
140 BrowserDistribution* chrome = | 141 BrowserDistribution* chrome = |
141 BrowserDistribution::GetSpecificDistribution( | 142 BrowserDistribution::GetSpecificDistribution( |
142 BrowserDistribution::CHROME_BROWSER); | 143 BrowserDistribution::CHROME_BROWSER); |
143 std::wstring value; | 144 base::string16 value; |
144 #if defined(GOOGLE_CHROME_BUILD) | 145 #if defined(GOOGLE_CHROME_BUILD) |
145 EXPECT_TRUE(chrome->ShouldSetExperimentLabels()); | 146 EXPECT_TRUE(chrome->ShouldSetExperimentLabels()); |
146 | 147 |
147 // Before anything is set, ReadExperimentLabels should succeed but return | 148 // Before anything is set, ReadExperimentLabels should succeed but return |
148 // an empty string. | 149 // an empty string. |
149 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( | 150 EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels( |
150 install == SYSTEM_INSTALL, &value)); | 151 install == SYSTEM_INSTALL, &value)); |
151 EXPECT_EQ(base::string16(), value); | 152 EXPECT_EQ(base::string16(), value); |
152 | 153 |
153 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( | 154 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( |
(...skipping 30 matching lines...) Expand all Loading... |
184 key.Close(); | 185 key.Close(); |
185 #else | 186 #else |
186 EXPECT_FALSE(chrome->ShouldSetExperimentLabels()); | 187 EXPECT_FALSE(chrome->ShouldSetExperimentLabels()); |
187 EXPECT_FALSE(GoogleUpdateSettings::ReadExperimentLabels( | 188 EXPECT_FALSE(GoogleUpdateSettings::ReadExperimentLabels( |
188 install == SYSTEM_INSTALL, &value)); | 189 install == SYSTEM_INSTALL, &value)); |
189 #endif // GOOGLE_CHROME_BUILD | 190 #endif // GOOGLE_CHROME_BUILD |
190 } | 191 } |
191 | 192 |
192 // Creates "ap" key with the value given as parameter. Also adds work | 193 // Creates "ap" key with the value given as parameter. Also adds work |
193 // items to work_item_list given so that they can be rolled back later. | 194 // items to work_item_list given so that they can be rolled back later. |
194 bool CreateApKey(WorkItemList* work_item_list, const std::wstring& value) { | 195 bool CreateApKey(WorkItemList* work_item_list, const base::string16& value) { |
195 HKEY reg_root = HKEY_CURRENT_USER; | 196 HKEY reg_root = HKEY_CURRENT_USER; |
196 std::wstring reg_key = GetApKeyPath(); | 197 base::string16 reg_key = GetApKeyPath(); |
197 work_item_list->AddCreateRegKeyWorkItem( | 198 work_item_list->AddCreateRegKeyWorkItem( |
198 reg_root, reg_key, WorkItem::kWow64Default); | 199 reg_root, reg_key, WorkItem::kWow64Default); |
199 work_item_list->AddSetRegValueWorkItem(reg_root, | 200 work_item_list->AddSetRegValueWorkItem(reg_root, |
200 reg_key, | 201 reg_key, |
201 WorkItem::kWow64Default, | 202 WorkItem::kWow64Default, |
202 google_update::kRegApField, | 203 google_update::kRegApField, |
203 value.c_str(), | 204 value.c_str(), |
204 true); | 205 true); |
205 if (!work_item_list->Do()) { | 206 if (!work_item_list->Do()) { |
206 work_item_list->Rollback(); | 207 work_item_list->Rollback(); |
207 return false; | 208 return false; |
208 } | 209 } |
209 return true; | 210 return true; |
210 } | 211 } |
211 | 212 |
212 // Returns the key path of "ap" key, e.g.: | 213 // Returns the key path of "ap" key, e.g.: |
213 // Google\Update\ClientState\<kTestProductGuid> | 214 // Google\Update\ClientState\<kTestProductGuid> |
214 std::wstring GetApKeyPath() { | 215 base::string16 GetApKeyPath() { |
215 std::wstring reg_key(google_update::kRegPathClientState); | 216 base::string16 reg_key(google_update::kRegPathClientState); |
216 reg_key.append(L"\\"); | 217 reg_key.append(L"\\"); |
217 reg_key.append(kTestProductGuid); | 218 reg_key.append(kTestProductGuid); |
218 return reg_key; | 219 return reg_key; |
219 } | 220 } |
220 | 221 |
221 // Utility method to read "ap" key value | 222 // Utility method to read "ap" key value |
222 std::wstring ReadApKeyValue() { | 223 base::string16 ReadApKeyValue() { |
223 RegKey key; | 224 RegKey key; |
224 std::wstring ap_key_value; | 225 base::string16 ap_key_value; |
225 std::wstring reg_key = GetApKeyPath(); | 226 base::string16 reg_key = GetApKeyPath(); |
226 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) == | 227 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) == |
227 ERROR_SUCCESS) { | 228 ERROR_SUCCESS) { |
228 key.ReadValue(google_update::kRegApField, &ap_key_value); | 229 key.ReadValue(google_update::kRegApField, &ap_key_value); |
229 } | 230 } |
230 | 231 |
231 return ap_key_value; | 232 return ap_key_value; |
232 } | 233 } |
233 | 234 |
234 bool SetUpdatePolicyForAppGuid(const base::string16& app_guid, | 235 bool SetUpdatePolicyForAppGuid(const base::string16& app_guid, |
235 GoogleUpdateSettings::UpdatePolicy policy) { | 236 GoogleUpdateSettings::UpdatePolicy policy) { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 ASSERT_TRUE(CreateApKey(work_item_list.get(), L"-full")) | 513 ASSERT_TRUE(CreateApKey(work_item_list.get(), L"-full")) |
513 << "Failed to create ap key."; | 514 << "Failed to create ap key."; |
514 GoogleUpdateSettings::UpdateInstallStatus(false, installer::FULL_ARCHIVE_TYPE, | 515 GoogleUpdateSettings::UpdateInstallStatus(false, installer::FULL_ARCHIVE_TYPE, |
515 installer::FIRST_INSTALL_SUCCESS, | 516 installer::FIRST_INSTALL_SUCCESS, |
516 kTestProductGuid); | 517 kTestProductGuid); |
517 EXPECT_STREQ(ReadApKeyValue().c_str(), L""); | 518 EXPECT_STREQ(ReadApKeyValue().c_str(), L""); |
518 work_item_list->Rollback(); | 519 work_item_list->Rollback(); |
519 | 520 |
520 work_item_list.reset(WorkItem::CreateWorkItemList()); | 521 work_item_list.reset(WorkItem::CreateWorkItemList()); |
521 // Test the case of when "ap" key doesnt exist at all | 522 // Test the case of when "ap" key doesnt exist at all |
522 std::wstring ap_key_value = ReadApKeyValue(); | 523 base::string16 ap_key_value = ReadApKeyValue(); |
523 std::wstring reg_key = GetApKeyPath(); | 524 base::string16 reg_key = GetApKeyPath(); |
524 HKEY reg_root = HKEY_CURRENT_USER; | 525 HKEY reg_root = HKEY_CURRENT_USER; |
525 bool ap_key_deleted = false; | 526 bool ap_key_deleted = false; |
526 RegKey key; | 527 RegKey key; |
527 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) != | 528 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) != |
528 ERROR_SUCCESS) { | 529 ERROR_SUCCESS) { |
529 work_item_list->AddCreateRegKeyWorkItem( | 530 work_item_list->AddCreateRegKeyWorkItem( |
530 reg_root, reg_key, WorkItem::kWow64Default); | 531 reg_root, reg_key, WorkItem::kWow64Default); |
531 ASSERT_TRUE(work_item_list->Do()) << "Failed to create ClientState key."; | 532 ASSERT_TRUE(work_item_list->Do()) << "Failed to create ClientState key."; |
532 } else if (key.DeleteValue(google_update::kRegApField) == ERROR_SUCCESS) { | 533 } else if (key.DeleteValue(google_update::kRegApField) == ERROR_SUCCESS) { |
533 ap_key_deleted = true; | 534 ap_key_deleted = true; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 static_cast<DWORD>(4))); | 682 static_cast<DWORD>(4))); |
682 is_overridden = true; | 683 is_overridden = true; |
683 EXPECT_EQ(GoogleUpdateSettings::kDefaultUpdatePolicy, | 684 EXPECT_EQ(GoogleUpdateSettings::kDefaultUpdatePolicy, |
684 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, | 685 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, |
685 &is_overridden)); | 686 &is_overridden)); |
686 EXPECT_FALSE(is_overridden); | 687 EXPECT_FALSE(is_overridden); |
687 } | 688 } |
688 | 689 |
689 // Test that an app-specific override is used if present. | 690 // Test that an app-specific override is used if present. |
690 TEST_F(GoogleUpdateSettingsTest, GetAppUpdatePolicyAppOverride) { | 691 TEST_F(GoogleUpdateSettingsTest, GetAppUpdatePolicyAppOverride) { |
691 std::wstring app_policy_value( | 692 base::string16 app_policy_value( |
692 GoogleUpdateSettings::kUpdateOverrideValuePrefix); | 693 GoogleUpdateSettings::kUpdateOverrideValuePrefix); |
693 app_policy_value.append(kTestProductGuid); | 694 app_policy_value.append(kTestProductGuid); |
694 | 695 |
695 EXPECT_EQ(ERROR_SUCCESS, | 696 EXPECT_EQ(ERROR_SUCCESS, |
696 RegKey(HKEY_LOCAL_MACHINE, GoogleUpdateSettings::kPoliciesKey, | 697 RegKey(HKEY_LOCAL_MACHINE, GoogleUpdateSettings::kPoliciesKey, |
697 KEY_SET_VALUE).WriteValue( | 698 KEY_SET_VALUE).WriteValue( |
698 GoogleUpdateSettings::kUpdatePolicyValue, | 699 GoogleUpdateSettings::kUpdatePolicyValue, |
699 static_cast<DWORD>(1))); | 700 static_cast<DWORD>(1))); |
700 EXPECT_EQ(ERROR_SUCCESS, | 701 EXPECT_EQ(ERROR_SUCCESS, |
701 RegKey(HKEY_LOCAL_MACHINE, GoogleUpdateSettings::kPoliciesKey, | 702 RegKey(HKEY_LOCAL_MACHINE, GoogleUpdateSettings::kPoliciesKey, |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 // A value parameterized test for testing the stats collection consent setting. | 1030 // A value parameterized test for testing the stats collection consent setting. |
1030 class CollectStatsConsent : public ::testing::TestWithParam<StatsState> { | 1031 class CollectStatsConsent : public ::testing::TestWithParam<StatsState> { |
1031 public: | 1032 public: |
1032 static void SetUpTestCase(); | 1033 static void SetUpTestCase(); |
1033 static void TearDownTestCase(); | 1034 static void TearDownTestCase(); |
1034 protected: | 1035 protected: |
1035 virtual void SetUp() OVERRIDE; | 1036 virtual void SetUp() OVERRIDE; |
1036 static void MakeChromeMultiInstall(HKEY root_key); | 1037 static void MakeChromeMultiInstall(HKEY root_key); |
1037 static void ApplySetting(StatsState::StateSetting setting, | 1038 static void ApplySetting(StatsState::StateSetting setting, |
1038 HKEY root_key, | 1039 HKEY root_key, |
1039 const std::wstring& reg_key); | 1040 const base::string16& reg_key); |
1040 | 1041 |
1041 static std::wstring* chrome_version_key_; | 1042 static base::string16* chrome_version_key_; |
1042 static std::wstring* chrome_state_key_; | 1043 static base::string16* chrome_state_key_; |
1043 static std::wstring* chrome_state_medium_key_; | 1044 static base::string16* chrome_state_medium_key_; |
1044 static std::wstring* binaries_state_key_; | 1045 static base::string16* binaries_state_key_; |
1045 static std::wstring* binaries_state_medium_key_; | 1046 static base::string16* binaries_state_medium_key_; |
1046 registry_util::RegistryOverrideManager override_manager_; | 1047 registry_util::RegistryOverrideManager override_manager_; |
1047 }; | 1048 }; |
1048 | 1049 |
1049 std::wstring* CollectStatsConsent::chrome_version_key_; | 1050 base::string16* CollectStatsConsent::chrome_version_key_; |
1050 std::wstring* CollectStatsConsent::chrome_state_key_; | 1051 base::string16* CollectStatsConsent::chrome_state_key_; |
1051 std::wstring* CollectStatsConsent::chrome_state_medium_key_; | 1052 base::string16* CollectStatsConsent::chrome_state_medium_key_; |
1052 std::wstring* CollectStatsConsent::binaries_state_key_; | 1053 base::string16* CollectStatsConsent::binaries_state_key_; |
1053 std::wstring* CollectStatsConsent::binaries_state_medium_key_; | 1054 base::string16* CollectStatsConsent::binaries_state_medium_key_; |
1054 | 1055 |
1055 void CollectStatsConsent::SetUpTestCase() { | 1056 void CollectStatsConsent::SetUpTestCase() { |
1056 BrowserDistribution* dist = | 1057 BrowserDistribution* dist = |
1057 BrowserDistribution::GetSpecificDistribution( | 1058 BrowserDistribution::GetSpecificDistribution( |
1058 BrowserDistribution::CHROME_BROWSER); | 1059 BrowserDistribution::CHROME_BROWSER); |
1059 chrome_version_key_ = new std::wstring(dist->GetVersionKey()); | 1060 chrome_version_key_ = new base::string16(dist->GetVersionKey()); |
1060 chrome_state_key_ = new std::wstring(dist->GetStateKey()); | 1061 chrome_state_key_ = new base::string16(dist->GetStateKey()); |
1061 chrome_state_medium_key_ = new std::wstring(dist->GetStateMediumKey()); | 1062 chrome_state_medium_key_ = new base::string16(dist->GetStateMediumKey()); |
1062 | 1063 |
1063 dist = BrowserDistribution::GetSpecificDistribution( | 1064 dist = BrowserDistribution::GetSpecificDistribution( |
1064 BrowserDistribution::CHROME_BINARIES); | 1065 BrowserDistribution::CHROME_BINARIES); |
1065 binaries_state_key_ = new std::wstring(dist->GetStateKey()); | 1066 binaries_state_key_ = new base::string16(dist->GetStateKey()); |
1066 binaries_state_medium_key_ = new std::wstring(dist->GetStateMediumKey()); | 1067 binaries_state_medium_key_ = new base::string16(dist->GetStateMediumKey()); |
1067 } | 1068 } |
1068 | 1069 |
1069 void CollectStatsConsent::TearDownTestCase() { | 1070 void CollectStatsConsent::TearDownTestCase() { |
1070 delete chrome_version_key_; | 1071 delete chrome_version_key_; |
1071 delete chrome_state_key_; | 1072 delete chrome_state_key_; |
1072 delete chrome_state_medium_key_; | 1073 delete chrome_state_medium_key_; |
1073 delete binaries_state_key_; | 1074 delete binaries_state_key_; |
1074 delete binaries_state_medium_key_; | 1075 delete binaries_state_medium_key_; |
1075 } | 1076 } |
1076 | 1077 |
1077 // Install the registry override and apply the settings to the registry. | 1078 // Install the registry override and apply the settings to the registry. |
1078 void CollectStatsConsent::SetUp() { | 1079 void CollectStatsConsent::SetUp() { |
1079 const StatsState& stats_state = GetParam(); | 1080 const StatsState& stats_state = GetParam(); |
1080 const HKEY root_key = stats_state.root_key(); | 1081 const HKEY root_key = stats_state.root_key(); |
1081 std::wstring reg_temp_name(stats_state.system_level() ? L"HKLM_" : L"HKCU_"); | 1082 base::string16 reg_temp_name( |
| 1083 stats_state.system_level() ? L"HKLM_" : L"HKCU_"); |
1082 reg_temp_name += L"CollectStatsConsent"; | 1084 reg_temp_name += L"CollectStatsConsent"; |
1083 override_manager_.OverrideRegistry(root_key, reg_temp_name); | 1085 override_manager_.OverrideRegistry(root_key, reg_temp_name); |
1084 | 1086 |
1085 if (stats_state.multi_install()) { | 1087 if (stats_state.multi_install()) { |
1086 MakeChromeMultiInstall(root_key); | 1088 MakeChromeMultiInstall(root_key); |
1087 ApplySetting(stats_state.state_value(), root_key, *binaries_state_key_); | 1089 ApplySetting(stats_state.state_value(), root_key, *binaries_state_key_); |
1088 ApplySetting(stats_state.state_medium_value(), root_key, | 1090 ApplySetting(stats_state.state_medium_value(), root_key, |
1089 *binaries_state_medium_key_); | 1091 *binaries_state_medium_key_); |
1090 } else { | 1092 } else { |
1091 ApplySetting(stats_state.state_value(), root_key, *chrome_state_key_); | 1093 ApplySetting(stats_state.state_value(), root_key, *chrome_state_key_); |
(...skipping 13 matching lines...) Expand all Loading... |
1105 ASSERT_EQ( | 1107 ASSERT_EQ( |
1106 ERROR_SUCCESS, | 1108 ERROR_SUCCESS, |
1107 RegKey(root_key, chrome_state_key_->c_str(), | 1109 RegKey(root_key, chrome_state_key_->c_str(), |
1108 KEY_SET_VALUE).WriteValue(installer::kUninstallArgumentsField, | 1110 KEY_SET_VALUE).WriteValue(installer::kUninstallArgumentsField, |
1109 L"--multi-install")); | 1111 L"--multi-install")); |
1110 } | 1112 } |
1111 | 1113 |
1112 // Write the correct value to represent |setting| in the registry. | 1114 // Write the correct value to represent |setting| in the registry. |
1113 void CollectStatsConsent::ApplySetting(StatsState::StateSetting setting, | 1115 void CollectStatsConsent::ApplySetting(StatsState::StateSetting setting, |
1114 HKEY root_key, | 1116 HKEY root_key, |
1115 const std::wstring& reg_key) { | 1117 const base::string16& reg_key) { |
1116 if (setting != StatsState::NO_SETTING) { | 1118 if (setting != StatsState::NO_SETTING) { |
1117 DWORD value = setting != StatsState::FALSE_SETTING ? 1 : 0; | 1119 DWORD value = setting != StatsState::FALSE_SETTING ? 1 : 0; |
1118 ASSERT_EQ( | 1120 ASSERT_EQ( |
1119 ERROR_SUCCESS, | 1121 ERROR_SUCCESS, |
1120 RegKey(root_key, reg_key.c_str(), | 1122 RegKey(root_key, reg_key.c_str(), |
1121 KEY_SET_VALUE).WriteValue(google_update::kRegUsageStatsField, | 1123 KEY_SET_VALUE).WriteValue(google_update::kRegUsageStatsField, |
1122 value)); | 1124 value)); |
1123 } | 1125 } |
1124 } | 1126 } |
1125 | 1127 |
1126 // Test that stats consent can be read. | 1128 // Test that stats consent can be read. |
1127 TEST_P(CollectStatsConsent, GetCollectStatsConsentAtLevel) { | 1129 TEST_P(CollectStatsConsent, GetCollectStatsConsentAtLevel) { |
1128 if (GetParam().is_consent_granted()) { | 1130 if (GetParam().is_consent_granted()) { |
1129 EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( | 1131 EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( |
1130 GetParam().system_level())); | 1132 GetParam().system_level())); |
1131 } else { | 1133 } else { |
1132 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( | 1134 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( |
1133 GetParam().system_level())); | 1135 GetParam().system_level())); |
1134 } | 1136 } |
1135 } | 1137 } |
1136 | 1138 |
1137 // Test that stats consent can be flipped to the opposite setting, that the new | 1139 // Test that stats consent can be flipped to the opposite setting, that the new |
1138 // setting takes affect, and that the correct registry location is modified. | 1140 // setting takes affect, and that the correct registry location is modified. |
1139 TEST_P(CollectStatsConsent, SetCollectStatsConsentAtLevel) { | 1141 TEST_P(CollectStatsConsent, SetCollectStatsConsentAtLevel) { |
1140 EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsentAtLevel( | 1142 EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsentAtLevel( |
1141 GetParam().system_level(), | 1143 GetParam().system_level(), |
1142 !GetParam().is_consent_granted())); | 1144 !GetParam().is_consent_granted())); |
1143 const std::wstring* const reg_keys[] = { | 1145 const base::string16* const reg_keys[] = { |
1144 chrome_state_key_, | 1146 chrome_state_key_, |
1145 chrome_state_medium_key_, | 1147 chrome_state_medium_key_, |
1146 binaries_state_key_, | 1148 binaries_state_key_, |
1147 binaries_state_medium_key_, | 1149 binaries_state_medium_key_, |
1148 }; | 1150 }; |
1149 int key_index = ((GetParam().system_level() ? 1 : 0) + | 1151 int key_index = ((GetParam().system_level() ? 1 : 0) + |
1150 (GetParam().multi_install() ? 2 : 0)); | 1152 (GetParam().multi_install() ? 2 : 0)); |
1151 const std::wstring& reg_key = *reg_keys[key_index]; | 1153 const base::string16& reg_key = *reg_keys[key_index]; |
1152 DWORD value = 0; | 1154 DWORD value = 0; |
1153 EXPECT_EQ( | 1155 EXPECT_EQ( |
1154 ERROR_SUCCESS, | 1156 ERROR_SUCCESS, |
1155 RegKey(GetParam().root_key(), reg_key.c_str(), | 1157 RegKey(GetParam().root_key(), reg_key.c_str(), |
1156 KEY_QUERY_VALUE).ReadValueDW(google_update::kRegUsageStatsField, | 1158 KEY_QUERY_VALUE).ReadValueDW(google_update::kRegUsageStatsField, |
1157 &value)); | 1159 &value)); |
1158 if (GetParam().is_consent_granted()) { | 1160 if (GetParam().is_consent_granted()) { |
1159 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( | 1161 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsentAtLevel( |
1160 GetParam().system_level())); | 1162 GetParam().system_level())); |
1161 EXPECT_EQ(0UL, value); | 1163 EXPECT_EQ(0UL, value); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1225 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1224 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 1226 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), |
1225 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1227 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1226 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 1228 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), |
1227 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1229 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1228 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 1230 StatsState::TRUE_SETTING, StatsState::NO_SETTING), |
1229 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1231 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1230 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 1232 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), |
1231 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1233 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1232 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | 1234 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); |
OLD | NEW |