| 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 dlls in those parameters to the registry. |
| 199 AddFinchBlacklistToRegistry(); |
| 200 |
| 201 // Check that all the values in desired_params were added to the registry. |
| 202 base::win::RegKey finch_blacklist_registry_key( |
| 203 HKEY_CURRENT_USER, |
| 204 blacklist::kRegistryFinchListPath, |
| 205 KEY_QUERY_VALUE | KEY_SET_VALUE); |
| 206 |
| 207 ASSERT_EQ(desired_params.size(), |
| 208 finch_blacklist_registry_key.GetValueCount()); |
| 209 |
| 210 for (std::map<std::string, std::string>::iterator it = desired_params.begin(); |
| 211 it != desired_params.end(); |
| 212 ++it) { |
| 213 std::wstring name = base::UTF8ToWide(it->first); |
| 214 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name.c_str())); |
| 215 } |
| 216 } |
| 217 |
| 218 } // namespace |
| OLD | NEW |