Roll src/third_party/WebKit 116cf7f:79abaa8 (svn 189234:189235)
[chromium-blink-merge.git] / chrome / installer / util / legacy_firewall_manager_win_unittest.cc
blob26df3b889bb28d0f483df1fe4e3eca68a757c4e9
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"
11 namespace installer {
13 class LegacyFirewallManagerTest : public ::testing::Test {
14 public:
15 LegacyFirewallManagerTest() : skip_test_(true) {}
17 protected:
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.";
24 return;
26 skip_test_ = false;
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 {
35 if (!skip_test_)
36 manager_.DeleteRule();
39 bool skip_test_;
40 LegacyFirewallManager manager_;
42 private:
43 DISALLOW_COPY_AND_ASSIGN(LegacyFirewallManagerTest);
46 TEST_F(LegacyFirewallManagerTest, NoRule) {
47 if (skip_test_)
48 return;
49 EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
52 TEST_F(LegacyFirewallManagerTest, AllowRule) {
53 if (skip_test_)
54 return;
55 EXPECT_TRUE(manager_.SetAllowIncomingConnection(true));
56 bool allowed = false;
57 EXPECT_TRUE(manager_.GetAllowIncomingConnection(&allowed));
58 EXPECT_TRUE(allowed);
59 manager_.DeleteRule();
60 EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
63 TEST_F(LegacyFirewallManagerTest, BlockRule) {
64 if (skip_test_)
65 return;
66 EXPECT_TRUE(manager_.SetAllowIncomingConnection(false));
67 bool allowed = true;
68 EXPECT_TRUE(manager_.GetAllowIncomingConnection(&allowed));
69 EXPECT_FALSE(allowed);
70 manager_.DeleteRule();
71 EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
74 } // namespace installer