ozone: drm: Fix HardwareDisplayController use-after-free
[chromium-blink-merge.git] / chrome / installer / util / advanced_firewall_manager_win_unittest.cc
blob5920ea2d3c3afc200b7f4736108d8e9d35e430ce
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/advanced_firewall_manager_win.h"
7 #include "base/path_service.h"
8 #include "base/process/process_info.h"
9 #include "base/win/scoped_bstr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace installer {
14 class AdvancedFirewallManagerTest : public ::testing::Test {
15 public:
16 AdvancedFirewallManagerTest() : skip_test_(true) {}
18 protected:
19 // Sets up the test fixture.
20 virtual void SetUp() override {
21 if (base::GetCurrentProcessIntegrityLevel() != base::HIGH_INTEGRITY) {
22 LOG(WARNING) << "XP or not elevated. Skipping the test.";
23 return;
25 skip_test_ = false;
26 base::FilePath exe_path;
27 PathService::Get(base::FILE_EXE, &exe_path);
28 EXPECT_TRUE(manager_.Init(L"AdvancedFirewallManagerTest", exe_path));
29 manager_.DeleteAllRules();
32 // Tears down the test fixture.
33 virtual void TearDown() override {
34 if (!skip_test_)
35 manager_.DeleteAllRules();
38 // Forwards calls to |manager_| to avoid making each test a friend of
39 // |AdvancedFirewallManager|.
40 void GetAllRules(std::vector<base::string16>* rule_names) {
41 std::vector<base::win::ScopedComPtr<INetFwRule> > rules;
42 manager_.GetAllRules(&rules);
43 for (size_t i = 0; i < rules.size(); ++i) {
44 base::win::ScopedBstr name;
45 EXPECT_TRUE(SUCCEEDED(rules[i]->get_Name(name.Receive())));
46 EXPECT_TRUE(name);
47 rule_names->push_back(base::string16(name));
51 bool skip_test_;
52 AdvancedFirewallManager manager_;
54 private:
55 DISALLOW_COPY_AND_ASSIGN(AdvancedFirewallManagerTest);
58 TEST_F(AdvancedFirewallManagerTest, NoRule) {
59 if (skip_test_)
60 return;
61 std::vector<base::string16> rule_names;
62 GetAllRules(&rule_names);
63 EXPECT_TRUE(rule_names.empty());
66 TEST_F(AdvancedFirewallManagerTest, AddRule) {
67 if (skip_test_)
68 return;
69 const wchar_t kRuleName[] = L"Port56789";
70 EXPECT_TRUE(manager_.AddUDPRule(kRuleName, L"Test Description", 56789));
72 std::vector<base::string16> rule_names;
73 GetAllRules(&rule_names);
74 ASSERT_EQ(1u, rule_names.size());
75 EXPECT_EQ(rule_names[0], kRuleName);
76 EXPECT_TRUE(manager_.HasAnyRule());
78 manager_.DeleteRuleByName(kRuleName);
79 rule_names.clear();
80 GetAllRules(&rule_names);
81 EXPECT_TRUE(rule_names.empty());
82 EXPECT_FALSE(manager_.HasAnyRule());
85 } // namespace installer