event_name_filter_unittest.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2015 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.
  4. #include "base/trace_event/event_name_filter.h"
  5. #include "base/memory/ptr_util.h"
  6. #include "base/trace_event/trace_event_impl.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace base {
  9. namespace trace_event {
  10. const TraceEvent& MakeTraceEvent(const char* name) {
  11. static TraceEvent event;
  12. event.Reset(0, TimeTicks(), ThreadTicks(), 'b', nullptr, name, "", 0, 0,
  13. nullptr, 0);
  14. return event;
  15. }
  16. TEST(TraceEventNameFilterTest, Allowlist) {
  17. auto empty_allowlist =
  18. std::make_unique<EventNameFilter::EventNamesAllowlist>();
  19. auto filter = std::make_unique<EventNameFilter>(std::move(empty_allowlist));
  20. // No events should be filtered if the allowlist is empty.
  21. EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("foo")));
  22. auto allowlist = std::make_unique<EventNameFilter::EventNamesAllowlist>();
  23. allowlist->insert("foo");
  24. allowlist->insert("bar");
  25. filter = std::make_unique<EventNameFilter>(std::move(allowlist));
  26. EXPECT_TRUE(filter->FilterTraceEvent(MakeTraceEvent("foo")));
  27. EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("fooz")));
  28. EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("afoo")));
  29. EXPECT_TRUE(filter->FilterTraceEvent(MakeTraceEvent("bar")));
  30. EXPECT_FALSE(filter->FilterTraceEvent(MakeTraceEvent("foobar")));
  31. }
  32. } // namespace trace_event
  33. } // namespace base