Chromium Code Reviews| 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 | 
| 20 class ChromeBlacklistTrialTest : public testing::Test { | 21 class ChromeBlacklistTrialTest : public testing::Test { | 
| 21 protected: | 22 protected: | 
| 22 ChromeBlacklistTrialTest() {} | 23 ChromeBlacklistTrialTest() {} | 
| 23 virtual ~ChromeBlacklistTrialTest() {} | 24 virtual ~ChromeBlacklistTrialTest() {} | 
| 24 | 25 | 
| 25 virtual void SetUp() OVERRIDE { | 26 virtual void SetUp() OVERRIDE { | 
| 26 testing::Test::SetUp(); | 27 testing::Test::SetUp(); | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 InitializeChromeElf(); | 70 InitializeChromeElf(); | 
| 70 | 71 | 
| 71 // Ensure the beacon values are now correct, indicating the | 72 // Ensure the beacon values are now correct, indicating the | 
| 72 // blacklist beacon was setup. | 73 // blacklist beacon was setup. | 
| 73 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 74 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 
| 74 chrome::VersionInfo version_info; | 75 chrome::VersionInfo version_info; | 
| 75 base::string16 version(base::UTF8ToUTF16(version_info.Version())); | 76 base::string16 version(base::UTF8ToUTF16(version_info.Version())); | 
| 76 ASSERT_EQ(version, GetBlacklistVersion()); | 77 ASSERT_EQ(version, GetBlacklistVersion()); | 
| 77 } | 78 } | 
| 78 | 79 | 
| 79 | |
| 80 // Ensure that the blacklist is disabled for any users in the | 80 // Ensure that the blacklist is disabled for any users in the | 
| 81 // "BlacklistDisabled" finch group. | 81 // "BlacklistDisabled" finch group. | 
| 82 TEST_F(ChromeBlacklistTrialTest, BlacklistDisabledRun) { | 82 TEST_F(ChromeBlacklistTrialTest, BlacklistDisabledRun) { | 
| 83 // Set the beacons to enabled values. | 83 // Set the beacons to enabled values. | 
| 84 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 84 blacklist_registry_key_->WriteValue(blacklist::kBeaconState, | 
| 85 blacklist::BLACKLIST_ENABLED); | 85 blacklist::BLACKLIST_ENABLED); | 
| 86 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); | 86 blacklist_registry_key_->WriteValue(blacklist::kBeaconVersion, L"Data"); | 
| 87 | 87 | 
| 88 // Create the field trial with the blacklist disabled group. | 88 // Create the field trial with the blacklist disabled group. | 
| 89 base::FieldTrialList field_trial_list( | 89 base::FieldTrialList field_trial_list( | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 165 | 
| 166 BrowserBlacklistBeaconSetup(); | 166 BrowserBlacklistBeaconSetup(); | 
| 167 | 167 | 
| 168 // The beacon should now be marked as enabled for the current version. | 168 // The beacon should now be marked as enabled for the current version. | 
| 169 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 169 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState()); | 
| 170 | 170 | 
| 171 chrome::VersionInfo version_info; | 171 chrome::VersionInfo version_info; | 
| 172 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 172 base::string16 expected_version(base::UTF8ToUTF16(version_info.Version())); | 
| 173 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 173 ASSERT_EQ(expected_version, GetBlacklistVersion()); | 
| 174 } | 174 } | 
| 175 | |
| 176 TEST_F(ChromeBlacklistTrialTest, AddFinchBlacklistToRegistry) { | |
| 177 // Create the field trial with the blacklist enabled group. | |
| 178 base::FieldTrialList field_trial_list( | |
| 179 new metrics::SHA1EntropyProvider("test")); | |
| 180 | |
| 181 scoped_refptr<base::FieldTrial> trial( | |
| 182 base::FieldTrialList::CreateFieldTrial( | |
| 183 kBrowserBlacklistTrialName, kBrowserBlacklistTrialEnabledGroupName)); | |
| 
 
csharp
2014/05/29 20:51:52
Since this is only used in this file (I think), ju
 
krstnmnlsn
2014/05/30 14:09:13
Done.
 
 | |
| 184 | |
| 185 // Set up the trial with the desired parameters. | |
| 186 std::map<std::string, std::string> desired_params; | |
| 187 desired_params["TestDllName1"] = "TestDll1.dll"; | |
| 188 desired_params["TestDllName2"] = "TestDll2.dll"; | |
| 189 | |
| 190 chrome_variations::AssociateVariationParams(kBrowserBlacklistTrialName, | |
| 191 kBrowserBlacklistTrialEnabledGroupName, desired_params); | |
| 192 | |
| 193 // This should add the dll's in those parameters to the registry. | |
| 194 AddFinchBlacklistToRegistry(); | |
| 195 | |
| 196 // Check that the set of values in the registry is the same | |
| 197 // as those in desired_params by comparing size and containment one way. | |
| 198 base::win::RegKey finch_blacklist_registry_key(HKEY_CURRENT_USER, | |
| 199 blacklist::kRegistryFinchListPath, | |
| 
 
csharp
2014/05/29 20:51:52
nit: These lines need to line up H, or all the arg
 
krstnmnlsn
2014/05/30 14:09:13
Done.
 
 | |
| 200 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
| 201 | |
| 202 ASSERT_EQ(desired_params.size(), | |
| 203 finch_blacklist_registry_key.GetValueCount()); | |
| 204 | |
| 205 std::map<std::string, std::string>::iterator it = desired_params.begin(); | |
| 206 while (it != desired_params.end()) { | |
| 207 const char* name_str = (it->first).c_str(); | |
| 
 
csharp
2014/05/29 20:51:52
Same comment here about using wstring
 
krstnmnlsn
2014/05/30 14:09:13
Done.
 
 | |
| 208 size_t name_len = MultiByteToWideChar(CP_UTF8, 0, name_str, -1, NULL, 0); | |
| 209 wchar_t* name_wstr = new wchar_t[name_len]; | |
| 210 MultiByteToWideChar(CP_UTF8, 0, name_str, -1, name_wstr, name_len); | |
| 211 | |
| 212 LONG ret = ::RegQueryValueEx(HKEY_CURRENT_USER, name_wstr, | |
| 213 NULL, NULL, NULL, NULL); | |
| 214 | |
| 215 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name_wstr)); | |
| 216 ++it; | |
| 217 } | |
| 218 } | |
| OLD | NEW |