OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/chrome_elf_init_win.h" | 5 #include "chrome/browser/chrome_elf_init_win.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/test_reg_util_win.h" | 13 #include "base/test/test_reg_util_win.h" |
14 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
15 #include "chrome_elf/chrome_elf_constants.h" | 15 #include "chrome_elf/chrome_elf_constants.h" |
16 #include "components/variations/entropy_provider.h" | 16 #include "components/variations/entropy_provider.h" |
17 #include "components/variations/variations_associated_data.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "version.h" // NOLINT | 19 #include "version.h" // NOLINT |
19 | 20 |
21 namespace { | |
22 | |
23 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled"; | |
24 | |
20 class ChromeBlacklistTrialTest : public testing::Test { | 25 class ChromeBlacklistTrialTest : public testing::Test { |
21 protected: | 26 protected: |
22 ChromeBlacklistTrialTest() {} | 27 ChromeBlacklistTrialTest() {} |
23 virtual ~ChromeBlacklistTrialTest() {} | 28 virtual ~ChromeBlacklistTrialTest() {} |
24 | 29 |
25 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() OVERRIDE { |
26 testing::Test::SetUp(); | 31 testing::Test::SetUp(); |
27 | 32 |
28 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, | 33 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, |
29 L"browser_blacklist_test"); | 34 L"browser_blacklist_test"); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 InitializeChromeElf(); | 74 InitializeChromeElf(); |
70 | 75 |
71 // Ensure the beacon values are now correct, indicating the | 76 // Ensure the beacon values are now correct, indicating the |
72 // blacklist beacon was setup. | 77 // blacklist beacon was setup. |
73 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 78 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
74 chrome::VersionInfo version_info; | 79 chrome::VersionInfo version_info; |
75 base::string16 version(base::UTF8ToUTF16(version_info.Version())); | 80 base::string16 version(base::UTF8ToUTF16(version_info.Version())); |
76 ASSERT_EQ(version, GetBlacklistVersion()); | 81 ASSERT_EQ(version, GetBlacklistVersion()); |
77 } | 82 } |
78 | 83 |
79 | |
80 // Ensure that the blacklist is disabled for any users in the | 84 // Ensure that the blacklist is disabled for any users in the |
81 // "BlacklistDisabled" finch group. | 85 // "BlacklistDisabled" finch group. |
82 TEST_F(ChromeBlacklistTrialTest, BlacklistDisabledRun) { | 86 TEST_F(ChromeBlacklistTrialTest, BlacklistDisabledRun) { |
83 // Set the beacons to enabled values. | 87 // Set the beacons to enabled values. |
84 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 88 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, |
85 blacklist::BLACKLIST_ENABLED); | 89 blacklist::BLACKLIST_ENABLED); |
86 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); | 90 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); |
87 | 91 |
88 // Create the field trial with the blacklist disabled group. | 92 // Create the field trial with the blacklist disabled group. |
89 base::FieldTrialList field_trial_list( | 93 base::FieldTrialList field_trial_list( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 | 169 |
166 BrowserBlacklistBeaconSetup(); | 170 BrowserBlacklistBeaconSetup(); |
167 | 171 |
168 // The beacon should now be marked as enabled for the current version. | 172 // The beacon should now be marked as enabled for the current version. |
169 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 173 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); |
170 | 174 |
171 chrome::VersionInfo version_info; | 175 chrome::VersionInfo version_info; |
172 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 176 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); |
173 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 177 ASSERT_EQ(expected_version, GetBlacklistVersion()); |
174 } | 178 } |
179 | |
180 TEST_F(ChromeBlacklistTrialTest, AddFinchBlacklistToRegistry) { | |
181 // Create the field trial with the blacklist enabled group. | |
182 base::FieldTrialList field_trial_list( | |
183 new metrics::SHA1EntropyProvider("test")); | |
184 | |
185 scoped_refptr<base::FieldTrial> trial(base::FieldTrialList::CreateFieldTrial( | |
186 kBrowserBlacklistTrialName, kBrowserBlacklistTrialEnabledGroupName)); | |
187 | |
188 // Set up the trial with the desired parameters. | |
189 std::map<std::string, std::string> desired_params; | |
190 desired_params["TestDllName1"] = "TestDll1.dll"; | |
191 desired_params["TestDllName2"] = "TestDll2.dll"; | |
192 | |
193 chrome_variations::AssociateVariationParams( | |
194 kBrowserBlacklistTrialName, | |
195 kBrowserBlacklistTrialEnabledGroupName, | |
196 desired_params); | |
197 | |
198 // This should add the dll's in those parameters to the registry. | |
robertshield
2014/05/30 21:07:08
s/dll's/dlls
krstnmnlsn
2014/06/02 14:00:37
Done.
| |
199 AddFinchBlacklistToRegistry(); | |
200 | |
201 // Check that the set of values in the registry is the same | |
202 // as those in desired_params by comparing size and containment one way. | |
203 base::win::RegKey finch_blacklist_registry_key( | |
204 HKEY_CURRENT_USER, | |
205 blacklist::kRegistryFinchListPath, | |
206 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
207 | |
208 ASSERT_EQ(desired_params.size(), | |
209 finch_blacklist_registry_key.GetValueCount()); | |
210 | |
211 std::map<std::string, std::string>::iterator it = desired_params.begin(); | |
212 while (it != desired_params.end()) { | |
robertshield
2014/05/30 21:07:08
minor nit, this form:
for (; it != desired_params
krstnmnlsn
2014/06/02 14:00:37
Done.
| |
213 std::wstring name = base::UTF8ToWide(it->first); | |
214 const wchar_t* name_cstr = name.c_str(); | |
robertshield
2014/05/30 21:07:08
why create the name_cstr temporary?
adding |name|
krstnmnlsn
2014/06/02 14:00:37
Done.
| |
215 | |
216 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name_cstr)); | |
217 ++it; | |
218 } | |
219 } | |
220 | |
221 } // namespace | |
OLD | NEW |