summaryrefslogtreecommitdiff
path: root/base/trace_event/event_name_filter_unittest.cc
blob: 134be0df33a114540e2300a7decd09cc3d120181 (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
// Copyright 2015 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 "base/trace_event/event_name_filter.h"

#include "base/memory/ptr_util.h"
#include "base/trace_event/trace_event_impl.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace trace_event {

const TraceEvent& MakeTraceEvent(const char* name) {
  static TraceEvent event;
  event.Reset();
  event.Initialize(0, TimeTicks(), ThreadTicks(), 'b', nullptr, name, "", 0, 0,
                   0, nullptr, nullptr, nullptr, nullptr, 0);
  return event;
}

TEST(TraceEventNameFilterTest, Whitelist) {
  auto empty_whitelist =
      std::make_unique<EventNameFilter::EventNamesWhitelist>();
  auto filter = std::make_unique<EventNameFilter>(std::move(empty_whitelist));

  // No events should be filtered if the whitelist is empty.
  EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("foo")));

  auto whitelist = std::make_unique<EventNameFilter::EventNamesWhitelist>();
  whitelist->insert("foo");
  whitelist->insert("bar");
  filter = std::make_unique<EventNameFilter>(std::move(whitelist));
  EXPECT_TRUE(filter->FilterTraceEvent(MakeTraceEvent("foo")));
  EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("fooz")));
  EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("afoo")));
  EXPECT_TRUE(filter->FilterTraceEvent(MakeTraceEvent("bar")));
  EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("foobar")));
}

}  // namespace trace_event
}  // namespace base