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