| 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/files/file_path.h" | |
| 9 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 11 #include "base/path_service.h" | |
| 12 #include "base/scoped_native_library.h" | |
| 13 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_util.h" | |
| 15 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/test_reg_util_win.h" | 12 #include "base/test/test_reg_util_win.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
| 18 #include "chrome_elf/blacklist/blacklist.h" | |
| 19 #include "chrome_elf/chrome_elf_constants.h" | 14 #include "chrome_elf/chrome_elf_constants.h" |
| 20 #include "components/variations/entropy_provider.h" | 15 #include "components/variations/entropy_provider.h" |
| 21 #include "components/variations/variations_associated_data.h" | 16 #include "components/variations/variations_associated_data.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "version.h" // NOLINT | 18 #include "version.h" // NOLINT |
| 24 | 19 |
| 25 namespace { | 20 namespace { |
| 26 | 21 |
| 27 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled"; | 22 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled"; |
| 28 const wchar_t kTestDllName[] = L"blacklist_test_dll_1.dll"; | |
| 29 | 23 |
| 30 class ChromeBlacklistTrialTest : public testing::Test { | 24 class ChromeBlacklistTrialTest : public testing::Test { |
| 31 protected: | 25 protected: |
| 32 ChromeBlacklistTrialTest() {} | 26 ChromeBlacklistTrialTest() {} |
| 33 virtual ~ChromeBlacklistTrialTest() {} | 27 virtual ~ChromeBlacklistTrialTest() {} |
| 34 | 28 |
| 35 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() OVERRIDE { |
| 36 testing::Test::SetUp(); | 30 testing::Test::SetUp(); |
| 37 | 31 |
| 38 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, | 32 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 finch_blacklist_registry_key.GetValueCount()); | 187 finch_blacklist_registry_key.GetValueCount()); |
| 194 | 188 |
| 195 for (std::map<std::string, std::string>::iterator it = desired_params.begin(); | 189 for (std::map<std::string, std::string>::iterator it = desired_params.begin(); |
| 196 it != desired_params.end(); | 190 it != desired_params.end(); |
| 197 ++it) { | 191 ++it) { |
| 198 std::wstring name = base::UTF8ToWide(it->first); | 192 std::wstring name = base::UTF8ToWide(it->first); |
| 199 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name.c_str())); | 193 ASSERT_TRUE(finch_blacklist_registry_key.HasValue(name.c_str())); |
| 200 } | 194 } |
| 201 } | 195 } |
| 202 | 196 |
| 203 TEST_F(ChromeBlacklistTrialTest, TestBlacklistBypass) { | |
| 204 base::FilePath current_dir; | |
| 205 ASSERT_TRUE(PathService::Get(base::DIR_EXE, ¤t_dir)); | |
| 206 | |
| 207 // Load test dll. | |
| 208 base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName)); | |
| 209 | |
| 210 // No blacklisted dll should be found. | |
| 211 std::vector<base::string16> module_names; | |
| 212 EXPECT_TRUE(GetLoadedBlacklistedModules(&module_names)); | |
| 213 EXPECT_TRUE(module_names.empty()); | |
| 214 // For posterity, print any that are. | |
| 215 std::vector<base::string16>::const_iterator module_iter(module_names.begin()); | |
| 216 for (; module_iter != module_names.end(); ++module_iter) { | |
| 217 LOG(ERROR) << "Found blacklisted module: " << *module_iter; | |
| 218 } | |
| 219 | |
| 220 // Add test dll to blacklist | |
| 221 blacklist::AddDllToBlacklist(kTestDllName); | |
| 222 | |
| 223 // Check that the test dll appears in list. | |
| 224 module_names.clear(); | |
| 225 EXPECT_TRUE(GetLoadedBlacklistedModules(&module_names)); | |
| 226 ASSERT_EQ(1, module_names.size()); | |
| 227 EXPECT_STREQ(kTestDllName, | |
| 228 base::StringToLowerASCII( | |
| 229 base::FilePath(module_names[0]).BaseName().value()).c_str()); | |
| 230 } | |
| 231 | |
| 232 } // namespace | 197 } // namespace |
| OLD | NEW |