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
3 // found in the LICENSE file.
5 #include "chrome/installer/util/legacy_firewall_manager_win.h"
7 #include "base/path_service.h"
8 #include "base/process/process_handle.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 class LegacyFirewallManagerTest
: public ::testing::Test
{
15 LegacyFirewallManagerTest() : skip_test_(true) {}
18 // Sets up the test fixture.
19 virtual void SetUp() override
{
20 base::IntegrityLevel level
= base::INTEGRITY_UNKNOWN
;
21 if (GetProcessIntegrityLevel(base::GetCurrentProcessHandle(), &level
) &&
22 level
!= base::HIGH_INTEGRITY
) {
23 LOG(WARNING
) << "Not elevated. Skipping the test.";
27 base::FilePath exe_path
;
28 PathService::Get(base::FILE_EXE
, &exe_path
);
29 EXPECT_TRUE(manager_
.Init(L
"LegacyFirewallManagerTest", exe_path
));
30 manager_
.DeleteRule();
33 // Tears down the test fixture.
34 virtual void TearDown() override
{
36 manager_
.DeleteRule();
40 LegacyFirewallManager manager_
;
43 DISALLOW_COPY_AND_ASSIGN(LegacyFirewallManagerTest
);
46 TEST_F(LegacyFirewallManagerTest
, NoRule
) {
49 EXPECT_FALSE(manager_
.GetAllowIncomingConnection(NULL
));
52 TEST_F(LegacyFirewallManagerTest
, AllowRule
) {
55 EXPECT_TRUE(manager_
.SetAllowIncomingConnection(true));
57 EXPECT_TRUE(manager_
.GetAllowIncomingConnection(&allowed
));
59 manager_
.DeleteRule();
60 EXPECT_FALSE(manager_
.GetAllowIncomingConnection(NULL
));
63 TEST_F(LegacyFirewallManagerTest
, BlockRule
) {
66 EXPECT_TRUE(manager_
.SetAllowIncomingConnection(false));
68 EXPECT_TRUE(manager_
.GetAllowIncomingConnection(&allowed
));
69 EXPECT_FALSE(allowed
);
70 manager_
.DeleteRule();
71 EXPECT_FALSE(manager_
.GetAllowIncomingConnection(NULL
));
74 } // namespace installer