Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / installer / util / legacy_firewall_manager_win_unittest.cc
blob61e5c24e5bfa903c1b5212dcaab15679458b1010
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_info.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 void SetUp() override {
20 if (base::GetCurrentProcessIntegrityLevel() != base::HIGH_INTEGRITY) {
21 LOG(WARNING) << "Not elevated. Skipping the test.";
22 return;
24 skip_test_ = false;
25 base::FilePath exe_path;
26 PathService::Get(base::FILE_EXE, &exe_path);
27 EXPECT_TRUE(manager_.Init(L"LegacyFirewallManagerTest", exe_path));
28 manager_.DeleteRule();
31 // Tears down the test fixture.
32 void TearDown() override {
33 if (!skip_test_)
34 manager_.DeleteRule();
37 bool skip_test_;
38 LegacyFirewallManager manager_;
40 private:
41 DISALLOW_COPY_AND_ASSIGN(LegacyFirewallManagerTest);
44 TEST_F(LegacyFirewallManagerTest, NoRule) {
45 if (skip_test_)
46 return;
47 EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
50 TEST_F(LegacyFirewallManagerTest, AllowRule) {
51 if (skip_test_)
52 return;
53 EXPECT_TRUE(manager_.SetAllowIncomingConnection(true));
54 bool allowed = false;
55 EXPECT_TRUE(manager_.GetAllowIncomingConnection(&allowed));
56 EXPECT_TRUE(allowed);
57 manager_.DeleteRule();
58 EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
61 TEST_F(LegacyFirewallManagerTest, BlockRule) {
62 if (skip_test_)
63 return;
64 EXPECT_TRUE(manager_.SetAllowIncomingConnection(false));
65 bool allowed = true;
66 EXPECT_TRUE(manager_.GetAllowIncomingConnection(&allowed));
67 EXPECT_FALSE(allowed);
68 manager_.DeleteRule();
69 EXPECT_FALSE(manager_.GetAllowIncomingConnection(NULL));
72 } // namespace installer