blob: 61e5c24e5bfa903c1b5212dcaab15679458b1010 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/installer/util/legacy_firewall_manager_win.h"
#include "base/path_service.h"
#include "base/process/process_info.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace installer {
class LegacyFirewallManagerTest : public ::testing::Test {
public:
LegacyFirewallManagerTest() : skip_test_(true) {}
protected:
// Sets up the test fixture.
void SetUp() override {
if (base::GetCurrentProcessIntegrityLevel() != base::HIGH_INTEGRITY) {
LOG(WARNING) << "Not elevated. Skipping the test.";
return;
};
skip_test_ = false;
base::FilePath exe_path;
PathService::Get(base::FILE_EXE, &exe_path);
EXPECT_TRUE(manager_.Init(L"LegacyFirewallManagerTest", exe_path));
manager_.DeleteRule();
}
// Tears down the test fixture.
void TearDown() override {
if (!skip_test_)
manager_.DeleteRule();
}
bool skip_test_;
LegacyFirewallManager manager_;
private:
DISALLOW_COPY_AND_ASSIGN(LegacyFirewallManagerTest);
};
TEST_F(LegacyFirewallManagerTest, NoRule) {
if (skip_test_)
return;
EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
}
TEST_F(LegacyFirewallManagerTest, AllowRule) {
if (skip_test_)
return;
EXPECT_TRUE(manager_.SetAllowIncomingConnection(true));
bool allowed = false;
EXPECT_TRUE(manager_.GetAllowIncomingConnection(&allowed));
EXPECT_TRUE(allowed);
manager_.DeleteRule();
EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
}
TEST_F(LegacyFirewallManagerTest, BlockRule) {
if (skip_test_)
return;
EXPECT_TRUE(manager_.SetAllowIncomingConnection(false));
bool allowed = true;
EXPECT_TRUE(manager_.GetAllowIncomingConnection(&allowed));
EXPECT_FALSE(allowed);
manager_.DeleteRule();
EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
}
} // namespace installer
|