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

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

Issue 120963002: Use a Finch Experiment to control the Browser Blacklist (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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
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"
(...skipping 20 matching lines...) Expand all
31 __declspec(dllimport) void TestDll_AddDllToBlacklist(const wchar_t* dll_name); 31 __declspec(dllimport) void TestDll_AddDllToBlacklist(const wchar_t* dll_name);
32 __declspec(dllimport) void TestDll_RemoveDllFromBlacklist( 32 __declspec(dllimport) void TestDll_RemoveDllFromBlacklist(
33 const wchar_t* dll_name); 33 const wchar_t* dll_name);
34 } 34 }
35 35
36 class BlacklistTest : public testing::Test { 36 class BlacklistTest : public testing::Test {
37 virtual void SetUp() { 37 virtual void SetUp() {
38 // Force an import from blacklist_test_main_dll. 38 // Force an import from blacklist_test_main_dll.
39 InitBlacklistTestDll(); 39 InitBlacklistTestDll();
40 40
41 // Ensure that the beacon state starts off cleared. 41 // Ensure that the beacon state starts off enabled.
42 blacklist::ClearBeacon(); 42 blacklist::ResetBeacon();
43 } 43 }
44 44
45 virtual void TearDown() { 45 virtual void TearDown() {
46 TestDll_RemoveDllFromBlacklist(kTestDllName1); 46 TestDll_RemoveDllFromBlacklist(kTestDllName1);
47 TestDll_RemoveDllFromBlacklist(kTestDllName2); 47 TestDll_RemoveDllFromBlacklist(kTestDllName2);
48 } 48 }
49 }; 49 };
50 50
51 TEST_F(BlacklistTest, Beacon) { 51 TEST_F(BlacklistTest, Beacon) {
52 registry_util::RegistryOverrideManager override_manager; 52 registry_util::RegistryOverrideManager override_manager;
53 override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"beacon_test"); 53 override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"beacon_test");
54 54
55 // First call should succeed as the beacon is newly created. 55 // First call should find the beacon and reset it.
56 EXPECT_TRUE(blacklist::CreateBeacon()); 56 EXPECT_TRUE(blacklist::ResetBeacon());
57 57
58 // Second call should fail indicating the beacon already existed. 58 // First call should succeed as the beacon is enabled.
59 EXPECT_FALSE(blacklist::CreateBeacon()); 59 EXPECT_TRUE(blacklist::LeaveSetupBeacon());
60 60
61 // First call should find the beacon and delete it. 61 // Second call should fail indicating the beacon wasn't set as enabled.
62 EXPECT_TRUE(blacklist::ClearBeacon()); 62 EXPECT_FALSE(blacklist::LeaveSetupBeacon());
63 63
64 // Second call should fail to find the beacon and delete it. 64 // Resetting the beacon should still work, even if the setup beacon
65 EXPECT_FALSE(blacklist::ClearBeacon()); 65 // is present.
66 EXPECT_TRUE(blacklist::ResetBeacon());
66 } 67 }
67 68
68 TEST_F(BlacklistTest, AddAndRemoveModules) { 69 TEST_F(BlacklistTest, AddAndRemoveModules) {
69 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll")); 70 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll"));
70 // Adding the same item twice should be idempotent. 71 // Adding the same item twice should be idempotent.
71 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll")); 72 EXPECT_TRUE(blacklist::AddDllToBlacklist(L"foo.dll"));
72 EXPECT_TRUE(blacklist::RemoveDllFromBlacklist(L"foo.dll")); 73 EXPECT_TRUE(blacklist::RemoveDllFromBlacklist(L"foo.dll"));
73 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(L"foo.dll")); 74 EXPECT_FALSE(blacklist::RemoveDllFromBlacklist(L"foo.dll"));
74 75
75 std::vector<base::string16> added_dlls; 76 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 119 // Remove the DLL from the blacklist. Ensure that it loads and that its
119 // entry point was called. 120 // entry point was called.
120 TestDll_RemoveDllFromBlacklist(test_data[i].dll_name); 121 TestDll_RemoveDllFromBlacklist(test_data[i].dll_name);
121 base::ScopedNativeLibrary dll(current_dir.Append(test_data[i].dll_name)); 122 base::ScopedNativeLibrary dll(current_dir.Append(test_data[i].dll_name));
122 EXPECT_TRUE(dll.is_valid()); 123 EXPECT_TRUE(dll.is_valid());
123 EXPECT_NE(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); 124 EXPECT_NE(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
124 dll.Reset(NULL); 125 dll.Reset(NULL);
125 } 126 }
126 #endif 127 #endif
127 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698