Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: chrome_elf/blacklist/test/blacklist_test.cc

Issue 133923002: Use a Finch Experiment to control the Browser Blacklist (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix unittests Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome_elf/blacklist/blacklist.cc ('k') | chrome_elf/chrome_elf.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/environment.h" 5 #include "base/environment.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_native_library.h" 9 #include "base/scoped_native_library.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.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 "base/win/registry.h"
14 #include "chrome_elf/blacklist/blacklist.h" 15 #include "chrome_elf/blacklist/blacklist.h"
15 #include "chrome_elf/blacklist/test/blacklist_test_main_dll.h" 16 #include "chrome_elf/blacklist/test/blacklist_test_main_dll.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "version.h" // NOLINT
17 19
18 const wchar_t kTestDllName1[] = L"blacklist_test_dll_1.dll"; 20 const wchar_t kTestDllName1[] = L"blacklist_test_dll_1.dll";
19 const wchar_t kTestDllName2[] = L"blacklist_test_dll_2.dll"; 21 const wchar_t kTestDllName2[] = L"blacklist_test_dll_2.dll";
20 const wchar_t kTestDllName3[] = L"blacklist_test_dll_3.dll"; 22 const wchar_t kTestDllName3[] = L"blacklist_test_dll_3.dll";
21 23
22 const wchar_t kDll2Beacon[] = L"{F70A0100-2889-4629-9B44-610FE5C73231}"; 24 const wchar_t kDll2Beacon[] = L"{F70A0100-2889-4629-9B44-610FE5C73231}";
23 const wchar_t kDll3Beacon[] = L"{9E056AEC-169E-400c-B2D0-5A07E3ACE2EB}"; 25 const wchar_t kDll3Beacon[] = L"{9E056AEC-169E-400c-B2D0-5A07E3ACE2EB}";
24 26
25 extern const wchar_t* kEnvVars[]; 27 extern const wchar_t* kEnvVars[];
26 28
27 extern "C" { 29 extern "C" {
28 // When modifying the blacklist in the test process, use the exported test dll 30 // When modifying the blacklist in the test process, use the exported test dll
29 // functions on the test blacklist dll, not the ones linked into the test 31 // functions on the test blacklist dll, not the ones linked into the test
30 // executable itself. 32 // executable itself.
31 __declspec(dllimport) void TestDll_AddDllToBlacklist(const wchar_t* dll_name); 33 __declspec(dllimport) void TestDll_AddDllToBlacklist(const wchar_t* dll_name);
32 __declspec(dllimport) void TestDll_RemoveDllFromBlacklist( 34 __declspec(dllimport) void TestDll_RemoveDllFromBlacklist(
33 const wchar_t* dll_name); 35 const wchar_t* dll_name);
34 } 36 }
35 37
36 class BlacklistTest : public testing::Test { 38 class BlacklistTest : public testing::Test {
37 virtual void SetUp() { 39 virtual void SetUp() {
38 // Force an import from blacklist_test_main_dll. 40 // Force an import from blacklist_test_main_dll.
39 InitBlacklistTestDll(); 41 InitBlacklistTestDll();
40
41 // Ensure that the beacon state starts off cleared.
42 blacklist::ClearBeacon();
43 } 42 }
44 43
45 virtual void TearDown() { 44 virtual void TearDown() {
46 TestDll_RemoveDllFromBlacklist(kTestDllName1); 45 TestDll_RemoveDllFromBlacklist(kTestDllName1);
47 TestDll_RemoveDllFromBlacklist(kTestDllName2); 46 TestDll_RemoveDllFromBlacklist(kTestDllName2);
48 } 47 }
49 }; 48 };
50 49
51 TEST_F(BlacklistTest, Beacon) { 50 TEST_F(BlacklistTest, Beacon) {
52 registry_util::RegistryOverrideManager override_manager; 51 registry_util::RegistryOverrideManager override_manager;
53 override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"beacon_test"); 52 override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"beacon_test");
54 53
55 // First call should succeed as the beacon is newly created. 54 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER,
56 EXPECT_TRUE(blacklist::CreateBeacon()); 55 blacklist::kRegistryBeaconPath,
56 KEY_QUERY_VALUE | KEY_SET_VALUE);
57 57
58 // Second call should fail indicating the beacon already existed. 58 // Ensure that the beacon state starts off enabled for this version.
59 EXPECT_FALSE(blacklist::CreateBeacon()); 59 LONG result = blacklist_registry_key.WriteValue(blacklist::kBeaconState,
60 blacklist::BLACKLIST_ENABLED);
61 EXPECT_EQ(ERROR_SUCCESS, result);
60 62
61 // First call should find the beacon and delete it. 63 result = blacklist_registry_key.WriteValue(blacklist::kBeaconVersion,
62 EXPECT_TRUE(blacklist::ClearBeacon()); 64 TEXT(CHROME_VERSION_STRING));
65 EXPECT_EQ(ERROR_SUCCESS, result);
63 66
64 // Second call should fail to find the beacon and delete it. 67 // First call should find the beacon and reset it.
65 EXPECT_FALSE(blacklist::ClearBeacon()); 68 EXPECT_TRUE(blacklist::ResetBeacon());
69
70 // First call should succeed as the beacon is enabled.
71 EXPECT_TRUE(blacklist::LeaveSetupBeacon());
72
73 // Second call should fail indicating the beacon wasn't set as enabled.
74 EXPECT_FALSE(blacklist::LeaveSetupBeacon());
75
76 // Resetting the beacon should work when setup beacon is present.
77 EXPECT_TRUE(blacklist::ResetBeacon());
78
79 // Change the version and ensure that the setup fails due to the version
80 // mismatch.
81 base::string16 different_version(L"other_version");
82 ASSERT_NE(different_version, TEXT(CHROME_VERSION_STRING));
83
84 result = blacklist_registry_key.WriteValue(blacklist::kBeaconVersion,
85 different_version.c_str());
86 EXPECT_EQ(ERROR_SUCCESS, result);
87
88 EXPECT_FALSE(blacklist::LeaveSetupBeacon());
66 } 89 }
67 90
68 TEST_F(BlacklistTest, AddAndRemoveModules) { 91 TEST_F(BlacklistTest, AddAndRemoveModules) {
69 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll")); 92 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll"));
70 // Adding the same item twice should be idempotent. 93 // Adding the same item twice should be idempotent.
71 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll")); 94 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll"));
72 EXPECT_TRUE(blacklist::RemoveDllFromBlacklist(L"foo.dll")); 95 EXPECT_TRUE(blacklist::RemoveDllFromBlacklist(L"foo.dll"));
73 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(L"foo.dll")); 96 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(L"foo.dll"));
74 97
75 std::vector<base::string16> added_dlls; 98 std::vector<base::string16> added_dlls;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // Remove the DLL from the blacklist. Ensure that it loads and that its 141 // Remove the DLL from the blacklist. Ensure that it loads and that its
119 // entry point was called. 142 // entry point was called.
120 TestDll_RemoveDllFromBlacklist(test_data[i].dll_name); 143 TestDll_RemoveDllFromBlacklist(test_data[i].dll_name);
121 base::ScopedNativeLibrary dll(current_dir.Append(test_data[i].dll_name)); 144 base::ScopedNativeLibrary dll(current_dir.Append(test_data[i].dll_name));
122 EXPECT_TRUE(dll.is_valid()); 145 EXPECT_TRUE(dll.is_valid());
123 EXPECT_NE(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); 146 EXPECT_NE(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
124 dll.Reset(NULL); 147 dll.Reset(NULL);
125 } 148 }
126 #endif 149 #endif
127 } 150 }
OLDNEW
« no previous file with comments | « chrome_elf/blacklist/blacklist.cc ('k') | chrome_elf/chrome_elf.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698